aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorManuel Mall <manuel@apache.org>2006-04-08 07:17:59 +0000
committerManuel Mall <manuel@apache.org>2006-04-08 07:17:59 +0000
commited8109d21bf00f54b3aaee0a0c51f779be31c950 (patch)
treefa0a67aa81af30fd6801259785d0161fab24dde6 /src/java/org/apache/fop
parenta2fb12dbc072c9a89848a0977e9859f8a374863e (diff)
downloadxmlgraphics-fop-ed8109d21bf00f54b3aaee0a0c51f779be31c950.tar.gz
xmlgraphics-fop-ed8109d21bf00f54b3aaee0a0c51f779be31c950.zip
Fixed various white space (non)removal issues during line building. white-space-treatment is now supported properly especially for the "preserve" case.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@392488 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/fo/FOPropertyMapping.java2
-rw-r--r--src/java/org/apache/fop/fo/FOText.java11
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java53
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java158
4 files changed, 181 insertions, 43 deletions
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index 06d83a37f..9597c69c8 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -2823,7 +2823,7 @@ public class FOPropertyMapping implements Constants {
m.setInherited(true);
m.addEnum("normal", getEnumProperty(EN_NORMAL, "NORMAL"));
m.addEnum("pre", getEnumProperty(EN_PRE, "PRE"));
- m.addEnum("no-wrap", getEnumProperty(EN_NO_WRAP, "NO_WRAP"));
+ m.addEnum("nowrap", getEnumProperty(EN_NO_WRAP, "NO_WRAP"));
m.setDefault("normal");
m.setDatatypeParser(new WhiteSpaceShorthandParser());
addPropertyMaker("white-space", m);
diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java
index 7a75f68da..d4bd5f24b 100644
--- a/src/java/org/apache/fop/fo/FOText.java
+++ b/src/java/org/apache/fop/fo/FOText.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -80,6 +80,7 @@ public class FOText extends FONode {
private ColorType color;
private Property letterSpacing;
private SpaceProperty lineHeight;
+ private int whiteSpaceTreatment;
private int whiteSpaceCollapse;
private int textTransform;
private Property wordSpacing;
@@ -159,6 +160,7 @@ public class FOText extends FONode {
lineHeight = pList.get(Constants.PR_LINE_HEIGHT).getSpace();
letterSpacing = pList.get(Constants.PR_LETTER_SPACING);
whiteSpaceCollapse = pList.get(Constants.PR_WHITE_SPACE_COLLAPSE).getEnum();
+ whiteSpaceTreatment = pList.get(Constants.PR_WHITE_SPACE_TREATMENT).getEnum();
textTransform = pList.get(Constants.PR_TEXT_TRANSFORM).getEnum();
wordSpacing = pList.get(Constants.PR_WORD_SPACING);
wrapOption = pList.get(Constants.PR_WRAP_OPTION).getEnum();
@@ -578,6 +580,13 @@ public class FOText extends FONode {
}
/**
+ * @return the "white-space-treatment" property
+ */
+ public int getWhitespaceTreatment() {
+ return whiteSpaceTreatment;
+ }
+
+ /**
* @return the "word-spacing" property.
*/
public Property getWordSpacing() {
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
index ef84d1c73..ab1079fbc 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
@@ -85,6 +85,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
hyphenationProperties = fobj.getCommonHyphenation();
hyphenationLadderCount = fobj.getHyphenationLadderCount();
wrapOption = fobj.getWrapOption();
+ whiteSpaceTreament = fobj.getWhitespaceTreatment();
//
effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
isFirstInBlock = (this == getParent().getChildLMs().get(0));
@@ -149,6 +150,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
private CommonHyphenation hyphenationProperties;
private Numeric hyphenationLadderCount;
private int wrapOption = EN_WRAP;
+ private int whiteSpaceTreament;
//private LayoutProps layoutProps;
private Length lineHeight;
@@ -1639,32 +1641,41 @@ public class LineLayoutManager extends InlineStackingLayoutManager
}
}
- // ignore the last element in the line if it is a KnuthGlue object
- seqIterator = seq.listIterator(iEndElement);
- tempElement = (KnuthElement) seqIterator.next();
- if (tempElement.isGlue()) {
- iEndElement--;
- // this returns the same KnuthElement
- seqIterator.previous();
- if (seqIterator.hasPrevious()) {
- tempElement = (KnuthElement) seqIterator.previous();
- } else {
- tempElement = null;
+ // Remove trailing spaces if allowed so
+ if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
+ || whiteSpaceTreament == EN_IGNORE
+ || whiteSpaceTreament == EN_IGNORE_IF_BEFORE_LINEFEED) {
+ // ignore the last element in the line if it is a KnuthGlue object
+ seqIterator = seq.listIterator(iEndElement);
+ tempElement = (KnuthElement) seqIterator.next();
+ if (tempElement.isGlue()) {
+ iEndElement--;
+ // this returns the same KnuthElement
+ seqIterator.previous();
+ if (seqIterator.hasPrevious()) {
+ tempElement = (KnuthElement) seqIterator.previous();
+ } else {
+ tempElement = null;
+ }
+ }
+ if (tempElement != null) {
+ lastLM = tempElement.getLayoutManager();
}
- }
- if (tempElement != null) {
- lastLM = tempElement.getLayoutManager();
}
- // ignore KnuthGlue and KnuthPenalty objects
- // at the beginning of the line
- seqIterator = seq.listIterator(iStartElement);
- tempElement = (KnuthElement) seqIterator.next();
- while (!tempElement.isBox() && seqIterator.hasNext()) {
+ // Remove leading spaces if allowed so
+ if (whiteSpaceTreament == EN_IGNORE_IF_SURROUNDING_LINEFEED
+ || whiteSpaceTreament == EN_IGNORE
+ || whiteSpaceTreament == EN_IGNORE_IF_AFTER_LINEFEED) {
+ // ignore KnuthGlue and KnuthPenalty objects
+ // at the beginning of the line
+ seqIterator = seq.listIterator(iStartElement);
tempElement = (KnuthElement) seqIterator.next();
- iStartElement++;
+ while (!tempElement.isBox() && seqIterator.hasNext()) {
+ tempElement = (KnuthElement) seqIterator.next();
+ iStartElement++;
+ }
}
-
// Add the inline areas to lineArea
PositionIterator inlinePosIter
= new KnuthPossPosIter(seq, iStartElement, iEndElement + 1);
diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
index e7190797c..1582ea30d 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
@@ -25,6 +25,7 @@ import java.util.ListIterator;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.TextArea;
+import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FOText;
import org.apache.fop.fo.flow.Inline;
import org.apache.fop.fonts.Font;
@@ -438,11 +439,13 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
for (int i = firstIndex; i <= lastIndex; i++) {
areaInfo = (AreaInfo) vecAreaInfo.get(i);
if (areaInfo.isSpace) {
- // areaInfo stores information about a space
- // add a space to the TextArea
- char spaceChar = textArray[areaInfo.iStartIndex];
- textArea.addSpace(spaceChar, 0,
- CharUtilities.isAdjustableSpace(spaceChar));
+ // areaInfo stores information about spaces
+ // add the spaces to the TextArea
+ for (int j = areaInfo.iStartIndex; j < areaInfo.iBreakIndex; j++) {
+ char spaceChar = textArray[j];
+ textArea.addSpace(spaceChar, 0,
+ CharUtilities.isAdjustableSpace(spaceChar));
+ }
} else {
// areaInfo stores information about a word fragment
if (wordStartIndex == -1) {
@@ -529,9 +532,29 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
while (iNextStart < textArray.length) {
char ch = textArray[iNextStart];
- if (ch == CharUtilities.SPACE
- || ch == CharUtilities.NBSPACE) {
- // normal space or non-breaking space:
+ if (ch == CharUtilities.SPACE
+ && foText.getWhitespaceTreatment() != Constants.EN_PRESERVE) {
+ // normal non preserved space - collect them all
+ // advance to the next character
+ iThisStart = iNextStart;
+ iNextStart++;
+ while (iNextStart < textArray.length
+ && textArray[iNextStart] == CharUtilities.SPACE) {
+ iNextStart++;
+ }
+ // create the AreaInfo object
+ ai = new AreaInfo(iThisStart, (short) (iNextStart),
+ (short) (iNextStart - iThisStart), (short) 0,
+ MinOptMax.multiply(wordSpaceIPD, iNextStart - iThisStart),
+ false, true);
+ vecAreaInfo.add(ai);
+
+ // create the elements
+ sequence.addAll
+ (createElementsForASpace(alignment, ai, vecAreaInfo.size() - 1));
+
+ } else if (ch == CharUtilities.SPACE || ch == CharUtilities.NBSPACE) {
+ // preserved space or non-breaking space:
// create the AreaInfo object
ai = new AreaInfo(iNextStart, (short) (iNextStart + 1),
(short) 1, (short) 0,
@@ -867,8 +890,9 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
spaceElements.add(new KnuthInlineBox(ai.ipdArea.opt, null,
mainPosition, true));
}
- } else {
- // a breaking space
+ } else if (textArray[ai.iStartIndex] == CharUtilities.SPACE
+ && foText.getWhitespaceTreatment() == Constants.EN_PRESERVE) {
+ // a breaking space that needs to be preserved
switch (alignment) {
case EN_CENTER:
// centered text:
@@ -885,6 +909,97 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
? KnuthElement.INFINITE
: 0), false,
new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthGlue(
+ - (lineStartBAP + lineEndBAP), -6
+ * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthInlineBox(0, null,
+ notifyPos(new LeafPosition(this, -1)), false));
+ spaceElements.add(new KnuthPenalty(0, KnuthElement.INFINITE,
+ false, new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthGlue(ai.ipdArea.opt + lineStartBAP,
+ 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ mainPosition, false));
+ break;
+
+ case EN_START: // fall through
+ case EN_END:
+ // left- or right-aligned text:
+ // if the second element is chosen as a line break these elements
+ // add a constant amount of stretch at the end of a line, otherwise
+ // they don't add any stretch
+ spaceElements.add(new KnuthGlue(lineEndBAP,
+ 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthPenalty(0, 0, false,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthGlue(
+ - (lineStartBAP + lineEndBAP), -3
+ * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthInlineBox(0, null,
+ notifyPos(new LeafPosition(this, -1)), false));
+ spaceElements.add(new KnuthPenalty(0,
+ KnuthElement.INFINITE, false, new LeafPosition(
+ this, -1), false));
+ spaceElements.add(new KnuthGlue(ai.ipdArea.opt + lineStartBAP, 0, 0,
+ mainPosition, false));
+ break;
+
+ case EN_JUSTIFY:
+ // justified text:
+ // the stretch and shrink depends on the space width
+ spaceElements.add(new KnuthGlue(lineEndBAP, 0, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthPenalty(0, 0, false,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthGlue(
+ - (lineStartBAP + lineEndBAP), ai.ipdArea.max
+ - ai.ipdArea.opt, ai.ipdArea.opt - ai.ipdArea.min,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthInlineBox(0, null,
+ notifyPos(new LeafPosition(this, -1)), false));
+ spaceElements.add(new KnuthPenalty(0,
+ KnuthElement.INFINITE, false, new LeafPosition(
+ this, -1), false));
+ spaceElements.add(new KnuthGlue(lineStartBAP + ai.ipdArea.opt, 0, 0,
+ mainPosition, false));
+ break;
+
+ default:
+ // last line justified, the other lines unjustified:
+ // use only the space stretch
+ spaceElements.add(new KnuthGlue(lineEndBAP, 0, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthPenalty(0, 0, false,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthGlue(
+ - (lineStartBAP + lineEndBAP), ai.ipdArea.max
+ - ai.ipdArea.opt, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements.add(new KnuthInlineBox(0, null,
+ notifyPos(new LeafPosition(this, -1)), false));
+ spaceElements.add(new KnuthPenalty(0,
+ KnuthElement.INFINITE, false, new LeafPosition(
+ this, -1), false));
+ spaceElements.add(new KnuthGlue(lineStartBAP + ai.ipdArea.opt, 0, 0,
+ mainPosition, false));
+ }
+ } else {
+ // a (possible block) of breaking spaces
+ switch (alignment) {
+ case EN_CENTER:
+ // centered text:
+ // if the second element is chosen as a line break these elements
+ // add a constant amount of stretch at the end of a line and at the
+ // beginning of the next one, otherwise they don't add any stretch
+ spaceElements.add(new KnuthGlue(lineEndBAP,
+ 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ spaceElements
+ .add(new KnuthPenalty(
+ 0, 0, false,
+ new LeafPosition(this, -1), false));
spaceElements.add(new KnuthGlue(ai.ipdArea.opt
- (lineStartBAP + lineEndBAP), -6
* LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
@@ -941,9 +1056,10 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
- spaceElements.add(new KnuthGlue(ai.ipdArea.opt
- - (lineStartBAP + lineEndBAP), ai.ipdArea.max
- - ai.ipdArea.opt, ai.ipdArea.opt - ai.ipdArea.min,
+ spaceElements.add(new KnuthGlue(
+ ai.ipdArea.opt - (lineStartBAP + lineEndBAP),
+ ai.ipdArea.max - ai.ipdArea.opt,
+ ai.ipdArea.opt - ai.ipdArea.min,
mainPosition, false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
@@ -954,8 +1070,9 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
new LeafPosition(this, -1), false));
} else {
spaceElements.add(new KnuthGlue(ai.ipdArea.opt,
- ai.ipdArea.max - ai.ipdArea.opt, ai.ipdArea.opt
- - ai.ipdArea.min, mainPosition, false));
+ ai.ipdArea.max - ai.ipdArea.opt,
+ ai.ipdArea.opt - ai.ipdArea.min,
+ mainPosition, false));
}
break;
@@ -967,9 +1084,10 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
new LeafPosition(this, -1), false));
spaceElements.add(new KnuthPenalty(0, 0, false,
new LeafPosition(this, -1), false));
- spaceElements.add(new KnuthGlue(ai.ipdArea.opt
- - (lineStartBAP + lineEndBAP), ai.ipdArea.max
- - ai.ipdArea.opt, 0, mainPosition, false));
+ spaceElements.add(new KnuthGlue(
+ ai.ipdArea.opt - (lineStartBAP + lineEndBAP),
+ ai.ipdArea.max - ai.ipdArea.opt,
+ 0, mainPosition, false));
spaceElements.add(new KnuthInlineBox(0, null,
notifyPos(new LeafPosition(this, -1)), false));
spaceElements.add(new KnuthPenalty(0,
@@ -979,8 +1097,8 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
new LeafPosition(this, -1), false));
} else {
spaceElements.add(new KnuthGlue(ai.ipdArea.opt,
- ai.ipdArea.max - ai.ipdArea.opt, 0, mainPosition,
- false));
+ ai.ipdArea.max - ai.ipdArea.opt, 0,
+ mainPosition, false));
}
}
}