]> source.dussan.org Git - poi.git/commitdiff
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-63924...
authorNick Burch <nick@apache.org>
Tue, 15 Apr 2008 22:47:30 +0000 (22:47 +0000)
committerNick Burch <nick@apache.org>
Tue, 15 Apr 2008 22:47:30 +0000 (22:47 +0000)
https://svn.apache.org/repos/asf/poi/trunk

........
  r648156 | yegor | 2008-04-15 08:54:20 +0100 (Tue, 15 Apr 2008) | 1 line

  TextShape is a common superclass of all shapes that can hold text. The subclasses are TextBox and AutoShape.
........
  r648203 | yegor | 2008-04-15 11:05:22 +0100 (Tue, 15 Apr 2008) | 1 line

  start improving handling of resources in HSLF. PPFont object represents a font in a presenatation.
........
  r648274 | yegor | 2008-04-15 16:11:13 +0100 (Tue, 15 Apr 2008) | 1 line

  TextSpecInfoAtom is present in PPT 2003+. When the text is changed we must update this record, otherwise the ppt becomes corrupted
........
  r648276 | yegor | 2008-04-15 16:12:58 +0100 (Tue, 15 Apr 2008) | 1 line

  Improved factoring of ppt objects. For ppt tabels Slide.getShapes() returns the Table object (was ShapeGroup)
........
  r648303 | nick | 2008-04-15 17:00:50 +0100 (Tue, 15 Apr 2008) | 1 line

  Nice and small change here... Update the formula parser code to use usermodel.HSSFWorkbook instead of model.Workbook. This should keep things a bit cleaner, and make it much easier for the formula code to work with XSSF
........
  r648334 | josh | 2008-04-15 18:07:06 +0100 (Tue, 15 Apr 2008) | 1 line

  Conditional Formatting (30311) - API improvements, added HSSFSheetConditionalFormatting
........

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@648444 13f79535-47bb-0310-9956-ffa450edef68

106 files changed:
src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/dev/FormulaViewer.java
src/java/org/apache/poi/hssf/model/FormulaParser.java
src/java/org/apache/poi/hssf/record/CFRuleRecord.java
src/java/org/apache/poi/hssf/record/NameRecord.java
src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
src/java/org/apache/poi/hssf/record/formula/AddPtg.java
src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaAPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaNAPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaNVPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
src/java/org/apache/poi/hssf/record/formula/AreaVPtg.java
src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
src/java/org/apache/poi/hssf/record/formula/ArrayPtgA.java
src/java/org/apache/poi/hssf/record/formula/ArrayPtgV.java
src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java
src/java/org/apache/poi/hssf/record/formula/DividePtg.java
src/java/org/apache/poi/hssf/record/formula/EqualPtg.java
src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
src/java/org/apache/poi/hssf/record/formula/GreaterEqualPtg.java
src/java/org/apache/poi/hssf/record/formula/GreaterThanPtg.java
src/java/org/apache/poi/hssf/record/formula/IntPtg.java
src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java
src/java/org/apache/poi/hssf/record/formula/LessEqualPtg.java
src/java/org/apache/poi/hssf/record/formula/LessThanPtg.java
src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java
src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java
src/java/org/apache/poi/hssf/record/formula/NamePtg.java
src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java
src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java
src/java/org/apache/poi/hssf/record/formula/PercentPtg.java
src/java/org/apache/poi/hssf/record/formula/PowerPtg.java
src/java/org/apache/poi/hssf/record/formula/Ptg.java
src/java/org/apache/poi/hssf/record/formula/RangePtg.java
src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
src/java/org/apache/poi/hssf/record/formula/RefNAPtg.java
src/java/org/apache/poi/hssf/record/formula/RefNPtg.java
src/java/org/apache/poi/hssf/record/formula/RefNVPtg.java
src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java
src/java/org/apache/poi/hssf/record/formula/StringPtg.java
src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java
src/java/org/apache/poi/hssf/record/formula/UnaryMinusPtg.java
src/java/org/apache/poi/hssf/record/formula/UnaryPlusPtg.java
src/java/org/apache/poi/hssf/record/formula/UnionPtg.java
src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java
src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
src/java/org/apache/poi/hssf/usermodel/HSSFName.java
src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
src/scratchpad/src/org/apache/poi/hslf/model/AutoShape.java
src/scratchpad/src/org/apache/poi/hslf/model/Line.java
src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java [new file with mode: 0755]
src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java
src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java
src/scratchpad/src/org/apache/poi/hslf/model/ShapeGroup.java
src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java
src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java
src/scratchpad/src/org/apache/poi/hslf/model/Table.java
src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java
src/scratchpad/src/org/apache/poi/hslf/model/TextBox.java
src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java [new file with mode: 0755]
src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java [new file with mode: 0755]
src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt
src/scratchpad/testcases/org/apache/poi/hslf/data/text_shapes.ppt [new file with mode: 0755]
src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java [new file with mode: 0755]
src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java [new file with mode: 0755]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java
src/testcases/org/apache/poi/hssf/record/formula/TestArea3DPtg.java
src/testcases/org/apache/poi/hssf/record/formula/TestRef3DPtg.java
src/testcases/org/apache/poi/hssf/record/formula/function/TestParseMissingBuiltInFuncs.java
src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
src/testcases/org/apache/poi/hssf/util/TestAreaReference.java

index d8c366b2be253be904120eb9bfc4860c636793e9..0fb5cac07c7924f258459ddba36e5b3d67cee8e4 100644 (file)
@@ -44,6 +44,8 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.0.3-beta1" date="2008-04-??">
+           <action dev="POI-DEVELOPERS" type="add">30311 - Conditional Formatting - improved API, added HSSFSheetConditionalFormatting</action>
+           <action dev="POI-DEVELOPERS" type="fix">Update the formula parser code to use a HSSFWorkbook, rather than the low level model.Workbook, to make things cleaner and make supporting XSSF formulas in future much easier</action>
            <action dev="POI-DEVELOPERS" type="fix">Fix the logger used by POIFSFileSystem, so that commons-logging isn't required when not used</action>
            <action dev="POI-DEVELOPERS" type="add">Update HSLFSlideShow and HSSFWorkbook to take advantage of POIFS updates, and allow reading embeded documents</action>
            <action dev="POI-DEVELOPERS" type="add">Improve how POIFS works with directory entries, and update HWPFDocument to support reading an embeded word document</action>
index 2b7cf09eb1a510dd7a22e6804f3ec379e697bc69..cef12de4c80ca9ef148c9c8aef24e4a067a2c9a1 100644 (file)
@@ -41,6 +41,8 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.0.3-beta1" date="2008-04-??">
+           <action dev="POI-DEVELOPERS" type="add">30311 - Conditional Formatting - improved API, added HSSFSheetConditionalFormatting</action>
+           <action dev="POI-DEVELOPERS" type="fix">Update the formula parser code to use a HSSFWorkbook, rather than the low level model.Workbook, to make things cleaner and make supporting XSSF formulas in future much easier</action>
            <action dev="POI-DEVELOPERS" type="fix">Fix the logger used by POIFSFileSystem, so that commons-logging isn't required when not used</action>
            <action dev="POI-DEVELOPERS" type="add">Update HSLFSlideShow and HSSFWorkbook to take advantage of POIFS updates, and allow reading embeded documents</action>
            <action dev="POI-DEVELOPERS" type="add">Improve how POIFS works with directory entries, and update HWPFDocument to support reading an embeded word document</action>
index eb28c9006f7f43c2971c3c3ecf9dfee24adc7b99..91d342099bb7bf9817c920483df5ea31286ee5c9 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.hssf.record.*;
 import org.apache.poi.hssf.record.formula.*;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.model.*;
 
 /**
@@ -99,7 +100,7 @@ public class FormulaViewer
             StringBuffer buf = new StringBuffer();
             
             if (token instanceof ExpPtg) return;
-            buf.append(name=((OperationPtg) token).toFormulaString((Workbook)null));
+            buf.append(name=((OperationPtg) token).toFormulaString((HSSFWorkbook)null));
             buf.append(sep);
             switch (token.getPtgClass()) {
                 case Ptg.CLASS_REF :
@@ -168,7 +169,7 @@ public class FormulaViewer
         StringBuffer buf = new StringBuffer();
            for (int i=0;i<numptgs;i++) {
            token = (Ptg) tokens.get(i);
-            buf.append( token.toFormulaString((Workbook)null));
+            buf.append( token.toFormulaString((HSSFWorkbook)null));
             switch (token.getPtgClass()) {
                 case Ptg.CLASS_REF :
                     buf.append("(R)");
@@ -188,7 +189,7 @@ public class FormulaViewer
     
     private String composeFormula(FormulaRecord record)
     {
-       return  org.apache.poi.hssf.model.FormulaParser.toFormulaString((Workbook)null,record.getParsedExpression());
+       return  org.apache.poi.hssf.model.FormulaParser.toFormulaString((HSSFWorkbook)null,record.getParsedExpression());
     }
 
     /**
index 721928474339001a7a9d67eebe4e800fc55413f0..05b4d80f4a2b57f397a074419f8c5427a6959aea 100644 (file)
@@ -27,6 +27,7 @@ import java.util.regex.Pattern;
 import org.apache.poi.hssf.record.formula.*;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * This class parses a formula string into a List of tokens in RPN order.
@@ -86,7 +87,7 @@ public final class FormulaParser {
      */
     private char look;
 
-    private Workbook book;
+    private HSSFWorkbook book;
 
 
     /**
@@ -101,14 +102,14 @@ public final class FormulaParser {
      *  model.Workbook, then use the convenience method on
      *  usermodel.HSSFFormulaEvaluator
      */
