diff options
author | Luca Furini <lfurini@apache.org> | 2005-10-27 14:38:12 +0000 |
---|---|---|
committer | Luca Furini <lfurini@apache.org> | 2005-10-27 14:38:12 +0000 |
commit | 7d01c0732e96ddf3dac732bf177dd0513cd844b1 (patch) | |
tree | d173fd7e662af51745749e675355e698624731ae /src/java/org/apache/fop/area/inline | |
parent | 9a0772f9559bce29a13b5e4b8845320dd07fe740 (diff) | |
download | xmlgraphics-fop-7d01c0732e96ddf3dac732bf177dd0513cd844b1.tar.gz xmlgraphics-fop-7d01c0732e96ddf3dac732bf177dd0513cd844b1.zip |
Moved the text-splitting logic from TextArea to TextLM, as suggested by Manuel and Jeremias.
Some simplification in TextLM#addAreas().
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@328882 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/area/inline')
4 files changed, 55 insertions, 41 deletions
diff --git a/src/java/org/apache/fop/area/inline/SpaceArea.java b/src/java/org/apache/fop/area/inline/SpaceArea.java index 1b5a1ae6e..6ec573107 100644 --- a/src/java/org/apache/fop/area/inline/SpaceArea.java +++ b/src/java/org/apache/fop/area/inline/SpaceArea.java @@ -31,13 +31,22 @@ public class SpaceArea extends InlineArea { * The correction offset for the next area
*/
protected int offset = 0;
+
+ /**
+ * Is this space adjustable?
+ */
+ protected boolean isAdjustable;
/**
- * Create a text inline area
+ * Create a space area
* @param s the space character
+ * @param o the offset for the next area
+ * @param a is this space adjustable?
*/
- public SpaceArea(char s) {
+ public SpaceArea(char s, int o, boolean a) {
space = new String() + s;
+ offset = o;
+ isAdjustable = a;
}
/**
diff --git a/src/java/org/apache/fop/area/inline/TextArea.java b/src/java/org/apache/fop/area/inline/TextArea.java index d57171e8a..3bee4254f 100644 --- a/src/java/org/apache/fop/area/inline/TextArea.java +++ b/src/java/org/apache/fop/area/inline/TextArea.java @@ -18,8 +18,6 @@ package org.apache.fop.area.inline; -import org.apache.fop.util.CharUtilities; - /** * A text inline area. */ @@ -43,46 +41,49 @@ public class TextArea extends AbstractTextArea { } /** - * Set the text string - * - * @param t the text string + * Remove the old text */ - public void setText(String t) { - // split the text and create WordAreas and SpaceAreas - char charArray[] = t.toCharArray(); - int wordStartIndex = -1; - for (int i = 0; i < charArray.length; i ++) { - if (CharUtilities.isAnySpace(charArray[i])) { - // a space character - // create a SpaceArea child - SpaceArea space = new SpaceArea(charArray[i]); - this.addChildArea(space); - space.setParentArea(this); - } else { - // a non-space character - if (wordStartIndex == -1) { - // first character of the text, or after a space - wordStartIndex = i; - } - if (i == charArray.length - 1 - || CharUtilities.isAnySpace(charArray[i + 1])) { - // last character before the end of the text or a space: - // create a WordArea child - WordArea word = new WordArea(t.substring(wordStartIndex, i + 1)); - this.addChildArea(word); - word.setParentArea(this); - wordStartIndex = -1; - } - } - } + public void removeText() { + inlines.clear(); } - + + /** + * Create and add a WordArea child to this TextArea. + * + * @param word the word string + * @param offset the offset for the next area + */ + public void addWord(String word, int offset) { + WordArea wordArea = new WordArea(word, offset); + addChildArea(wordArea); + wordArea.setParentArea(this); + } + + /** + * Create and add a SpaceArea child to this TextArea + * + * @param space the space character + * @param offset the offset for the next area + * @param adjustable is this space adjustable? + */ + public void addSpace(char space, int offset, boolean adjustable) { + SpaceArea spaceArea = new SpaceArea(space, offset, adjustable); + addChildArea(spaceArea); + spaceArea.setParentArea(this); + } + /** - * Get the text string. + * Get the whole text string. + * Renderers whose space adjustment handling is not affected + * by multi-byte characters can use this method to render the + * whole TextArea at once; the other renderers (for example + * PDFRenderer) have to implement renderWord(WordArea) and + * renderSpace(SpaceArea) in order to correctly place each + * text fragment. * * @return the text string */ - public String getTextArea() { + public String getText() { StringBuffer text = new StringBuffer(); InlineArea child; // assemble the text diff --git a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java index 0b429b665..7b5eae941 100644 --- a/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java +++ b/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java @@ -70,7 +70,9 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable { if (pageIDRef.equals(id) && pages != null) { resolved = true; PageViewport page = (PageViewport)pages.get(0); - setText(page.getPageNumberString()); + // replace the text + removeText(); + addWord(page.getPageNumberString(), 0); // update ipd updateIPD(getStringWidth(text)); // set the Font object to null, as we don't need it any more diff --git a/src/java/org/apache/fop/area/inline/WordArea.java b/src/java/org/apache/fop/area/inline/WordArea.java index c766e0e62..b998b819e 100644 --- a/src/java/org/apache/fop/area/inline/WordArea.java +++ b/src/java/org/apache/fop/area/inline/WordArea.java @@ -33,11 +33,13 @@ public class WordArea extends InlineArea { protected int offset = 0;
/**
- * Create a text inline area
+ * Create a word area
* @param w the word string
+ * @param o the offset for the next area
*/
- public WordArea(String w) {
+ public WordArea(String w, int o) {
word = w;
+ offset = o;
}
/**
|