]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Simplifications to FOText whitespace removal; fewer arraycopies performed.
authorGlen Mazza <gmazza@apache.org>
Fri, 12 Mar 2004 00:41:05 +0000 (00:41 +0000)
committerGlen Mazza <gmazza@apache.org>
Fri, 12 Mar 2004 00:41:05 +0000 (00:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197443 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/layoutmgr/AbstractLayoutManager.java
src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
src/java/org/apache/fop/render/rtf/RTFHandler.java

index ea25beeef29891415bae6ca1aae400c09599e1e2..b59f628c5c00ce54952b4f45d6f2fd25a6c62ded 100644 (file)
@@ -44,14 +44,14 @@ public class FOText extends FObj {
     public char[] ca;
 
     /**
-     * The actual length of the text to be rendered within ca,
-     * starting from position 0 of the array.  
+     * The starting valid index of the ca array 
+     * to be processed.
      *
-     * This value is originally equal to ca.length, but becomes decremented
-     * during whitespace removal by the flow.Block class, via the 
-     * TextCharIterator.remove() method below.
+     * This value is originally equal to ca.length, but becomes 
+     * incremented during whitespace removal by the flow.Block class,  
+     * via the TextCharIterator.remove() method below.
      */
-    public int length;
+    public int start = 0;
 
     /**
      * The TextInfo object attached to the text
@@ -100,7 +100,7 @@ public class FOText extends FObj {
      */
     public FOText(char[] chars, int start, int end, TextInfo ti, FONode parent) {
         super(parent);
-        length = end - start;
+        int length = end - start;
         this.ca = new char[length];
         System.arraycopy(chars, start, ca, 0, length);
         textInfo = ti;
@@ -119,11 +119,11 @@ public class FOText extends FObj {
      */
     public boolean willCreateArea() {
         if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE
-                && length > 0) {
+                && ca.length - start > 0) {
             return true;
         }
 
-        for (int i = 0; i < length; i++) {
+        for (int i = start; i < ca.length; i++) {
             char ch = ca[i];
             if (!((ch == ' ')
                     || (ch == '\n')
@@ -146,11 +146,11 @@ public class FOText extends FObj {
         private int curIndex = 0;
 
         public boolean hasNext() {
-            return (curIndex < length);
+            return (curIndex < ca.length);
         }
 
         public char nextChar() {
-            if (curIndex < length) {
+            if (curIndex < ca.length) {
                 // Just a char class? Don't actually care about the value!
                 return ca[curIndex++];
             } else {
@@ -159,25 +159,17 @@ public class FOText extends FObj {
         }
 
         public void remove() {
-            if (curIndex > 0 && curIndex < length) {
-                // copy from curIndex to end to curIndex-1
-                System.arraycopy(ca, curIndex, ca, curIndex - 1,
-                                 length - curIndex);
-                length--;
-                curIndex--;
-            } else if (curIndex == length) {
-                curIndex = --length;
+            if (start < ca.length) {
+                start++;
             }
         }
 
-
         public void replaceChar(char c) {
-            if (curIndex > 0 && curIndex <= length) {
+            if (curIndex > 0 && curIndex <= ca.length) {
                 ca[curIndex - 1] = c;
             }
         }
 
-
     }
 
     /**
@@ -239,7 +231,7 @@ public class FOText extends FObj {
      * @return True if the character at this location is the start of a new
      * word.
      */
-    public boolean isStartOfWord (int i) {
+    private boolean isStartOfWord(int i) {
         char prevChar = getRelativeCharInBlock(i, -1);
         /* All we are really concerned about here is of what type prevChar
            is. If inputChar is not part of a word, then the Java
@@ -285,9 +277,9 @@ public class FOText extends FObj {
      * @return the character in the offset position within the block; \u0000 if
      * the offset points to an area outside of the block.
      */
-    public char getRelativeCharInBlock(int i, int offset) {
+    private char getRelativeCharInBlock(int i, int offset) {
         // The easy case is where the desired character is in the same FOText
-        if (((i + offset) >= 0) && ((i + offset) <= this.length)) {
+        if (((i + offset) >= 0) && ((i + offset) <= this.ca.length)) {
             return ca[i + offset];
         }
         // For now, we can't look at following FOText nodes
@@ -345,7 +337,7 @@ public class FOText extends FObj {
      * @param i the index into ca[]
      * @return char with transformed value
      */
-    public char charTransform(int i) {
+    private char charTransform(int i) {
         switch (textInfo.textTransform) {
         /* put NONE first, as this is probably the common case */
         case TextTransform.NONE:
index 8803992a503988b61135bfab98ac1f698e5c7b0a..f1deac548e589a1a77dba154a737c016e27cefcf 100644 (file)
@@ -55,7 +55,7 @@ public class FObjMixed extends FObj {
         ft.setName("text");
         
         /* characters() processing empty for FOTreeHandler, not empty for RTF & MIFHandlers */
-        getFOTreeControl().getFOInputHandler().characters(ft.ca, 0, ft.ca.length);
+        getFOTreeControl().getFOInputHandler().characters(ft.ca, ft.start, ft.ca.length);
 
         addChild(ft);
     }
index 9379e03284b34241bbe6ae737e380e6b6f1c3c77..a1e20cd7f94dd815053e61a32120a5d032d6a813 100644 (file)
@@ -54,10 +54,19 @@ public abstract class AbstractLayoutManager implements LayoutProcessor, Constant
     public AbstractLayoutManager() {
     }
 
+    /**
+     * Abstract layout manager.
+     *
+     * @param fo the formatting object for this layout manager
+     */
+    public AbstractLayoutManager(FObj fo) {
+        setFObj(fo);
+    }
+
     /**
      * Set the FO object for this layout manager
      *
-     * @param fo the fo for this layout manager
+     * @param fo the formatting object for this layout manager
      */
     public void setFObj(FObj fo) {
         this.fobj = fo;
index 852f198c0858ec3faf9faafd0fd3923d5c7615a2..a34f912de3c2dd56e884815f53cae31ab6940cd8 100644 (file)
@@ -179,11 +179,9 @@ public class AddLMVisitor implements FOTreeVisitor {
         return saveLMList;
     }
 
-    public void serveFOText(FOText node) {
-        if (node.length > 0) {
-            LayoutManager lm = new TextLayoutManager(node.ca, node.length, node.textInfo);
-            lm.setFObj(node);
-            currentLMList.add(lm);
+    public void serveFOText(FOText foText) {
+        if (foText.ca.length - foText.start > 0) {
+            currentLMList.add(new TextLayoutManager(foText));
         }
     }
 
index 08db32806c71e79d2c2ec7d2c7470f74bff28808..e44a9aa9065ffae9826ddbd7d62697d35dbfd854 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.fop.layoutmgr;
 
 import java.util.ArrayList;
 
+import org.apache.fop.fo.FOText;
 import org.apache.fop.fo.TextInfo;
 import org.apache.fop.traits.SpaceVal;
 import org.apache.fop.area.Trait;
@@ -98,10 +99,13 @@ public class TextLayoutManager extends AbstractLayoutManager {
      * @param length length of the above array to be processed
      * @param textInfo the text information for doing layout
      */
-    public TextLayoutManager(char[] chars, int length, TextInfo textInfo) {
-        this.textArray = chars;
-        this.textArrayLength = length;
-        this.textInfo = textInfo;
+    public TextLayoutManager(FOText node) {
+        super(node);
+        this.textArray = new char[node.ca.length - node.start];
+        System.arraycopy(node.ca, node.start, this.textArray, 0,
+            node.ca.length - node.start);
+        this.textArrayLength = node.ca.length - node.start;
+        this.textInfo = node.textInfo;
         this.vecAreaInfo = new java.util.ArrayList();
 
         // With CID fonts, space isn't neccesary currentFontState.width(32)
index 3141276b018dfc08947b2c3d5a88e5ca36852448..593c67d710b8c311651809247a9bb77974398635 100644 (file)
@@ -1152,7 +1152,7 @@ public class RTFHandler extends FOInputHandler {
         } else if (fobj instanceof FOText) {
             if (bStart) {
                 FOText text = (FOText) fobj;
-                characters(text.ca, 0, text.length);
+                characters(text.ca, text.start, text.ca.length);
             }
         } else if (fobj instanceof BasicLink) {
             if (bStart) {