-    public FormulaParser(String formula, Workbook book){
+    public FormulaParser(String formula, HSSFWorkbook book){
         formulaString = formula;
         pointer=0;
         this.book = book;
         formulaLength = formulaString.length();
     }
 
-    public static Ptg[] parse(String formula, Workbook book) {
+    public static Ptg[] parse(String formula, HSSFWorkbook book) {
         FormulaParser fp = new FormulaParser(formula, book);
         fp.parse();
         return fp.getRPNPtg();
@@ -251,7 +252,7 @@ public final class FormulaParser {
             Match('!');
             String sheetName = name;
             String first = GetName();
-            short externIdx = book.checkExternSheet(book.getSheetIndex(sheetName));
+            short externIdx = book.getExternalSheetIndex(book.getSheetIndex(sheetName));
             if (look == ':') {
                 Match(':');
                 String second=GetName();
@@ -282,9 +283,9 @@ public final class FormulaParser {
             return new ReferencePtg(name);
         }
 
-        for(int i = 0; i < book.getNumNames(); i++) {
+        for(int i = 0; i < book.getNumberOfNames(); i++) {
             // named range name matching is case insensitive
-            if(book.getNameRecord(i).getNameText().equalsIgnoreCase(name)) {
+               if(book.getNameAt(i).getNameName().equalsIgnoreCase(name)) {
                 return new NamePtg(name, book);
             }
         }
@@ -926,7 +927,7 @@ end;
      * @param lptgs  list of Ptg, can be null or empty
      * @return a human readable String
      */
-    public static String toFormulaString(Workbook book, List lptgs) {
+    public static String toFormulaString(HSSFWorkbook book, List lptgs) {
         String retval = null;
         if (lptgs == null || lptgs.size() == 0) return "#NAME";
         Ptg[] ptgs = new Ptg[lptgs.size()];
@@ -952,7 +953,7 @@ end;
      * @param ptgs  array of Ptg, can be null or empty
      * @return a human readable String
      */
-    public static String toFormulaString(Workbook book, Ptg[] ptgs) {
+    public static String toFormulaString(HSSFWorkbook book, Ptg[] ptgs) {
         if (ptgs == null || ptgs.length == 0) {
             // TODO - what is the justification for returning "#NAME" (which is not "#NAME?", btw)
             return "#NAME";
index 0890f1f32d238c98dd9c978b14438adfc96142ad..2b1705abe2d382e20f2034192e7cff04d6169ec8 100644 (file)
@@ -26,9 +26,11 @@ import org.apache.poi.hssf.record.cf.BorderFormatting;
 import org.apache.poi.hssf.record.cf.FontFormatting;
 import org.apache.poi.hssf.record.cf.PatternFormatting;
 import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.StringUtil;
 
 /**
  * Conditional Formatting Rule Record.
@@ -62,7 +64,7 @@ public final class CFRuleRecord extends Record
 
        private int   field_5_options;
 
-       private static final BitField modificationBits = bf(0x83FFFFFF); // Bits: font,align,bord,patt,prot
+       private static final BitField modificationBits = bf(0x003FFFFF); // Bits: font,align,bord,patt,prot
        private static final BitField alignHor      = bf(0x00000001); // 0 = Horizontal alignment modified
        private static final BitField alignVer      = bf(0x00000002); // 0 = Vertical alignment modified
        private static final BitField alignWrap     = bf(0x00000004); // 0 = Text wrapped flag modified
@@ -152,7 +154,7 @@ public final class CFRuleRecord extends Record
        /**
         * Creates a new comparison operation rule
         */
-       public static CFRuleRecord create(Workbook workbook, String formulaText) {
+       public static CFRuleRecord create(HSSFWorkbook workbook, String formulaText) {
                Ptg[] formula1 = parseFormula(formulaText, workbook);
                return new CFRuleRecord(CONDITION_TYPE_FORMULA, ComparisonOperator.NO_COMPARISON,
                                formula1, null);
@@ -160,7 +162,7 @@ public final class CFRuleRecord extends Record
        /**
         * Creates a new comparison operation rule
         */
-       public static CFRuleRecord create(Workbook workbook, byte comparisonOperation,
+       public static CFRuleRecord create(HSSFWorkbook workbook, byte comparisonOperation,
                        String formulaText1, String formulaText2) {
                Ptg[] formula1 = parseFormula(formulaText1, workbook);
                Ptg[] formula2 = parseFormula(formulaText2, workbook);
@@ -607,6 +609,8 @@ public final class CFRuleRecord extends Record
        {
                StringBuffer buffer = new StringBuffer();
                buffer.append("[CFRULE]\n");
+               buffer.append("    OPTION FLAGS=0x"+Integer.toHexString(getOptions()));
+               /*
                if( containsFontFormattingBlock())
                {
                        buffer.append(fontFormatting.toString());
@@ -619,7 +623,7 @@ public final class CFRuleRecord extends Record
                {
                        buffer.append(patternFormatting.toString());
                }
-               buffer.append("[/CFRULE]\n");
+               buffer.append("[/CFRULE]\n");*/
                return buffer.toString();
        }
        
@@ -651,7 +655,7 @@ public final class CFRuleRecord extends Record
        /**
         * @return <code>null</code> if <tt>formula</tt> was null.
         */
-       private static Ptg[] parseFormula(String formula, Workbook workbook)
+       private static Ptg[] parseFormula(String formula, HSSFWorkbook workbook)
        {
                if(formula == null) {
                        return null;
index a06bc8aedd7c06761d5ae4c2dadbd605a6c091bf..23af4b17cc8a0bb4418f92aee8403acea4472087 100644 (file)
 
 package org.apache.poi.hssf.record;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.Stack;
-import java.util.Iterator;
 
-import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.formula.*;
+import org.apache.poi.hssf.record.formula.Area3DPtg;
+import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
+import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.Ref3DPtg;
+import org.apache.poi.hssf.record.formula.UnionPtg;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.RangeAddress;
 import org.apache.poi.util.HexDump;
@@ -645,7 +650,7 @@ public class NameRecord extends Record {
     /** gets the reference , the area only (range)
      * @return area reference
      */
-    public String getAreaReference(Workbook book){
+    public String getAreaReference(HSSFWorkbook book){
         if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return "Error";
         Ptg ptg = (Ptg) field_13_name_definition.peek();
         String result = "";
@@ -679,7 +684,7 @@ public class NameRecord extends Record {
      *  return an empty string if nothing is possible
      *  for it.
      */
-    private String getAreaRefString(Ptg ptg,Workbook book) {
+    private String getAreaRefString(Ptg ptg,HSSFWorkbook book) {
         if (ptg.getClass() == Area3DPtg.class){
             return ptg.toFormulaString(book);
         } else if (ptg.getClass() == Ref3DPtg.class){
index f0fc1fccf4c69b083ad7bd937b033df65341f489..82d85ccebbb16c86131ea67f7f057a86534a0cfa 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
 
@@ -73,7 +73,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
         return field_2_fnc_index == FUNCTION_INDEX_EXTERNAL;
     }
 
-    public String toFormulaString(Workbook book) {
+    public String toFormulaString(HSSFWorkbook book) {
         return getName();
     }
 
index 12c49f114808c91f8b0123bc9b42e5bd0d0363bd..4f79d76027c5e32fee678d09b259d62db4b54c2c 100644 (file)
@@ -23,7 +23,7 @@
  */
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -75,7 +75,7 @@ public class AddPtg
     }
     
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "+";
     }
index 9075920897f402dbdee74c4e92536bf8d44c1d03..5a02394c7c221278cf4b85051b2c0a03a1a629f4 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
@@ -273,7 +273,7 @@ public class Area3DPtg extends Ptg implements AreaI
         * @return text representation of this area reference that can be used in text
         *  formulas. The sheet name will get properly delimited if required.
         */
-       public String toFormulaString(Workbook book)
+       public String toFormulaString(HSSFWorkbook book)
        {
                // First do the sheet name
                StringBuffer retval = new StringBuffer();
index 515d07dd41535e64601be7c90be6dfcadb8390eb..6ff0b05b1632a59bc98c5702e5c63e14fbc5df20 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Specifies a rectangular area of cells A1:A4 for instance.
index ed48431dee8395c4749075d2428fe090eeabc8a7..187957e587f9aa96b23c2b068e3cd9b9ca9fbece 100644 (file)
@@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -66,7 +66,7 @@ public class AreaErrPtg extends AreaPtg
         array[offset] = (byte) (sid + ptgClass);
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "#REF!";
     }
index da24158acef2623948a4282cedae6dbe198c7098..6b0eb908ac4fff9306597a5d852438a7bfa11f59 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Specifies a rectangular area of cells A1:A4 for instance.
@@ -58,7 +58,7 @@ public class AreaNAPtg
       return "AreaNAPtg";
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
       throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
     }
index 9507e37a8e54792de1f69dfa42f101e08fcb169e..71e413fead0fbd6451036521d3c8c88b089be160 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Specifies a rectangular area of cells A1:A4 for instance.
@@ -61,7 +61,7 @@ public class AreaNPtg
     return "AreaNPtg";
   }
 
-  public String toFormulaString(Workbook book)
+  public String toFormulaString(HSSFWorkbook book)
   {
     throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
   }
index c91ed502c91aa0c00d11d83b486921d488c1fd9d..2ebf01982962430048da11c262011f3b8ff3bc15 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Specifies a rectangular area of cells A1:A4 for instance.
@@ -59,7 +59,7 @@ public class AreaNVPtg
     return "AreaNVPtg";
   }
 
-  public String toFormulaString(Workbook book)
+  public String toFormulaString(HSSFWorkbook book)
   {
     throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
   }
index be34e0074a3139547467be6ac203d334535d4306..27e4d1759cb8ba036252cc3757e03cd16dd907af 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.poi.util.BitFieldFactory;
 
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -303,11 +303,11 @@ public class AreaPtg
         field_4_last_column = column;
     }
     
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
        return toFormulaString(this, book);
     }
-    protected static String toFormulaString(AreaI area, Workbook book) {
+    protected static String toFormulaString(AreaI area, HSSFWorkbook book) {
        CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative());
        CellReference botRight = new CellReference(area.getLastRow(),area.getLastColumn(),!area.isLastRowRelative(),!area.isLastColRelative());
        
index 42dc11fa326772bb356b139681f6196983b9f930..e5e3d525cc8aa14be432a304fcd14b79422bcb2e 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.util.BitField;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.AreaReference;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Specifies a rectangular area of cells A1:A4 for instance.
index 12166b7967ecc639f2baef58b896b019a42192d7..01942be55cf869881c61b51ef3b2e1242d35b2c6 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.StringUtil;
 
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.SSTRecord;
@@ -198,7 +198,7 @@ public class ArrayPtg extends Ptg
         return size;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
        StringBuffer b = new StringBuffer();
        b.append("{");
index 0319175ba4b5ab9e248b1ac996605f3346fd26b5..616f737b84793b7fd80a2ca769df1697c964404d 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.StringUtil;
 
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.SSTRecord;
index 49a28c97cc9604d47dd98dc57004f07498ecd1af..94aa32383f42d3feedae5cb068fa0ab29a848bb8 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.StringUtil;
 
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.SSTRecord;
index d355fbfa1f3d2bb9b5e8aa4a3ac2ea40e59a269c..351d44a421a5f4e920e119687250b7b2cd616b47 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 import org.apache.poi.util.LittleEndian;
@@ -209,11 +209,11 @@ public final class AttrPtg extends OperationPtg {
         if(space.isSet(field_1_options)) {
             return operands[ 0 ];
         } else if (optiIf.isSet(field_1_options)) {
-            return toFormulaString((Workbook)null) + "(" + operands[ 0 ]             +")";
+            return toFormulaString((HSSFWorkbook)null) + "(" + operands[ 0 ]             +")";
         } else if (optGoto.isSet(field_1_options)) {
-            return toFormulaString((Workbook)null) + operands[0];   //goto isn't a real formula element should not show up
+            return toFormulaString((HSSFWorkbook)null) + operands[0];   //goto isn't a real formula element should not show up
         } else {
-            return toFormulaString((Workbook)null) + "(" + operands[ 0 ] + ")";
+            return toFormulaString((HSSFWorkbook)null) + "(" + operands[ 0 ] + ")";
         }
     }
   
@@ -228,7 +228,7 @@ public final class AttrPtg extends OperationPtg {
         return -1;
     }
         
-   public String toFormulaString(Workbook book) {
+   public String toFormulaString(HSSFWorkbook book) {
       if(semiVolatile.isSet(field_1_options)) {
         return "ATTR(semiVolatile)";
       }
index 0248f8466f1e10adf17a59abe1a07ddc2185e1fb..80c9f39d79c2f5816363c8944e99948af52cfdb1 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -70,7 +70,7 @@ public class BoolPtg
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return field_1_value ? "TRUE" : "FALSE";
     }
index 41d2de0cbae58ca2f0147003ee663f47869148eb..951872f43b9f99e1abd858bd5389ed45f82b024e 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -64,7 +64,7 @@ public class ConcatPtg
         return 2;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return CONCAT;
     }    
index cde67c5dc87362d9da19bc16405f98a15387e933..70fa62e58badef1554e704b522cd84d46de2f42e 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -65,7 +65,7 @@ public class DividePtg
         return 2;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "/";
     }
@@ -74,7 +74,7 @@ public class DividePtg
         StringBuffer buffer = new StringBuffer();
 
         buffer.append(operands[ 0 ]);
-        buffer.append(toFormulaString((Workbook)null));
+        buffer.append(toFormulaString((HSSFWorkbook)null));
         buffer.append(operands[ 1 ]);
         return buffer.toString();
     }      
index 26f66e4fe2ce3c4ca5ab91df0b2bcf5d88ec0f94..a08a863d1c8046de0ecdd7d06c8b802acb9eb288 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -64,7 +64,7 @@ public class EqualPtg
         return 2;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "=";
     }
@@ -74,7 +74,7 @@ public class EqualPtg
 
         
         buffer.append(operands[ 0 ]);
-        buffer.append(toFormulaString((Workbook)null));
+        buffer.append(toFormulaString((HSSFWorkbook)null));
         buffer.append(operands[ 1 ]);
         return buffer.toString();
     }       
index 26cc2e027bc9f9147a747e5ba807124722ffb459..a16992f94385d0ee49586e07be58e163c9295cdb 100644 (file)
@@ -19,7 +19,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
 
@@ -70,7 +70,7 @@ public final class ErrPtg extends Ptg {
         array[offset + 1] = (byte)field_1_error_code;
     }
 
-    public String toFormulaString(Workbook book) {
+    public String toFormulaString(HSSFWorkbook book) {
         return HSSFErrorConstants.getText(field_1_error_code);
     }
 
index a7fc0274adb3c05aa1791cf699ec64c6476c0fb2..0cd54e5f55f827067b47ee4ac31f62aa81e3d32e 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
 
@@ -73,7 +73,7 @@ public class ExpPtg
       return field_2_first_col;
     }    
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         throw new RecordFormatException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't");
     }
index d8d08fecb889b11dfe384579e142125bc382ff55..677d78c3e5c665380cba4e5ae10e656b2ac0cdb3 100755 (executable)
@@ -19,7 +19,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 
@@ -67,7 +67,7 @@ public class GreaterEqualPtg
         return 2;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return ">=";
     }
@@ -77,7 +77,7 @@ public class GreaterEqualPtg
 
         buffer.append(operands[ 0 ]);
 
-        buffer.append(toFormulaString((Workbook)null));
+        buffer.append(toFormulaString((HSSFWorkbook)null));
         buffer.append(operands[ 1 ]);
 
         return buffer.toString();
index 6d66307b3d3b921ec0707042471d293acf13a7c9..6501203edcc9b070d4dabd1e8fbe2f44f818174b 100644 (file)
@@ -25,7 +25,7 @@ package org.apache.poi.hssf.record.formula;
 
 import java.util.List;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -97,7 +97,7 @@ public class GreaterThanPtg
      * Implementation of method from Ptg 
      * @param book the Sheet References
      */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return this.GREATERTHAN;
     }
index f4106b6aa8fc221e7ba949b4e5213157ab392d5d..f3dd16f068a6750bf69c8238742f2bf8bf71fd3f 100644 (file)
@@ -18,7 +18,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -72,7 +72,7 @@ public final class IntPtg extends Ptg {
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book) {
+    public String toFormulaString(HSSFWorkbook book) {
         return String.valueOf(getValue());
     }
     public byte getDefaultOperandClass() {
index 9b225912ed6000109395e6892051e689ced613cb..8f5bddc190b6a3c5107c9e10a059f01f25621c28 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -59,7 +59,7 @@ public class IntersectionPtg extends OperationPtg
     }
 
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return " ";
     }
index c395ed3b1c234cad3514743dfedb709fe6296198..f42966394b749f8fb9306e8f8406cc6e802af79e 100755 (executable)
@@ -20,7 +20,7 @@
 package org.apache.poi.hssf.record.formula;
 
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 
@@ -68,7 +68,7 @@ public class LessEqualPtg
         return 2;
     }
 
-    public String toFormulaString( Workbook book )
+    public String toFormulaString( HSSFWorkbook book )
     {
         return "<=";
     }
@@ -77,7 +77,7 @@ public class LessEqualPtg
     {
         StringBuffer buffer = new StringBuffer();
         buffer.append( operands[0] );
-        buffer.append( toFormulaString( (Workbook) null ) );
+        buffer.append( toFormulaString( (HSSFWorkbook) null ) );
         buffer.append( operands[1] );
         return buffer.toString();
     }
index 4bccd9274ed449ceab58ddc71697e89146c20a14..c23658d2db4302995e5c2baa2d779d929d1f892b 100644 (file)
@@ -27,7 +27,7 @@ package org.apache.poi.hssf.record.formula;
 import java.util.List;
 
 //POI
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -106,7 +106,7 @@ public class LessThanPtg
      * Implementation of method from Ptg 
      * @param book the Sheet References
      */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return this.LESSTHAN;
     }
index ee0b761854098a931b1c2df4896bcad7606c6804..ec33d10921475187d5234ccd5d01372781b597dd 100644 (file)
@@ -25,7 +25,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -83,7 +83,7 @@ public class MemAreaPtg
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return ""; // TODO: Not sure how to format this. -- DN
     }
index bfc33c12843b229981733a2849f77bd285e8d168..359c76e6681dc69c6c5bd36770f358bcb92cb660 100644 (file)
@@ -25,7 +25,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -57,7 +57,7 @@ public class MemErrPtg
         array[offset] = (byte) (sid + ptgClass);
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "ERR#";
     }
index 89d4cae329010e94927145a2130014b0d6637b7d..63c07a79e71def40c614e648255b4120ccb65167 100644 (file)
@@ -24,7 +24,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -60,7 +60,7 @@ public class MemFuncPtg extends ControlPtg
         LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "";
     }
index 17a31a4e6a474af9c75d85088e9c5c16c04ce36a..d539405cd061c899349d9b6e8ac14909464b8f02 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -55,7 +55,7 @@ public class MissingArgPtg
     }
 
    
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return " ";
     }
index 626eff2b8e4b12253c8f39cd9ddf36c6383de250..cbc0b6700216df9d0f7cb1c049e2a7527d058bda 100644 (file)
@@ -16,7 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -68,7 +68,7 @@ public class MultiplyPtg
     }
     
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "*";
     }
@@ -77,9 +77,9 @@ public class MultiplyPtg
     {
         StringBuffer buffer = new StringBuffer();
 
-        buffer.append(operands[ 0 ].toFormulaString((Workbook)null));
+        buffer.append(operands[ 0 ].toFormulaString((HSSFWorkbook)null));
         buffer.append("*");
-        buffer.append(operands[ 1 ].toFormulaString((Workbook)null));
+        buffer.append(operands[ 1 ].toFormulaString((HSSFWorkbook)null));
         return buffer.toString();
     }
     
@@ -87,7 +87,7 @@ public class MultiplyPtg
         StringBuffer buffer = new StringBuffer();
 
         buffer.append(operands[ 0 ]);
-        buffer.append(toFormulaString((Workbook)null));
+        buffer.append(toFormulaString((HSSFWorkbook)null));
         buffer.append(operands[ 1 ]);
         return buffer.toString();
     }                  
index 5405481a09a315468c113d12f7769c0d112e3eb6..9d93f1e9827bb4b4df60745d3c041dfe645a8fb1 100644 (file)
@@ -18,7 +18,8 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFName;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.NameRecord;
 import org.apache.poi.hssf.record.RecordInputStream;
 
@@ -48,26 +49,24 @@ public class NamePtg
      * in the workbook.  The search for the name record is case insensitive.  If it is not found, 
      * it gets created.
      */
-    public NamePtg(String name, Workbook book) {
+    public NamePtg(String name, HSSFWorkbook book) {
         field_1_label_index = (short)(1+getOrCreateNameRecord(book, name)); // convert to 1-based
     }
     /**
      * @return zero based index of the found or newly created defined name record. 
      */
-    private static final int getOrCreateNameRecord(Workbook book, String name) {
-        // perhaps this logic belongs in Workbook
-        int countNames = book.getNumNames();
-        NameRecord rec;
+    private static final int getOrCreateNameRecord(HSSFWorkbook book, String name) {
+        // perhaps this logic belongs in Workbook?
+        int countNames = book.getNumberOfNames();
         for (int i = 0; i < countNames; i++) {
-            rec = book.getNameRecord(i);
-            if (name.equalsIgnoreCase(rec.getNameText())) {
+            if(name.equalsIgnoreCase( book.getNameName(i) )) {
                 return i; 
             }
         }
-        rec = new NameRecord();
-        rec.setNameText(name);
-        rec.setNameTextLength((byte) name.length());
-        book.addName(rec);
+        
+        HSSFName nameObj = book.createName();
+        nameObj.setNameName(name);
+        
         return countNames;
     }
 
@@ -100,10 +99,9 @@ public class NamePtg
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
-        NameRecord rec = book.getNameRecord(field_1_label_index - 1);
-        return rec.getNameText();
+       return book.getNameName(field_1_label_index - 1);
     }
     
     public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
index ccf5ab6fcd342551ac34ae9352115b5e1d133c98..3036800b1032f89b5fe11070ba5abde16fc0e89c 100644 (file)
@@ -18,7 +18,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -61,7 +61,7 @@ public final class NameXPtg extends Ptg {
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         // -1 to convert definedNameIndex from 1-based to zero-based
         return book.resolveNameXText(field_1_ixals, field_2_ilbl-1); 
index 8eea4d80041edaa3aea3ea1ea116a64528928210..5dbbec875494e01c85d6cebbb59bac1008abb653 100755 (executable)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -64,7 +64,7 @@ public class NotEqualPtg
         return 2;
     }
 
-    public String toFormulaString( Workbook book )
+    public String toFormulaString( HSSFWorkbook book )
     {
         return "<>";
     }
@@ -75,7 +75,7 @@ public class NotEqualPtg
 
         buffer.append( operands[0] );
 
-        buffer.append( toFormulaString( (Workbook) null ) );
+        buffer.append( toFormulaString( (HSSFWorkbook) null ) );
         buffer.append( operands[1] );
 
         return buffer.toString();
index 43617f290977407836251f2500192af449a820b4..8ec67345b41d7f5137ce7e127cc12534d5731458 100644 (file)
@@ -18,7 +18,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -78,7 +78,7 @@ public class NumberPtg
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "" + getValue();
     }
index 374458a15d1c3d7ed24bb01450a480d3e463fdf1..402dbd377428b0900cd39b5737f107f4212082eb 100644 (file)
@@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula;
 
 import java.util.List;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -71,7 +71,7 @@ public class ParenthesisPtg
         return 1;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "()";
     }
index 9db4d6c43b0270db93396b8503a37c4aa66d859d..0c59bb7acb55a6d90ba025a8e6cc2b5842a85f49 100644 (file)
@@ -23,7 +23,7 @@
  */
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -74,7 +74,7 @@ public class PercentPtg
     }
     
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "%";
     }
index 73f41fa49c9b2db8a9d77dc1dee3decd1f3c9875..0dbb3ba283991e9473c78c0e2a76345ec70fc635 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.hssf.record.formula;
 
 import java.util.List;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -66,7 +66,7 @@ public class PowerPtg
         return 2;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "^";
     }
@@ -76,7 +76,7 @@ public class PowerPtg
 
         
         buffer.append(operands[ 0 ]);
-        buffer.append(toFormulaString((Workbook)null));
+        buffer.append(toFormulaString((HSSFWorkbook)null));
         buffer.append(operands[ 1 ]);
         return buffer.toString();
     }       
index f006509c23fcbffc116eb6d25300725cfa691e08..0e8c7741ac27568717184c6a968808703820a95a 100644 (file)
@@ -21,7 +21,7 @@ import java.util.List;
 import java.util.ArrayList;
 import java.util.Stack;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -418,7 +418,7 @@ public abstract class Ptg
     /**
      * return a string representation of this token alone
      */
-    public abstract String toFormulaString(Workbook book);
+    public abstract String toFormulaString(HSSFWorkbook book);
     /**
      * dump a debug representation (hexdump) to a string
      */
index 51df7844a4babd69afee4d7977c9a9f8c273d3cf..4726a70c17265db0b1f454c7ec07d039438099fa 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -59,7 +59,7 @@ public class RangePtg extends OperationPtg
     }
 
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return ":";
     }
index 7fb2c9c43a220fc42b23a38552494f826c8d451e..f9f5c6e20289f1e77da594a897ac3b4fe5bd2847 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.hssf.util.RangeAddress;
@@ -162,8 +162,8 @@ public class Ref3DPtg extends Ptg {
     }
 
     // TODO - find a home for this method
-    // There is already a method on Workbook called getSheetName but it seems to do something different.
-       static String getSheetName(Workbook book, int externSheetIndex) {
+    // There is already a method on HSSFWorkbook called getSheetName but it seems to do something different.
+       static String getSheetName(HSSFWorkbook book, int externSheetIndex) {
         // TODO - there are 3 ways this method can return null. Is each valid?
         if (book == null) {
             return null;
@@ -179,7 +179,7 @@ public class Ref3DPtg extends Ptg {
      * @return text representation of this cell reference that can be used in text 
      * formulas. The sheet name will get properly delimited if required.
      */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         StringBuffer retval = new StringBuffer();
         String sheetName = getSheetName(book, field_1_index_extern_sheet);
index 4d655756d42047feb046a5fcc6919ad2365a5e5f..c29b55bf94948dc9a61ec98931f95816eaf2862d 100755 (executable)
@@ -21,7 +21,7 @@ import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.BitField;
 
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -74,7 +74,7 @@ public class RefErrorPtg extends Ptg
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         //TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
         return "#REF!";
index 4e05e1387dda6f07aa5cacef97a87ca0d48aeaeb..6f18e4b94efc670962a002b1e713fd06eaa609a6 100644 (file)
@@ -28,7 +28,7 @@ import org.apache.poi.util.BitField;
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * RefNAPtg
@@ -57,7 +57,7 @@ public class RefNAPtg extends ReferencePtg
       return "RefNAPtg";
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
       throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
     }
index e062f0c4e471e1087d8d988bd67d0b9e775af193..e7522e7e5f1f3653f2451f0fce40ddc66d5d1ff1 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.poi.util.BitField;
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * RefNPtg
@@ -58,7 +58,7 @@ public class RefNPtg extends ReferencePtg
       return "RefNPtg";
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
       throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
     }
index 615a9c0b0a55caade3e175a637b15d6e1a307062..40b111b3ecd26ada2b0692acf7f7b6f137ac1cf7 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.poi.util.BitField;
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * RefNVPtg
@@ -54,7 +54,7 @@ public class RefNVPtg extends ReferencePtg
     return "RefNVPtg";
   }
 
-  public String toFormulaString(Workbook book)
+  public String toFormulaString(HSSFWorkbook book)
   {
     throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
   }
index 4983c9d0706aabe0a4a71d5a087c9105c73e44af..3df731c7ace74866a9b5e4f399c57ddfdd5d7213 100644 (file)
@@ -22,7 +22,7 @@ import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 
 import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -176,7 +176,7 @@ public class ReferencePtg extends Ptg {
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook 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();
index 491b6c6c3658d0a56cd007065d31cdbfdc0376e7..ca6fb55dc67e2b32ecd6c7c607f28a9574991e5c 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.StringUtil;
@@ -109,7 +109,7 @@ public class StringPtg
         }
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "\""+getValue()+"\"";
     }
index 384db9357bdbbc77f509a7c8c028ee6d485ddd7d..37af74ba9ec2e1eee8b9eb2101e40434e8670992 100644 (file)
@@ -18,7 +18,7 @@
 package org.apache.poi.hssf.record.formula;
 
 import java.util.List;
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -63,7 +63,7 @@ public class SubtractPtg
         return 2;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "-";
     }
index 31efdcd63c9735c6801f37bd8fd97d08fdb05e11..7c134b97d136f677d39b3d64ecdac5b138f03f19 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.hssf.record.formula;
 
 import java.util.List;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -69,7 +69,7 @@ public class UnaryMinusPtg extends OperationPtg
     }
     
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "+";
     }
index ce3ba7cf4a0041156dbcdce150149b5e184645d0..148c83fa4157535599750fc76bbfb33c33da10ae 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.poi.hssf.record.formula;
 
 import java.util.List;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -69,7 +69,7 @@ public class UnaryPlusPtg extends OperationPtg
     }
     
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "+";
     }
index 40298a0cffa595e6d6e0ac8b968d77bf910636fe..8d00ec34dff3a5f111b82fe20542f14d2f257625 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -59,7 +59,7 @@ public class UnionPtg extends OperationPtg
     }
 
     /** Implementation of method from Ptg */
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return ",";
     }
index 1badf519705b489fe8360cf219fd7c57fa2a620a..56493d906ab0104300334364333159046b73029e 100644 (file)
@@ -16,7 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
@@ -51,7 +51,7 @@ public class UnknownPtg
         return size;
     }
 
-    public String toFormulaString(Workbook book)
+    public String toFormulaString(HSSFWorkbook book)
     {
         return "UNKNOWN";
     }
index ba2d5876249870f6a6bca89764acb05300f21d2b..33e1d3a8501f43e595cc381289a89add54e2607f 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.cf.BorderFormatting;
 
 /**
@@ -58,18 +59,15 @@ public final class HSSFBorderFormatting
        public final static short BORDER_SLANTED_DASH_DOT =  BorderFormatting.BORDER_SLANTED_DASH_DOT;
 
        
+       private final CFRuleRecord cfRuleRecord;
        private final BorderFormatting borderFormatting;
        
-       public HSSFBorderFormatting()
+       protected HSSFBorderFormatting(CFRuleRecord cfRuleRecord)
        {
-               borderFormatting = new BorderFormatting();
+               this.cfRuleRecord = cfRuleRecord;
+               this.borderFormatting = cfRuleRecord.getBorderFormatting();
        }
 
-       protected HSSFBorderFormatting(BorderFormatting borderFormatting)
-       {
-               this.borderFormatting = borderFormatting;
-       }
-       
        protected BorderFormatting getBorderFormattingBlock()
        {
                return borderFormatting;
@@ -138,60 +136,110 @@ public final class HSSFBorderFormatting
        public void setBackwardDiagonalOn(boolean on)
        {
                borderFormatting.setBackwardDiagonalOn(on);
+               if( on )
+               {
+                       cfRuleRecord.setTopLeftBottomRightBorderModified(on);
+               }
        }
 
        public void setBorderBottom(short border)
        {
                borderFormatting.setBorderBottom(border);
+               if( border != 0)
+               {
+                       cfRuleRecord.setBottomBorderModified(true);
+               }
        }
 
        public void setBorderDiagonal(short border)
        {
                borderFormatting.setBorderDiagonal(border);
+               if( border != 0)
+               {
+                       cfRuleRecord.setBottomLeftTopRightBorderModified(true);
+                       cfRuleRecord.setTopLeftBottomRightBorderModified(true);
+               }
        }
 
        public void setBorderLeft(short border)
        {
                borderFormatting.setBorderLeft(border);
+               if( border != 0)
+               {
+                       cfRuleRecord.setLeftBorderModified(true);
+               }
        }
 
        public void setBorderRight(short border)
        {
                borderFormatting.setBorderRight(border);
+               if( border != 0)
+               {
+                       cfRuleRecord.setRightBorderModified(true);
+               }
        }
 
        public void setBorderTop(short border)
        {
                borderFormatting.setBorderTop(border);
+               if( border != 0)
+               {
+                       cfRuleRecord.setTopBorderModified(true);
+               }
        }
 
        public void setBottomBorderColor(short color)
        {
                borderFormatting.setBottomBorderColor(color);
+               if( color != 0)
+               {
+                       cfRuleRecord.setBottomBorderModified(true);
+               }
        }
 
        public void setDiagonalBorderColor(short color)
        {
                borderFormatting.setDiagonalBorderColor(color);
+               if( color != 0)
+               {
+                       cfRuleRecord.setBottomLeftTopRightBorderModified(true);
+                       cfRuleRecord.setTopLeftBottomRightBorderModified(true);
+               }
        }
 
        public void setForwardDiagonalOn(boolean on)
        {
                borderFormatting.setForwardDiagonalOn(on);
+               if( on )
+               {
+                       cfRuleRecord.setBottomLeftTopRightBorderModified(on);
+               }
        }
 
        public void setLeftBorderColor(short color)
        {
                borderFormatting.setLeftBorderColor(color);
+               if( color != 0)
+               {
+                       cfRuleRecord.setLeftBorderModified(true);
+               }
        }
 
        public void setRightBorderColor(short color)
        {
                borderFormatting.setRightBorderColor(color);
+               if( color != 0)
+               {
+                       cfRuleRecord.setRightBorderModified(true);
+               }
        }
 
        public void setTopBorderColor(short color)
        {
                borderFormatting.setTopBorderColor(color);
+               if( color != 0)
+               {
+                       cfRuleRecord.setTopBorderModified(true);
+               }
        }
 }
index 2a605c8a7537f058d0168f3134c26ff126295d98..0d2cfade4c8c6ed035d06b685860c3754c489f87 100644 (file)
@@ -118,7 +118,7 @@ public class HSSFCell implements Cell
     private int                      cellType;
     private HSSFRichTextString       stringValue;
     private short                    encoding = ENCODING_UNCHANGED;
-    private Workbook                 book;
+    private HSSFWorkbook             book;
     private Sheet                    sheet;
     private CellValueRecordInterface record;
     private HSSFComment              comment;
@@ -141,7 +141,7 @@ public class HSSFCell implements Cell
      */
 
     //protected HSSFCell(Workbook book, Sheet sheet, short row, short col)
