diff options
author | Glen Mazza <gmazza@apache.org> | 2004-03-12 00:41:05 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-03-12 00:41:05 +0000 |
commit | 2211452edf300b026061569655723094ee883bcd (patch) | |
tree | 51baca2f28a37a91be412c65b56436b5da3c58a4 | |
parent | 479147c89407e12cd0e5a208e1e6f85ee39535f1 (diff) | |
download | xmlgraphics-fop-2211452edf300b026061569655723094ee883bcd.tar.gz xmlgraphics-fop-2211452edf300b026061569655723094ee883bcd.zip |
Simplifications to FOText whitespace removal; fewer arraycopies performed.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197443 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/fo/FOText.java | 44 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/FObjMixed.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java | 11 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/AddLMVisitor.java | 8 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/TextLayoutManager.java | 12 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/rtf/RTFHandler.java | 2 |
6 files changed, 41 insertions, 38 deletions
diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index ea25beeef..b59f628c5 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -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: diff --git a/src/java/org/apache/fop/fo/FObjMixed.java b/src/java/org/apache/fop/fo/FObjMixed.java index 8803992a5..f1deac548 100644 --- a/src/java/org/apache/fop/fo/FObjMixed.java +++ b/src/java/org/apache/fop/fo/FObjMixed.java @@ -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); } diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 9379e0328..a1e20cd7f 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -55,9 +55,18 @@ public abstract class AbstractLayoutManager implements LayoutProcessor, Constant } /** + * 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; diff --git a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java index 852f198c0..a34f912de 100644 --- a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java +++ b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java @@ -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)); } } diff --git a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java index 08db32806..e44a9aa90 100644 --- a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -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) diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 3141276b0..593c67d71 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -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) { |