]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Improvement for FOText instance creation. The text is consolidated into single FOText...
authorJeremias Maerki <jeremias@apache.org>
Thu, 9 Jun 2005 06:45:49 +0000 (06:45 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 9 Jun 2005 06:45:49 +0000 (06:45 +0000)
Submitted by: "Hock Szabolcs" <Hock.Szabolcs.at.t-online.co.hu>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198724 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/FOText.java
src/java/org/apache/fop/fo/FObjMixed.java
src/java/org/apache/fop/fo/flow/Block.java
src/java/org/apache/fop/fo/flow/Inline.java
src/java/org/apache/fop/fo/flow/Marker.java

index ec86ef8673b0424d8044ee49712466db7dcac7d7..01674f6153c14dcbb7e81a13a3f56b4d84bec268 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.fop.fo.properties.CommonHyphenation;
 import org.apache.fop.fo.properties.CommonTextDecoration;
 import org.apache.fop.fo.properties.Property;
 import org.apache.fop.fo.properties.SpaceProperty;
+import org.xml.sax.Locator;
 
 /**
  * A text node (PCDATA) in the formatting object tree.
@@ -88,21 +89,32 @@ public class FOText extends FONode {
     private static final int IS_WORD_CHAR_MAYBE = 2;
 
     /**
-     *
-     * @param chars array of chars which contains the text in this object (may
-     * be a superset of the text in this object)
-     * @param start starting index into char[] for the text in this object
-     * @param end ending index into char[] for the text in this object
+     * Creates a now FO text node.
      * @param parent FONode that is the parent of this object
      */
-    public FOText(char[] chars, int start, int end, FONode parent) {
+    public FOText(FONode parent) {
         super(parent);
-        endIndex = end - start;
-        this.ca = new char[endIndex];
-        System.arraycopy(chars, start, ca, 0, endIndex);
-//      System.out.println("->" + new String(ca) + "<-");
     }
 
+    /** @see org.apache.fop.fo.FONode */
+    protected void addCharacters(char[] data, int start, int end,
+            PropertyList list, Locator locator) throws FOPException {
+
+        int length = end - start;
+        int calength = 0;
+        char[] nca = null;
+        if (ca != null) {
+            calength = ca.length;
+            nca = new char[calength + length];
+            System.arraycopy(ca, 0, nca, 0, calength);
+        } else {
+            nca = new char[length];
+        }
+        System.arraycopy(data, start, nca, calength, length);
+        endIndex = nca.length;
+        this.ca = nca;
+     }
+
     /**
      * @see org.apache.fop.fo.FObj#bind(PropertyList)
      */
@@ -120,7 +132,8 @@ public class FOText extends FONode {
         textDecoration = pList.getTextDecorationProps();
     }
 
-    protected void startOfNode() {
+    /** @see org.apache.fop.fo.FONode#endOfNode() */
+    protected void endOfNode() throws FOPException {
         textTransform();
     }
 
index b20cedc143662f7ae73432cb61686695a4b34949..853ff57b3f339a2b245d397527dfa430bdaa776a 100644 (file)
@@ -28,6 +28,10 @@ import org.apache.fop.apps.FOPException;
  * It should not be instantiated directly.
  */
 public abstract class FObjMixed extends FObj {
+    
+    /** Represents accumulated, pending FO text. See flushText(). */
+    protected FOText ft = null;
+    
     /**
      * @param parent FONode that is the parent of this object
      */
@@ -35,26 +39,41 @@ public abstract class FObjMixed extends FObj {
         super(parent);
     }
 
-    /**
-     * Adds characters
-     * @param data array of characters containing text to be added
-     * @param start starting array element to add
-     * @param end ending array element to add
-     * @param pList currently applicable PropertyList 
-     * @param locator location in fo source file.
-     * @throws FOPException if there's a problem during processing
-     * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, org.apache.fop.fo.PropertyList, org.xml.sax.Locator)
-     */
+    /** @see org.apache.fop.fo.FONode */
     protected void addCharacters(char[] data, int start, int end,
                                  PropertyList pList,
                                  Locator locator) throws FOPException {
-        FOText ft = new FOText(data, start, end, this);
-        ft.setLocator(locator);
-        ft.bind(pList);
-        ft.startOfNode();
-        
-        getFOEventHandler().characters(ft.ca, ft.startIndex, ft.endIndex);
-        addChildNode(ft);
+        if (ft == null) {
+            ft = new FOText(this);
+            ft.setLocator(locator);
+            ft.bind(pList);
+        }
+        ft.addCharacters(data, start, end, null, null);
+    }
+
+    /** @see org.apache.fop.fo.FONode#endOfNode() */
+    protected void endOfNode() throws FOPException {
+        flushText();
+        super.endOfNode();
+    }
+
+    /**
+     * Adds accumulated text as one FOText instance.
+     * @throws FOPException if there is a problem during processing
+     */
+    protected void flushText() throws FOPException {
+       if (ft != null) {
+            FOText lft = ft;
+            ft = null;
+            lft.endOfNode();
+            getFOEventHandler().characters(lft.ca, lft.startIndex, lft.endIndex);
+            addChildNode(lft);
+        }
+    }
+
+    protected void addChildNode(FONode child) throws FOPException {
+        flushText();
+        super.addChildNode(child);
     }
 
     /**
index 73fd6bf9c40cd3f4c9e104c3bc1adae50d89744c..a1c03be5afdd673fb9088cf97d3ed1e0083fd773 100644 (file)
@@ -174,6 +174,7 @@ public class Block extends FObjMixed {
      * @see org.apache.fop.fo.FONode#endOfNode
      */
     protected void endOfNode() throws FOPException {
+        super.endOfNode();
         handleWhiteSpace();
         getFOEventHandler().endBlock(this);
     }
@@ -330,6 +331,7 @@ public class Block extends FObjMixed {
      * @see org.apache.fop.fo.FONode#addChildNode(FONode)
      */
     public void addChildNode(FONode child) throws FOPException {
+        flushText();
         // Handle whitespace based on values of properties
         // Handle a sequence of inline-producing child nodes in
         // one pass
index f396c7dc2d7220b1c1572e629778e46c8add7768..fb62c77b26706a26e1b77335b2635e033e9dc5bd 100644 (file)
@@ -117,6 +117,7 @@ public class Inline extends InlineLevel {
      * @see org.apache.fop.fo.FONode#endOfNode
      */
     protected void endOfNode() throws FOPException {
+        super.endOfNode();
         getFOEventHandler().endInline(this);
     }
 
index 15fe81aed06a9e4a4bbf4c602971a497da0dfb7d..eb03f2f734b327088c82fdfe5ac698a5fbaee601 100644 (file)
@@ -83,6 +83,7 @@ public class Marker extends FObjMixed {
         return new MarkerPropertyList(this, parent);
     }
 
+    /** @see org.apache.fop.fo.FONode#startOfNode() */
     protected void startOfNode() {
         FOEventHandler foEventHandler = getFOEventHandler(); 
         // Push a new property list maker which will make MarkerPropertyLists.
@@ -96,7 +97,9 @@ public class Marker extends FObjMixed {
         });
     }
 
-    protected void endOfNode() {
+    /** @see org.apache.fop.fo.FONode#endOfNode() */
+    protected void endOfNode() throws FOPException {
+        super.endOfNode();
         // Pop the MarkerPropertyList maker.
         getFOEventHandler().setPropertyListMaker(savePropertyListMaker);
         savePropertyListMaker = null;