-    protected HSSFCell(Workbook book, Sheet sheet, int row, short col)
+    protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row, short col)
     {
         checkBounds(col);
         stringValue  = null;
@@ -170,7 +170,7 @@ public class HSSFCell implements Cell
      */
 
     //protected HSSFCell(Workbook book, Sheet sheet, short row, short col,
-    protected HSSFCell(Workbook book, Sheet sheet, int row, short col,
+    protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row, short col,
                        int type)
     {
         checkBounds(col);
@@ -193,7 +193,7 @@ public class HSSFCell implements Cell
      */
 
     //protected HSSFCell(Workbook book, Sheet sheet, short row,
-    protected HSSFCell(Workbook book, Sheet sheet, int row,
+    protected HSSFCell(HSSFWorkbook book, Sheet sheet, int row,
                        CellValueRecordInterface cval)
     {
         record      = cval;
@@ -204,7 +204,7 @@ public class HSSFCell implements Cell
         switch (cellType)
         {
             case CELL_TYPE_STRING :
-                stringValue = new HSSFRichTextString(book, (LabelSSTRecord ) cval);
+                stringValue = new HSSFRichTextString(book.getWorkbook(), (LabelSSTRecord ) cval);
                 break;
 
             case CELL_TYPE_BLANK :
@@ -214,7 +214,7 @@ public class HSSFCell implements Cell
                 stringValue=new HSSFRichTextString(((FormulaRecordAggregate) cval).getStringValue());
                 break;
         }
-        ExtendedFormatRecord xf = book.getExFormatAt(cval.getXFIndex());
+        ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(cval.getXFIndex());
 
         setCellStyle(new HSSFCellStyle(( short ) cval.getXFIndex(), xf, book));
     }
@@ -270,7 +270,7 @@ public class HSSFCell implements Cell
      * @return
      */
     protected Workbook getBoundWorkbook() {
-       return book;
+       return book.getWorkbook();
     }
 
     /**
@@ -416,9 +416,9 @@ public class HSSFCell implements Cell
 //                      jmh                        {
 //                      jmh                            str.setUncompressedUnicode();
 //                      jmh                        }
-                        sst = book.addSSTString(str);
+                        sst = book.getWorkbook().addSSTString(str);
                         lrec.setSSTIndex(sst);
-                        getRichStringCellValue().setUnicodeString(book.getSSTString(sst));
+                        getRichStringCellValue().setUnicodeString(book.getWorkbook().getSSTString(sst));
                     }
                 }
                 record = lrec;
@@ -545,7 +545,7 @@ public class HSSFCell implements Cell
      */
     public void setCellValue(Date value)
     {
-        setCellValue(HSSFDateUtil.getExcelDate(value, this.book.isUsing1904DateWindowing()));
+        setCellValue(HSSFDateUtil.getExcelDate(value, this.book.getWorkbook().isUsing1904DateWindowing()));
     }
 
     /**
@@ -565,7 +565,7 @@ public class HSSFCell implements Cell
      */
     public void setCellValue(Calendar value)
     {
-        setCellValue( HSSFDateUtil.getExcelDate(value, this.book.isUsing1904DateWindowing()) );
+        setCellValue( HSSFDateUtil.getExcelDate(value, this.book.getWorkbook().isUsing1904DateWindowing()) );
     }
 
     /**
@@ -623,11 +623,11 @@ public class HSSFCell implements Cell
         int index = 0;
 
         UnicodeString str = hvalue.getUnicodeString();
-        index = book.addSSTString(str);
+        index = book.getWorkbook().addSSTString(str);
         (( LabelSSTRecord ) record).setSSTIndex(index);
         stringValue = hvalue;
-        stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record));
-        stringValue.setUnicodeString(book.getSSTString(index));
+        stringValue.setWorkbookReferences(book.getWorkbook(), (( LabelSSTRecord ) record));
+        stringValue.setUnicodeString(book.getWorkbook().getSSTString(index));
     }
 
     public void setCellFormula(String formula) {
@@ -737,7 +737,7 @@ public class HSSFCell implements Cell
                 "You cannot get a date value from an error cell");
         }
         double value=this.getNumericCellValue();
-        if (book.isUsing1904DateWindowing()) {
+        if (book.getWorkbook().isUsing1904DateWindowing()) {
             return HSSFDateUtil.getJavaDate(value,true);
         }
         else {
@@ -922,7 +922,7 @@ public class HSSFCell implements Cell
     public HSSFCellStyle getCellStyle()
     {
       short styleIndex=record.getXFIndex();
-      ExtendedFormatRecord xf = book.getExFormatAt(styleIndex);
+      ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(styleIndex);
       return new HSSFCellStyle(styleIndex, xf, book);
     }
 
index 6a08c4b3041267915396c25ca5346accbdb6c521..53706b58a66ad40b17d232c25469a59eee9f6ca8 100644 (file)
@@ -16,7 +16,6 @@
 ==================================================================== */
 package org.apache.poi.hssf.usermodel;
 
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
@@ -50,52 +49,46 @@ import org.apache.poi.ss.util.Region;
  * To create a new Conditional Formatting set use the following approach:
  * 
  * <PRE>
+ * 
+ * // Define a Conditional Formatting rule, which triggers formatting
+ * // when cell's value is greater or equal than 100.0 and
+ * // applies patternFormatting defined below.
+ * HSSFConditionalFormattingRule rule = sheet.createConditionalFormattingRule(
+ *     ComparisonOperator.GE, 
+ *     "100.0", // 1st formula 
+ *     null     // 2nd formula is not used for comparison operator GE
+ * );
+ * 
  * // Create pattern with red background
- * HSSFPatternFormatting patternFormatting = new HSSFPatternFormatting();
+ * HSSFPatternFormatting patternFmt = rule.cretePatternFormatting();
  * patternFormatting.setFillBackgroundColor(HSSFColor.RED.index);
  * 
+ * // Define a region containing first column
  * Region [] regions =
  * {
- *     // Define a region containing first column
  *     new Region(1,(short)1,-1,(short)1)
  * };
  *     
- * HSSFConditionalFormattingRule[] rules = 
- * {
- *     // Define a Conditional Formatting rule, which triggers formatting
- *     // when cell's value is greater or equal than 100.0 and
- *     // applies patternFormatting defined above.
- *         
- *     sheet.createConditionalFormattingRule(
- *             HSSFConditionalFormattingRule.COMPARISON_OPERATOR_GE, 
- *             "100.0", // 1st formula 
- *             null,    // 2nd formula is not used for comparison operator GE
- *             null,    // do not override Font Formatting
- *             null,    // do not override Border Formatting
- *             patternFormatting
- *     )
- * };
- *     
- * // Apply Conditional Formatting rules defined above to the regions  
- * sheet.addConditionalFormatting(regions, rules);
+ * // Apply Conditional Formatting rule defined above to the regions  
+ * sheet.addConditionalFormatting(regions, rule);
  * </PRE>
  * 
  * @author Dmitriy Kumshayev
  */
 public final class HSSFConditionalFormatting
 {
-       private final Workbook workbook;
+       private final HSSFWorkbook _workbook;
        private final CFRecordsAggregate cfAggregate;
 
-       HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate)
+       HSSFConditionalFormatting(HSSFWorkbook workbook, CFRecordsAggregate cfAggregate)
        {
-               if(sheet == null) {
-                       throw new IllegalArgumentException("sheet must not be null");
+               if(workbook == null) {
+                       throw new IllegalArgumentException("workbook must not be null");
                }
                if(cfAggregate == null) {
                        throw new IllegalArgumentException("cfAggregate must not be null");
                }
-               workbook = sheet.workbook.getWorkbook();
+               _workbook = workbook;
                this.cfAggregate = cfAggregate;
        }
        CFRecordsAggregate getCFRecordsAggregate() {
@@ -141,7 +134,7 @@ public final class HSSFConditionalFormatting
        public HSSFConditionalFormattingRule getRule(int idx)
        {
                CFRuleRecord ruleRecord = cfAggregate.getRule(idx);
-               return new HSSFConditionalFormattingRule(workbook, ruleRecord);
+               return new HSSFConditionalFormattingRule(_workbook, ruleRecord);
        }
 
        /**
index 490ff4d342e7c450bff3326834149c99c56f3a6f..1d4100655a686f5b9a0147116cb76f2160a7f045 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.poi.hssf.usermodel;
 
 import org.apache.poi.hssf.model.FormulaParser;
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
 import org.apache.poi.hssf.record.cf.BorderFormatting;
@@ -40,33 +39,36 @@ public final class HSSFConditionalFormattingRule
     private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
 
        private final CFRuleRecord cfRuleRecord;
-       private final Workbook workbook;
+       private final HSSFWorkbook workbook;
 
-       HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord) {
+       HSSFConditionalFormattingRule(HSSFWorkbook pWorkbook, CFRuleRecord pRuleRecord) {
                workbook = pWorkbook;
                cfRuleRecord = pRuleRecord;
        }
-       HSSFConditionalFormattingRule(Workbook pWorkbook, CFRuleRecord pRuleRecord, 
-                       HSSFFontFormatting fontFmt, HSSFBorderFormatting bordFmt, HSSFPatternFormatting patternFmt) {
-               this(pWorkbook, pRuleRecord);
-               setFontFormatting(fontFmt);
-               setBorderFormatting(bordFmt);
-               setPatternFormatting(patternFmt);
-       }
 
        CFRuleRecord getCfRuleRecord()
        {
                return cfRuleRecord;
        }
        
-       
-       /**
-        * @param fontFmt pass <code>null</code> to signify 'font unchanged'
-        */
-       public void setFontFormatting(HSSFFontFormatting fontFmt)
+       private HSSFFontFormatting getFontFormatting(boolean create)
        {
-               FontFormatting block = fontFmt==null ? null : fontFmt.getFontFormattingBlock();
-               cfRuleRecord.setFontFormatting(block);
+               FontFormatting fontFormatting = cfRuleRecord.getFontFormatting();
+               if ( fontFormatting != null) 
+               {
+                       cfRuleRecord.setFontFormatting(fontFormatting);
+                       return new HSSFFontFormatting(cfRuleRecord);
+               }
+               else if( create )
+               {
+                       fontFormatting = new FontFormatting();
+                       cfRuleRecord.setFontFormatting(fontFormatting);
+                       return new HSSFFontFormatting(cfRuleRecord);
+               }
+               else
+               {
+                       return null;
+               }
        }
        
        /**
@@ -74,50 +76,89 @@ public final class HSSFConditionalFormattingRule
         */
        public HSSFFontFormatting getFontFormatting()
        {
-               FontFormatting ff = cfRuleRecord.getFontFormatting();
-               if ( ff == null ) {
-                       return null;
-               }
-               return new HSSFFontFormatting(ff);
+               return getFontFormatting(false);
        }
-       
        /**
-        * @param borderFmt pass <code>null</code> to signify 'border unchanged'
+        * create a new font formatting structure if it does not exist, 
+        * otherwise just return existing object.
+        * @return - font formatting object, never returns <code>null</code>. 
         */
-       public void setBorderFormatting(HSSFBorderFormatting borderFmt)
+       public HSSFFontFormatting createFontFormatting()
+       {
+               return getFontFormatting(true);
+       }
+       
+       private HSSFBorderFormatting getBorderFormatting(boolean create)
        {
-               BorderFormatting block = borderFmt==null ? null : borderFmt.getBorderFormattingBlock();
-               cfRuleRecord.setBorderFormatting(block);
+               BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting();
+               if ( borderFormatting != null) 
+               {
+                       cfRuleRecord.setBorderFormatting(borderFormatting);
+                       return new HSSFBorderFormatting(cfRuleRecord);
+               }
+               else if( create )
+               {
+                       borderFormatting = new BorderFormatting();
+                       cfRuleRecord.setBorderFormatting(borderFormatting);
+                       return new HSSFBorderFormatting(cfRuleRecord);
+               }
+               else
+               {
+                       return null;
+               }
        }
        /**
         * @return - border formatting object  if defined,  <code>null</code> otherwise
         */
        public HSSFBorderFormatting getBorderFormatting()
        {
-               BorderFormatting bf = cfRuleRecord.getBorderFormatting();
-               if ( bf == null ) {
-                       return null;
-               }
-               return new HSSFBorderFormatting(bf);
+               return getBorderFormatting(false);
        }
        /**
-        * @param patternFmt pass <code>null</code> to signify 'pattern unchanged'
+        * create a new border formatting structure if it does not exist, 
+        * otherwise just return existing object.
+        * @return - border formatting object, never returns <code>null</code>. 
         */
-       public void setPatternFormatting(HSSFPatternFormatting patternFmt)
+       public HSSFBorderFormatting createBorderFormatting()
        {
-               PatternFormatting block = patternFmt==null ? null : patternFmt.getPatternFormattingBlock();
-               cfRuleRecord.setPatternFormatting(block);
+               return getBorderFormatting(true);
        }
+       
+       private HSSFPatternFormatting getPatternFormatting(boolean create)
+       {
+               PatternFormatting patternFormatting = cfRuleRecord.getPatternFormatting();
+               if ( patternFormatting != null) 
+               {
+                       cfRuleRecord.setPatternFormatting(patternFormatting);
+                       return new HSSFPatternFormatting(cfRuleRecord);
+               }
+               else if( create )
+               {
+                       patternFormatting = new PatternFormatting();
+                       cfRuleRecord.setPatternFormatting(patternFormatting);
+                       return new HSSFPatternFormatting(cfRuleRecord);
+               }
+               else
+               {
+                       return null;
+               }
+       }
+       
        /**
         * @return - pattern formatting object  if defined, <code>null</code> otherwise
         */
        public HSSFPatternFormatting getPatternFormatting()
        {
-               PatternFormatting pf = cfRuleRecord.getPatternFormatting();
-               if ( pf == null ) {
-                       return null;
-               }
-               return new HSSFPatternFormatting(pf);
+               return getPatternFormatting(false);
+       }
+       /**
+        * create a new pattern formatting structure if it does not exist, 
+        * otherwise just return existing object.
+        * @return - pattern formatting object, never returns <code>null</code>. 
+        */
+       public HSSFPatternFormatting createPatternFormatting()
+       {
+               return getPatternFormatting(true);
        }
        
        public String getFormula1()
index a701eb63afdd05388f58e95ff0c4fd6916b41dda..774bc1ea4d87b2aa55f850cdfbbf1f3c42269c46 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.cf.FontFormatting;
 /**
  * High level representation for Font Formatting component
@@ -33,28 +34,23 @@ public final class HSSFFontFormatting
        public final static short SS_SUPER = FontFormatting.SS_SUPER;
        /** Escapement type - Subscript */
        public final static short SS_SUB   = FontFormatting.SS_SUB;
-    
+
        /** Underline type - None */ 
        public final static byte U_NONE              = FontFormatting.U_NONE;
-    /** Underline type - Single */ 
+       /** Underline type - Single */ 
        public final static byte U_SINGLE            = FontFormatting.U_SINGLE;
-    /** Underline type - Double */ 
+       /** Underline type - Double */ 
        public final static byte U_DOUBLE            = FontFormatting.U_DOUBLE;
        /**  Underline type - Single Accounting */ 
        public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
-    /** Underline type - Double Accounting */ 
+       /** Underline type - Double Accounting */ 
        public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
-    
+
        private final FontFormatting fontFormatting;
        
-       public HSSFFontFormatting()
-       {
-               fontFormatting = new FontFormatting();
-       }
-
-       protected HSSFFontFormatting(FontFormatting ff)
+       protected HSSFFontFormatting(CFRuleRecord cfRuleRecord)
        {
-               fontFormatting = ff;
+               this.fontFormatting = cfRuleRecord.getFontFormatting();
        }
        
        protected FontFormatting getFontFormattingBlock()
index 3da5f968829cf9eb8371bc9958e90f71621d27b1..57ec2500388603db834192fb3e6069e13d68bfa1 100644 (file)
@@ -20,12 +20,8 @@ package org.apache.poi.hssf.usermodel;
 import org.apache.poi.hssf.model.FormulaParser;
 import org.apache.poi.hssf.record.formula.OperationPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CreationHelper;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.FormulaEvaluator.CellValue;
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@@ -44,7 +40,7 @@ public class HSSFFormulaEvaluator extends FormulaEvaluator {
      *  formula evaluated. 
      */
     public static FormulaParser getUnderlyingParser(HSSFWorkbook workbook, String formula) {
-        return new FormulaParser(formula, workbook.getWorkbook());
+        return new FormulaParser(formula, workbook);
     }
     
 
@@ -57,7 +53,7 @@ public class HSSFFormulaEvaluator extends FormulaEvaluator {
      */
     void inspectPtgs(String formula) {
        HSSFWorkbook hssfWb = (HSSFWorkbook)workbook;
-        FormulaParser fp = new FormulaParser(formula, hssfWb.getWorkbook());
+        FormulaParser fp = new FormulaParser(formula, hssfWb);
         fp.parse();
         Ptg[] ptgs = fp.getRPNPtg();
         System.out.println("<ptg-group>");
index 501373e35f38d18b834861f7490cbd1264db6696..4152e3ae19175810a4b946907580b51b8da67bcf 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.ss.usermodel.Name;
  */
 
 public class HSSFName implements Name {
-    private Workbook         book;
+    private HSSFWorkbook         book;
     private NameRecord       name;
     
     /** Creates new HSSFName   - called by HSSFWorkbook to create a sheet from
@@ -40,7 +40,7 @@ public class HSSFName implements Name {
      * @param book lowlevel Workbook object associated with the sheet.
      */
     
-    protected HSSFName(Workbook book, NameRecord name) {
+    protected HSSFName(HSSFWorkbook book, NameRecord name) {
         this.book = book;
         this.name = name;
     }
@@ -53,7 +53,7 @@ public class HSSFName implements Name {
         String result ;
         short indexToExternSheet = name.getExternSheetNumber();
         
-        result = book.findSheetNameFromExternSheet(indexToExternSheet);
+        result = book.getWorkbook().findSheetNameFromExternSheet(indexToExternSheet);
         
         return result;
     }
@@ -77,11 +77,12 @@ public class HSSFName implements Name {
     public void setNameName(String nameName){
         name.setNameText(nameName);
         name.setNameTextLength((byte)nameName.length());
+        Workbook wb = book.getWorkbook();
         
         //Check to ensure no other names have the same case-insensitive name
-        for ( int i = book.getNumNames()-1; i >=0; i-- )
+        for ( int i = wb.getNumNames()-1; i >=0; i-- )
         {
-               NameRecord rec = book.getNameRecord(i);
+               NameRecord rec = wb.getNameRecord(i);
                if (rec != name) {
                        if (rec.getNameText().equalsIgnoreCase(getNameName()))
                                throw new IllegalArgumentException("The workbook already contains this name (case-insensitive)");
@@ -111,7 +112,7 @@ public class HSSFName implements Name {
     private void setSheetName(String sheetName){
         int sheetNumber = book.getSheetIndex(sheetName);
 
-        short externSheetNumber = book.checkExternSheet(sheetNumber);
+        short externSheetNumber = book.getExternalSheetIndex(sheetNumber);
         name.setExternSheetNumber(externSheetNumber);
 //        name.setIndexToSheet(externSheetNumber);
 
index b94d19601a5ad1db4ed14e46ddb8f5e73d757249..cb1ae9365eaaae0aef175f9a57589abf8a4628ac 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.cf.PatternFormatting;
 
 /**
@@ -66,15 +67,13 @@ public class HSSFPatternFormatting
        /**  Least Dots */
        public final static short LEAST_DOTS                    =  PatternFormatting.LEAST_DOTS;
 
-       private PatternFormatting patternFormatting;
+       private final CFRuleRecord cfRuleRecord;
+       private final PatternFormatting patternFormatting;
        
-       public HSSFPatternFormatting()
+       protected HSSFPatternFormatting(CFRuleRecord cfRuleRecord)
        {
-               patternFormatting = new PatternFormatting();
-       }
-       protected HSSFPatternFormatting(PatternFormatting patternFormatting)
-       {
-               this.patternFormatting = patternFormatting;
+               this.cfRuleRecord = cfRuleRecord; 
+               this.patternFormatting = cfRuleRecord.getPatternFormatting();
        }
 
        protected PatternFormatting getPatternFormattingBlock()
@@ -116,6 +115,10 @@ public class HSSFPatternFormatting
        public void setFillBackgroundColor(short bg)
        {
                patternFormatting.setFillBackgroundColor(bg);
+               if( bg != 0)
+               {
+                       cfRuleRecord.setPatternBackgroundColorModified(true);
+               }
        }
 
        /**
@@ -125,6 +128,10 @@ public class HSSFPatternFormatting
        public void setFillForegroundColor(short fg)
        {
                patternFormatting.setFillForegroundColor(fg);
+               if( fg != 0)
+               {
+                       cfRuleRecord.setPatternColorModified(true);
+               }
        }
 
        /**
@@ -134,5 +141,9 @@ public class HSSFPatternFormatting
        public void setFillPattern(short fp)
        {
                patternFormatting.setFillPattern(fp);
+               if( fp != 0)
+               {
+                       cfRuleRecord.setPatternStyleModified(true);
+               }
        }
 }
index 06a704d7f00e184ac467f9c34d208f8f7aa38647..5a154c6faceabafef804529bdcc04e398d936b7e 100644 (file)
@@ -55,7 +55,7 @@ public final class HSSFRow implements Comparable, Row {
      * reference to containing low level Workbook
      */
 
-    private Workbook book;
+    private HSSFWorkbook book;
 
     /**
      * reference to containing Sheet
@@ -77,7 +77,7 @@ public final class HSSFRow implements Comparable, Row {
      */
 
     //protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
-    protected HSSFRow(Workbook book, Sheet sheet, int rowNum)
+    protected HSSFRow(HSSFWorkbook book, Sheet sheet, int rowNum)
     {
         this.rowNum = rowNum;
         this.book = book;
@@ -101,7 +101,7 @@ public final class HSSFRow implements Comparable, Row {
      * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
      */
 
-    protected HSSFRow(Workbook book, Sheet sheet, RowRecord record)
+    protected HSSFRow(HSSFWorkbook book, Sheet sheet, RowRecord record)
     {
         this.book = book;
         this.sheet = sheet;
index 992a0f5ee7d827828b45444785460fe0a5fc9c01..230d4bea389ef56a798a929e6c6bf6472d229bfa 100644 (file)
@@ -49,7 +49,6 @@ import org.apache.poi.hssf.record.SCLRecord;
 import org.apache.poi.hssf.record.VCenterRecord;
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
-import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.ReferencePtg;
 import org.apache.poi.hssf.util.HSSFCellRangeAddress;
@@ -210,7 +209,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
      */
     public HSSFRow createRow(int rownum)
     {
-        HSSFRow row = new HSSFRow(book, sheet, rownum);
+        HSSFRow row = new HSSFRow(workbook, sheet, rownum);
 
         addRow(row, true);
         return row;
@@ -225,7 +224,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
 
     private HSSFRow createRowFromRecord(RowRecord row)
     {
-        HSSFRow hrow = new HSSFRow(book, sheet, row);
+        HSSFRow hrow = new HSSFRow(workbook, sheet, row);
 
         addRow(hrow, false);
         return hrow;
@@ -411,7 +410,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
 
        //formula fields ( size and data )
        String str_formula = obj_validation.getFirstFormula();
-       FormulaParser fp = new FormulaParser(str_formula, book);
+       FormulaParser fp = new FormulaParser(str_formula, workbook);
        fp.parse();
        Stack ptg_arr = new Stack();
        Ptg[] ptg  = fp.getRPNPtg();
@@ -435,7 +434,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
        if ( obj_validation.getSecondFormula() != null )
        {
          str_formula = obj_validation.getSecondFormula();
-         fp = new FormulaParser(str_formula, book);
+         fp = new FormulaParser(str_formula, workbook);
          fp.parse();
          ptg_arr = new Stack();
          ptg  = fp.getRPNPtg();
@@ -1281,7 +1280,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
                     // Since it's a formula cell, process the
                     //  formula string, and look to see if
                     //  it contains any references
-                    FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook());
+                    FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook);
                     fp.parse();
 
                     // Look for references, and update if needed
@@ -1856,137 +1855,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
         return null;
     }
 
-
-     /**
-      * A factory method allowing to create a conditional formatting rule
-      * with a cell comparison operator and
-      * formatting rules such as font format, border format and pattern format
-      *
-      * @param comparisonOperation - a constant value from
-      *         <tt>{@link HSSFConditionalFormattingRule.ComparisonOperator}</tt>: <p>
-      * <ul>
-      *         <li>BETWEEN</li>
-      *         <li>NOT_BETWEEN</li>
-      *         <li>EQUAL</li>
-      *         <li>NOT_EQUAL</li>
-      *         <li>GT</li>
-      *         <li>LT</li>
-      *         <li>GE</li>
-      *         <li>LE</li>
-      * </ul>
-      * </p>
-      * @param formula1 - formula for the valued, compared with the cell
-      * @param formula2 - second formula (only used with
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
-      * @param fontFmt - font formatting rules (may be <code>null</code>)
-      * @param bordFmt - border formatting rules (may be <code>null</code>)
-      * @param patternFmt - pattern formatting rules (may be <code>null</code>)
-      */
-     public HSSFConditionalFormattingRule createConditionalFormattingRule(
-             byte comparisonOperation,
-             String formula1,
-             String formula2,
-             HSSFFontFormatting fontFmt,
-             HSSFBorderFormatting bordFmt,
-             HSSFPatternFormatting patternFmt) {
-        
-        Workbook wb = workbook.getWorkbook();
-        CFRuleRecord rr = CFRuleRecord.create(wb, comparisonOperation, formula1, formula2);
-        return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
-     }
-
-     /**
-      * A factory method allowing to create a conditional formatting rule with a formula
-      * and formatting rules such as font format, border format and pattern format. <br>
-      *
-      * The formatting rules are applied by Excel when the value of the formula not equal to 0.
-      *
-      * @param formula - formula for the valued, compared with the cell
-      * @param fontFmt - font formatting rules (may be <code>null</code>)
-      * @param bordFmt - border formatting rules (may be <code>null</code>)
-      * @param patternFmt - pattern formatting rules (may be <code>null</code>)
-      */
-     public HSSFConditionalFormattingRule createConditionalFormattingRule(
-             String formula,
-             HSSFFontFormatting fontFmt,
-             HSSFBorderFormatting bordFmt,
-             HSSFPatternFormatting patternFmt) {
-         Workbook wb = workbook.getWorkbook();
-         CFRuleRecord rr = CFRuleRecord.create(wb, formula);
-         return new HSSFConditionalFormattingRule(wb, rr, fontFmt, bordFmt, patternFmt);
-     }
-
-     /**
-      * Adds a copy of HSSFConditionalFormatting object to the sheet
-      * <p>This method could be used to copy HSSFConditionalFormatting object
-      * from one sheet to another. For example:
-      * <pre>
-      * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
-      * newSheet.addConditionalFormatting(cf);
-      * </pre>
-      *
-      * @param cf HSSFConditionalFormatting object
-      * @return index of the new Conditional Formatting object
-      */
-     public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
-         CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
-
-         return sheet.addConditionalFormatting(cfraClone);
-     }
-
-     /**
-      * Allows to add a new Conditional Formatting set to the sheet.
-      *
-      * @param regions - list of rectangular regions to apply conditional formatting rules
-      * @param hcfRules - set of up to three conditional formatting rules
-      *
-      * @return index of the newly created Conditional Formatting object
-      */
-
-    public int addConditionalFormatting(Region [] regions, HSSFConditionalFormattingRule [] hcfRules) {
-        if (regions == null) {
-            throw new IllegalArgumentException("regions must not be null");
-        }
-        if (hcfRules == null) {
-            throw new IllegalArgumentException("hcfRules must not be null");
-        }
-
-        CFRuleRecord[] rules = new CFRuleRecord[hcfRules.length];
-        for (int i = 0; i != hcfRules.length; i++) {
-            rules[i] = hcfRules[i].getCfRuleRecord();
-        }
-        CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
-        return sheet.addConditionalFormatting(cfra);
-     }
-
-    /**
-     * gets Conditional Formatting object at a particular index
-     * 
-     * @param index
-     *            of the Conditional Formatting object to fetch
-     * @return Conditional Formatting object
-     */
-    public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
-        CFRecordsAggregate cf = sheet.getCFRecordsAggregateAt(index);
-        if (cf == null) {
-            return null;
-        }
-        return new HSSFConditionalFormatting(this,cf);
-    }
-
-    /**
-     * @return number of Conditional Formatting objects of the sheet
-     */
-    public int getNumConditionalFormattings() {
-        return sheet.getNumConditionalFormattings();
-    }
-
-    /**
-     * removes a Conditional Formatting object by index
-     * @param index of a Conditional Formatting object to remove
-     */
-    public void removeConditionalFormatting(int index) {
-        sheet.removeConditionalFormatting(index);
+    public HSSFSheetConditionalFormatting getSheetConditionalFormatting() {
+        return new HSSFSheetConditionalFormatting(workbook, sheet);
     }
 }
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
new file mode 100644 (file)
index 0000000..c042456
--- /dev/null
@@ -0,0 +1,196 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hssf.usermodel;\r
+\r
+import org.apache.poi.hssf.model.Sheet;\r
+import org.apache.poi.hssf.record.CFRuleRecord;\r
+import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;\r
+import org.apache.poi.ss.util.Region;\r
+\r
+/**\r
+ * The 'Conditional Formatting' facet of <tt>HSSFSheet</tt>\r
+ * \r
+ * @author Dmitriy Kumshayev\r
+ */\r
+public final class HSSFSheetConditionalFormatting {\r
+       \r
+       private final HSSFWorkbook _workbook;\r
+       private final Sheet _sheet;\r
+\r
+       /* package */ HSSFSheetConditionalFormatting(HSSFWorkbook workbook, Sheet sheet) {\r
+               _workbook = workbook;\r
+               _sheet = sheet;\r
+       }\r
+\r
+       /**\r
+        * A factory method allowing to create a conditional formatting rule\r
+        * with a cell comparison operator \r
+        *\r
+        * @param comparisonOperation - a constant value from\r
+        *               <tt>{@link HSSFConditionalFormattingRule.ComparisonOperator}</tt>: <p>\r
+        * <ul>\r
+        *               <li>BETWEEN</li>\r
+        *               <li>NOT_BETWEEN</li>\r
+        *               <li>EQUAL</li>\r
+        *               <li>NOT_EQUAL</li>\r
+        *               <li>GT</li>\r
+        *               <li>LT</li>\r
+        *               <li>GE</li>\r
+        *               <li>LE</li>\r
+        * </ul>\r
+        * </p>\r
+        * @param formula1 - formula for the valued, compared with the cell\r
+        * @param formula2 - second formula (only used with\r
+        * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and\r
+        * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)\r
+        */\r
+       public HSSFConditionalFormattingRule createConditionalFormattingRule(\r
+                       byte comparisonOperation,\r
+                       String formula1,\r
+                       String formula2) {\r
+\r
+               HSSFWorkbook wb = _workbook;\r
+               CFRuleRecord rr = CFRuleRecord.create(wb, comparisonOperation, formula1, formula2);\r
+               return new HSSFConditionalFormattingRule(wb, rr);\r
+       }\r
+\r
+       /**\r
+        * A factory method allowing to create a conditional formatting rule with a formula.<br>\r
+        *\r
+        * The formatting rules are applied by Excel when the value of the formula not equal to 0.\r
+        *\r
+        * @param formula - formula for the valued, compared with the cell\r
+        */\r
+       public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {\r
+               HSSFWorkbook wb = _workbook;\r
+               CFRuleRecord rr = CFRuleRecord.create(wb, formula);\r
+               return new HSSFConditionalFormattingRule(wb, rr);\r
+       }\r
+\r
+       /**\r
+        * Adds a copy of HSSFConditionalFormatting object to the sheet\r
+        * <p>This method could be used to copy HSSFConditionalFormatting object\r
+        * from one sheet to another. For example:\r
+        * <pre>\r
+        * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);\r
+        * newSheet.addConditionalFormatting(cf);\r
+        * </pre>\r
+        *\r
+        * @param cf HSSFConditionalFormatting object\r
+        * @return index of the new Conditional Formatting object\r
+        */\r
+       public int addConditionalFormatting( HSSFConditionalFormatting cf ) {\r
+               CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();\r
+\r
+               return _sheet.addConditionalFormatting(cfraClone);\r
+       }\r
+\r
+       /**\r
+        * Allows to add a new Conditional Formatting set to the sheet.\r
+        *\r
+        * @param regions - list of rectangular regions to apply conditional formatting rules\r
+        * @param cfRules - set of up to three conditional formatting rules\r
+        *\r
+        * @return index of the newly created Conditional Formatting object\r
+        */\r
+\r
+       public int addConditionalFormatting(Region[] regions, HSSFConditionalFormattingRule[] cfRules) {\r
+               if (regions == null) {\r
+                       throw new IllegalArgumentException("regions must not be null");\r
+               }\r
+               if (cfRules == null) {\r
+                       throw new IllegalArgumentException("cfRules must not be null");\r
+               }\r
+               if (cfRules.length == 0) {\r
+                       throw new IllegalArgumentException("cfRules must not be empty");\r
+               }\r
+               if (cfRules.length > 3) {\r
+                       throw new IllegalArgumentException("Number of rules must not exceed 3");\r
+               }\r
+\r
+               CFRuleRecord[] rules = new CFRuleRecord[cfRules.length];\r
+               for (int i = 0; i != cfRules.length; i++) {\r
+                       rules[i] = cfRules[i].getCfRuleRecord();\r
+               }\r
+               CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);\r
+               return _sheet.addConditionalFormatting(cfra);\r
+       }\r
+\r
+       public int addConditionalFormatting(Region[] regions,\r
+                       HSSFConditionalFormattingRule rule1)\r
+       {\r
+               return addConditionalFormatting(regions,\r
+                               new HSSFConditionalFormattingRule[]\r
+                               {\r
+                                       rule1\r
+                               });\r
+       }\r
+\r
+       public int addConditionalFormatting(Region[] regions,\r
+                       HSSFConditionalFormattingRule rule1,\r
+                       HSSFConditionalFormattingRule rule2)\r
+       {\r
+               return addConditionalFormatting(regions,\r
+                               new HSSFConditionalFormattingRule[]\r
+                               {\r
+                                               rule1, rule2\r
+                               });\r
+       }\r
+\r
+       public int addConditionalFormatting(Region[] regions,\r
+                       HSSFConditionalFormattingRule rule1,\r
+                       HSSFConditionalFormattingRule rule2,\r
+                       HSSFConditionalFormattingRule rule3)\r
+       {\r
+               return addConditionalFormatting(regions,\r
+                               new HSSFConditionalFormattingRule[]\r
+                               {\r
+                                               rule1, rule2, rule3\r
+                               });\r
+       }\r
+\r
+       /**\r
+       * gets Conditional Formatting object at a particular index\r
+       * \r
+       * @param index\r
+       *                       of the Conditional Formatting object to fetch\r
+       * @return Conditional Formatting object\r
+       */\r
+       public HSSFConditionalFormatting getConditionalFormattingAt(int index) {\r
+               CFRecordsAggregate cf = _sheet.getCFRecordsAggregateAt(index);\r
+               if (cf == null) {\r
+                       return null;\r
+               }\r
+               return new HSSFConditionalFormatting(_workbook, cf);\r
+       }\r
+\r
+       /**\r
+       * @return number of Conditional Formatting objects of the sheet\r
+       */\r
+       public int getNumConditionalFormattings() {\r
+               return _sheet.getNumConditionalFormattings();\r
+       }\r
+\r
+       /**\r
+       * removes a Conditional Formatting object by index\r
+       * @param index of a Conditional Formatting object to remove\r
+       */\r
+       public void removeConditionalFormatting(int index) {\r
+               _sheet.removeConditionalFormatting(index);\r
+       }\r
+}\r
index 57f44148b8fd8c4d41383dbf7998d2499fb4a7b6..41356948306609d84abd75a818f360b81d4b5ec5 100644 (file)
@@ -62,6 +62,7 @@ import org.apache.poi.hssf.record.formula.Area3DPtg;
 import org.apache.poi.hssf.record.formula.MemFuncPtg;
 import org.apache.poi.hssf.record.formula.UnionPtg;
 import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.hssf.util.SheetReferences;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.CreationHelper;
@@ -266,7 +267,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
         }
 
         for (int i = 0 ; i < workbook.getNumNames() ; ++i){
-            HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i));
+            HSSFName name = new HSSFName(this, workbook.getNameRecord(i));
             names.add(name);
         }
     }
@@ -539,6 +540,17 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
        }
        return -1;
     }
+    
+    /**
+     * Returns the external sheet index of the sheet
+     *  with the given internal index, creating one
+     *  if needed.
+     * Used by some of the more obscure formula and 
+     *  named range things.
+     */
+    public short getExternalSheetIndex(int internalSheetIndex) {
+       return workbook.checkExternSheet(internalSheetIndex);
+    }
 
     /**
      * create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
@@ -668,6 +680,10 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
         }
         return retval;
     }
+    
+    public SheetReferences getSheetReferences() {
+       return workbook.getSheetReferences();
+    }
 
     /**
      * removes sheet at the given index
@@ -811,7 +827,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
 
         if (isNewRecord)
         {
-            HSSFName newName = new HSSFName(workbook, nameRecord);
+            HSSFName newName = new HSSFName(this, nameRecord);
             names.add(newName);
         }
 
@@ -1122,6 +1138,17 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
 
         return result;
     }
+    
+    /**
+     * TODO - make this less cryptic / move elsewhere
+     * @param refIndex Index to REF entry in EXTERNSHEET record in the Link Table
+     * @param definedNameIndex zero-based to DEFINEDNAME or EXTERNALNAME record
+     * @return the string representation of the defined or external name
+     */
+    public String resolveNameXText(int refIndex, int definedNameIndex) {
+       return workbook.resolveNameXText(refIndex, definedNameIndex);
+    }
+
 
        /**
         * Sets the printarea for the sheet provided
@@ -1180,7 +1207,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
                if (name == null) return null;
                //adding one here because 0 indicates a global named region; doesnt make sense for print areas
 
-               return name.getAreaReference(workbook);
+               return name.getAreaReference(this);
        }
 
     /**
@@ -1197,7 +1224,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
     public HSSFName createName(){
         NameRecord nameRecord = workbook.createName();
 
-        HSSFName newName = new HSSFName(workbook, nameRecord);
+        HSSFName newName = new HSSFName(this, nameRecord);
 
         names.add(newName);
 
index 0f28c2a8c921df2085799870490ee67419042506..962349876a0736f1a7a6676fef4774c6b2441964 100755 (executable)
@@ -459,6 +459,7 @@ public class ApacheconEU08 {
         TextBox box2 = new TextBox();\r
         TextRun tr2 = box2.getTextRun();\r
         tr2.setRunType(TextHeaderAtom.BODY_TYPE);\r
+        tr2.getRichTextRuns()[0].setFontSize(32);\r
         tr2.setText(\r
                 "Support for more PowerPoint functionality\r" +\r
                 "Rendering slides into java.awt.Graphics2D");\r
@@ -477,6 +478,7 @@ public class ApacheconEU08 {
         TextBox box4 = new TextBox();\r
         TextRun tr4 = box4.getTextRun();\r
         tr4.setRunType(TextHeaderAtom.BODY_TYPE);\r
+        tr4.getRichTextRuns()[0].setFontSize(32);\r
         tr4.setText(\r
                 "Integration with Apache FOP - Formatting Objects Processor");\r
         box4.setAnchor(new Rectangle(36, 290, 648, 90));\r
index b3ddce37da7961be68a97bdae606324e2671e422..cf65a9b13cb2cf3007cab12b461a81f71925f08f 100644 (file)
@@ -20,11 +20,15 @@ package org.apache.poi.hslf.model;
 import org.apache.poi.ddf.*;
 
 /**
- * Represents a autoshape in a PowerPoint drawing
+ * Represents an AutoShape.
+ * <p>
+ * AutoShapes are drawing objects with a particular shape that may be customized through smart resizing and adjustments.
+ * See {@link ShapeTypes}
+ * </p>
  *
  *  @author Yegor Kozlov
  */
-public class AutoShape extends SimpleShape {
+public class AutoShape extends TextShape {
 
     protected AutoShape(EscherContainerRecord escherRecord, Shape parent){
         super(escherRecord, parent);
@@ -40,23 +44,62 @@ public class AutoShape extends SimpleShape {
     }
 
     protected EscherContainerRecord createSpContainer(int shapeType, boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
+        _escherContainer = super.createSpContainer(isChild);
 
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
-        short type = (short)((shapeType << 4) | 0x2);
-        spRecord.setOptions(type);
+        setShapeType(shapeType);
 
         //set default properties for an autoshape
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+        setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
+        setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+        setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+        setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
+        setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010);
+        setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+        setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008);
+        setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
 
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008));
-        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002));
+        return _escherContainer;
+    }
+
+    protected void setDefaultTextProperties(TextRun _txtrun){
+        setVerticalAlignment(TextBox.AnchorMiddle);
+        setHorizontalAlignment(TextBox.AlignCenter);
+        setWordWrap(TextBox.WrapNone);
+    }
 
-        return spcont;
+    /**
+     * Gets adjust value which controls smart resizing of the auto-shape.
+     *
+     * <p>
+     * The adjustment values are given in shape coordinates:
+     * the origin is at the top-left, positive-x is to the right, positive-y is down.
+     * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
+     * </p>
+     *
+     * @param idx the adjust index in the [0, 9] range
+     * @return the adjustment value
+     */
+    public int getAdjustmentValue(int idx){
+        if(idx < 0 || idx > 9) throw new IllegalArgumentException("The index of an adjustment value must be in the [0, 9] range");
+
+        return getEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx));
     }
 
+    /**
+     * Sets adjust value which controls smart resizing of the auto-shape.
+     *
+     * <p>
+     * The adjustment values are given in shape coordinates:
+     * the origin is at the top-left, positive-x is to the right, positive-y is down.
+     * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
+     * </p>
+     *
+     * @param idx the adjust index in the [0, 9] range
+     * @param val the adjustment value
+     */
+    public void setAdjustmentValue(int idx, int val){
+        if(idx < 0 || idx > 9) throw new IllegalArgumentException("The index of an adjustment value must be in the [0, 9] range");
+
+        setEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx), val);
+    }
 }
index 0d3f616e929352895d6cd9b31d2b118fcb9f92ce..9237183689aef981e9985767d16b3a0a08949d49 100644 (file)
@@ -106,14 +106,14 @@ public class Line extends SimpleShape {
     }
 
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
+        _escherContainer = super.createSpContainer(isChild);
 
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         short type = (ShapeTypes.Line << 4) | 0x2;
         spRecord.setOptions(type);
   
         //set default properties for a line
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
 
         //default line properties
         setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
@@ -123,7 +123,7 @@ public class Line extends SimpleShape {
         setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
         setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
 
-        return spcont;
+        return _escherContainer;
     }
 
 }
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java b/src/scratchpad/src/org/apache/poi/hslf/model/PPFont.java
new file mode 100755 (executable)
index 0000000..8b4de90
--- /dev/null
@@ -0,0 +1,243 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.model;\r
+\r
+import org.apache.poi.hslf.record.FontEntityAtom;\r
+\r
+/**\r
+ * Represents a Font used in a presenation.\r
+ * <p>\r
+ * In PowerPoint Font is a shared resource and can be shared among text object in the presentation.\r
+ * </p>\r
+ * Some commonly used fonts are predefined in static constants. \r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class PPFont {\r
+    /**\r
+     * ANSI character set\r
+     */\r
+    public final static byte ANSI_CHARSET = 0;\r
+\r
+    /**\r
+     * Default character set.\r
+     */\r
+    public final static byte DEFAULT_CHARSET = 1;\r
+\r
+    /**\r
+     * Symbol character set\r
+     */\r
+    public final static byte SYMBOL_CHARSET = 2;\r
+\r
+\r
+    /**\r
+     * Constants for the pitch and family of the font.\r
+     * The two low-order bits specify the pitch of the font and can be one of the following values\r
+     */\r
+    public final static byte DEFAULT_PITCH  = 0;\r
+    public final static byte FIXED_PITCH    = 1;\r
+    public final static byte VARIABLE_PITCH = 2;\r
+\r
+    /**\r
+     * Don't care or don't know.\r
+     */\r
+    public final static byte FF_DONTCARE    = 0;\r
+    /**\r
+     * Fonts with variable stroke width (proportional) and with serifs. Times New Roman is an example.\r
+     */\r
+    public final static byte FF_ROMAN       = 16;\r
+    /**\r
+     * Fonts with variable stroke width (proportional) and without serifs. Arial is an example.\r
+     */\r
+    public final static byte FF_SWISS       = 32;\r
+    /**\r
+     * Fonts designed to look like handwriting. Script and Cursive are examples.\r
+     */\r
+    public final static byte FF_SCRIPT      = 64;\r
+    /**\r
+     * Fonts with constant stroke width (monospace), with or without serifs.\r
+     * Monospace fonts are usually modern. CourierNew is an example\r
+     */\r
+    public final static byte FF_MODERN      = 48;\r
+    /**\r
+     * Novelty fonts. Old English is an example\r
+     */\r
+    public final static byte FF_DECORATIVE  = 80;\r
+\r
+\r
+    protected int charset;\r
+    protected int type;\r
+    protected int flags;\r
+    protected int pitch;\r
+    protected String name;\r
+\r
+    /**\r
+     * Creates a new instance of PPFont\r
+     */\r
+    public PPFont(){\r
+\r
+    }\r
+\r
+    /**\r
+     * Creates a new instance of PPFont and initialize it from the supplied font atom\r
+     */\r
+    public PPFont(FontEntityAtom fontAtom){\r
+        name = fontAtom.getFontName();\r
+        charset = fontAtom.getCharSet();\r
+        type = fontAtom.getFontType();\r
+        flags = fontAtom.getFontFlags();\r
+        pitch = fontAtom.getPitchAndFamily();\r
+    }\r
+\r
+    /**\r
+     * set the name for the font (i.e. Arial)\r
+     *\r
+     * @param val  String representing the name of the font to use\r
+     */\r
+     public void setFontName(String val){\r
+        name = val;\r
+    }\r
+\r
+    /**\r
+     * get the name for the font (i.e. Arial)\r
+     *\r
+     * @return String representing the name of the font to use\r
+     */\r
+    public String getFontName(){\r
+        return name;\r
+    }\r
+\r
+    /**\r
+     * set the character set\r
+     *\r
+     * @param val - characterset\r
+     */\r
+    public void setCharSet(int val){\r
+        charset = val;\r
+    }\r
+\r
+    /**\r
+     * get the character set\r
+     *\r
+     * @return charset - characterset\r
+     */\r
+    public int getCharSet(){\r
+        return charset;\r
+    }\r
+\r
+    /**\r
+     * set the font flags\r
+     * Bit 1: If set, font is subsetted\r
+     *\r
+     * @param val - the font flags\r
+     */\r
+    public void setFontFlags(int val){\r
+        flags = val;\r
+    }\r
+\r
+    /**\r
+     * get the character set\r
+     * Bit 1: If set, font is subsetted\r
+     *\r
+     * @return the font flags\r
+     */\r
+    public int getFontFlags(){\r
+        return flags;\r
+    }\r
+\r
+    /**\r
+     * set the font type\r
+     * <p>\r
+     * Bit 1: Raster Font\r
+     * Bit 2: Device Font\r
+     * Bit 3: TrueType Font\r
+     * </p>\r
+     *\r
+     * @param val - the font type\r
+     */\r
+    public void setFontType(int val){\r
+        type = val;\r
+    }\r
+\r
+    /**\r
+     * get the font type\r
+     * <p>\r
+     * Bit 1: Raster Font\r
+     * Bit 2: Device Font\r
+     * Bit 3: TrueType Font\r
+     * </p>\r
+     *\r
+     * @return the font type\r
+     */\r
+    public int getFontType(){\r
+        return type;\r
+    }\r
+\r
+    /**\r
+     * set lfPitchAndFamily\r
+     *\r
+     *\r
+     * @param val - Corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure\r
+     */\r
+    public void setPitchAndFamily(int val){\r
+        pitch = val;\r
+    }\r
+\r
+    /**\r
+     * get lfPitchAndFamily\r
+     *\r
+     * @return corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure\r
+     */\r
+    public int getPitchAndFamily(){\r
+        return pitch;\r
+    }\r
+\r
+    public static final PPFont ARIAL;\r
+    public static final PPFont TIMES_NEW_ROMAN ;\r
+    public static final PPFont COURIER_NEW;\r
+    public static final PPFont WINGDINGS;\r
+    static {\r
+        ARIAL = new PPFont();\r
+        ARIAL.setFontName("Arial");\r
+        ARIAL.setCharSet(ANSI_CHARSET);\r
+        ARIAL.setFontType(4);\r
+        ARIAL.setFontFlags(0);\r
+        ARIAL.setPitchAndFamily(VARIABLE_PITCH | FF_SWISS);\r
+\r
+        TIMES_NEW_ROMAN = new PPFont();\r
+        TIMES_NEW_ROMAN.setFontName("Times New Roman");\r
+        TIMES_NEW_ROMAN.setCharSet(ANSI_CHARSET);\r
+        TIMES_NEW_ROMAN.setFontType(4);\r
+        TIMES_NEW_ROMAN.setFontFlags(0);\r
+        TIMES_NEW_ROMAN.setPitchAndFamily(VARIABLE_PITCH | FF_ROMAN);\r
+\r
+        COURIER_NEW = new PPFont();\r
+        COURIER_NEW.setFontName("Courier New");\r
+        COURIER_NEW.setCharSet(ANSI_CHARSET);\r
+        COURIER_NEW.setFontType(4);\r
+        COURIER_NEW.setFontFlags(0);\r
+        COURIER_NEW.setPitchAndFamily(FIXED_PITCH | FF_MODERN);\r
+\r
+        WINGDINGS = new PPFont();\r
+        WINGDINGS.setFontName("Wingdings");\r
+        WINGDINGS.setCharSet(SYMBOL_CHARSET);\r
+        WINGDINGS.setFontType(4);\r
+        WINGDINGS.setFontFlags(0);\r
+        WINGDINGS.setPitchAndFamily(VARIABLE_PITCH | FF_DONTCARE);\r
+    }\r
+}\r
index 90efd5f3ee5a1f41348ede304f5097b43861fc97..910d5c850344e79d12dc4aa68cd65e5bcaeb68b7 100644 (file)
@@ -120,20 +120,20 @@ public class Picture extends SimpleShape {
      * @return the create Picture object
      */
     protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
-        EscherContainerRecord spContainer = super.createSpContainer(isChild);
-        spContainer.setOptions((short)15);
+        _escherContainer = super.createSpContainer(isChild);
+        _escherContainer.setOptions((short)15);
 
-        EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2));
 
         //set default properties for a picture
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
         setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 8388736);
 
         //another weird feature of powerpoint: for picture id we must add 0x4000.
         setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
 
