You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/06/09 15:30:19 UTC
svn commit: r664700 [2/3] - in /poi/branches/ooxml: ./
src/documentation/content/xdocs/ src/java/org/apache/poi/ddf/
src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/
src/java/org/apache/poi/hssf/record/formula/ src/java/org/apac...
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java Mon Jun 9 06:30:17 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -18,70 +17,36 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Ptg class to implement not equal
*
* @author fred at stsci dot edu
*/
public final class NotEqualPtg extends ValueOperatorPtg {
- public final static int SIZE = 1;
public final static byte sid = 0x0e;
- /**
- * Creates new NotEqualPtg
- */
- public NotEqualPtg()
- {
- }
-
- public NotEqualPtg( RecordInputStream in )
- {
- // doesn't need anything
- }
-
- public void writeBytes( byte[] array, int offset )
- {
- array[offset + 0] = sid;
- }
+ public static final ValueOperatorPtg instance = new NotEqualPtg();
- public int getSize()
- {
- return SIZE;
+ private NotEqualPtg() {
+ // enforce singleton
}
-
- public int getType()
- {
- return TYPE_BINARY;
+
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
- public String toFormulaString( Workbook book )
- {
- return "<>";
- }
-
- public String toFormulaString( String[] operands )
- {
+ public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
buffer.append( operands[0] );
- buffer.append( toFormulaString( (Workbook) null ) );
+ buffer.append("<>");
buffer.append( operands[1] );
return buffer.toString();
}
-
- public Object clone()
- {
- return new NotEqualPtg();
- }
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java Mon Jun 9 06:30:17 2008
@@ -31,16 +31,12 @@
public final class NumberPtg extends ScalarConstantPtg {
public final static int SIZE = 9;
public final static byte sid = 0x1f;
- private double field_1_value;
-
- private NumberPtg() {
- //Required for clone methods
- }
+ private final double field_1_value;
/** Create a NumberPtg from a byte array read from disk */
public NumberPtg(RecordInputStream in)
{
- setValue(in.readDouble());
+ field_1_value = in.readDouble();
}
/** Create a NumberPtg from a string representation of the number
@@ -49,13 +45,7 @@
* @param value : String representation of a floating point number
*/
public NumberPtg(String value) {
- setValue(Double.parseDouble(value));
- }
-
-
- public void setValue(double value)
- {
- field_1_value = value;
+ field_1_value = Double.parseDouble(value);
}
@@ -79,10 +69,4 @@
{
return "" + getValue();
}
-
- public Object clone() {
- NumberPtg ptg = new NumberPtg();
- ptg.field_1_value = field_1_value;
- return ptg;
- }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/OperationPtg.java Mon Jun 9 06:30:17 2008
@@ -17,21 +17,15 @@
package org.apache.poi.hssf.record.formula;
-
-
/**
* defines a Ptg that is an operation instead of an operand
* @author andy
*/
-
-public abstract class OperationPtg extends Ptg
-{
+public abstract class OperationPtg extends Ptg {
public final static int TYPE_UNARY = 0;
public final static int TYPE_BINARY = 1;
public final static int TYPE_FUNCTION = 2;
- public abstract int getType();
-
/**
* returns a string representation of the operations
* the length of the input array should equal the number returned by
@@ -45,6 +39,12 @@
*/
public abstract int getNumberOfOperands();
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_VALUE;
+ }
+ public final int getType() {
+ // TODO remove "int getType();" from Eval hierarchy
+ throw new RuntimeException("remove this method");
+ }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java Mon Jun 9 06:30:17 2008
@@ -37,18 +37,11 @@
private final static int SIZE = 1;
public final static byte sid = 0x15;
- public ParenthesisPtg()
- {
- }
-
- public ParenthesisPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ public static final ControlPtg instance = new ParenthesisPtg();
+ private ParenthesisPtg() {
+ // enforce singleton
}
-
-
public void writeBytes(byte [] array, int offset)
{
array[ offset + 0 ] = sid;
@@ -68,9 +61,4 @@
public String toFormulaString(String[] operands) {
return "("+operands[0]+")";
}
-
- public Object clone() {
- return new ParenthesisPtg();
- }
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PercentPtg.java Mon Jun 9 06:30:17 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -16,68 +15,33 @@
limitations under the License.
==================================================================== */
-/*
- * PercentPtg.java
- *
- * Created on March 29, 2006, 9:23 PM
- */
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Percent PTG.
*
* @author Daniel Noll (daniel at nuix.com.au)
*/
-
public final class PercentPtg extends ValueOperatorPtg {
public final static int SIZE = 1;
public final static byte sid = 0x14;
private final static String PERCENT = "%";
- /** Creates new PercentPtg */
+ public static final ValueOperatorPtg instance = new PercentPtg();
- public PercentPtg()
- {
- }
-
- public PercentPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ private PercentPtg() {
+ // enforce singleton
}
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
+ protected byte getSid() {
+ return sid;
}
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return TYPE_UNARY;
- }
-
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 1;
}
-
- /** Implementation of method from Ptg */
- public String toFormulaString(Workbook book)
- {
- return "%";
- }
- /** implementation of method from OperationsPtg*/
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -85,9 +49,4 @@
buffer.append(PERCENT);
return buffer.toString();
}
-
- public Object clone() {
- return new PercentPtg();
- }
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/PowerPtg.java Mon Jun 9 06:30:17 2008
@@ -17,53 +17,26 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
*
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
public final class PowerPtg extends ValueOperatorPtg {
- public final static int SIZE = 1;
public final static byte sid = 0x07;
- /** Creates new AddPtg */
-
- public PowerPtg()
- {
- }
-
- public PowerPtg(RecordInputStream in)
- {
-
- // doesn't need anything
- }
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- public int getSize()
- {
- return SIZE;
- }
+ public static final ValueOperatorPtg instance = new PowerPtg();
- public int getType()
- {
- return TYPE_BINARY;
+ private PowerPtg() {
+ // enforce singleton
}
-
- public int getNumberOfOperands()
- {
- return 2;
+
+ protected byte getSid() {
+ return sid;
}
- public String toFormulaString(Workbook book)
- {
- return "^";
+ public int getNumberOfOperands() {
+ return 2; // TODO - 2 seems wrong (Jun 2008). Maybe this method is not relevant
}
public String toFormulaString(String[] operands) {
@@ -71,13 +44,8 @@
buffer.append(operands[ 0 ]);
- buffer.append(toFormulaString((Workbook)null));
+ buffer.append("^");
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- public Object clone() {
- return new PowerPtg();
- }
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ptg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ptg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ptg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ptg.java Mon Jun 9 06:30:17 2008
@@ -17,226 +17,243 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import java.util.Stack;
-import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.ss.usermodel.Workbook;
/**
+ * <tt>Ptg</tt> represents a syntactic token in a formula. 'PTG' is an acronym for
+ * '<b>p</b>arse <b>t</b>hin<b>g</b>'. Originally, the name referred to the single
+ * byte identifier at the start of the token, but in POI, <tt>Ptg</tt> encapsulates
+ * the whole formula token (initial byte + value data).
+ * <p/>
+ *
+ * <tt>Ptg</tt>s are logically arranged in a tree representing the structure of the
+ * parsed formula. However, in BIFF files <tt>Ptg</tt>s are written/read in
+ * <em>Reverse-Polish Notation</em> order. The RPN ordering also simplifies formula
+ * evaluation logic, so POI mostly accesses <tt>Ptg</tt>s in the same way.
*
* @author andy
* @author avik
* @author Jason Height (jheight at chariot dot net dot au)
*/
-public abstract class Ptg
-{
+public abstract class Ptg implements Cloneable {
+ /* convert infix order ptg list to rpn order ptg list
+ * @return List ptgs in RPN order
+ * @param infixPtgs List of ptgs in infix order
+ */
+
+ /* DO NOT REMOVE
+ *we keep this method in case we wish to change the way we parse
+ *It needs a getPrecedence in OperationsPtg
+
+ public static List ptgsToRpn(List infixPtgs) {
+ java.util.Stack operands = new java.util.Stack();
+ java.util.List retval = new java.util.Stack();
+
+ java.util.ListIterator i = infixPtgs.listIterator();
+ Object p;
+ OperationPtg o ;
+ boolean weHaveABracket = false;
+ while (i.hasNext()) {
+ p=i.next();
+ if (p instanceof OperationPtg) {
+ if (p instanceof ParenthesisPtg) {
+ if (!weHaveABracket) {
+ operands.push(p);
+ weHaveABracket = true;
+ } else {
+ o = (OperationPtg) operands.pop();
+ while (!(o instanceof ParenthesisPtg)) {
+ retval.add(o);
+ }
+ weHaveABracket = false;
+ }
+ } else {
+
+ while (!operands.isEmpty() && ((OperationPtg) operands.peek()).getPrecedence() >= ((OperationPtg) p).getPrecedence() ) { //TODO handle ^ since it is right associative
+ retval.add(operands.pop());
+ }
+ operands.push(p);
+ }
+ } else {
+ retval.add(p);
+ }
+ }
+ while (!operands.isEmpty()) {
+ if (operands.peek() instanceof ParenthesisPtg ){
+ //throw some error
+ } else {
+ retval.add(operands.pop());
+ }
+ }
+ return retval;
+ }
+ */
+
+ /**
+ * Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
+ * Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
+ */
+ public static Ptg[] readTokens(int size, RecordInputStream in) {
+ Stack temp = createParsedExpressionTokens((short)size, in);
+ return toPtgArray(temp);
+ }
+
+ /**
+ * @deprecated - use readTokens()
+ */
+ public static Stack createParsedExpressionTokens(short size, RecordInputStream in)
+ {
+ Stack stack = new Stack();
+ int pos = 0;
+ List arrayPtgs = null;
+ while ( pos < size )
+ {
+ Ptg ptg = Ptg.createPtg( in );
+ if (ptg instanceof ArrayPtg) {
+ if (arrayPtgs == null)
+ arrayPtgs = new ArrayList(5);
+ arrayPtgs.add(ptg);
+ pos += 8;
+ } else pos += ptg.getSize();
+ stack.push( ptg );
+ }
+ if(pos != size) {
+ throw new RuntimeException("Ptg array size mismatch");
+ }
+ if (arrayPtgs != null) {
+ for (int i=0;i<arrayPtgs.size();i++) {
+ ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
+ p.readTokenValues(in);
+ }
+ }
+ return stack;
+ }
- /* convert infix order ptg list to rpn order ptg list
- * @return List ptgs in RPN order
- * @param infixPtgs List of ptgs in infix order
- */
-
- /* DO NOT REMOVE
- *we keep this method in case we wish to change the way we parse
- *It needs a getPrecedence in OperationsPtg
-
- public static List ptgsToRpn(List infixPtgs) {
- java.util.Stack operands = new java.util.Stack();
- java.util.List retval = new java.util.Stack();
-
- java.util.ListIterator i = infixPtgs.listIterator();
- Object p;
- OperationPtg o ;
- boolean weHaveABracket = false;
- while (i.hasNext()) {
- p=i.next();
- if (p instanceof OperationPtg) {
- if (p instanceof ParenthesisPtg) {
- if (!weHaveABracket) {
- operands.push(p);
- weHaveABracket = true;
- } else {
- o = (OperationPtg) operands.pop();
- while (!(o instanceof ParenthesisPtg)) {
- retval.add(o);
- }
- weHaveABracket = false;
- }
- } else {
-
- while (!operands.isEmpty() && ((OperationPtg) operands.peek()).getPrecedence() >= ((OperationPtg) p).getPrecedence() ) { //TODO handle ^ since it is right associative
- retval.add(operands.pop());
- }
- operands.push(p);
- }
- } else {
- retval.add(p);
- }
- }
- while (!operands.isEmpty()) {
- if (operands.peek() instanceof ParenthesisPtg ){
- //throw some error
- } else {
- retval.add(operands.pop());
- }
- }
- return retval;
- }
- */
-
- /**
- * Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
- * Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
- */
- public static Stack createParsedExpressionTokens(short size, RecordInputStream in )
- {
- Stack stack = new Stack();
- int pos = 0;
- List arrayPtgs = null;
- while ( pos < size )
- {
- Ptg ptg = Ptg.createPtg( in );
- if (ptg instanceof ArrayPtg) {
- if (arrayPtgs == null)
- arrayPtgs = new ArrayList(5);
- arrayPtgs.add(ptg);
- pos += 8;
- } else pos += ptg.getSize();
- stack.push( ptg );
- }
- if(pos != size) {
- throw new RuntimeException("Ptg array size mismatch");
- }
- if (arrayPtgs != null) {
- for (int i=0;i<arrayPtgs.size();i++) {
- ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
- p.readTokenValues(in);
- }
- }
- return stack;
- }
-
- public static Ptg createPtg(RecordInputStream in) {
- byte id = in.readByte();
-
- if (id < 0x20) {
- return createBasePtg(id, in);
- }
-
- Ptg retval = createClassifiedPtg(id, in);
-
- if (id > 0x60) {
- retval.setClass(CLASS_ARRAY);
- } else if (id > 0x40) {
- retval.setClass(CLASS_VALUE);
- } else {
- retval.setClass(CLASS_REF);
- }
+ public static Ptg createPtg(RecordInputStream in) {
+ byte id = in.readByte();
+
+ if (id < 0x20) {
+ return createBasePtg(id, in);
+ }
+
+ Ptg retval = createClassifiedPtg(id, in);
- return retval;
+ if (id > 0x60) {
+ retval.setClass(CLASS_ARRAY);
+ } else if (id > 0x40) {
+ retval.setClass(CLASS_VALUE);
+ } else {
+ retval.setClass(CLASS_REF);
+ }
- }
+ return retval;
+ }
private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
int baseId = id & 0x1F | 0x20;
- switch (baseId) {
- case FuncPtg.sid: return new FuncPtg(in); // 0x21, 0x41, 0x61
- case FuncVarPtg.sid: return new FuncVarPtg(in); // 0x22, 0x42, 0x62
- case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
-
- case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
- case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
- case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
- case RefErrorPtg.sid: return new RefErrorPtg(in);// 0x2a, 0x4a, 0x6a
- case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
-
- case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
- case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
- case Area3DPtg.sid: return new Area3DPtg(in); // 0x3b, 0x5b, 0x7b
- case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
- case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
- }
-
-
- switch (id) {
- // TODO - why are specific subclasses needed for these Ptgs?
- case ArrayPtg.sid: return new ArrayPtg(in); // 0x20
- case ArrayPtgV.sid: return new ArrayPtgV(in); // 0x40
- case ArrayPtgA.sid: return new ArrayPtgA(in); // 0x60
-
- case ReferencePtg.sid: return new ReferencePtg(in);// 0x24
- case RefAPtg.sid: return new RefAPtg(in); // 0x64
- case RefVPtg.sid: return new RefVPtg(in); // 0x44
-
- case RefNAPtg.sid: return new RefNAPtg(in); // 0x6C
- case RefNPtg.sid: return new RefNPtg(in); // 0x2C
- case RefNVPtg.sid: return new RefNVPtg(in); // 0x4C
-
- case AreaPtg.sid: return new AreaPtg(in); // 0x25
- case AreaVPtg.sid: return new AreaVPtg(in); // 0x45
- case AreaAPtg.sid: return new AreaAPtg(in); // 0x65
-
- case AreaNAPtg.sid: return new AreaNAPtg(in); // 0x6D
- case AreaNPtg.sid: return new AreaNPtg(in); // 0x2D
- case AreaNVPtg.sid: return new AreaNVPtg(in); // 0x4D
-
- }
- throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
- Integer.toHexString(id) + " (" + ( int ) id + ")");
+ switch (baseId) {
+ case ArrayPtg.sid: return new ArrayPtg(in); // 0x20, 0x40, 0x60
+ case FuncPtg.sid: return new FuncPtg(in); // 0x21, 0x41, 0x61
+ case FuncVarPtg.sid: return new FuncVarPtg(in); // 0x22, 0x42, 0x62
+ case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
+ case RefPtg.sid: return new RefPtg(in); // 0x24, 0x44, 0x64
+ case AreaPtg.sid: return new AreaPtg(in); // 0x25, 0x45, 0x65
+ case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
+ case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
+ case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
+ case RefErrorPtg.sid: return new RefErrorPtg(in);// 0x2a, 0x4a, 0x6a
+ case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
+ case RefNPtg.sid: return new RefNPtg(in); // 0x2c, 0x4c, 0x6c
+ case AreaNPtg.sid: return new AreaNPtg(in); // 0x2d, 0x4d, 0x6d
+
+ case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
+ case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
+ case Area3DPtg.sid: return new Area3DPtg(in); // 0x3b, 0x5b, 0x7b
+ case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
+ case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
+ }
+ throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
+ Integer.toHexString(id) + " (" + ( int ) id + ")");
}
private static Ptg createBasePtg(byte id, RecordInputStream in) {
switch(id) {
- case 0x00: return new UnknownPtg(); // TODO - not a real Ptg
- case ExpPtg.sid: return new ExpPtg(in); // 0x01
- case AddPtg.sid: return new AddPtg(in); // 0x03
- case SubtractPtg.sid: return new SubtractPtg(in); // 0x04
- case MultiplyPtg.sid: return new MultiplyPtg(in); // 0x05
- case DividePtg.sid: return new DividePtg(in); // 0x06
- case PowerPtg.sid: return new PowerPtg(in); // 0x07
- case ConcatPtg.sid: return new ConcatPtg(in); // 0x08
- case LessThanPtg.sid: return new LessThanPtg(in); // 0x09
- case LessEqualPtg.sid: return new LessEqualPtg(in); // 0x0a
- case EqualPtg.sid: return new EqualPtg(in); // 0x0b
- case GreaterEqualPtg.sid: return new GreaterEqualPtg(in);// 0x0c
- case GreaterThanPtg.sid: return new GreaterThanPtg(in); // 0x0d
- case NotEqualPtg.sid: return new NotEqualPtg(in); // 0x0e
- case IntersectionPtg.sid: return new IntersectionPtg(in);// 0x0f
- case UnionPtg.sid: return new UnionPtg(in); // 0x10
- case RangePtg.sid: return new RangePtg(in); // 0x11
- case UnaryPlusPtg.sid: return new UnaryPlusPtg(in); // 0x12
- case UnaryMinusPtg.sid: return new UnaryMinusPtg(in); // 0x13
- case PercentPtg.sid: return new PercentPtg(in); // 0x14
- case ParenthesisPtg.sid: return new ParenthesisPtg(in); // 0x15
- case MissingArgPtg.sid: return new MissingArgPtg(in); // 0x16
- case StringPtg.sid: return new StringPtg(in); // 0x17
- case AttrPtg.sid:
- case 0x1a: return new AttrPtg(in); // 0x19
- case ErrPtg.sid: return new ErrPtg(in); // 0x1c
- case BoolPtg.sid: return new BoolPtg(in); // 0x1d
- case IntPtg.sid: return new IntPtg(in); // 0x1e
- case NumberPtg.sid: return new NumberPtg(in); // 0x1f
+ case 0x00: return new UnknownPtg(); // TODO - not a real Ptg
+ case ExpPtg.sid: return new ExpPtg(in); // 0x01
+ case AddPtg.sid: return AddPtg.instance; // 0x03
+ case SubtractPtg.sid: return SubtractPtg.instance; // 0x04
+ case MultiplyPtg.sid: return MultiplyPtg.instance; // 0x05
+ case DividePtg.sid: return DividePtg.instance; // 0x06
+ case PowerPtg.sid: return PowerPtg.instance; // 0x07
+ case ConcatPtg.sid: return ConcatPtg.instance; // 0x08
+ case LessThanPtg.sid: return LessThanPtg.instance; // 0x09
+ case LessEqualPtg.sid: return LessEqualPtg.instance; // 0x0a
+ case EqualPtg.sid: return EqualPtg.instance; // 0x0b
+ case GreaterEqualPtg.sid: return GreaterEqualPtg.instance;// 0x0c
+ case GreaterThanPtg.sid: return GreaterThanPtg.instance; // 0x0d
+ case NotEqualPtg.sid: return NotEqualPtg.instance; // 0x0e
+ case IntersectionPtg.sid: return IntersectionPtg.instance;// 0x0f
+ case UnionPtg.sid: return UnionPtg.instance; // 0x10
+ case RangePtg.sid: return RangePtg.instance; // 0x11
+ case UnaryPlusPtg.sid: return UnaryPlusPtg.instance; // 0x12
+ case UnaryMinusPtg.sid: return UnaryMinusPtg.instance; // 0x13
+ case PercentPtg.sid: return PercentPtg.instance; // 0x14
+ case ParenthesisPtg.sid: return ParenthesisPtg.instance; // 0x15
+ case MissingArgPtg.sid: return MissingArgPtg.instance; // 0x16
+
+ case StringPtg.sid: return new StringPtg(in); // 0x17
+ case AttrPtg.sid:
+ case 0x1a: return new AttrPtg(in); // 0x19
+ case ErrPtg.sid: return new ErrPtg(in); // 0x1c
+ case BoolPtg.sid: return new BoolPtg(in); // 0x1d
+ case IntPtg.sid: return new IntPtg(in); // 0x1e
+ case NumberPtg.sid: return new NumberPtg(in); // 0x1f
}
throw new RuntimeException("Unexpected base token id (" + id + ")");
}
- /**
- *
- *
- */
+ /**
+ *
+ *
+ */
public static int getEncodedSize(Stack ptgs) {
return getEncodedSize(toPtgArray(ptgs));
}
+ /**
+ * @return a distinct copy of this <tt>Ptg</tt> if the class is mutable, or the same instance
+ * if the class is immutable.
+ */
+ public final Ptg copy() {
+ // TODO - all base tokens are logically immutable, but AttrPtg needs some clean-up
+ if (this instanceof ValueOperatorPtg) {
+ return this;
+ }
+ if (this instanceof ScalarConstantPtg) {
+ return this;
+ }
+ return (Ptg) clone();
+ }
+
+ protected Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ }
private static Ptg[] toPtgArray(List l) {
Ptg[] result = new Ptg[l.size()];
l.toArray(result);
return result;
}
- private static Stack createStack(Ptg[] formulaTokens) {
+ private static Stack createStack(Ptg[] formulaTokens) {
Stack result = new Stack();
for (int i = 0; i < formulaTokens.length; i++) {
result.add(formulaTokens[i]);
@@ -251,110 +268,120 @@
}
return result;
}
+ /**
+ * Writes the ptgs to the data buffer, starting at the specified offset.
+ *
+ * <br/>
+ * The 2 byte encode length field is <b>not</b> written by this method.
+ * @return number of bytes written
+ */
+ public static int serializePtgs(Ptg[] ptgs, byte[] data, int offset) {
+ return serializePtgStack(createStack(ptgs), data, offset);
+ }
- public static int serializePtgStack(Stack expression, byte[] array, int offset) {
- int pos = 0;
- int size = 0;
- if (expression != null)
- size = expression.size();
-
- List arrayPtgs = null;
-
- for (int k = 0; k < size; k++) {
- Ptg ptg = ( Ptg ) expression.get(k);
-
- ptg.writeBytes(array, pos + offset);
- if (ptg instanceof ArrayPtg) {
- if (arrayPtgs == null)
- arrayPtgs = new ArrayList(5);
- arrayPtgs.add(ptg);
- pos += 8;
- } else pos += ptg.getSize();
- }
- if (arrayPtgs != null) {
- for (int i=0;i<arrayPtgs.size();i++) {
- ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
- pos += p.writeTokenValueBytes(array, pos + offset);
- }
- }
- return pos;
- }
-
- /**
- * @return the encoded length of this Ptg, including the initial Ptg type identifier byte.
- */
- public abstract int getSize();
-
- /**
- * @return the encoded length of this Ptg, not including the initial Ptg type identifier byte.
- */
+ /**
+ * @deprecated use serializePtgs()
+ */
+ public static int serializePtgStack(Stack expression, byte[] array, int offset) {
+ int pos = 0;
+ int size = 0;
+ if (expression != null)
+ size = expression.size();
+
+ List arrayPtgs = null;
+
+ for (int k = 0; k < size; k++) {
+ Ptg ptg = ( Ptg ) expression.get(k);
+
+ ptg.writeBytes(array, pos + offset);
+ if (ptg instanceof ArrayPtg) {
+ if (arrayPtgs == null)
+ arrayPtgs = new ArrayList(5);
+ arrayPtgs.add(ptg);
+ pos += 8;
+ } else pos += ptg.getSize();
+ }
+ if (arrayPtgs != null) {
+ for (int i=0;i<arrayPtgs.size();i++) {
+ ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
+ pos += p.writeTokenValueBytes(array, pos + offset);
+ }
+ }
+ return pos;
+ }
+
+ /**
+ * @return the encoded length of this Ptg, including the initial Ptg type identifier byte.
+ */
+ public abstract int getSize();
+
+ /**
+ * @return the encoded length of this Ptg, not including the initial Ptg type identifier byte.
+ */
// public abstract int getDataSize();
- public final byte [] getBytes()
- {
- int size = getSize();
- byte[] bytes = new byte[ size ];
-
- writeBytes(bytes, 0);
- return bytes;
- }
- /** write this Ptg to a byte array*/
- public abstract void writeBytes(byte [] array, int offset);
-
- /**
- * return a string representation of this token alone
- */
- public abstract String toFormulaString(Workbook book);
- /**
- * dump a debug representation (hexdump) to a string
- */
- public String toDebugString() {
- byte[] ba = new byte[getSize()];
- String retval=null;
- writeBytes(ba,0);
- try {
- retval = org.apache.poi.util.HexDump.dump(ba,0,0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return retval;
- }
-
- /** Overridden toString method to ensure object hash is not printed.
- * This helps get rid of gratuitous diffs when comparing two dumps
- * Subclasses may output more relevant information by overriding this method
- **/
- public String toString(){
- return this.getClass().toString();
- }
-
- public static final byte CLASS_REF = 0x00;
- public static final byte CLASS_VALUE = 0x20;
- public static final byte CLASS_ARRAY = 0x40;
-
- protected byte ptgClass = CLASS_REF; //base ptg
-
- public void setClass(byte thePtgClass) {
- if (isBaseToken()) {
- throw new RuntimeException("setClass should not be called on a base token");
- }
- ptgClass = thePtgClass;
- }
-
- /**
- * @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
- */
- public byte getPtgClass() {
- return ptgClass;
- }
-
- public abstract byte getDefaultOperandClass();
-
- public abstract Object clone();
-
-
- /**
- * @return <code>false</code> if this token is classified as 'reference', 'value', or 'array'
- */
- public abstract boolean isBaseToken();
+ public final byte [] getBytes()
+ {
+ int size = getSize();
+ byte[] bytes = new byte[ size ];
+
+ writeBytes(bytes, 0);
+ return bytes;
+ }
+ /** write this Ptg to a byte array*/
+ public abstract void writeBytes(byte [] array, int offset);
+
+ /**
+ * return a string representation of this token alone
+ */
+ public abstract String toFormulaString(Workbook book);
+ /**
+ * dump a debug representation (hexdump) to a string
+ */
+ public final String toDebugString() {
+ byte[] ba = new byte[getSize()];
+ String retval=null;
+ writeBytes(ba,0);
+ try {
+ retval = org.apache.poi.util.HexDump.dump(ba,0,0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return retval;
+ }
+
+ /** Overridden toString method to ensure object hash is not printed.
+ * This helps get rid of gratuitous diffs when comparing two dumps
+ * Subclasses may output more relevant information by overriding this method
+ **/
+ public String toString(){
+ return this.getClass().toString();
+ }
+
+ public static final byte CLASS_REF = 0x00;
+ public static final byte CLASS_VALUE = 0x20;
+ public static final byte CLASS_ARRAY = 0x40;
+
+ private byte ptgClass = CLASS_REF; //base ptg
+
+ public final void setClass(byte thePtgClass) {
+ if (isBaseToken()) {
+ throw new RuntimeException("setClass should not be called on a base token");
+ }
+ ptgClass = thePtgClass;
+ }
+
+ /**
+ * @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
+ */
+ public final byte getPtgClass() {
+ return ptgClass;
+ }
+
+ public abstract byte getDefaultOperandClass();
+
+ /**
+ * @return <code>false</code> if this token is classified as 'reference', 'value', or 'array'
+ */
+ public abstract boolean isBaseToken();
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RangePtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RangePtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RangePtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RangePtg.java Mon Jun 9 06:30:17 2008
@@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
* @author Daniel Noll (daniel at nuix dot com dot au)
@@ -27,20 +26,16 @@
public final static int SIZE = 1;
public final static byte sid = 0x11;
- public RangePtg()
- {
- }
+ public static final OperationPtg instance = new RangePtg();
- public RangePtg(RecordInputStream in)
- {
- // No contents
+ private RangePtg() {
+ // enforce singleton
}
public final boolean isBaseToken() {
return true;
}
-
public int getSize()
{
return SIZE;
@@ -51,17 +46,6 @@
array[ offset + 0 ] = sid;
}
- public Object clone()
- {
- return new RangePtg();
- }
-
- public int getType()
- {
- return TYPE_BINARY;
- }
-
- /** Implementation of method from Ptg */
public String toFormulaString(Workbook book)
{
return ":";
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java Mon Jun 9 06:30:17 2008
@@ -82,7 +82,7 @@
}
public void writeBytes(byte [] array, int offset) {
- array[ 0 + offset ] = (byte) (sid + ptgClass);
+ array[ 0 + offset ] = (byte) (sid + getPtgClass());
LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
LittleEndian.putShort(array, 3 + offset , (short)getRow());
LittleEndian.putShort(array, 5 + offset , (short)getColumnRaw());
@@ -190,14 +190,7 @@
return retval.toString();
}
- public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
-
- public Object clone() {
- Ref3DPtg ptg = new Ref3DPtg();
- ptg.field_1_index_extern_sheet = field_1_index_extern_sheet;
- ptg.field_2_row = field_2_row;
- ptg.field_3_column = field_3_column;
- ptg.setClass(ptgClass);
- return ptg;
- }
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_REF;
+ }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java Mon Jun 9 06:30:17 2008
@@ -17,12 +17,9 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.BitField;
-
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.util.LittleEndian;
/**
* RefError - handles deleted cell reference
@@ -34,10 +31,6 @@
public final static byte sid = 0x2a;
private int field_1_reserved;
- private RefErrorPtg() {
- //Required for clone methods
- }
-
public RefErrorPtg(RecordInputStream in)
{
field_1_reserved = in.readInt();
@@ -54,7 +47,7 @@
public void writeBytes(byte [] array, int offset)
{
- array[offset] = (byte) (sid + ptgClass);
+ array[offset] = (byte) (sid + getPtgClass());
LittleEndian.putInt(array,offset+1,field_1_reserved);
}
@@ -82,11 +75,4 @@
public byte getDefaultOperandClass() {
return Ptg.CLASS_REF;
}
-
- public Object clone() {
- RefErrorPtg ptg = new RefErrorPtg();
- ptg.field_1_reserved = field_1_reserved;
- ptg.setClass(ptgClass);
- return ptg;
- }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java Mon Jun 9 06:30:17 2008
@@ -18,37 +18,21 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.ss.usermodel.Workbook;
/**
* RefNPtg
* @author Jason Height (jheight at apache dot com)
*/
-public final class RefNPtg extends ReferencePtg
-{
+public final class RefNPtg extends RefPtgBase {
public final static byte sid = 0x2C;
- protected RefNPtg() {
- //Required for clone methods
- }
-
/** Creates new ValueReferencePtg */
- public RefNPtg(RecordInputStream in)
- {
+ public RefNPtg(RecordInputStream in) {
super(in);
}
-
- public String getRefPtgName() {
- return "RefNPtg";
- }
-
- public String toFormulaString(Workbook book)
- {
- throw notImplemented();
- }
-
- public Object clone() {
- throw notImplemented();
+
+ protected byte getSid() {
+ return sid;
}
}
Copied: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java (from r664515, poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java?p2=poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java&p1=poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java&r1=664515&r2=664700&rev=664700&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java Mon Jun 9 06:30:17 2008
@@ -21,8 +21,8 @@
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.hssf.record.RecordInputStream;
/**
@@ -154,7 +154,7 @@
return SIZE;
}
- public final String toFormulaString(HSSFWorkbook book) {
+ public final String toFormulaString(Workbook book) {
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString();
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ScalarConstantPtg.java Mon Jun 9 06:30:17 2008
@@ -27,5 +27,4 @@
public final byte getDefaultOperandClass() {
return Ptg.CLASS_VALUE;
}
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/StringPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/StringPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/StringPtg.java Mon Jun 9 06:30:17 2008
@@ -42,15 +42,11 @@
* NOTE: OO doc says 16bit length, but BiffViewer says 8 Book says something
* totally different, so don't look there!
*/
- private int field_1_length;
- private byte field_2_options;
- private String field_3_string;
+ private final int field_1_length;
+ private final byte field_2_options;
+ private final String field_3_string;
- private StringPtg() {
- // Required for clone methods
- }
-
- /** Create a StringPtg from a byte array read from disk */
+ /** Create a StringPtg from a stream */
public StringPtg(RecordInputStream in) {
field_1_length = in.readUByte();
field_2_options = in.readByte();
@@ -76,9 +72,7 @@
throw new IllegalArgumentException(
"String literals in formulas can't be bigger than 255 characters ASCII");
}
- field_2_options = 0;
- field_2_options = (byte) fHighByte.setBoolean(field_2_options, StringUtil
- .hasMultibyte(value));
+ field_2_options = (byte) fHighByte.setBoolean(0, StringUtil.hasMultibyte(value));
field_3_string = value;
field_1_length = value.length(); // for the moment, we support only ASCII strings in formulas we create
}
@@ -124,14 +118,6 @@
return sb.toString();
}
- public Object clone() {
- StringPtg ptg = new StringPtg();
- ptg.field_1_length = field_1_length;
- ptg.field_2_options = field_2_options;
- ptg.field_3_string = field_3_string;
- return ptg;
- }
-
public String toString() {
StringBuffer sb = new StringBuffer(64);
sb.append(getClass().getName()).append(" [");
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java Mon Jun 9 06:30:17 2008
@@ -17,54 +17,27 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
*
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
public final class SubtractPtg extends ValueOperatorPtg {
- public final static int SIZE = 1;
public final static byte sid = 0x04;
- public SubtractPtg()
- {
- }
-
- public SubtractPtg(RecordInputStream in)
- {
+ public static final ValueOperatorPtg instance = new SubtractPtg();
- // doesn't need anything
+ private SubtractPtg() {
+ // enforce singleton
}
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
+
+ protected byte getSid() {
+ return sid;
}
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return TYPE_BINARY;
- }
-
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 2;
}
-
- public String toFormulaString(Workbook book)
- {
- return "-";
- }
-
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -74,8 +47,4 @@
buffer.append(operands[ 1 ]);
return buffer.toString();
}
-
- public Object clone() {
- return new SubtractPtg();
- }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java Mon Jun 9 06:30:17 2008
@@ -17,62 +17,30 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Unary Plus operator
* does not have any effect on the operand
* @author Avik Sengupta
*/
-
public final class UnaryMinusPtg extends ValueOperatorPtg {
- public final static int SIZE = 1;
public final static byte sid = 0x13;
private final static String MINUS = "-";
- /** Creates new AddPtg */
+ public static final ValueOperatorPtg instance = new UnaryMinusPtg();
- public UnaryMinusPtg()
- {
- }
-
- public UnaryMinusPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ private UnaryMinusPtg() {
+ // enforce singleton
}
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return this.TYPE_UNARY;
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 1;
}
- /** Implementation of method from Ptg */
- public String toFormulaString(Workbook book)
- {
- return "+";
- }
-
/** implementation of method from OperationsPtg*/
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -80,9 +48,4 @@
buffer.append(operands[ 0]);
return buffer.toString();
}
-
- public Object clone() {
- return new UnaryPlusPtg();
- }
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryPlusPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryPlusPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryPlusPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnaryPlusPtg.java Mon Jun 9 06:30:17 2008
@@ -17,62 +17,30 @@
package org.apache.poi.hssf.record.formula;
-import java.util.List;
-
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
-
/**
* Unary Plus operator
* does not have any effect on the operand
* @author Avik Sengupta
*/
-
public final class UnaryPlusPtg extends ValueOperatorPtg {
- public final static int SIZE = 1;
public final static byte sid = 0x12;
private final static String ADD = "+";
- /** Creates new AddPtg */
+ public static final ValueOperatorPtg instance = new UnaryPlusPtg();
- public UnaryPlusPtg()
- {
- }
-
- public UnaryPlusPtg(RecordInputStream in)
- {
-
- // doesn't need anything
+ private UnaryPlusPtg() {
+ // enforce singleton
}
-
- public void writeBytes(byte [] array, int offset)
- {
- array[ offset + 0 ] = sid;
- }
-
- public int getSize()
- {
- return SIZE;
- }
-
- public int getType()
- {
- return this.TYPE_UNARY;
+ protected byte getSid() {
+ return sid;
}
- public int getNumberOfOperands()
- {
+ public int getNumberOfOperands() {
return 1;
}
- /** Implementation of method from Ptg */
- public String toFormulaString(Workbook book)
- {
- return "+";
- }
-
/** implementation of method from OperationsPtg*/
public String toFormulaString(String[] operands) {
StringBuffer buffer = new StringBuffer();
@@ -80,9 +48,4 @@
buffer.append(operands[ 0]);
return buffer.toString();
}
-
- public Object clone() {
- return new UnaryPlusPtg();
- }
-
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java Mon Jun 9 06:30:17 2008
@@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
/**
* @author Glen Stampoultzis (glens at apache.org)
@@ -26,14 +25,10 @@
public final class UnionPtg extends OperationPtg {
public final static byte sid = 0x10;
+ public static final OperationPtg instance = new UnionPtg();
- public UnionPtg()
- {
- }
-
- public UnionPtg(RecordInputStream in)
- {
- // doesn't need anything
+ private UnionPtg() {
+ // enforce singleton
}
public final boolean isBaseToken() {
@@ -50,17 +45,6 @@
array[ offset + 0 ] = sid;
}
- public Object clone()
- {
- return new UnionPtg();
- }
-
- public int getType()
- {
- return TYPE_BINARY;
- }
-
- /** Implementation of method from Ptg */
public String toFormulaString(Workbook book)
{
return ",";
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java Mon Jun 9 06:30:17 2008
@@ -17,6 +17,8 @@
package org.apache.poi.hssf.record.formula;
+import org.apache.poi.ss.usermodel.Workbook;
+
/**
* Common superclass of all value operators.
* Subclasses include all unary and binary operators except for the reference operators (IntersectionPtg, RangePtg, UnionPtg)
@@ -26,12 +28,27 @@
public abstract class ValueOperatorPtg extends OperationPtg {
/**
- * All Operator <tt>Ptg</tt>s are base tokens (i.e. are not RVA classifed)
+ * All Operator <tt>Ptg</tt>s are base tokens (i.e. are not RVA classified)
*/
public final boolean isBaseToken() {
return true;
}
+
public final byte getDefaultOperandClass() {
return Ptg.CLASS_VALUE;
}
+
+ public final void writeBytes(byte[] array, int offset) {
+ array[offset + 0] = getSid();
+ }
+
+ protected abstract byte getSid();
+
+ public final int getSize() {
+ return 1;
+ }
+ public final String toFormulaString(Workbook book) {
+ // TODO - prune this method out of the hierarchy
+ throw new RuntimeException("toFormulaString(String[] operands) should be used for subclasses of OperationPtgs");
+ }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java Mon Jun 9 06:30:17 2008
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula.eval;
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
/**
* @author adeshmukh
@@ -26,9 +26,9 @@
public final class Ref2DEval implements RefEval {
private final ValueEval value;
- private final ReferencePtg delegate;
+ private final RefPtg delegate;
- public Ref2DEval(ReferencePtg ptg, ValueEval ve) {
+ public Ref2DEval(RefPtg ptg, ValueEval ve) {
if(ve == null) {
throw new IllegalArgumentException("ve must not be null");
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java Mon Jun 9 06:30:17 2008
@@ -26,6 +26,7 @@
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
+import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Iterator;
@@ -46,6 +47,20 @@
public static final int PICTURE_TYPE_PNG = HSSFWorkbook.PICTURE_TYPE_PNG; // PNG
public static final int PICTURE_TYPE_DIB = HSSFWorkbook.PICTURE_TYPE_DIB; // Windows DIB
+ /**
+ * width of 1px in columns with default width in units of 1/256 of a character width
+ */
+ private static final float PX_DEFAULT = 32.00f;
+ /**
+ * width of 1px in columns with overridden width in units of 1/256 of a character width
+ */
+ private static final float PX_MODIFIED = 36.56f;
+
+ /**
+ * Height of 1px of a row
+ */
+ private static final int PX_ROW = 15;
+
int pictureIndex;
HSSFPatriarch patriarch;
@@ -100,59 +115,77 @@
* @since POI 3.0.2
*/
public HSSFClientAnchor getPreferredSize(){
- HSSFClientAnchor anchor = new HSSFClientAnchor();
-
- EscherBSERecord bse = (EscherBSERecord)patriarch.sheet.book.getBSERecord(pictureIndex);
- byte[] data = bse.getBlipRecord().getPicturedata();
- int type = bse.getBlipTypeWin32();
- switch (type){
- //we can calculate the preferred size only for JPEG and PNG
- //other formats like WMF, EMF and PICT are not supported in Java
- case HSSFWorkbook.PICTURE_TYPE_JPEG:
- case HSSFWorkbook.PICTURE_TYPE_PNG:
- BufferedImage img = null;
- ImageReader r = null;
- try {
- //read the image using javax.imageio.*
- ImageInputStream iis = ImageIO.createImageInputStream( new ByteArrayInputStream(data) );
- Iterator i = ImageIO.getImageReaders( iis );
- r = (ImageReader) i.next();
- r.setInput( iis );
- img = r.read(0);
+ HSSFClientAnchor anchor = (HSSFClientAnchor)getAnchor();
- int[] dpi = getResolution(r);
- int imgWidth = img.getWidth()*96/dpi[0];
- int imgHeight = img.getHeight()*96/dpi[1];
+ Dimension size = getImageDimension();
- //Excel measures cells in units of 1/256th of a character width.
- //The cell width calculated based on this info is always "off".
- //A better approach seems to be to use empirically obtained cell width and row height
- int cellwidth = 64;
- int rowheight = 17;
-
- int col2 = imgWidth/cellwidth;
- int row2 = imgHeight/rowheight;
+ float w = 0;
- int dx2 = (int)((float)(imgWidth % cellwidth)/cellwidth * 1024);
- int dy2 = (int)((float)(imgHeight % rowheight)/rowheight * 256);
+ //space in the leftmost cell
+ w += getColumnWidthInPixels(anchor.col1)*(1 - anchor.dx1/1024);
+ short col2 = (short)(anchor.col1 + 1);
+ int dx2 = 0;
- anchor.setCol2((short)col2);
- anchor.setDx2(dx2);
+ while(w < size.width){
+ w += getColumnWidthInPixels(col2++);
+ }
- anchor.setRow2(row2);
- anchor.setDy2(dy2);
+ if(w > size.width) {
+ //calculate dx2, offset in the rightmost cell
+ col2--;
+ float cw = getColumnWidthInPixels(col2);
+ float delta = w - size.width;
+ dx2 = (int)((cw-delta)/cw*1024);
+ }
+ anchor.col2 = col2;
+ anchor.dx2 = dx2;
- } catch (IOException e){
- //silently return if ImageIO failed to read the image
- log.log(POILogger.WARN, e);
- img = null;
- }
+ float h = 0;
+ h += (1 - anchor.dy1/256)* getRowHeightInPixels(anchor.row1);
+ int row2 = anchor.row1 + 1;
+ int dy2 = 0;
- break;
+ while(h < size.height){
+ h += getRowHeightInPixels(row2++);
}
+ if(h > size.height) {
+ row2--;
+ float ch = getRowHeightInPixels(row2);
+ float delta = h - size.height;
+ dy2 = (int)((ch-delta)/ch*256);
+ }
+ anchor.row2 = row2;
+ anchor.dy2 = dy2;
+
return anchor;
}
+ private float getColumnWidthInPixels(short column){
+
+ short cw = patriarch.sheet.getColumnWidth(column);
+ float px = getPixelWidth(column);
+
+ return cw/px;
+ }
+
+ private float getRowHeightInPixels(int i){
+
+ HSSFRow row = patriarch.sheet.getRow(i);
+ float height;
+ if(row != null) height = row.getHeight();
+ else height = patriarch.sheet.getDefaultRowHeight();
+
+ return height/PX_ROW;
+ }
+
+ private float getPixelWidth(short column){
+
+ int def = patriarch.sheet.getDefaultColumnWidth()*256;
+ short cw = patriarch.sheet.getColumnWidth(column);
+
+ return cw == def ? PX_DEFAULT : PX_MODIFIED;
+ }
+
/**
* The metadata of PNG and JPEG can contain the width of a pixel in millimeters.
* Return the the "effective" dpi calculated as <code>25.4/HorizontalPixelSize</code>
@@ -176,4 +209,42 @@
return new int[]{hdpi, vdpi};
}
+ /**
+ * Return the dimension of this image
+ *
+ * @return image dimension
+ */
+ public Dimension getImageDimension(){
+ EscherBSERecord bse = patriarch.sheet.book.getBSERecord(pictureIndex);
+ byte[] data = bse.getBlipRecord().getPicturedata();
+ int type = bse.getBlipTypeWin32();
+ Dimension size = new Dimension();
+
+ switch (type){
+ //we can calculate the preferred size only for JPEG and PNG
+ //other formats like WMF, EMF and PICT are not supported in Java
+ case HSSFWorkbook.PICTURE_TYPE_JPEG:
+ case HSSFWorkbook.PICTURE_TYPE_PNG:
+ case HSSFWorkbook.PICTURE_TYPE_DIB:
+ try {
+ //read the image using javax.imageio.*
+ ImageInputStream iis = ImageIO.createImageInputStream( new ByteArrayInputStream(data) );
+ Iterator i = ImageIO.getImageReaders( iis );
+ ImageReader r = (ImageReader) i.next();
+ r.setInput( iis );
+ BufferedImage img = r.read(0);
+
+ int[] dpi = getResolution(r);
+ size.width = img.getWidth()*96/dpi[0];
+ size.height = img.getHeight()*96/dpi[1];
+
+ } catch (IOException e){
+ //silently return if ImageIO failed to read the image
+ log.log(POILogger.WARN, e);
+ }
+
+ break;
+ }
+ return size;
+ }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Mon Jun 9 06:30:17 2008
@@ -50,7 +50,7 @@
import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
import org.apache.poi.hssf.util.HSSFCellRangeAddress;
import org.apache.poi.hssf.util.HSSFDataValidation;
import org.apache.poi.hssf.util.PaneInformation;
@@ -1322,8 +1322,8 @@
Ptg[] ptgs = fp.getRPNPtg();
boolean changed = false;
for(int i=0; i<ptgs.length; i++) {
- if(ptgs[i] instanceof ReferencePtg) {
- ReferencePtg rptg = (ReferencePtg)ptgs[i];
+ if(ptgs[i] instanceof RefPtg) {
+ RefPtg rptg = (RefPtg)ptgs[i];
if(startRow <= rptg.getRowAsInt() &&
rptg.getRowAsInt() <= endRow) {
// References a row that moved
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Mon Jun 9 06:30:17 2008
@@ -930,9 +930,7 @@
if (settingRowAndColumn)
{
- MemFuncPtg memFuncPtg = new MemFuncPtg();
- memFuncPtg.setLenRefSubexpression(23);
- ptgs.add(memFuncPtg);
+ ptgs.add(new MemFuncPtg(23)); // TODO - where did constant '23' come from?
}
if (startColumn >= 0)
{
@@ -956,8 +954,7 @@
}
if (settingRowAndColumn)
{
- UnionPtg unionPtg = new UnionPtg();
- ptgs.add(unionPtg);
+ ptgs.add(UnionPtg.instance);
}
nameRecord.setNameDefinition(ptgs);
Modified: poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java Mon Jun 9 06:30:17 2008
@@ -39,7 +39,7 @@
import org.apache.poi.hssf.record.formula.ParenthesisPtg;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.Ref3DPtg;
-import org.apache.poi.hssf.record.formula.ReferencePtg;
+import org.apache.poi.hssf.record.formula.RefPtg;
import org.apache.poi.hssf.record.formula.StringPtg;
import org.apache.poi.hssf.record.formula.UnionPtg;
import org.apache.poi.hssf.record.formula.UnknownPtg;
@@ -337,17 +337,10 @@
// since we don't know how to handle these yet :(
Ptg ptg = ptgs[i];
-<<<<<<< .mine
if (ptg instanceof ControlPtg) {
// skip Parentheses, Attr, etc
continue;
}
-=======
- if (ptg instanceof ControlPtg) {
- // skip Parentheses, Attr, etc
- continue;
- }
->>>>>>> .r663896
if (ptg instanceof MemErrPtg) { continue; }
if (ptg instanceof MissingArgPtg) { continue; }
if (ptg instanceof NamePtg) {
@@ -380,8 +373,8 @@
Eval opresult = invokeOperation(operation, ops, srcRowNum, srcColNum, workbook, sheet);
stack.push(opresult);
}
- else if (ptg instanceof ReferencePtg) {
- ReferencePtg refPtg = (ReferencePtg) ptg;
+ else if (ptg instanceof RefPtg) {
+ RefPtg refPtg = (RefPtg) ptg;
int colIx = refPtg.getColumn();
int rowIx = refPtg.getRow();
Row row = sheet.getRow(rowIx);
@@ -526,7 +519,7 @@
/**
* returns an appropriate Eval impl instance for the Ptg. The Ptg must be
- * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg,
+ * one of: Area3DPtg, AreaPtg, RefPtg, Ref3DPtg, IntPtg, NumberPtg,
* StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be
* passed here!
*
@@ -545,7 +538,7 @@
Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
}
- else if (ptg instanceof ReferencePtg) {
+ else if (ptg instanceof RefPtg) {
Constructor constructor = clazz.getConstructor(REFERENCE_CONSTRUCTOR_CLASS_ARRAY);
retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
}
@@ -600,10 +593,10 @@
}
/**
- * Creates a Ref2DEval for ReferencePtg.
+ * Creates a Ref2DEval for RefPtg.
* Non existent cells are treated as RefEvals containing BlankEval.
*/
- private static Ref2DEval createRef2DEval(ReferencePtg ptg, Cell cell,
+ private static Ref2DEval createRef2DEval(RefPtg ptg, Cell cell,
Row row, Sheet sheet, Workbook workbook) {
if (cell == null) {
return new Ref2DEval(ptg, BlankEval.INSTANCE);
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/MasterSheet.java Mon Jun 9 06:30:17 2008
@@ -51,21 +51,7 @@
if(!(shape instanceof TextShape)) return false;
TextShape tx = (TextShape)shape;
- TextRun run = tx.getTextRun();
- if(run == null) return false;
-
- Record[] records = run._records;
- for (int i = 0; i < records.length; i++) {
- int type = (int)records[i].getRecordType();
- if (type == RecordTypes.BaseTextPropAtom.typeID ||
- type == RecordTypes.DateTimeMCAtom.typeID ||
- type == RecordTypes.GenericDateMCAtom.typeID ||
- type == RecordTypes.FooterMCAtom.typeID ||
- type == RecordTypes.SlideNumberMCAtom.typeID
- ) return true;
-
- }
- return false;
+ return tx.getPlaceholderAtom() != null;
}
/**
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java Mon Jun 9 06:30:17 2008
@@ -176,16 +176,11 @@
public PictureData getPictureData(){
SlideShow ppt = getSheet().getSlideShow();
PictureData[] pict = ppt.getPictureData();
- Document doc = ppt.getDocumentRecord();
- EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
- EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
- List lst = bstore.getChildRecords();
- int idx = getPictureIndex();
- if (idx == 0){
+ EscherBSERecord bse = getEscherBSERecord();
+ if (bse == null){
logger.log(POILogger.ERROR, "no reference to picture data found ");
} else {
- EscherBSERecord bse = (EscherBSERecord)lst.get(idx-1);
for ( int i = 0; i < pict.length; i++ ) {
if (pict[i].getOffset() == bse.getOffset()){
return pict[i];
@@ -196,6 +191,21 @@
return null;
}
+ protected EscherBSERecord getEscherBSERecord(){
+ SlideShow ppt = getSheet().getSlideShow();
+ Document doc = ppt.getDocumentRecord();
+ EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
+ EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
+
+ List lst = bstore.getChildRecords();
+ int idx = getPictureIndex();
+ if (idx == 0){
+ return null;
+ } else {
+ return (EscherBSERecord)lst.get(idx-1);
+ }
+ }
+
/**
* Name of this picture.
*
@@ -238,6 +248,10 @@
*/
protected void afterInsert(Sheet sh){
super.afterInsert(sh);
+
+ EscherBSERecord bse = getEscherBSERecord();
+ bse.setRef(bse.getRef() + 1);
+
java.awt.Rectangle anchor = getAnchor();
if (anchor.equals(new java.awt.Rectangle())){
setDefaultSize();
@@ -249,21 +263,8 @@
ShapePainter.paint(this, graphics);
PictureData data = getPictureData();
- if (data instanceof Bitmap){
- BufferedImage img = null;
- try {
- img = ImageIO.read(new ByteArrayInputStream(data.getData()));
- }
- catch (Exception e){
- logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + data.getType());
- return;
- }
- Rectangle anchor = getAnchor();
- Image scaledImg = img.getScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);
- graphics.drawImage(scaledImg, anchor.x, anchor.y, null);
- } else {
- logger.log(POILogger.WARN, "Rendering of metafiles is not yet supported. image.type: " + (data == null ? "NA" : data.getClass().getName()));
- }
+ data.draw(graphics, this);
+
graphics.setTransform(at);
}
}
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java Mon Jun 9 06:30:17 2008
@@ -20,10 +20,12 @@
import org.apache.poi.ddf.*;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.hslf.record.Record;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
/**
* An abstract simple (non-group) shape.
@@ -284,4 +286,28 @@
ShapePainter.paint(this, graphics);
graphics.setTransform(at);
}
+
+ /**
+ * Find a record in the underlying EscherClientDataRecord
+ *
+ * @param recordType type of the record to search
+ */
+ protected Record getClientDataRecord(int recordType) {
+ Record oep = null;
+ EscherContainerRecord spContainer = getSpContainer();
+ for (Iterator it = spContainer.getChildRecords().iterator(); it.hasNext();) {
+ EscherRecord obj = (EscherRecord) it.next();
+ if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
+ byte[] data = obj.serialize();
+ Record[] records = Record.findChildRecords(data, 8, data.length - 8);
+ for (int j = 0; j < records.length; j++) {
+ if (records[j].getRecordType() == recordType) {
+ return records[j];
+ }
+ }
+ }
+ }
+ return oep;
+ }
+
}
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java Mon Jun 9 06:30:17 2008
@@ -147,6 +147,7 @@
int dgId = dgg.getMaxDrawingGroupId() + 1;
dg.setOptions((short)(dgId << 4));
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
+ dgg.setMaxDrawingGroupId(dgId);
for (Iterator it = dgContainer.getChildContainers().iterator(); it.hasNext(); ) {
EscherContainerRecord c = (EscherContainerRecord)it.next();
Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java?rev=664700&r1=664699&r2=664700&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java Mon Jun 9 06:30:17 2008
@@ -683,4 +683,13 @@
String ns = s.replaceAll("\\r?\\n", "\r");
return ns;
}
+
+ /**
+ * Returns records that make up this text run
+ *
+ * @return text run records
+ */
+ public Record[] getRecords(){
+ return _records;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org