diff options
author | Glen Mazza <gmazza@apache.org> | 2004-04-04 06:29:44 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-04-04 06:29:44 +0000 |
commit | 5d01341611123b217c6440d8d7e5578e67feda68 (patch) | |
tree | c7947d1bd9aac11ba2f326d3e9df140b85a9ce60 | |
parent | a3ae5cb800f737b9b719e5a68a9f60aff46b2ba5 (diff) | |
download | xmlgraphics-fop-5d01341611123b217c6440d8d7e5578e67feda68.tar.gz xmlgraphics-fop-5d01341611123b217c6440d8d7e5578e67feda68.zip |
Another attempt at fixing the space removal issue. This method
combines the long-standing previous method (the one that removed spaces
between words correctly, at a cost of a leading extra space for the first
FOText instance of an fo:block) with my later patch (which would
fix the extra space issue but had problems with spaces between words). It
appears to work well, but the fo:inline issues Simon brought up will still
need further work.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197489 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/fo/FOText.java | 116 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/FObjMixed.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/AddLMVisitor.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/TextLayoutManager.java | 6 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/rtf/RTFHandler.java | 2 |
5 files changed, 79 insertions, 49 deletions
diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index b59f628c5..ad203a5ab 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -47,11 +47,21 @@ public class FOText extends FObj { * The starting valid index of the ca array * to be processed. * + * This value is originally equal to 0, but becomes + * incremented during leading whitespace removal by the flow.Block class, + * via the TextCharIterator.remove() method below. + */ + public int startIndex = 0; + + /** + * The ending valid index of the ca array + * to be processed. + * * This value is originally equal to ca.length, but becomes - * incremented during whitespace removal by the flow.Block class, + * decremented during between-word whitespace removal by the flow.Block class, * via the TextCharIterator.remove() method below. */ - public int start = 0; + public int endIndex = 0; /** * The TextInfo object attached to the text @@ -100,9 +110,10 @@ public class FOText extends FObj { */ public FOText(char[] chars, int start, int end, TextInfo ti, FONode parent) { super(parent); - int length = end - start; - this.ca = new char[length]; - System.arraycopy(chars, start, ca, 0, length); + endIndex = end - start; + this.ca = new char[endIndex]; + System.arraycopy(chars, start, ca, 0, endIndex); +// System.out.println("->" + new String(ca) + "<-"); textInfo = ti; createBlockPointers(); textTransform(); @@ -119,11 +130,11 @@ public class FOText extends FObj { */ public boolean willCreateArea() { if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE - && ca.length - start > 0) { + && endIndex - startIndex > 0) { return true; } - for (int i = start; i < ca.length; i++) { + for (int i = startIndex; i < endIndex; i++) { char ch = ca[i]; if (!((ch == ' ') || (ch == '\n') @@ -142,37 +153,7 @@ public class FOText extends FObj { return new TextCharIterator(); } - private class TextCharIterator extends AbstractCharIterator { - private int curIndex = 0; - - public boolean hasNext() { - return (curIndex < ca.length); - } - - public char nextChar() { - if (curIndex < ca.length) { - // Just a char class? Don't actually care about the value! - return ca[curIndex++]; - } else { - throw new NoSuchElementException(); - } - } - - public void remove() { - if (start < ca.length) { - start++; - } - } - - public void replaceChar(char c) { - if (curIndex > 0 && curIndex <= ca.length) { - ca[curIndex - 1] = c; - } - } - - } - - /** + /** * This method is run as part of the Constructor, to create xref pointers to * the previous FOText objects within the same Block */ @@ -214,7 +195,7 @@ public class FOText extends FObj { if (textInfo.textTransform == TextTransform.NONE) { return; } - for (int i = 0; i < ca.length; i++) { + for (int i = 0; i < endIndex; i++) { ca[i] = charTransform(i); } } @@ -279,7 +260,7 @@ public class FOText extends FObj { */ 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.ca.length)) { + if (((i + offset) >= 0) && ((i + offset) <= this.endIndex)) { return ca[i + offset]; } // For now, we can't look at following FOText nodes @@ -297,11 +278,11 @@ public class FOText extends FObj { break; } nodeToTest = nodeToTest.prevFOTextThisBlock; - if ((nodeToTest.ca.length + remainingOffset) >= 0) { - charToReturn = nodeToTest.ca[nodeToTest.ca.length + remainingOffset]; + if ((nodeToTest.endIndex + remainingOffset) >= 0) { + charToReturn = nodeToTest.ca[nodeToTest.endIndex + remainingOffset]; foundChar = true; } else { - remainingOffset = remainingOffset + nodeToTest.ca.length; + remainingOffset = remainingOffset + nodeToTest.endIndex; } } return charToReturn; @@ -458,4 +439,53 @@ public class FOText extends FObj { public void acceptVisitor(FOTreeVisitor fotv) { fotv.serveFOText(this); } + + + private class TextCharIterator extends AbstractCharIterator { + private int curIndex = 0; + private int nextCharCalled = 0; + + public boolean hasNext() { + if (curIndex == 0) { +// System.out.println("->" + new String(ca) + "<-"); + } + return (curIndex < endIndex); + } + + public char nextChar() { + if (curIndex < endIndex) { + nextCharCalled++; + // Just a char class? Don't actually care about the value! + return ca[curIndex++]; + } else { + throw new NoSuchElementException(); + } + } + + public void remove() { + if (curIndex < endIndex && nextCharCalled < 2) { + startIndex++; + nextCharCalled = 0; +// System.out.println("removeA: " + new String(ca, startIndex, endIndex - startIndex)); + } else if (curIndex < endIndex) { + // copy from curIndex to end to curIndex-1 + System.arraycopy(ca, curIndex, ca, curIndex - 1, + endIndex - curIndex); + endIndex--; + curIndex--; +// System.out.println("removeB: " + new String(ca, startIndex, endIndex - startIndex)); + } else if (curIndex == endIndex) { +// System.out.println("removeC: " + new String(ca, startIndex, endIndex - startIndex)); + curIndex = --endIndex; + } + } + + public void replaceChar(char c) { + if (curIndex > 0 && curIndex <= endIndex) { + ca[curIndex - 1] = c; + } + } + + } + } diff --git a/src/java/org/apache/fop/fo/FObjMixed.java b/src/java/org/apache/fop/fo/FObjMixed.java index f1deac548..513294ad6 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, ft.start, ft.ca.length); + getFOTreeControl().getFOInputHandler().characters(ft.ca, ft.startIndex, ft.endIndex); addChild(ft); } diff --git a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java index 6d56e6f99..bf6f8aee9 100644 --- a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java +++ b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java @@ -180,7 +180,7 @@ public class AddLMVisitor implements FOTreeVisitor { } public void serveFOText(FOText foText) { - if (foText.ca.length - foText.start > 0) { + if (foText.endIndex - foText.startIndex > 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 d7fae3dc4..ae6987258 100644 --- a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -98,9 +98,9 @@ public class TextLayoutManager extends AbstractLayoutManager { public TextLayoutManager(FOText node) { super(node); foText = node; - textArray = new char[node.ca.length - node.start]; - System.arraycopy(node.ca, node.start, textArray, 0, - node.ca.length - node.start); + textArray = new char[node.endIndex - node.startIndex]; + System.arraycopy(node.ca, node.startIndex, textArray, 0, + node.endIndex - node.startIndex); vecAreaInfo = new java.util.ArrayList(); diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 3d65a071a..708bc6f4d 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, text.start, text.ca.length); + characters(text.ca, text.startIndex, text.endIndex); } } else if (fobj instanceof BasicLink) { if (bStart) { |