-        return spContainer;
+        return _escherContainer;
     }
 
     /**
index dd0132ebe0926c610ae229cd34c3ff647468b779..f0bc74558fe3d28cfc46c29335c88f9207a7b949 100644 (file)
@@ -49,15 +49,15 @@ public class Placeholder extends TextBox {
      * @return the created <code>EscherContainerRecord</code> which holds shape data
      */
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
+        _escherContainer = super.createSpContainer(isChild);
 
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER);
 
         EscherClientDataRecord cldata = new EscherClientDataRecord();
         cldata.setOptions((short)15);
 
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
 
         //Placeholders can't be grouped
         setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);
@@ -86,7 +86,7 @@ public class Placeholder extends TextBox {
         cldata.setRemainingData(out.toByteArray());
 
         //append placeholder container before EscherTextboxRecord
-        List lst = spcont.getChildRecords();
+        List lst = _escherContainer.getChildRecords();
         for (int i = 0; i < lst.size(); i++) {
               EscherRecord rec = (EscherRecord)lst.get(i);
               if(rec.getRecordId() == EscherTextboxRecord.RECORD_ID){
@@ -94,6 +94,6 @@ public class Placeholder extends TextBox {
               }
         }
 
-        return spcont;
+        return _escherContainer;
     }
 }
