]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Avoid null values in generated Font classes so the encoding can be inspected.
authorJeremias Maerki <jeremias@apache.org>
Mon, 12 Nov 2007 09:40:16 +0000 (09:40 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 12 Nov 2007 09:40:16 +0000 (09:40 +0000)
Don't warn about missing hyphenation characters for fonts such as Symbol and ZapfDingbats which don't have the default hyphenation character.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@594067 13f79535-47bb-0310-9956-ffa450edef68

src/codegen/fonts/font-file.xsl
src/java/org/apache/fop/fo/properties/CommonHyphenation.java
src/java/org/apache/fop/fonts/Font.java
src/java/org/apache/fop/fonts/SingleByteFont.java
src/java/org/apache/fop/render/ps/PSFontUtils.java

index 17d6de2e352ccf9b1e191d4e690ae0436599bece..dbca3eba5ac7e5fffd64e46793e58dbada70e747 100644 (file)
@@ -30,7 +30,6 @@
   <xsl:output method="text"/>
 
   <xsl:param name="encoding" select="/font-metrics/encoding"/>
-  <xsl:variable name="native-encoding" select="/font-metrics/encoding"/>
   <xsl:variable name="glyphs" select="document('encodings.xml')/encoding-set/encoding[@id=$encoding]/glyph"/>
 
   <xsl:template match="font-metrics">
@@ -48,7 +47,7 @@ public class <xsl:value-of select="class-name"/> extends Typeface {
     private final static String fontName = "<xsl:value-of select="font-name"/>";
     private final static String fullName = "<xsl:value-of select="full-name"/>";
     private final static Set familyNames;
-    private final static String encoding = <xsl:choose><xsl:when test="$encoding != $native-encoding">"<xsl:value-of select="$encoding"/>"</xsl:when><xsl:otherwise>null</xsl:otherwise></xsl:choose>;
+    private final static String encoding = "<xsl:value-of select="$encoding"/>";
     private final static int capHeight = <xsl:value-of select="cap-height"/>;
     private final static int xHeight = <xsl:value-of select="x-height"/>;
     private final static int ascender = <xsl:value-of select="ascender"/>;
index 28f44fbce9c33292b01c99615bf0cd2d95b92f84..abb242f4540153ec5a7e8c299ef8df6601780e5b 100644 (file)
@@ -24,6 +24,8 @@ 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;
+import org.apache.fop.fonts.FontMetrics;
+import org.apache.fop.fonts.Typeface;
 
 /**
  * Store all common hyphenation properties.
@@ -127,17 +129,40 @@ public final class CommonHyphenation {
      */
     public char getHyphChar(org.apache.fop.fonts.Font font) {
         char hyphChar = hyphenationCharacter.getCharacter();
+        if (font.hasChar(hyphChar)) {
+            return hyphChar; //short-cut
+        }
         char effHyphChar = hyphChar;
-        if (font.hasChar(effHyphChar)) {
-            //nop
-        } else if (font.hasChar(HYPHEN_MINUS)) {
+        boolean warn = false;
+        if (font.hasChar(HYPHEN_MINUS)) {
             effHyphChar = HYPHEN_MINUS;
+            warn = true;
         } else if (font.hasChar(MINUS_SIGN)) {
             effHyphChar = MINUS_SIGN;
+            FontMetrics metrics = font.getFontMetrics();
+            if (metrics instanceof Typeface) {
+                Typeface typeface = (Typeface)metrics;
+                if ("SymbolEncoding".equals(typeface.getEncoding())) {
+                    //SymbolEncoding doesn't have HYPHEN_MINUS, so replace by MINUS_SIGN
+                } else {
+                    //only warn if the encoding is not SymbolEncoding
+                    warn = true;
+                }
+            }
         } else {
             effHyphChar = ' ';
+            FontMetrics metrics = font.getFontMetrics();
+            if (metrics instanceof Typeface) {
+                Typeface typeface = (Typeface)metrics;
+                if ("ZapfDingbatsEncoding".equals(typeface.getEncoding())) {
+                    //ZapfDingbatsEncoding doesn't have HYPHEN_MINUS, so replace by ' '
+                } else {
+                    //only warn if the encoding is not ZapfDingbatsEncoding
+                    warn = true;
+                }
+            }
         }
-        if (hyphChar != effHyphChar) {
+        if (warn) {
             log.warn("Substituted specified hyphenation character (0x"
                     + Integer.toHexString(hyphChar)
                     + ") with 0x" + Integer.toHexString(effHyphChar) 
index 96aaf80d2db3fde59ff5d4ef300602fade043699..e123513c21e85c030cab2090d7a80e7241747b51 100644 (file)
@@ -80,6 +80,14 @@ public class Font {
         this.fontSize = fontSize;
     }
 
+    /**
+     * Returns the associated font metrics object.
+     * @return the font metrics
+     */
+    public FontMetrics getFontMetrics() {
+        return this.metric;
+    }
+    
     /**
      * Returns the font's ascender.
      * @return the ascender
index 1baee3f9872439889c665eaed0acafc867bf009c..1df44b3a2d8979b50fb061073f03219e93e37dff 100644 (file)
@@ -103,8 +103,8 @@ public class SingleByteFont extends CustomFont {
         if (d != 0) {
             return d;
         } else {
-            log.warn("Glyph " + (int) c + " not available in font "
-                    + getFontName());
+            log.warn("Glyph " + (int)c + " (0x" + Integer.toHexString(c) 
+                    + ") not available in font " + getFontName());
             return '#';
         }
     }
index c568fe8269eb03229109a76899e50ada7df36e94..8fb29d3027618f5aba0fdf1f173cdc84ef58c7e1 100644 (file)
@@ -100,8 +100,11 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
             if (fm instanceof LazyFont && ((LazyFont)fm).getRealFont() == null) {
                 continue;
             } else if (null == fm.getEncoding()) {
-                //ignore (ZapfDingbats and Symbol run through here
-                //TODO: ZapfDingbats and Symbol should get getEncoding() fixed!
+                //ignore (ZapfDingbats and Symbol used to run through here, kept for safety reasons)
+            } else if ("SymbolEncoding".equals(fm.getEncoding())) {
+                //ignore (no encoding redefinition)
+            } else if ("ZapfDingbatsEncoding".equals(fm.getEncoding())) {
+                //ignore (no encoding redefinition)
             } else if ("WinAnsiEncoding".equals(fm.getEncoding())) {
                 redefineFontEncoding(gen, fm.getFontName(), fm.getEncoding());
             } else {