You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by gm...@apache.org on 2004/04/04 08:29:44 UTC
cvs commit: xml-fop/src/java/org/apache/fop/render/rtf RTFHandler.java
gmazza 2004/04/03 22:29:44
Modified: src/java/org/apache/fop/fo FOText.java FObjMixed.java
src/java/org/apache/fop/layoutmgr AddLMVisitor.java
TextLayoutManager.java
src/java/org/apache/fop/render/rtf RTFHandler.java
Log:
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.
Revision Changes Path
1.18 +73 -43 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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FOText.java 12 Mar 2004 00:41:04 -0000 1.17
+++ FOText.java 4 Apr 2004 06:29:44 -0000 1.18
@@ -47,11 +47,21 @@
* 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 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 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 @@
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 @@
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 @@
*/
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 @@
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 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;
+ }
+ }
+
+ }
+
}
1.23 +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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- FObjMixed.java 12 Mar 2004 00:41:04 -0000 1.22
+++ FObjMixed.java 4 Apr 2004 06:29:44 -0000 1.23
@@ -55,7 +55,7 @@
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);
}
1.37 +2 -2 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.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- AddLMVisitor.java 21 Mar 2004 17:31:29 -0000 1.36
+++ AddLMVisitor.java 4 Apr 2004 06:29:44 -0000 1.37
@@ -180,7 +180,7 @@
}
public void serveFOText(FOText foText) {
- if (foText.ca.length - foText.start > 0) {
+ if (foText.endIndex - foText.startIndex > 0) {
currentLMList.add(new TextLayoutManager(foText));
}
}
1.14 +3 -3 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TextLayoutManager.java 2 Apr 2004 10:38:29 -0000 1.13
+++ TextLayoutManager.java 4 Apr 2004 06:29:44 -0000 1.14
@@ -98,9 +98,9 @@
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();
1.22 +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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- RTFHandler.java 31 Mar 2004 10:55:07 -0000 1.21
+++ RTFHandler.java 4 Apr 2004 06:29:44 -0000 1.22
@@ -1152,7 +1152,7 @@
} 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) {
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org