index 66c95e50cf4c046dfcf52d6969ec80bd514573c4..76b43ebb8acae89773df3990942e1faab194ce89 100644 (file)
 package org.apache.poi.hslf.model;
 
 import org.apache.poi.ddf.*;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
+
+import java.util.List;
 
 /**
  * Create a <code>Shape</code> object depending on its type
@@ -24,27 +28,53 @@ import org.apache.poi.ddf.*;
  * @author Yegor Kozlov
  */
 public class ShapeFactory {
+    // For logging
+    protected static POILogger logger = POILogFactory.getLogger(ShapeFactory.class);
 
     /**
      * Create a new shape from the data provided.  
      */
     public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
         if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
-            return new ShapeGroup(spContainer, parent);
+            return createShapeGroup(spContainer, parent);
+        } else {
+            return createSimpeShape(spContainer, parent);
+
+        }
+    }
+
+    public static ShapeGroup createShapeGroup(EscherContainerRecord spContainer, Shape parent){
+        ShapeGroup group = null;
+        UnknownEscherRecord opt = (UnknownEscherRecord)Shape.getEscherChild((EscherContainerRecord)spContainer.getChild(0), (short)0xF122);
+        if(opt != null){
+            try {
+                EscherPropertyFactory f = new EscherPropertyFactory();
+                List props = f.createProperties( opt.getData(), 0, opt.getInstance() );
+                EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
+                if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() == 1){
+                    group = new ShapeGroup(spContainer, parent);
+                } else {
+                    group = new ShapeGroup(spContainer, parent);
+                }
+            } catch (Exception e){
+                logger.log(POILogger.WARN, e.getMessage());
+                group = new ShapeGroup(spContainer, parent);
+            }
+        }  else {
+            group = new ShapeGroup(spContainer, parent);
         }
 
+        return group;
+     }
+
+    public static Shape createSimpeShape(EscherContainerRecord spContainer, Shape parent){
         Shape shape;
         EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
 
         int type = spRecord.getOptions() >> 4;
         switch (type){
             case ShapeTypes.TextBox:
-            case ShapeTypes.Rectangle:
-                EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
-                if (txtbox == null)
-                    shape = new AutoShape(spContainer, parent);
-                else
-                    shape = new TextBox(spContainer, parent);
+                shape = new TextBox(spContainer, parent);
                 break;
             case ShapeTypes.PictureFrame:
                 shape = new Picture(spContainer, parent);
@@ -53,16 +83,21 @@ public class ShapeFactory {
                 shape = new Line(spContainer, parent);
                 break;
             case ShapeTypes.NotPrimitive:
-                if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
-                     shape = new ShapeGroup(spContainer, parent);
-                else
+                EscherOptRecord opt = (EscherOptRecord)Shape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+                EscherProperty prop = Shape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);
+                if(prop != null)
+                    shape = new Freeform(spContainer, parent);
+                else {
+
+                    logger.log(POILogger.WARN, "Creating AutoShape for a NotPrimitive shape");
                     shape = new AutoShape(spContainer, parent);
+                }
                 break;
             default:
                 shape = new AutoShape(spContainer, parent);
                 break;
         }
         return shape;
-    }
 
+    }
 }
