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 lf...@apache.org on 2005/09/14 15:47:52 UTC
svn commit: r280854 -
/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
Author: lfurini
Date: Wed Sep 14 06:47:31 2005
New Revision: 280854
URL: http://svn.apache.org/viewcvs?rev=280854&view=rev
Log:
Correct handling of the combination of hyphenation and text-align = center, left or right.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java?rev=280854&r1=280853&r2=280854&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java Wed Sep 14 06:47:31 2005
@@ -699,7 +699,7 @@
spaceElements.add
(new KnuthPenalty(0, KnuthElement.INFINITE, false,
new LeafPosition(this, -1),
- true));
+ false));
}
switch (alignment) {
@@ -710,24 +710,24 @@
// beginning of the next one, otherwise they don't add any stretch
spaceElements.add
(new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
- new LeafPosition(this, -1), true));
+ new LeafPosition(this, -1), false));
spaceElements.add
(new KnuthPenalty(0,
(textArray[ai.iStartIndex] == NBSPACE ? KnuthElement.INFINITE : 0),
- false, new LeafPosition(this, -1), true));
+ false, new LeafPosition(this, -1), false));
spaceElements.add
(new KnuthGlue(ai.ipdArea.opt,
- 6 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
mainPosition, false));
spaceElements.add
(new KnuthInlineBox(0, 0, 0, 0,
- new LeafPosition(this, -1), true));
+ new LeafPosition(this, -1), false));
spaceElements.add
(new KnuthPenalty(0, KnuthElement.INFINITE, false,
- new LeafPosition(this, -1), true));
+ new LeafPosition(this, -1), false));
spaceElements.add
(new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
- new LeafPosition(this, -1), true));
+ new LeafPosition(this, -1), false));
break;
case EN_START : // fall through
@@ -741,11 +741,11 @@
new LeafPosition(this, -1), false));
spaceElements.add
(new KnuthPenalty(0, 0, false,
- new LeafPosition(this, -1), true));
+ new LeafPosition(this, -1), false));
spaceElements.add
(new KnuthGlue(ai.ipdArea.opt,
- 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
- mainPosition, true));
+ mainPosition, false));
break;
case EN_JUSTIFY:
@@ -809,13 +809,12 @@
new LeafPosition(this, -1), true));
}
if (ai.bHyphenated) {
- wordElements.add
- (new KnuthPenalty(hyphIPD, KnuthPenalty.FLAGGED_PENALTY, true,
- new LeafPosition(this, -1), false));
+ wordElements.addAll(createElementsForAHyphen(alignment));
}
// add a flagged penalty element and a glue element representing a suppressible
// letter space if the next character is not a space
if (ai.iLScount - unsuppressibleLetterSpaces == 1) {
+ //TODO: this is correct only if text is justified
wordElements.add
(new KnuthPenalty(0, KnuthPenalty.FLAGGED_PENALTY, true,
new LeafPosition(this, -1), false));
@@ -828,6 +827,68 @@
return wordElements;
+ }
+
+ private LinkedList createElementsForAHyphen(int alignment) {
+ LinkedList hyphenElements = new LinkedList();
+
+ 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
+ hyphenElements.add
+ (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthPenalty(hyphIPD,
+ KnuthPenalty.FLAGGED_PENALTY, true,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthGlue(0,
+ - 6 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthInlineBox(0, 0, 0, 0,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthPenalty(0, KnuthElement.INFINITE, true,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), 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
+ hyphenElements.add
+ (new KnuthGlue(0, 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthPenalty(hyphIPD,
+ KnuthPenalty.FLAGGED_PENALTY, true,
+ new LeafPosition(this, -1), false));
+ hyphenElements.add
+ (new KnuthGlue(0,
+ - 3 * LineLayoutManager.DEFAULT_SPACE_WIDTH, 0,
+ new LeafPosition(this, -1), false));
+ break;
+
+ default:
+ // justified text, or last line justified:
+ // just a flagged penalty
+ hyphenElements.add
+ (new KnuthPenalty(hyphIPD,
+ KnuthPenalty.FLAGGED_PENALTY, true,
+ new LeafPosition(this, -1), false));
+ }
+
+ return hyphenElements;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org