]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Better solution for missing hyphenation character problem.
authorJeremias Maerki <jeremias@apache.org>
Mon, 12 Nov 2007 08:52:11 +0000 (08:52 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 12 Nov 2007 08:52:11 +0000 (08:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@594054 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/properties/CommonHyphenation.java
src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java

index d08d18312efd74947e325a5a7f5ce78e36fd3ab5..28f44fbce9c33292b01c99615bf0cd2d95b92f84 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.fo.properties;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.expr.PropertyException;
@@ -29,6 +31,9 @@ import org.apache.fop.fo.expr.PropertyException;
  * Public "structure" allows direct member access.
  */
 public final class CommonHyphenation {
+
+    /** Logger */
+    protected static Log log = LogFactory.getLog(CommonHyphenation.class);
     
     private static final PropertyCache cache = new PropertyCache();
     
@@ -111,6 +116,47 @@ public final class CommonHyphenation {
         
     }
     
+    private static final char HYPHEN_MINUS = '-';
+    private static final char MINUS_SIGN = '\u2212';
+    
+    /**
+     * Returns the effective hyphenation character for a font. The hyphenation character specified
+     * in XSL-FO may be substituted if it's not available in the font.
+     * @param font the font
+     * @return the effective hyphenation character.
+     */
+    public char getHyphChar(org.apache.fop.fonts.Font font) {
+        char hyphChar = hyphenationCharacter.getCharacter();
+        char effHyphChar = hyphChar;
+        if (font.hasChar(effHyphChar)) {
+            //nop
+        } else if (font.hasChar(HYPHEN_MINUS)) {
+            effHyphChar = HYPHEN_MINUS;
+        } else if (font.hasChar(MINUS_SIGN)) {
+            effHyphChar = MINUS_SIGN;
+        } else {
+            effHyphChar = ' ';
+        }
+        if (hyphChar != effHyphChar) {
+            log.warn("Substituted specified hyphenation character (0x"
+                    + Integer.toHexString(hyphChar)
+                    + ") with 0x" + Integer.toHexString(effHyphChar) 
+                    + " because the font doesn't have the specified hyphenation character: " 
+                    + font.getFontTriplet());
+        }
+        return effHyphChar;
+    }
+    
+    /**
+     * Returns the IPD for the hyphenation character for a font.
+     * @param font the font
+     * @return the IPD in millipoints for the hyphenation character.
+     */
+    public int getHyphIPD(org.apache.fop.fonts.Font font) {
+        char hyphChar = getHyphChar(font);
+        return font.getCharWidth(hyphChar);
+    }
+    
     /** {@inheritDoc */
     public boolean equals(Object obj) {
         if (obj == this) {
index f470e137e59c0baffd393b47634cb54dc466e7f5..0430eef0c8682a14e69c56ccf71ef5a9c1b42bfe 100644 (file)
 
 package org.apache.fop.layoutmgr.inline;
 
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.fop.area.Trait;
 import org.apache.fop.fo.flow.Character;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
@@ -32,16 +37,10 @@ import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LeafPosition;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.TraitSetter;
-import org.apache.fop.area.Trait;
 import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.traits.SpaceVal;
 import org.apache.fop.util.CharUtilities;
 
-import java.util.List;
-import java.util.LinkedList;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-import org.apache.fop.layoutmgr.inline.AlignmentContext;
-
 /**
  * LayoutManager for the fo:character formatting object
  */
@@ -70,7 +69,7 @@ public class CharacterLayoutManager extends LeafNodeLayoutManager {
         font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this));
         SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing());
         letterSpaceIPD = ls.getSpace();
-        hyphIPD = font.getCharWidth(fobj.getCommonHyphenation().hyphenationCharacter.getCharacter());
+        hyphIPD = fobj.getCommonHyphenation().getHyphIPD(font);
         borderProps = fobj.getCommonBorderPaddingBackground();
         setCommonBorderPaddingBackground(borderProps);
         org.apache.fop.area.inline.TextArea chArea = getCharacterInlineArea(fobj);
index d446e0e7d592d12127dc75d7a96250cbb2183cd6..63f11147c5052ba33743584a8a6e7f7f7f56aa97 100644 (file)
@@ -195,13 +195,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
         // With CID fonts, space isn't neccesary currentFontState.width(32)
         spaceCharIPD = font.getCharWidth(' ');
         // Use hyphenationChar property
-        char hyphChar = foText.getCommonHyphenation().hyphenationCharacter.getCharacter();
-        if (font.hasChar(hyphChar)) {
-            hyphIPD = font.getCharWidth(hyphChar);
-        } else {
-            log.warn("Hyphenation character 0x" + Integer.toHexString(hyphChar)
-                    + " is not available for font: " + font.getFontTriplet());
-        }
+        hyphIPD = foText.getCommonHyphenation().getHyphIPD(font);
         
         SpaceVal ls = SpaceVal.makeLetterSpacing(foText.getLetterSpacing());
         halfLS = new SpaceVal(MinOptMax.multiply(ls.getSpace(), 0.5),
@@ -514,7 +508,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
                         && i == lastIndex 
                         && areaInfo.bHyphenated) {
                         // add the hyphenation character
-                        wordChars.append(foText.getCommonHyphenation().hyphenationCharacter.getCharacter());
+                        wordChars.append(foText.getCommonHyphenation().getHyphChar(font));
                     }
                     textArea.addWord(wordChars.toString(), 0, letterAdjust);
                     wordStartIndex = -1;