index dbcc8069c24e04a2702f9858c848f0aeb55055f8..b22ed8d70b1222f0041b2e6a257cb6439383780a 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.model;
 import org.apache.poi.ddf.*;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.hslf.record.EscherTextboxWrapper;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -154,9 +155,10 @@ public class ShapeGroup extends Shape{
         shape.setSheet(sheet);
         shape.afterInsert(sheet);
 
-        if(shape instanceof TextBox) {
-            TextBox tbox = (TextBox)shape;
-            getSheet().getPPDrawing().addTextboxWrapper(tbox._txtbox);
+        if (shape instanceof TextShape) {
+            TextShape tbox = (TextShape) shape;
+            EscherTextboxWrapper txWrapper = tbox.getEscherTextboxWrapper();
+            if(txWrapper != null) getSheet().getPPDrawing().addTextboxWrapper(txWrapper);
         }
     }
 
index 135b625f1d7ba7640ebfb7805cec41fe0bfcdb5c..abf2fec5890050779205c21f3edfc7627a46b51f 100644 (file)
@@ -257,11 +257,12 @@ public abstract class Sheet {
         shape.setSheet(this);
         shape.afterInsert(this);
 
-        // If it's a TextBox, we need to tell the PPDrawing, as it has to
+        // If it's a TextShape, we need to tell the PPDrawing, as it has to
         //  track TextboxWrappers specially
-        if (shape instanceof TextBox) {
-            TextBox tbox = (TextBox) shape;
-            ppdrawing.addTextboxWrapper(tbox._txtbox);
+        if (shape instanceof TextShape) {
+            TextShape tbox = (TextShape) shape;
+            EscherTextboxWrapper txWrapper = tbox.getEscherTextboxWrapper();
+            if(txWrapper != null) ppdrawing.addTextboxWrapper(txWrapper);
         }
     }
 
index 85d672fe899aa2757ea020529a04a6a4adfa825a..0831d453b5925b35de5f838cc6b606203051bb4f 100644 (file)
@@ -48,19 +48,19 @@ public class SimpleShape extends Shape {
      * @return the record container which holds this shape
      */
     protected EscherContainerRecord createSpContainer(boolean isChild) {
-        EscherContainerRecord spContainer = new EscherContainerRecord();
-        spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
-        spContainer.setOptions((short)15);
+        _escherContainer = new EscherContainerRecord();
+        _escherContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
+        _escherContainer.setOptions((short)15);
 
         EscherSpRecord sp = new EscherSpRecord();
         int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
         if (isChild) flags |= EscherSpRecord.FLAG_CHILD;
         sp.setFlags(flags);
-        spContainer.addChildRecord(sp);
+        _escherContainer.addChildRecord(sp);
 
         EscherOptRecord opt = new EscherOptRecord();
         opt.setRecordId(EscherOptRecord.RECORD_ID);
-        spContainer.addChildRecord(opt);
+        _escherContainer.addChildRecord(opt);
 
         EscherRecord anchor;
         if(isChild) anchor = new EscherChildAnchorRecord();
@@ -75,9 +75,9 @@ public class SimpleShape extends Shape {
             LittleEndian.putInt(header, 4, 8);
             anchor.fillFields(header, 0, null);
         }
-        spContainer.addChildRecord(anchor);
+        _escherContainer.addChildRecord(anchor);
 
-        return spContainer;
+        return _escherContainer;
     }
 
     /**
index a9f21b54f3924c8a71b2e1595d676f5627f1660b..947c41af63e06e61aae0f7b4dc4623088a2eb5e4 100755 (executable)
@@ -20,10 +20,10 @@ package org.apache.poi.hslf.model;
 import org.apache.poi.ddf.*;\r
 import org.apache.poi.util.LittleEndian;\r
 \r
-import java.util.ArrayList;\r
+import java.util.*;\r
 import java.util.List;\r
-import java.util.Iterator;\r
 import java.awt.*;\r
+import java.awt.geom.Rectangle2D;\r
 \r
 /**\r
  * Represents a table in a PowerPoint presentation\r
@@ -144,6 +144,54 @@ public class Table extends ShapeGroup {
 \r
     }\r
 \r
+    protected void initTable(){\r
+        Shape[] sh = getShapes();\r
+        Arrays.sort(sh, new Comparator(){\r
+            public int compare( Object o1, Object o2 ) {\r
+                Rectangle anchor1 = ((Shape)o1).getAnchor();\r
+                Rectangle anchor2 = ((Shape)o2).getAnchor();\r
+                int delta = anchor1.y - anchor2.y;\r
+                if(delta == 0) delta = anchor1.x - anchor2.y;\r
+                return delta;\r
+            }\r
+        });\r
+        int y0 = -1;\r
+        int maxrowlen = 0;\r
+        ArrayList lst = new ArrayList();\r
+        ArrayList row = null;\r
+        for (int i = 0; i < sh.length; i++) {\r
+            if(sh[i] instanceof TextShape){\r
+                Rectangle anchor = sh[i].getAnchor();\r
+                if(anchor.y != y0){\r
+                    y0 = anchor.y;\r
+                    if(row != null) maxrowlen = Math.max(maxrowlen, row.size());\r
+                    row = new ArrayList();\r
+                    lst.add(row);\r
+                }\r
+                row.add(sh[i]);\r
+            }\r
+        }\r
+        cells = new TableCell[lst.size()][maxrowlen];\r
+        for (int i = 0; i < lst.size(); i++) {\r
+            row = (ArrayList)lst.get(i);\r
+            for (int j = 0; j < row.size(); j++) {\r
+                TextShape tx = (TextShape)row.get(j);\r
+                cells[i][j] = new TableCell(tx.getSpContainer(), getParent());\r
+                cells[i][j].setSheet(tx.getSheet());\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Assign the <code>SlideShow</code> this shape belongs to\r
+     *\r
+     * @param sheet owner of this shape\r
+     */\r
+    public void setSheet(Sheet sheet){\r
+        super.setSheet(sheet);\r
+        if(cells == null) initTable();\r
+    }\r
+\r
     /**\r
      * Sets the row height.\r
      *\r
index bb93e06b7154f5e31ea7b371b8b8eb393f71af23..36789ad91a2f0462c52b0e95311c9c84e1d400dc 100755 (executable)
@@ -63,15 +63,15 @@ public class TableCell extends TextBox {
     }\r
 \r
     protected EscherContainerRecord createSpContainer(boolean isChild){\r
-        EscherContainerRecord spContainer = super.createSpContainer(isChild);\r
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);\r
+        _escherContainer = super.createSpContainer(isChild);\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
         setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);\r
         setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);\r
         setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);\r
         setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);\r
         setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);\r
 \r
-        return spContainer;\r
+        return _escherContainer;\r
     }\r
 \r
     protected void anchorBorder(int type, Line line){\r
index 1f9a489a78be29eb2b08babd6e1922e6a487a5f0..a1d45ffbaed9ad44678541b769249b2cfedef6e2 100644 (file)
@@ -38,55 +38,7 @@ import java.io.IOException;
  *
  * @author Yegor Kozlov
  */
-public class TextBox extends SimpleShape {
-
-    /**
-     * How to anchor the text
-     */
-    public static final int AnchorTop = 0;
-    public static final int AnchorMiddle = 1;
-    public static final int AnchorBottom = 2;
-    public static final int AnchorTopCentered = 3;
-    public static final int AnchorMiddleCentered = 4;
-    public static final int AnchorBottomCentered = 5;
-    public static final int AnchorTopBaseline = 6;
-    public static final int AnchorBottomBaseline = 7;
-    public static final int AnchorTopCenteredBaseline = 8;
-    public static final int AnchorBottomCenteredBaseline = 9;
-
-    /**
-     * How to wrap the text
-     */
-    public static final int WrapSquare = 0;
-    public static final int WrapByPoints = 1;
-    public static final int WrapNone = 2;
-    public static final int WrapTopBottom = 3;
-    public static final int WrapThrough = 4;
-
-    /**
-     * How to align the text
-     */
-    public static final int AlignLeft = 0;
-    public static final int AlignCenter = 1;
-    public static final int AlignRight = 2;
-    public static final int AlignJustify = 3;
-
-    /**
-     * Low-level object which holds actual text and format data
-     */
-    protected TextRun _txtrun;
-
-    /**
-     * Escher container which holds text attributes such as
-     * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.
-     */
-    protected EscherTextboxWrapper _txtbox;
-    
-    /**
-     * Is the TextBox missing the text records which actually
-     *  store the text?
-     */
-    private boolean _missingTextRecords = false;
+public class TextBox extends TextShape {
 
     /**
      * Create a TextBox object and initialize it from the supplied Record container.
@@ -97,8 +49,6 @@ public class TextBox extends SimpleShape {
    protected TextBox(EscherContainerRecord escherRecord, Shape parent){
         super(escherRecord, parent);
 
-        EscherTextboxRecord textbox = (EscherTextboxRecord)Shape.getEscherChild(_escherContainer, EscherTextboxRecord.RECORD_ID);
-        _txtbox = new EscherTextboxWrapper(textbox);
     }
 
     /**
@@ -108,8 +58,7 @@ public class TextBox extends SimpleShape {
      * in a table then the parent is Table.
      */
     public TextBox(Shape parent){
-        super(null, parent);
-        _escherContainer = createSpContainer(parent instanceof ShapeGroup);
+        super(parent);
     }
 
     /**
@@ -121,376 +70,31 @@ public class TextBox extends SimpleShape {
     }
 
     /**
-     * Create a new textBox and initialize internal structures
+     * Create a new TextBox and initialize its internal structures
      *
      * @return the created <code>EscherContainerRecord</code> which holds shape data
      */
     protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
-
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
-        short type = (ShapeTypes.TextBox << 4) | 0x2;
-        spRecord.setOptions(type);
-
-        //set default properties for a textbox
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
-
-        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, 0x8000004);
-        setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
-        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
-        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
-        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
-        setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
-
-        //create EscherTextboxWrapper
-        _txtbox = new EscherTextboxWrapper();
-
-        TextHeaderAtom tha = new TextHeaderAtom();
-        tha.setParentRecord(_txtbox); // TextHeaderAtom is parent aware
-        _txtbox.appendChildRecord(tha);
-
-        TextCharsAtom tca = new TextCharsAtom();
-        _txtbox.appendChildRecord(tca);
-
-        StyleTextPropAtom sta = new StyleTextPropAtom(0);
-        _txtbox.appendChildRecord(sta);
-
-        _txtrun = new TextRun(tha,tca,sta);
-        _txtrun.setText("");
-        spcont.addChildRecord(_txtbox.getEscherRecord());
-
-        return spcont;
-    }
-
-    /**
-     * Returns the text contained in this text frame.
-     *
-     * @return the text string for this textbox.
-     */
-     public String getText(){
-        return _txtrun == null ? null : _txtrun.getText();
-    }
-
-    /**
-     * Sets the text contained in this text frame.
-     *
-     * @param text the text string used by this object.
-     */
-    public void setText(String text){
-        _txtrun.setText(text);
-    }
-
-    /**
-     * When a textbox is added to  a sheet we need to tell upper-level
-     * <code>PPDrawing</code> about it.
-     *
-     * @param sh the sheet we are adding to
-     */
-    protected void afterInsert(Sheet sh){
-        PPDrawing ppdrawing = sh.getPPDrawing();
-        ppdrawing.addTextboxWrapper(_txtbox);
-        // Ensure the escher layer knows about the added records 
-        try {
-            _txtbox.writeOut(null);
-        } catch (IOException e){
-            throw new HSLFException(e);
-        }
-        if(getAnchor().equals(new java.awt.Rectangle()) && !"".equals(getText())) resizeToFitText();
-    }
-
-    /**
-     * Adjust the size of the TextBox so it encompasses the text inside it.
-     */
-    public void resizeToFitText(){
-        try{
-        FontRenderContext frc = new FontRenderContext(null, true, true);
-        RichTextRun rt = _txtrun.getRichTextRuns()[0];
-        int size = rt.getFontSize();
-        int style = 0;
-        if (rt.isBold()) style |= Font.BOLD;
-        if (rt.isItalic()) style |= Font.ITALIC;
-        String fntname = rt.getFontName();
-        Font font = new Font(fntname, style, size);
-
-        TextLayout layout = new TextLayout(getText(), font, frc);
-        int width = Math.round(layout.getAdvance());
-        int height = Math.round(layout.getAscent());
-
-        Dimension txsize = new Dimension(width, height);
-        java.awt.Rectangle anchor = getAnchor();
-        anchor.setSize(txsize);
-        setAnchor(anchor);
-        } catch (Exception e){
-            e.printStackTrace();
-
-        }
-    }
-
-    /**
-     * Returns the type of vertical alignment for the text.
-     * One of the <code>Anchor*</code> constants defined in this class.
-     *
-     * @return the type of alignment
-     */
-    public int getVerticalAlignment(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
-        int valign;
-        if (prop == null){
-            int type = getTextRun().getRunType();
-            switch (type){
-                case TextHeaderAtom.TITLE_TYPE:
-                case TextHeaderAtom.CENTER_TITLE_TYPE:
-                    valign = TextBox.AnchorMiddle;
-                    break;
-                default:
-                    valign = TextBox.AnchorTop;
-                    break;
-            }
-        } else {
-            valign = prop.getPropertyValue();
-        }
-        return valign;
-    }
-
-    /**
-     * Sets the type of vertical alignment for the text.
-     * One of the <code>Anchor*</code> constants defined in this class.
-     *
-     * @param align - the type of alignment
-     */
-    public void setVerticalAlignment(int align){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT, align);
-    }
-
-    public void setHorizontalAlignment(int align){
-        _txtrun.getRichTextRuns()[0].setAlignment(align);
-    }
-    public int getHorizontalAlignment(){
-        return _txtrun.getRichTextRuns()[0].getAlignment();
-    }
-
-    /**
-     * Returns the distance (in points) between the bottom of the text frame
-     * and the bottom of the inscribed rectangle of the shape that contains the text.
-     * Default value is 1/20 inch.
-     *
-     * @return the botom margin
-     */
-    public int getMarginBottom(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
-        int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
-
-    /**
-     * Sets the botom margin.
-     * @see #getMarginBottom()
-     *
-     * @param margin    the bottom margin
-     */
-    public void setMarginBottom(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM, margin*EMU_PER_POINT);
-    }
-
-    /**
-     *  Returns the distance (in EMUs) between the left edge of the text frame
-     *  and the left edge of the inscribed rectangle of the shape that contains
-     *  the text.
-     *  Default value is 1/10 inch.
-     *
-     * @return the left margin
-     */
-    public int getMarginLeft(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
-        int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
+        _escherContainer = super.createSpContainer(isChild);
 
-    /**
-     * Sets the left margin.
-     * @see #getMarginLeft()
-     *
-     * @param margin    the left margin
-     */
-    public void setMarginLeft(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT, margin*EMU_PER_POINT);
-    }
+        setShapeType(ShapeTypes.TextBox);
 
-    /**
-     *  Returns the distance (in EMUs) between the right edge of the
-     *  text frame and the right edge of the inscribed rectangle of the shape
-     *  that contains the text.
-     *  Default value is 1/10 inch.
-     *
-     * @return the right margin
-     */
-    public int getMarginRight(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
-        int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
-    }
+        //set default properties for a TextBox
+        setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+        setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
+        setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100000);
+        setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+        setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
+        setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
 
-    /**
-     * Sets the right margin.
-     * @see #getMarginRight()
-     *
-     * @param margin    the right margin
-     */
-    public void setMarginRight(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT, margin*EMU_PER_POINT);
-    }
+        _txtrun = createTextRun();
 
-     /**
-     *  Returns the distance (in EMUs) between the top of the text frame
-     *  and the top of the inscribed rectangle of the shape that contains the text.
-     *  Default value is 1/20 inch.
-     *
-     * @return the top margin
-     */
-    public int getMarginTop(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
-        int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
-        return val/EMU_PER_POINT;
+        return _escherContainer;
     }
 
-   /**
-     * Sets the top margin.
-     * @see #getMarginTop()
-     *
-     * @param margin    the top margin
-     */
-    public void setMarginTop(int margin){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTTOP, margin*EMU_PER_POINT);
+    protected void setDefaultTextProperties(TextRun _txtrun){
+        setVerticalAlignment(TextBox.AnchorTop);
+        setEscherProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20002);
     }
 
-
-    /**
-     * Returns the value indicating word wrap.
-     * One of the <code>Wrap*</code> constants defined in this class.
-     *
-     * @return the value indicating word wrap
-     */
-    public int getWordWrap(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
-        return prop == null ? WrapSquare : prop.getPropertyValue();
-    }
-
-    /**
-     *  Specifies how the text should be wrapped
-     *
-     * @param wrap  the value indicating how the text should be wrapped
-     */
-    public void setWordWrap(int wrap){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT, wrap);
-    }
-
-    /**
-     * @return id for the text.
-     */
-    public int getTextId(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
-        return prop == null ? 0 : prop.getPropertyValue();
-    }
-
-    /**
-     * Sets text ID
-     *
-     * @param id of the text
-     */
-    public void setTextId(int id){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.TEXT__TEXTID, id);
-    }
-
-    /**
-     * The color used to fill this shape.
-     *
-     * @param color the background color
-     */
-    public void setBackgroundColor(Color color){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
-        setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, rgb);
-    }
-
-    /**
-      * @return the TextRun object for this text box
-      */
-     public TextRun getTextRun(){
-         return _txtrun;
-     }
-
-     public void setSheet(Sheet sheet){
-        _sheet = sheet;
-
-        // Initialize _txtrun object.
-        // (We can't do it in the constructor because the sheet
-        //  is not assigned then, it's only built once we have
-        //  all the records)
-        if(_txtrun == null) initTextRun();
-        if(_txtrun == null) {
-               // No text records found, skip
-               _missingTextRecords = true;
-               return;
-        } else {
-               _missingTextRecords = false;
-        }
-        
-        // Supply the sheet to our child RichTextRuns
-        _txtrun.setSheet(sheet);
-        RichTextRun[] rt = _txtrun.getRichTextRuns();
-        for (int i = 0; i < rt.length; i++) {
-            rt[i].supplySlideShow(_sheet.getSlideShow());
-        }
-    }
-
-    private void initTextRun(){
-        OutlineTextRefAtom ota = null;
-        
-        // Find the interesting child records 
-        Record[] child = _txtbox.getChildRecords();
-        for (int i = 0; i < child.length; i++) {
-            if (child[i] instanceof OutlineTextRefAtom) {
-                ota = (OutlineTextRefAtom)child[i];
-                break;
-            }
-        }
-
-        Sheet sheet = getSheet();
-        TextRun[] runs = sheet.getTextRuns();
-        if (ota != null) {
-            int idx = ota.getTextIndex();
-            for (int i = 0; i < runs.length; i++) {
-                if(runs[i].getIndex() == idx){
-                    _txtrun = runs[i];
-                }
-            }
-            if(_txtrun == null) {
-                logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
-            }
-        } else {
-            int shapeId = _escherContainer.getChildById(EscherSpRecord.RECORD_ID).getShapeId();
-            if(runs != null) for (int i = 0; i < runs.length; i++) {
-                if(runs[i].getShapeId() == shapeId){
-                    _txtrun = runs[i];
-                    break;
-                }
-            }
-        }
-
-    }
 }
index 586932e739803672388eda184a8e3909b000dbb5..5834e2eaecbf0e9da4960bfc833ca98daea36970 100644 (file)
@@ -24,12 +24,7 @@ import java.util.LinkedList;
 import java.util.Vector;
 
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextBytesAtom;
-import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.record.*;
 import org.apache.poi.hslf.usermodel.RichTextRun;
 import org.apache.poi.hslf.usermodel.SlideShow;
 import org.apache.poi.util.StringUtil;
@@ -50,6 +45,7 @@ public class TextRun
        protected TextBytesAtom  _byteAtom;
        protected TextCharsAtom  _charAtom;
        protected StyleTextPropAtom _styleAtom;
+    protected TextSpecInfoAtom  _specAtom;
        protected boolean _isUnicode;
        protected RichTextRun[] _rtRuns;
        private SlideShow slideShow;
@@ -477,6 +473,18 @@ public class TextRun
                        // Recreate rich text run with no styling
                        _rtRuns[0] = new RichTextRun(this,0,s.length());
                }
