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 je...@apache.org on 2007/11/12 09:52:20 UTC

svn commit: r594054 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: fo/properties/CommonHyphenation.java layoutmgr/inline/CharacterLayoutManager.java layoutmgr/inline/TextLayoutManager.java

Author: jeremias
Date: Mon Nov 12 00:52:11 2007
New Revision: 594054

URL: http://svn.apache.org/viewvc?rev=594054&view=rev
Log:
Better solution for missing hyphenation character problem.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java?rev=594054&r1=594053&r2=594054&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java Mon Nov 12 00:52:11 2007
@@ -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 @@
  * 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();
     
@@ -109,6 +114,47 @@
         
         return cache.fetch(instance);
         
+    }
+    
+    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 */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java?rev=594054&r1=594053&r2=594054&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java Mon Nov 12 00:52:11 2007
@@ -19,7 +19,12 @@
 
 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.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 @@
         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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java?rev=594054&r1=594053&r2=594054&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 Mon Nov 12 00:52:11 2007
@@ -195,13 +195,7 @@
         // 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 @@
                         && 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;



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org