diff options
author | Simon Pepping <spepping@apache.org> | 2004-05-29 08:50:46 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2004-05-29 08:50:46 +0000 |
commit | ec0d3c558af3272a4693944c0fcf13b93c209d44 (patch) | |
tree | 65e843836899b07e28489ea4b791b19aa2e20608 /src/java/org/apache | |
parent | 14f6cb37411eedd98c3efd995e14430bb7db2ec7 (diff) | |
download | xmlgraphics-fop-ec0d3c558af3272a4693944c0fcf13b93c209d44.tar.gz xmlgraphics-fop-ec0d3c558af3272a4693944c0fcf13b93c209d44.zip |
Solve a few problems concerning hyphenation:
- show the '-' at the end of the hyphenated lines
- use the fo:hyphenate property to enable hyphenation, instead of the alignment
- specify the hyphenation character using the fo:hyphenation-character property
Patch by Luca Furini, bug 27773
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197651 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
4 files changed, 28 insertions, 14 deletions
diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index d84564d46..2505c323d 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -488,6 +488,9 @@ public class PropertyManager implements Constants { textInfo.textTransform = this.propertyList.get(PR_TEXT_TRANSFORM).getEnum(); + textInfo.hyphChar = this.propertyList.get( + PR_HYPHENATION_CHARACTER).getCharacter(); + } return textInfo; } diff --git a/src/java/org/apache/fop/fo/TextInfo.java b/src/java/org/apache/fop/fo/TextInfo.java index 2ef97ac09..c4f97a26f 100644 --- a/src/java/org/apache/fop/fo/TextInfo.java +++ b/src/java/org/apache/fop/fo/TextInfo.java @@ -50,8 +50,8 @@ public class TextInfo { /** fo:letter-spacing property */ public SpaceVal letterSpacing; - /** can this text be hyphenated? */ - public boolean bCanHyphenate = true; + /* the hyphenation character to be used */ + public char hyphChar = '-'; /** fo:text-decoration property: is text underlined? */ public boolean underlined = false; diff --git a/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java index 3fec26150..b32428953 100644 --- a/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java @@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyManager; +import org.apache.fop.fo.Constants; import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fo.properties.CommonHyphenation; import org.apache.fop.layout.hyphenation.Hyphenation; @@ -209,7 +210,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager { // This break position doesn't fit // TODO: If we are in nowrap, we use it as is! - if (bTextAlignment == TextAlign.JUSTIFY || prevBP == null) { + if (hyphProps.hyphenate == Constants.TRUE) { // If we are already in a hyphenation loop, then stop. if (inlineLC.tryHyphenate()) { diff --git a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java index a56233b8a..59ddcc73a 100644 --- a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -46,12 +46,14 @@ public class TextLayoutManager extends AbstractLayoutManager { private short iBreakIndex; private short iWScount; private MinOptMax ipdArea; + private boolean bHyphenated; public AreaInfo(short iSIndex, short iBIndex, short iWS, - MinOptMax ipd) { + MinOptMax ipd, boolean bHyph) { iStartIndex = iSIndex; iBreakIndex = iBIndex; iWScount = iWS; ipdArea = ipd; + bHyphenated = bHyph; } } @@ -107,7 +109,7 @@ public class TextLayoutManager extends AbstractLayoutManager { // With CID fonts, space isn't neccesary currentFontState.width(32) spaceCharIPD = foText.textInfo.fs.getCharWidth(' '); // Use hyphenationChar property - hyphIPD = foText.textInfo.fs.getCharWidth('-'); + hyphIPD = foText.textInfo.fs.getCharWidth(foText.textInfo.hyphChar); // Make half-space: <space> on either side of a word-space) SpaceVal ws = foText.textInfo.wordSpacing; halfWS = new SpaceVal(MinOptMax.multiply(ws.getSpace(), 0.5), @@ -201,7 +203,7 @@ public class TextLayoutManager extends AbstractLayoutManager { boolean bCanHyphenate = true; int iStopIndex = iNextStart + hc.getNextHyphPoint(); - if (textArray.length < iStopIndex || foText.textInfo.bCanHyphenate == false) { + if (textArray.length < iStopIndex) { iStopIndex = textArray.length; bCanHyphenate = false; } @@ -396,7 +398,8 @@ public class TextLayoutManager extends AbstractLayoutManager { // Position is the index of the info for this word in the vector vecAreaInfo.add( - new AreaInfo(iWordStart, iNextStart, iWScount, ipd)); + new AreaInfo(iWordStart, iNextStart, iWScount, ipd, + ((flags & BreakPoss.HYPHENATED) != 0))); BreakPoss bp = new BreakPoss( new LeafPosition(this, vecAreaInfo.size() - 1)); ipdTotal = ipd; @@ -465,6 +468,20 @@ public class TextLayoutManager extends AbstractLayoutManager { if (ai == null) { return; } + + // ignore newline character + int adjust = 0; + if (textArray[ai.iBreakIndex - 1] == NEWLINE) { + adjust = 1; + } + String str = new String(textArray, iStart, ai.iBreakIndex - iStart - adjust); + + // add hyphenation character if the last word is hyphenated + if (ai.bHyphenated) { + str += foText.textInfo.hyphChar; + ai.ipdArea = MinOptMax.add(ai.ipdArea, new MinOptMax(hyphIPD)); + } + // Calculate total adjustment int iRealWidth = ai.ipdArea.opt; int iAdjust = 0; @@ -482,13 +499,6 @@ public class TextLayoutManager extends AbstractLayoutManager { // Make an area containing all characters between start and end. InlineArea word = null; - int adjust = 0; - - // ignore newline character - if (textArray[ai.iBreakIndex - 1] == NEWLINE) { - adjust = 1; - } - String str = new String(textArray, iStart, ai.iBreakIndex - iStart - adjust); if (" ".equals(str)) { word = new Space(); |