You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by bu...@apache.org on 2004/03/18 13:53:52 UTC
DO NOT REPLY [Bug 27773] New: -
[PATCH] Hyphenation
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27773>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=27773
[PATCH] Hyphenation
Summary: [PATCH] Hyphenation
Product: Fop
Version: 1.0dev
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: Enhancement
Priority: Other
Component: page-master/layout
AssignedTo: fop-dev@xml.apache.org
ReportedBy: lfurini@cs.unibo.it
I have tried to 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
With this simple .fo file it is possible to see that before changes the result
is the opposite of what expected: hyphenation is done when it shoud not, and
not when it shoud.
<?xml version="1.0" encoding="iso-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" margin="0.5in">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block>The following block has language="it", hyphenate="false" and
text-align="justify"; it should NOT be hyphenated.</fo:block>
<fo:block start-indent="0.2in" end-indent="0.2in" language="it"
hyphenate="false" text-align="justify">Lunghissime parolone esagerevoli
costringerebbero sillabazione auspicabilmente: precipitevolissimevolmente
transatlantico catastrofico.</fo:block>
<fo:block>The following block has language="it", hyphenate="true" and
text-align="start"; it should be hyphenated.</fo:block>
<fo:block start-indent="0.2in" end-indent="0.2in" language="it"
hyphenate="true" text-align="start">Lunghissime parolone esagerevoli
costringerebbero sillabazione auspicabilmente: precipitevolissimevolmente
transatlantico catastrofico.</fo:block>
<fo:block>The following block has language="it", hyphenate="true", text-
align="justify" and hyphenation-character="_".</fo:block>
<fo:block start-indent="0.2in" end-indent="0.2in" language="it"
hyphenate="true" text-align="justify" hyphenation-character="_">Lunghissime
parolone esagerevoli costringerebbero sillabazione auspicabilmente:
precipitevolissimevolmente transatlantico catastrofico.</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
This is the diff:
Index: xml-fop/src/java/org/apache/fop/fo/PropertyManager.java
===================================================================
RCS file: /home/cvspublic/xml-
fop/src/java/org/apache/fop/fo/PropertyManager.java,v
retrieving revision 1.24
diff -w -u -r1.24 PropertyManager.java
--- xml-fop/src/java/org/apache/fop/fo/PropertyManager.java 27 Feb 2004
17:57:40 -0000 1.24
+++ xml-fop/src/java/org/apache/fop/fo/PropertyManager.java 18 Mar 2004
12:43:55 -0000
@@ -494,6 +494,9 @@
textInfo.textTransform
= this.propertyList.get(PR_TEXT_TRANSFORM).getEnum();
+ textInfo.hyphChar = this.propertyList.get(
+ PR_HYPHENATION_CHARACTER).getCharacter();
+
}
return textInfo;
}
Index: xml-fop/src/java/org/apache/fop/fo/TextInfo.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/java/org/apache/fop/fo/TextInfo.java,v
retrieving revision 1.6
diff -w -u -r1.6 TextInfo.java
--- xml-fop/src/java/org/apache/fop/fo/TextInfo.java 27 Feb 2004 17:57:40 -
0000 1.6
+++ xml-fop/src/java/org/apache/fop/fo/TextInfo.java 18 Mar 2004 12:43:55 -
0000
@@ -50,8 +50,8 @@
/** 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;
Index: xml-fop/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java
===================================================================
RCS file: /home/cvspublic/xml-
fop/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java,v
retrieving revision 1.15
diff -w -u -r1.15 LineLayoutManager.java
--- xml-fop/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java 18 Mar
2004 00:22:40 -0000 1.15
+++ xml-fop/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java 18 Mar
2004 12:44:00 -0000
@@ -20,6 +20,7 @@
import org.apache.fop.datatypes.Length;
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 @@
// 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()) {
Index: xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
===================================================================
RCS file: /home/cvspublic/xml-
fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java,v
retrieving revision 1.12
diff -w -u -r1.12 TextLayoutManager.java
--- xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java 17 Mar
2004 03:37:32 -0000 1.12
+++ xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java 18 Mar
2004 12:44:02 -0000
@@ -46,12 +46,14 @@
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 @@
// 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 @@
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 @@
// 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;
@@ -493,6 +496,11 @@
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;
+ }
if (" ".equals(str)) {
word = new Space();