+
+        /**
+         * If TextSpecInfoAtom is present, we must update the text size,
+         * otherwise the ppt will be corrupted
+         */
+        if(_records != null) for (int i = 0; i < _records.length; i++) {
+            if(_records[i] instanceof TextSpecInfoAtom){
+                TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_records[i];
+                specAtom.setTextSize(s.length());
+            }
+
+        }
        }
 
        /**
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
new file mode 100755 (executable)
index 0000000..3c45b34
--- /dev/null
@@ -0,0 +1,516 @@
+\r
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.model;\r
+\r
+import org.apache.poi.ddf.*;\r
+import org.apache.poi.hslf.record.*;\r
+import org.apache.poi.hslf.usermodel.RichTextRun;\r
+import org.apache.poi.hslf.exceptions.HSLFException;\r
+import org.apache.poi.util.POILogger;\r
+\r
+import java.awt.*;\r
+import java.awt.geom.Rectangle2D;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.font.FontRenderContext;\r
+import java.awt.font.TextLayout;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * A common superclass of all shapes that can hold text.\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public abstract class TextShape extends SimpleShape {\r
+\r
+    /**\r
+     * How to anchor the text\r
+     */\r
+    public static final int AnchorTop = 0;\r
+    public static final int AnchorMiddle = 1;\r
+    public static final int AnchorBottom = 2;\r
+    public static final int AnchorTopCentered = 3;\r
+    public static final int AnchorMiddleCentered = 4;\r
+    public static final int AnchorBottomCentered = 5;\r
+    public static final int AnchorTopBaseline = 6;\r
+    public static final int AnchorBottomBaseline = 7;\r
+    public static final int AnchorTopCenteredBaseline = 8;\r
+    public static final int AnchorBottomCenteredBaseline = 9;\r
+\r
+    /**\r
+     * How to wrap the text\r
+     */\r
+    public static final int WrapSquare = 0;\r
+    public static final int WrapByPoints = 1;\r
+    public static final int WrapNone = 2;\r
+    public static final int WrapTopBottom = 3;\r
+    public static final int WrapThrough = 4;\r
+\r
+    /**\r
+     * How to align the text\r
+     */\r
+    public static final int AlignLeft = 0;\r
+    public static final int AlignCenter = 1;\r
+    public static final int AlignRight = 2;\r
+    public static final int AlignJustify = 3;\r
+\r
+    /**\r
+     * TextRun object which holds actual text and format data\r
+     */\r
+    protected TextRun _txtrun;\r
+\r
+    /**\r
+     * Escher container which holds text attributes such as\r
+     * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.\r
+     */\r
+    protected EscherTextboxWrapper _txtbox;\r
+\r
+    /**\r
+     * Used to calculate text bounds\r
+     */\r
+    protected static final FontRenderContext _frc = new FontRenderContext(null, true, true);\r
+\r
+    /**\r
+     * Create a TextBox object and initialize it from the supplied Record container.\r
+     * \r
+     * @param escherRecord       <code>EscherSpContainer</code> container which holds information about this shape\r
+     * @param parent    the parent of the shape\r
+     */\r
+   protected TextShape(EscherContainerRecord escherRecord, Shape parent){\r
+        super(escherRecord, parent);\r
+\r
+    }\r
+\r
+    /**\r
+     * Create a new TextBox. This constructor is used when a new shape is created.\r
+     *\r
+     * @param parent    the parent of this Shape. For example, if this text box is a cell\r
+     * in a table then the parent is Table.\r
+     */\r
+    public TextShape(Shape parent){\r
+        super(null, parent);\r
+        _escherContainer = createSpContainer(parent instanceof ShapeGroup);\r
+    }\r
+\r
+    /**\r
+     * Create a new TextBox. This constructor is used when a new shape is created.\r
+     *\r
+     */\r
+    public TextShape(){\r
+        this(null);\r
+    }\r
+\r
+    public TextRun createTextRun(){\r
+        _txtbox = getEscherTextboxWrapper();\r
+        if(_txtbox == null) _txtbox = new EscherTextboxWrapper();\r
+\r
+        _txtrun = getTextRun();\r
+        if(_txtrun == null){\r
+            TextHeaderAtom tha = new TextHeaderAtom();\r
+            tha.setParentRecord(_txtbox);\r
+            _txtbox.appendChildRecord(tha);\r
+\r
+            TextCharsAtom tca = new TextCharsAtom();\r
+            _txtbox.appendChildRecord(tca);\r
+\r
+            StyleTextPropAtom sta = new StyleTextPropAtom(0);\r
+            _txtbox.appendChildRecord(sta);\r
+\r
+            _txtrun = new TextRun(tha,tca,sta);\r
+            _txtrun.setText("");\r
+\r
+            _escherContainer.addChildRecord(_txtbox.getEscherRecord());\r
+\r
+            setDefaultTextProperties(_txtrun);\r
+        }\r
+\r
+        return _txtrun;\r
+    }\r
+\r
+    /**\r
+     * Set default properties for the  TextRun.\r
+     * Depending on the text and shape type the defaults are different:\r
+     *   TextBox: align=left, valign=top\r
+     *   AutoShape: align=center, valign=middle\r
+     *\r
+     */\r
+    protected void setDefaultTextProperties(TextRun _txtrun){\r
+\r
+    }\r
+\r
+    /**\r
+     * Returns the text contained in this text frame.\r
+     *\r
+     * @return the text string for this textbox.\r
+     */\r
+     public String getText(){\r
+        TextRun tx = getTextRun();\r
+        return tx == null ? null : tx.getText();\r
+    }\r
+\r
+    /**\r
+     * Sets the text contained in this text frame.\r
+     *\r
+     * @param text the text string used by this object.\r
+     */\r
+    public void setText(String text){\r
+        TextRun tx = getTextRun();\r
+        if(tx == null){\r
+            tx = createTextRun();\r
+        }\r
+        tx.setText(text);\r
+        setTextId(text.hashCode());\r
+    }\r
+\r
+    /**\r
+     * When a textbox is added to  a sheet we need to tell upper-level\r
+     * <code>PPDrawing</code> about it.\r
+     *\r
+     * @param sh the sheet we are adding to\r
+     */\r
+    protected void afterInsert(Sheet sh){\r
+        EscherTextboxWrapper _txtbox = getEscherTextboxWrapper();\r
+        if(_txtbox != null){\r
+            PPDrawing ppdrawing = sh.getPPDrawing();\r
+            ppdrawing.addTextboxWrapper(_txtbox);\r
+            // Ensure the escher layer knows about the added records\r
+            try {\r
+                _txtbox.writeOut(null);\r
+            } catch (IOException e){\r
+                throw new HSLFException(e);\r
+            }\r
+            if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();\r
+        }\r
+    }\r
+\r
+    protected EscherTextboxWrapper getEscherTextboxWrapper(){\r
+        if(_txtbox == null){\r
+            EscherTextboxRecord textRecord = (EscherTextboxRecord)Shape.getEscherChild(_escherContainer, EscherTextboxRecord.RECORD_ID);\r
+            if(textRecord != null) _txtbox = new EscherTextboxWrapper(textRecord);\r
+        }\r
+        return _txtbox;\r
+    }\r
+    /**\r
+     * Adjust the size of the TextShape so it encompasses the text inside it.\r
+     *\r
+     * @return a <code>Rectangle2D</code> that is the bounds of this <code>TextShape</code>.\r
+     */\r
+    public Rectangle2D resizeToFitText(){\r
+        String txt = getText();\r
+        if(txt == null || txt.length() == 0) return new Rectangle2D.Float();\r
+\r
+        RichTextRun rt = getTextRun().getRichTextRuns()[0];\r
+        int size = rt.getFontSize();\r
+        int style = 0;\r
+        if (rt.isBold()) style |= Font.BOLD;\r
+        if (rt.isItalic()) style |= Font.ITALIC;\r
+        String fntname = rt.getFontName();\r
+        Font font = new Font(fntname, style, size);\r
+\r
+        float width = 0, height = 0;\r
+        String[] lines = txt.split("\r");\r
+        for (int i = 0; i < lines.length; i++) {\r
+            if(lines[i].length() == 0) continue;\r
+\r
+            TextLayout layout = new TextLayout(lines[i], font, _frc);\r
+\r
+            width = Math.max(width, layout.getAdvance());\r
+\r
+            /**\r
+             * Even if top and bottom margins are set to 0 PowerPoint\r
+             * always sets extra space between the text and its bounding box.\r
+             *\r
+             * The approximation height = ascent*2 works good enough in most cases\r
+             */\r
+            height = Math.max(height, 2*layout.getAscent());\r
+        }\r
+\r
+        width += getMarginLeft() + getMarginRight();\r
+        height += getMarginTop() + getMarginBottom();\r
+\r
+        Rectangle2D anchor = getAnchor2D();\r
+        anchor.setRect(anchor.getX(), anchor.getY(), width, height);\r
+        setAnchor(anchor);\r
+\r
+        return anchor;\r
+    }\r
+\r
+    /**\r
+     * Returns the type of vertical alignment for the text.\r
+     * One of the <code>Anchor*</code> constants defined in this class.\r
+     *\r
+     * @return the type of alignment\r
+     */\r
+    public int getVerticalAlignment(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);\r
+        int valign;\r
+        if (prop == null){\r
+            int type = getTextRun().getRunType();\r
+            switch (type){\r
+                case TextHeaderAtom.TITLE_TYPE:\r
+                case TextHeaderAtom.CENTER_TITLE_TYPE:\r
+                    valign = TextShape.AnchorMiddle;\r
+                    break;\r
+                default:\r
+                    valign = TextShape.AnchorTop;\r
+                    break;\r
+            }\r
+        } else {\r
+            valign = prop.getPropertyValue();\r
+        }\r
+        return valign;\r
+    }\r
+\r
+    /**\r
+     * Sets the type of vertical alignment for the text.\r
+     * One of the <code>Anchor*</code> constants defined in this class.\r
+     *\r
+     * @param align - the type of alignment\r
+     */\r
+    public void setVerticalAlignment(int align){\r
+        setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align);\r
+    }\r
+\r
+    /**\r
+     * Sets the type of horizontal alignment for the text.\r
+     * One of the <code>Align*</code> constants defined in this class.\r
+     *\r
+     * @param align - the type of horizontal alignment\r
+     */\r
+    public void setHorizontalAlignment(int align){\r
+        TextRun tx = getTextRun();\r
+        if(tx != null) tx.getRichTextRuns()[0].setAlignment(align);\r
+    }\r
+\r
+    /**\r
+     * Gets the type of horizontal alignment for the text.\r
+     * One of the <code>Align*</code> constants defined in this class.\r
+     *\r
+     * @return align - the type of horizontal alignment\r
+     */\r
+    public int getHorizontalAlignment(){\r
+        TextRun tx = getTextRun();\r
+        return tx == null ? -1 : tx.getRichTextRuns()[0].getAlignment();\r
+    }\r
+\r
+    /**\r
+     * Returns the distance (in points) between the bottom of the text frame\r
+     * and the bottom of the inscribed rectangle of the shape that contains the text.\r
+     * Default value is 1/20 inch.\r
+     *\r
+     * @return the botom margin\r
+     */\r
+    public float getMarginBottom(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);\r
+        int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();\r
+        return (float)val/EMU_PER_POINT;\r
+    }\r
+\r
+    /**\r
+     * Sets the botom margin.\r
+     * @see #getMarginBottom()\r
+     *\r
+     * @param margin    the bottom margin\r
+     */\r
+    public void setMarginBottom(float margin){\r
+        setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT));\r
+    }\r
+\r
+    /**\r
+     *  Returns the distance (in points) between the left edge of the text frame\r
+     *  and the left edge of the inscribed rectangle of the shape that contains\r
+     *  the text.\r
+     *  Default value is 1/10 inch.\r
+     *\r
+     * @return the left margin\r
+     */\r
+    public float getMarginLeft(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);\r
+        int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();\r
+        return (float)val/EMU_PER_POINT;\r
+    }\r
+\r
+    /**\r
+     * Sets the left margin.\r
+     * @see #getMarginLeft()\r
+     *\r
+     * @param margin    the left margin\r
+     */\r
+    public void setMarginLeft(float margin){\r
+        setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT));\r
+    }\r
+\r
+    /**\r
+     *  Returns the distance (in points) between the right edge of the\r
+     *  text frame and the right edge of the inscribed rectangle of the shape\r
+     *  that contains the text.\r
+     *  Default value is 1/10 inch.\r
+     *\r
+     * @return the right margin\r
+     */\r
+    public float getMarginRight(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);\r
+        int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();\r
+        return (float)val/EMU_PER_POINT;\r
+    }\r
+\r
+    /**\r
+     * Sets the right margin.\r
+     * @see #getMarginRight()\r
+     *\r
+     * @param margin    the right margin\r
+     */\r
+    public void setMarginRight(float margin){\r
+        setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT));\r
+    }\r
+\r
+     /**\r
+     *  Returns the distance (in points) between the top of the text frame\r
+     *  and the top of the inscribed rectangle of the shape that contains the text.\r
+     *  Default value is 1/20 inch.\r
+     *\r
+     * @return the top margin\r
+     */\r
+    public float getMarginTop(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);\r
+        int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();\r
+        return (float)val/EMU_PER_POINT;\r
+    }\r
+\r
+   /**\r
+     * Sets the top margin.\r
+     * @see #getMarginTop()\r
+     *\r
+     * @param margin    the top margin\r
+     */\r
+    public void setMarginTop(float margin){\r
+        setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT));\r
+    }\r
+\r
+\r
+    /**\r
+     * Returns the value indicating word wrap.\r
+     *\r
+     * @return the value indicating word wrap.\r
+     *  Must be one of the <code>Wrap*</code> constants defined in this class.\r
+     */\r
+    public int getWordWrap(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);\r
+        return prop == null ? WrapSquare : prop.getPropertyValue();\r
+    }\r
+\r
+    /**\r
+     *  Specifies how the text should be wrapped\r
+     *\r
+     * @param wrap  the value indicating how the text should be wrapped.\r
+     *  Must be one of the <code>Wrap*</code> constants defined in this class.\r
+     */\r
+    public void setWordWrap(int wrap){\r
+        setEscherProperty(EscherProperties.TEXT__WRAPTEXT, wrap);\r
+    }\r
+\r
+    /**\r
+     * @return id for the text.\r
+     */\r
+    public int getTextId(){\r
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTID);\r
+        return prop == null ? 0 : prop.getPropertyValue();\r
+    }\r
+\r
+    /**\r
+     * Sets text ID\r
+     *\r
+     * @param id of the text\r
+     */\r
+    public void setTextId(int id){\r
+        setEscherProperty(EscherProperties.TEXT__TEXTID, id);\r
+    }\r
+\r
+    /**\r
+      * @return the TextRun object for this text box\r
+      */\r
+     public TextRun getTextRun(){\r
+         if(_txtrun == null) initTextRun();\r
+         return _txtrun;\r
+     }\r
+\r
+    public void setSheet(Sheet sheet) {\r
+        _sheet = sheet;\r
+\r
+        // Initialize _txtrun object.\r
+        // (We can't do it in the constructor because the sheet\r
+        //  is not assigned then, it's only built once we have\r
+        //  all the records)\r
+        TextRun tx = getTextRun();\r
+        if (tx != null) {\r
+            // Supply the sheet to our child RichTextRuns\r
+            tx.setSheet(_sheet);\r
+            RichTextRun[] rt = tx.getRichTextRuns();\r
+            for (int i = 0; i < rt.length; i++) {\r
+                rt[i].supplySlideShow(_sheet.getSlideShow());\r
+            }\r
+        }\r
+\r
+    }\r
+\r
+    protected void initTextRun(){\r
+        EscherTextboxWrapper txtbox = getEscherTextboxWrapper();\r
+        Sheet sheet = getSheet();\r
+\r
+        if(sheet == null || txtbox == null) return;\r
+\r
+        OutlineTextRefAtom ota = null;\r
+\r
+        Record[] child = txtbox.getChildRecords();\r
+        for (int i = 0; i < child.length; i++) {\r
+            if (child[i] instanceof OutlineTextRefAtom) {\r
+                ota = (OutlineTextRefAtom)child[i];\r
+                break;\r
+            }\r
+        }\r
+\r
+        TextRun[] runs = _sheet.getTextRuns();\r
+        if (ota != null) {\r
+            int idx = ota.getTextIndex();\r
+            for (int i = 0; i < runs.length; i++) {\r
+                if(runs[i].getIndex() == idx){\r
+                    _txtrun = runs[i];\r
+                    break;\r
+                }\r
+            }\r
+            if(_txtrun == null) {\r
+                logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);\r
+            }\r
+        } else {\r
+            int shapeId = _escherContainer.getChildById(EscherSpRecord.RECORD_ID).getShapeId();\r
+            if(runs != null) for (int i = 0; i < runs.length; i++) {\r
+                if(runs[i].getShapeId() == shapeId){\r
+                    _txtrun = runs[i];\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+    }\r
+}\r
index 521e8468b3cd2302bf0c7f1baf94987adb3bdcf4..c0d55ac0ee708bd533e65b549ec0ece77d45f4a2 100644 (file)
@@ -75,16 +75,20 @@ public class FontCollection extends RecordContainer {
      * @return zero based index of the font in the collection
      */
     public int addFont(String name) {
-        for (int i = 0; i < fonts.size(); i++) {
-            if(fonts.get(i).equals(name)){
-                //if the font is already present return its index
-                return i;
-            }
-        }
+        int idx = getFontIndex(name);
+        if(idx != -1) return idx;
 
+        return addFont(name, 0, 0, 4, 34);
+    }
+
+    public int addFont(String name, int charset, int flags, int type, int pitch) {
         FontEntityAtom fnt = new FontEntityAtom();
         fnt.setFontIndex(fonts.size() << 4);
         fnt.setFontName(name);
+        fnt.setCharSet(charset);
+        fnt.setFontFlags(flags);
+        fnt.setFontType(type);
+        fnt.setPitchAndFamily(pitch);
         fonts.add(name);
 
         // Append new child to the end
@@ -92,8 +96,25 @@ public class FontCollection extends RecordContainer {
 
         return fonts.size()-1; //the added font is the last in the list
     }
-    
-       /**
+
+    /**
+     * @return zero based index of the font in the collection or -1 if not found
+     */
+    public int getFontIndex(String name) {
+        for (int i = 0; i < fonts.size(); i++) {
+            if(fonts.get(i).equals(name)){
+                //if the font is already present return its index
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    public int getNumberOfFonts() {
+        return fonts.size();
+    }
+
+    /**
         * Get the name of the font at the given ID, or null if there is
         *  no font at that ID.
         * @param id
index e4899bd6e13989c36f80f6a8d8920d4755a9972b..76cb4c264b81890b3a56e8a076c81324fdd64f9f 100644 (file)
@@ -61,7 +61,7 @@ public class FontEntityAtom extends RecordAtom {
     /**
      * Create a new instance of <code>FontEntityAtom</code>
      */
-    protected FontEntityAtom() {
+    public FontEntityAtom() {
         _recdata = new byte[68];
 
         _header = new byte[8];
@@ -124,15 +124,100 @@ public class FontEntityAtom extends RecordAtom {
         }
     }
 
-    protected void setFontIndex(int idx){
+    public void setFontIndex(int idx){
         LittleEndian.putShort(_header, 0, (short)idx);
     }
 
-    protected int getFontIndex(){
-        return LittleEndian.getShort(_header, 0);
+    public int getFontIndex(){
+        return LittleEndian.getShort(_header, 0) >> 4;
     }
 
-       /**
+    /**
+     * set the character set
+     *
+     * @param charset - characterset
+     */
+    public void setCharSet(int charset){
+        _recdata[64] = (byte)charset;
+    }
+
+    /**
+     * get the character set
+     *
+     * @return charset - characterset
+     */
+    public int getCharSet(){
+        return _recdata[64];
+    }
+
+    /**
+     * set the font flags
+     * Bit 1: If set, font is subsetted
+     *
+     * @param flags - the font flags
+     */
+    public void setFontFlags(int flags){
+        _recdata[65] = (byte)flags;
+    }
+
+    /**
+     * get the character set
+     * Bit 1: If set, font is subsetted
+     *
+     * @return the font flags
+     */
+    public int getFontFlags(){
+        return _recdata[65];
+    }
+
+    /**
+     * set the font type
+     * <p>
+     * Bit 1: Raster Font
+     * Bit 2: Device Font
+     * Bit 3: TrueType Font
+     * </p>
+     *
+     * @param type - the font type
+     */
+    public void setFontType(int type){
+        _recdata[66] = (byte)type;
+    }
+
+    /**
+     * get the font type
+     * <p>
+     * Bit 1: Raster Font
+     * Bit 2: Device Font
+     * Bit 3: TrueType Font
+     * </p>
+     *
+     * @return the font type
+     */
+    public int getFontType(){
+        return _recdata[66];
+    }
+
+    /**
+     * set lfPitchAndFamily
+     *
+     *
+     * @param val - Corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure
+     */
+    public void setPitchAndFamily(int val){
+        _recdata[67] = (byte)val;
+    }
+
+    /**
+     * get lfPitchAndFamily
+     *
+     * @return corresponds to the lfPitchAndFamily field of the Win32 API LOGFONT structure
+     */
+    public int getPitchAndFamily(){
+        return _recdata[67];
+    }
+
+    /**
         * Write the contents of the record back, so it can be written to disk
         */
        public void writeOut(OutputStream out) throws IOException {
index 69173bf5bb700708fd2bf57dff65466b17f193f0..a1bc499453b096748d9a7a7156c7f1c4c293e51d 100644 (file)
@@ -92,7 +92,7 @@ public class RecordTypes {
     public static final Type TextBookmarkAtom = new Type(4007,null);
     public static final Type TextBytesAtom = new Type(4008,TextBytesAtom.class);
     public static final Type TxSIStyleAtom = new Type(4009,null);
-    public static final Type TextSpecInfoAtom = new Type(4010,null);
+    public static final Type TextSpecInfoAtom = new Type(4010, TextSpecInfoAtom.class);
     public static final Type DefaultRulerAtom = new Type(4011,null);
     public static final Type FontEntityAtom = new Type(4023,FontEntityAtom.class);
     public static final Type FontEmbeddedData = new Type(4024,null);
diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
new file mode 100755 (executable)
index 0000000..a8915f0
--- /dev/null
@@ -0,0 +1,85 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.hslf.record;\r
+\r
+import org.apache.poi.util.LittleEndian;\r
+\r
+import java.io.OutputStream;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * The special info runs contained in this text.\r
+ * Special info runs consist of character properties which don?t follow styles.\r
+ * \r
+ * @author Yegor Kozlov\r
+ */\r
+public class TextSpecInfoAtom extends RecordAtom {\r
+    /**\r
+     * Record header.\r
+     */\r
+    private byte[] _header;\r
+\r
+    /**\r
+     * Record data.\r
+     */\r
+    private byte[] _data;\r
+\r
+    /**\r
+     * Constructs the link related atom record from its\r
+     *  source data.\r
+     *\r
+     * @param source the source data as a byte array.\r
+     * @param start the start offset into the byte array.\r
+     * @param len the length of the slice in the byte array.\r
+     */\r
+    protected TextSpecInfoAtom(byte[] source, int start, int len) {\r
+        // Get the header.\r
+        _header = new byte[8];\r
+        System.arraycopy(source,start,_header,0,8);\r
+\r
+        // Get the record data.\r
+        _data = new byte[len-8];\r
+        System.arraycopy(source,start+8,_data,0,len-8);\r
+\r
+    }\r
+    /**\r
+     * Gets the record type.\r
+     * @return the record type.\r
+     */\r
+    public long getRecordType() { return RecordTypes.TextSpecInfoAtom.typeID; }\r
+\r
+    /**\r
+     * Write the contents of the record back, so it can be written\r
+     * to disk\r
+     *\r
+     * @param out the output stream to write to.\r
+     * @throws java.io.IOException if an error occurs.\r
+     */\r
+    public void writeOut(OutputStream out) throws IOException {\r
+        out.write(_header);\r
+        out.write(_data);\r
+    }\r
+\r
+    /**\r
+     * Update the text length\r
+     *\r
+     * @param size the text length\r
+     */\r
+    public void setTextSize(int size){\r
+        LittleEndian.putInt(_data, 0, size);\r
+    }\r
+}\r
index 9ce9a12c9d794380e0350bbf037c11b8194aa756..21e30ac2a9328f655408e72c094082ad60602c55 100644 (file)
@@ -757,4 +757,50 @@ public class SlideShow
         }
         return addPicture(data, format);
     }
+
+    /**
+     * Add a font in this presentation
+     *
+     * @param font the font to add
+     * @return 0-based index of the font
+     */
+    public int addFont(PPFont font) {
+        FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection();
+        int idx = fonts.getFontIndex(font.getFontName());
+        if(idx == -1){
+            idx = fonts.addFont(font.getFontName(), font.getCharSet(), font.getFontFlags(), font.getFontType(), font.getPitchAndFamily());
+        }
+        return idx;
+    }
+
+    /**
+     * Get a font by index
+     *
+     * @param idx 0-based index of the font
+     * @return of an instance of <code>PPFont</code> or <code>null</code> if not found
+     */
+    public PPFont getFont(int idx) {
+        PPFont font = null;
+        FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection();
+        Record[] ch = fonts.getChildRecords();
+        for (int i = 0; i < ch.length; i++) {
+            if(ch[i] instanceof FontEntityAtom) {
+                FontEntityAtom atom = (FontEntityAtom)ch[i];
+                if(atom.getFontIndex() == idx){
+                    font = new PPFont(atom);
+                    break;
+                }
+            }
+        }
+        return font;
+    }
+
+    /**
+     * get the number of fonts in the presentation
+     *
+     * @return number of fonts
+     */
+    public int getNumberOfFonts() {
+        return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts();
+    }
 }
index 23e1e94ca8a5d1888d35fd89f307c4b01e57e059..20d2398e39f63764870e4548c7b7e3ffa50fd6db 100644 (file)
Binary files a/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt and b/src/scratchpad/testcases/org/apache/poi/hslf/data/empty.ppt differ
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/text_shapes.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/text_shapes.ppt
new file mode 100755 (executable)
index 0000000..c36183a
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/text_shapes.ppt differ
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
new file mode 100755 (executable)
index 0000000..b6864ea
--- /dev/null
@@ -0,0 +1,56 @@
+\r
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.model;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+\r
+import java.io.IOException;\r
+\r
+/**\r
+ * Test adding fonts to the presenataion resources\r
+ * \r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestPPFont extends TestCase{\r
+\r
+    public void testCreate() throws IOException {\r
+        SlideShow ppt = new SlideShow();\r
+        assertEquals(1, ppt.getNumberOfFonts());\r
+        assertEquals("Arial", ppt.getFont(0).getFontName());\r
+\r
+        //adding the same font twice\r
+        assertEquals(0, ppt.addFont(PPFont.ARIAL));\r
+        assertEquals(1, ppt.getNumberOfFonts());\r
+\r
+        assertEquals(1, ppt.addFont(PPFont.TIMES_NEW_ROMAN));\r
+        assertEquals(2, ppt.addFont(PPFont.COURIER_NEW));\r
+        assertEquals(3, ppt.addFont(PPFont.WINGDINGS));\r
+\r
+        assertEquals(4, ppt.getNumberOfFonts());\r
+\r
+        assertEquals(PPFont.TIMES_NEW_ROMAN.getFontName(), ppt.getFont(1).getFontName());\r
+        assertEquals(PPFont.COURIER_NEW.getFontName(), ppt.getFont(2).getFontName());\r
+\r
+        PPFont font3 = ppt.getFont(3);\r
+        assertEquals(PPFont.WINGDINGS.getFontName(), font3.getFontName());\r
+        assertEquals(PPFont.SYMBOL_CHARSET, font3.getCharSet());\r
+        assertEquals(PPFont.VARIABLE_PITCH, font3.getPitchAndFamily());\r
+    }\r
+}\r
index 1fe8f7e5e6d88d135c6edecabd2cabc31c20e19b..c2e081ee5caa407782fe441800a0f7ba6a040a99 100644 (file)
@@ -218,8 +218,8 @@ public class TestShapes extends TestCase {
             ArrayList lst2 = new ArrayList();
             Shape[] sh = sl[k].getShapes();
             for (int i = 0; i < sh.length; i++) {
-                if (sh[i] instanceof TextBox){
-                    TextBox tbox = (TextBox)sh[i];
+                if (sh[i] instanceof TextShape){
+                    TextShape tbox = (TextShape)sh[i];
                     lst2.add(tbox.getText());
                 }
             }
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java
new file mode 100755 (executable)
index 0000000..25a8db9
--- /dev/null
@@ -0,0 +1,160 @@
+\r
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+\r
+package org.apache.poi.hslf.model;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import java.io.*;\r
+import java.util.ArrayList;\r
+\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.record.TextHeaderAtom;\r
+\r
+/**\r
+ * Verify behavior of <code>TextShape</code> and its sub-classes\r
+ * \r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestTextShape extends TestCase {\r
+    protected String cwd = System.getProperty("HSLF.testdata.path");\r
+\r
+    public void testCreateAutoShape(){\r
+        TextShape shape = new AutoShape(ShapeTypes.Trapezoid);\r
+        assertNull(shape.getTextRun());\r
+        assertNull(shape.getText());\r
+        assertNull(shape.getEscherTextboxWrapper());\r
+\r
+        TextRun run = shape.createTextRun();\r
+        assertNotNull(run);\r
+        assertNotNull(shape.getTextRun());\r
+        assertNotNull(shape.getEscherTextboxWrapper());\r
+        assertEquals("", shape.getText());\r
+        assertSame(run, shape.createTextRun());\r
+\r
+    }\r
+\r
+    public void testCreateTextBox(){\r
+        TextShape shape = new TextBox();\r
+        TextRun run = shape.getTextRun();\r
+        assertNotNull(run);\r
+        assertNotNull(shape.getText());\r
+        assertNotNull(shape.getEscherTextboxWrapper());\r
+\r
+        assertSame(run, shape.createTextRun());\r
+        assertNotNull(shape.getTextRun());\r
+        assertNotNull(shape.getEscherTextboxWrapper());\r
+        assertEquals("", shape.getText());\r
+\r
+    }\r
+\r
+    /**\r
+     * Verify we can get text from TextShape in the following cases:\r
+     *  - placeholders\r
+     *  - normal TextBox object\r
+     *  - text in auto-shapes\r
+     */\r
+    public void testRead() throws IOException {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "text_shapes.ppt"));\r
+        SlideShow ppt = new SlideShow(is);\r
+        is.close();\r
+\r
+        ArrayList lst1 = new ArrayList();\r
+        Slide slide = ppt.getSlides()[0];\r
+        Shape[] shape = slide.getShapes();\r
+        for (int i = 0; i < shape.length; i++) {\r
+            assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof TextShape);\r
+            TextShape tx = (TextShape)shape[i];\r
+            TextRun run = tx.getTextRun();\r
+            assertNotNull(run);\r
+            int runType = run.getRunType();\r
+\r
+            int type = shape[i].getShapeType();\r
+            switch (type){\r
+                case ShapeTypes.TextBox:\r
+                    assertEquals("Text in a TextBox", run.getText());\r
+                    break;\r
+                case ShapeTypes.Rectangle:\r
+                    if(runType == TextHeaderAtom.OTHER_TYPE)\r
+                        assertEquals("Rectangle", run.getText());\r
+                    else if(runType == TextHeaderAtom.TITLE_TYPE)\r
+                        assertEquals("Title Placeholder", run.getText());\r
+                    break;\r
+                case ShapeTypes.Octagon:\r
+                    assertEquals("Octagon", run.getText());\r
+                    break;\r
+                case ShapeTypes.Ellipse:\r
+                    assertEquals("Ellipse", run.getText());\r
+                    break;\r
+                case ShapeTypes.RoundRectangle:\r
+                    assertEquals("RoundRectangle", run.getText());\r
+                    break;\r
+                default:\r
+                    fail("Unexpected shape: " + shape[i].getShapeName());\r
+\r
+            }\r
+            lst1.add(run.getText());\r
+        }\r
+\r
+        ArrayList lst2 = new ArrayList();\r
+        TextRun[] run = slide.getTextRuns();\r
+        for (int i = 0; i < run.length; i++) {\r
+            lst2.add(run[i].getText());\r
+        }\r
+\r
+        assertTrue(lst1.containsAll(lst2));\r
+    }\r
+\r
+    public void testReadWrite() throws IOException {\r
+        SlideShow ppt = new SlideShow();\r
+        Slide slide =  ppt.createSlide();\r
+\r
+        TextShape shape1 = new TextBox();\r
+        TextRun run1 = shape1.createTextRun();\r
+        run1.setText("Hello, World!");\r
+        slide.addShape(shape1);\r
+\r
+        shape1.moveTo(100, 100);\r
+\r
+        TextShape shape2 = new AutoShape(ShapeTypes.Arrow);\r
+        TextRun run2 = shape2.createTextRun();\r
+        run2.setText("Testing TextShape");\r
+        slide.addShape(shape2);\r
+        shape2.moveTo(300, 300);\r
+\r
+        ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+        ppt.write(out);\r
+        out.close();\r
+\r
+        ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));\r
+        slide = ppt.getSlides()[0];\r
+        Shape[] shape = slide.getShapes();\r
+\r
+        assertTrue(shape[0] instanceof TextShape);\r
+        shape1 = (TextShape)shape[0];\r
+        assertEquals(ShapeTypes.TextBox, shape1.getShapeType());\r
+        assertEquals("Hello, World!", shape1.getTextRun().getText());\r
+\r
+        assertTrue(shape[1] instanceof TextShape);\r
+        shape1 = (TextShape)shape[1];\r
+        assertEquals(ShapeTypes.Arrow, shape1.getShapeType());\r
+        assertEquals("Testing TextShape", shape1.getTextRun().getText());\r
+    }\r
+\r
+}\r
index 36e45501ec7f94e6985450e11e85deba15471ff5..19e7af64177e1119568846757a8dcff3c8031edb 100644 (file)
@@ -316,8 +316,8 @@ public class TestBugs extends TestCase {
         ArrayList lst = new ArrayList();\r
         Shape[] shape = slide.getShapes();\r
         for (int i = 0; i < shape.length; i++) {\r
-            if( shape[i] instanceof TextBox){\r
-                TextRun textRun = ((TextBox)shape[i]).getTextRun();\r
+            if( shape[i] instanceof TextShape){\r
+                TextRun textRun = ((TextShape)shape[i]).getTextRun();\r
                 if(textRun != null) lst.add(textRun);\r
             }\r
 \r
index 2589aa90dd0b2830fdd14d3c67aa6df445526752..31b4dd180abbe4e9b07c6e9f33913a36275d5770 100644 (file)
@@ -142,7 +142,7 @@ public final class TestFormulaParser extends TestCase {
         assertEquals(true, flag.getValue());
         assertEquals("Y", y.getValue());
         assertEquals("N", n.getValue());
-        assertEquals("IF", funif.toFormulaString((Workbook) null));
+        assertEquals("IF", funif.toFormulaString((HSSFWorkbook) null));
         assertTrue("Goto ptg exists", goto1.isGoto());
     }
 
@@ -283,7 +283,7 @@ public final class TestFormulaParser extends TestCase {
        }
        
     public void testMacroFunction() {
-        Workbook w = Workbook.createWorkbook();
+       HSSFWorkbook w = new HSSFWorkbook();
         FormulaParser fp = new FormulaParser("FOO()", w);
         fp.parse();
         Ptg[] ptg = fp.getRPNPtg();
@@ -589,8 +589,7 @@ public final class TestFormulaParser extends TestCase {
      * a formula consisting of a single no-arg function got rendered without the function braces
      */
     public void testToFormulaStringZeroArgFunction() {
-
-        Workbook book = Workbook.createWorkbook(); // not really used in this test
+       HSSFWorkbook book = new HSSFWorkbook();
 
         Ptg[] ptgs = {
                 new FuncPtg(10, 0),
@@ -889,7 +888,7 @@ public final class TestFormulaParser extends TestCase {
         }
     }
     public void testFuncPtgSelection() {
-        Workbook book = Workbook.createWorkbook();
+       HSSFWorkbook book = new HSSFWorkbook();
         Ptg[] ptgs;
         ptgs = FormulaParser.parse("countif(A1:A2, 1)", book);
         assertEquals(3, ptgs.length);
index 8f7593f09ff2ab7437aefb95534dbacefb6beeaf..afc44e7043e0d1e8a9e00b041fa8d1d4f153cc68 100644 (file)
@@ -19,11 +19,11 @@ package org.apache.poi.hssf.record;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
 import org.apache.poi.hssf.record.cf.BorderFormatting;
 import org.apache.poi.hssf.record.cf.FontFormatting;
 import org.apache.poi.hssf.record.cf.PatternFormatting;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.util.LittleEndian;
 
@@ -38,7 +38,7 @@ public final class TestCFRuleRecord extends TestCase
 
        public void testCreateCFRuleRecord () 
        {
-               Workbook workbook = Workbook.createWorkbook();
+               HSSFWorkbook workbook = new HSSFWorkbook();
                CFRuleRecord record = CFRuleRecord.create(workbook, "7");
                testCFRuleRecord(record);
 
@@ -278,7 +278,7 @@ public final class TestCFRuleRecord extends TestCase
        }
 
        public void testWrite() {
-               Workbook workbook = Workbook.createWorkbook();
+               HSSFWorkbook workbook = new HSSFWorkbook();
                CFRuleRecord rr = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "5", "10");
 
                PatternFormatting patternFormatting = new PatternFormatting();
@@ -293,7 +293,8 @@ public final class TestCFRuleRecord extends TestCase
                int flags = LittleEndian.getInt(data, 10);
                assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
                assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
-               assertEquals(0xA03FFFFF, flags);
+               // check all remaining flag bits (some are not well understood yet)
+               assertEquals(0x203FFFFF, flags);
        }
 
 
index f605097768d5523e013c254d6045fd8785b40aa0..2ae8230d5e95dd1f36195d6ac3c878bb80805499 100644 (file)
@@ -24,12 +24,12 @@ import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.RecordFactory;
 import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator;
 import org.apache.poi.hssf.record.cf.CellRange;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Tests the serialization and deserialization of the CFRecordsAggregate
@@ -42,7 +42,7 @@ public final class TestCFRecordsAggregate extends TestCase
 
        public void testCFRecordsAggregate() 
        {
-               Workbook workbook = Workbook.createWorkbook();
+               HSSFWorkbook workbook = new HSSFWorkbook();
                List recs = new ArrayList();
                CFHeaderRecord header = new CFHeaderRecord();
                CFRuleRecord rule1 = CFRuleRecord.create(workbook, "7");
index b8d223a4a883839b0c5c3842f0cdecc4af71781f..db29380a9cc65abe794fddf8b7ab8748f7897e48 100644 (file)
@@ -51,13 +51,9 @@ public abstract class AbstractPtgTestCase extends TestCase {
     /**
      * Creates a new Workbook and adds one sheet with the specified name
      */
-    protected static final Workbook createWorkbookWithSheet(String sheetName) {
-        
-        Workbook book = Workbook.createWorkbook();
-        // this creates sheet if it doesn't exist
-        book.checkExternSheet(0);
-        // TODO - this call alone does not create the sheet even though the javadoc says it does
-        book.setSheetName(0, sheetName); 
+    protected static final HSSFWorkbook createWorkbookWithSheet(String sheetName) {
+        HSSFWorkbook book = new HSSFWorkbook();
+        book.createSheet(sheetName);
         return book;
     }
 }
index 2af50d4b93b76e8dc68310df334a56b7825999a9..e83a59b42db4681a9a5ba79875b02e075c2c35d5 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Tests for Area3DPtg
@@ -35,7 +35,7 @@ public final class TestArea3DPtg extends AbstractPtgTestCase {
                Area3DPtg target = new Area3DPtg("A1:B1", (short)0);
                
                String sheetName = "my sheet";
-               Workbook book = createWorkbookWithSheet(sheetName);
+               HSSFWorkbook book = createWorkbookWithSheet(sheetName);
                assertEquals("'my sheet'!A1:B1", target.toFormulaString(book));
                
         book.setSheetName(0, "Sheet1");
@@ -44,7 +44,4 @@ public final class TestArea3DPtg extends AbstractPtgTestCase {
         book.setSheetName(0, "C64");
         assertEquals("'C64'!A1:B1", target.toFormulaString(book));
        }
-
-
-
 }
index b5fbe3b80d1158a438c7d31ebc8e8d635602a0b8..4de0c7bdb270b240d648d508b4f280a500dd7d5c 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
 /**
  * Tests for Ref3DPtg
@@ -31,7 +31,7 @@ public final class TestRef3DPtg extends AbstractPtgTestCase {
                
                Ref3DPtg target = new Ref3DPtg("A1", (short)0);
                
-               Workbook book = createWorkbookWithSheet("my sheet");
+               HSSFWorkbook book = createWorkbookWithSheet("my sheet");
                
                assertEquals("'my sheet'!A1", target.toFormulaString(book));
 
index fdad5f44d8f9ef7c8788e105af648404066ad15d..1e26fa706ed1f90cb79111b85e42a388969bb31a 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
 import org.apache.poi.hssf.record.formula.FuncPtg;
 import org.apache.poi.hssf.record.formula.FuncVarPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 /**
  * Tests parsing of some built-in functions that were not properly
  * registered in POI as bug #44675, #44733 (March/April 2008).
@@ -35,7 +36,7 @@ import org.apache.poi.hssf.record.formula.Ptg;
 public final class TestParseMissingBuiltInFuncs extends TestCase {
 
        private static Ptg[] parse(String formula) {
-               Workbook book = Workbook.createWorkbook();
+               HSSFWorkbook book = new HSSFWorkbook();
                return FormulaParser.parse(formula, book);
        }
        private static void confirmFunc(String formula, int expPtgArraySize, boolean isVarArgFunc, int funcIx) {
@@ -57,7 +58,7 @@ public final class TestParseMissingBuiltInFuncs extends TestCase {
                assertEquals(expCls, ptgF.getClass());
                
                // check that parsed Ptg array converts back to formula text OK
-               Workbook book = Workbook.createWorkbook();
+               HSSFWorkbook book = new HSSFWorkbook();
                String reRenderedFormula = FormulaParser.toFormulaString(book, ptgs);
                assertEquals(formula, reRenderedFormula);
        }
index 007cbd5760a9efb42d67f3e40b71d258f8eca00f..19069d32b25f645d7ad00ed7772a46c116b44d5d 100644 (file)
@@ -203,7 +203,7 @@ public final class TestFormulaEvaluatorBugs extends TestCase {
                assertEquals(2, ptg.getLastColumn());
                assertEquals(0, ptg.getFirstRow());
                assertEquals(65535, ptg.getLastRow());
-               assertEquals("C:C", ptg.toFormulaString(wb.getWorkbook()));
+               assertEquals("C:C", ptg.toFormulaString(wb));
 
                // Will show as C:C, but won't know how many
                //  rows it covers as we don't have the sheet
index 930970ea22e4e19b059a0951a3f44438ba9cfbd7..6dbcf815dc8486b3bb4e465bbe86d747269d3ed1 100644 (file)
@@ -34,22 +34,26 @@ public final class TestHSSFConditionalFormatting extends TestCase
                HSSFSheet sheet = workbook.createSheet();
                String formula = "7";
 
-               HSSFFontFormatting fontFmt = new HSSFFontFormatting();
+               HSSFSheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
+               
+               HSSFConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(formula);
+               HSSFFontFormatting fontFmt = rule1.createFontFormatting();
                fontFmt.setFontStyle(true, false);
 
-               HSSFBorderFormatting bordFmt = new HSSFBorderFormatting();
+               HSSFBorderFormatting bordFmt = rule1.createBorderFormatting();
                bordFmt.setBorderBottom(HSSFBorderFormatting.BORDER_THIN);
                bordFmt.setBorderTop(HSSFBorderFormatting.BORDER_THICK);
                bordFmt.setBorderLeft(HSSFBorderFormatting.BORDER_DASHED);
                bordFmt.setBorderRight(HSSFBorderFormatting.BORDER_DOTTED);
 
-               HSSFPatternFormatting patternFmt = new HSSFPatternFormatting();
-               patternFmt.setFillBackgroundColor(HSSFColor.RED.index);
+               HSSFPatternFormatting patternFmt = rule1.createPatternFormatting();
+               patternFmt.setFillBackgroundColor(HSSFColor.YELLOW.index);
 
+               
+               HSSFConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2");
                HSSFConditionalFormattingRule [] cfRules =
                {
-                       sheet.createConditionalFormattingRule(formula, fontFmt, bordFmt, patternFmt),
-                       sheet.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2", fontFmt, bordFmt, patternFmt)
+                       rule1, rule2
                };
 
                short col = 1;
@@ -58,14 +62,14 @@ public final class TestHSSFConditionalFormatting extends TestCase
                        new Region(0,col,65535,col)
                };
 
-               sheet.addConditionalFormatting(regions, cfRules);
-               sheet.addConditionalFormatting(regions, cfRules);
+               sheetCF.addConditionalFormatting(regions, cfRules);
+               sheetCF.addConditionalFormatting(regions, cfRules);
 
                // Verification
-               assertEquals(2, sheet.getNumConditionalFormattings());
-               sheet.removeConditionalFormatting(1);
-               assertEquals(1, sheet.getNumConditionalFormattings());
-               HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(0);
+               assertEquals(2, sheetCF.getNumConditionalFormattings());
+               sheetCF.removeConditionalFormatting(1);
+               assertEquals(1, sheetCF.getNumConditionalFormattings());
+               HSSFConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
                assertNotNull(cf);
 
                regions = cf.getFormattingRegions();
@@ -79,7 +83,7 @@ public final class TestHSSFConditionalFormatting extends TestCase
 
                assertEquals(2, cf.getNumberOfRules());
 
-               HSSFConditionalFormattingRule rule1 = cf.getRule(0);
+               rule1 = cf.getRule(0);
                assertEquals("7",rule1.getFormula1()); 
                assertNull(rule1.getFormula2());
                
@@ -98,11 +102,10 @@ public final class TestHSSFConditionalFormatting extends TestCase
 
                HSSFPatternFormatting r1pf = rule1.getPatternFormatting();
                assertNotNull(r1pf);
-               assertEquals(HSSFColor.RED.index,r1pf.getFillBackgroundColor());                
+               assertEquals(HSSFColor.YELLOW.index,r1pf.getFillBackgroundColor());             
 
-               HSSFConditionalFormattingRule rule2 = cf.getRule(1);
+               rule2 = cf.getRule(1);
                assertEquals("2",rule2.getFormula2()); 
                assertEquals("1",rule2.getFormula1()); 
        }
-       
 }
index a72c039cb821b7a638b22489fb02f2c9bf7dd693..5eb2abb6e690569e4ed13a4fdc01cde391c27593 100644 (file)
@@ -211,12 +211,12 @@ public final class TestAreaReference extends TestCase {
         Area3DPtg ptgB = (Area3DPtg)def.get(1);
         Area3DPtg ptgC = (Area3DPtg)def.get(2);
         UnionPtg ptgD = (UnionPtg)def.get(3);
-        assertEquals("", ptgA.toFormulaString(workbook));
-        assertEquals(refA, ptgB.toFormulaString(workbook));
-        assertEquals(refB, ptgC.toFormulaString(workbook));
-        assertEquals(",", ptgD.toFormulaString(workbook));
+        assertEquals("", ptgA.toFormulaString(wb));
+        assertEquals(refA, ptgB.toFormulaString(wb));
+        assertEquals(refB, ptgC.toFormulaString(wb));
+        assertEquals(",", ptgD.toFormulaString(wb));
 
-        assertEquals(ref, nr.getAreaReference(workbook));
+        assertEquals(ref, nr.getAreaReference(wb));
 
         // Check the high level definition
         int idx = wb.getNameIndex("test");