gmazza      2004/03/11 16:41:05

  Modified:    src/java/org/apache/fop/fo FOText.java FObjMixed.java
               src/java/org/apache/fop/layoutmgr AbstractLayoutManager.java
                        AddLMVisitor.java TextLayoutManager.java
               src/java/org/apache/fop/render/rtf RTFHandler.java
  Log:
  Simplifications to FOText whitespace removal; fewer arraycopies performed.
  
  Revision  Changes    Path
  1.17      +18 -26    xml-fop/src/java/org/apache/fop/fo/FOText.java
  
  Index: FOText.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOText.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- FOText.java       7 Mar 2004 17:52:43 -0000       1.16
  +++ FOText.java       12 Mar 2004 00:41:04 -0000      1.17
  @@ -44,14 +44,14 @@
       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 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 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 @@
           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 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 @@
        * @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 @@
        * @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 @@
        * @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:
  
  
  
  1.22      +1 -1      xml-fop/src/java/org/apache/fop/fo/FObjMixed.java
  
  Index: FObjMixed.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObjMixed.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- FObjMixed.java    1 Mar 2004 23:50:26 -0000       1.21
  +++ FObjMixed.java    12 Mar 2004 00:41:04 -0000      1.22
  @@ -55,7 +55,7 @@
           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);
       }
  
  
  
  1.7       +10 -1     
xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
  
  Index: AbstractLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractLayoutManager.java        27 Feb 2004 17:49:25 -0000      1.6
  +++ AbstractLayoutManager.java        12 Mar 2004 00:41:04 -0000      1.7
  @@ -55,9 +55,18 @@
       }
   
       /**
  +     * 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;
  
  
  
  1.32      +4 -6      xml-fop/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
  
  Index: AddLMVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- AddLMVisitor.java 1 Mar 2004 23:50:26 -0000       1.31
  +++ AddLMVisitor.java 12 Mar 2004 00:41:04 -0000      1.32
  @@ -179,11 +179,9 @@
           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));
           }
       }
   
  
  
  
  1.11      +8 -4      xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
  
  Index: TextLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TextLayoutManager.java    1 Mar 2004 23:50:26 -0000       1.10
  +++ TextLayoutManager.java    12 Mar 2004 00:41:04 -0000      1.11
  @@ -20,6 +20,7 @@
   
   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 @@
        * @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)
  
  
  
  1.20      +2 -2      xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java
  
  Index: RTFHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- RTFHandler.java   27 Feb 2004 17:54:39 -0000      1.19
  +++ RTFHandler.java   12 Mar 2004 00:41:05 -0000      1.20
  @@ -1152,7 +1152,7 @@
           } 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) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to