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 ma...@apache.org on 2008/05/11 09:30:55 UTC

svn commit: r655275 - in /xmlgraphics/fop/trunk/src: codegen/fonts/font-file.xsl java/org/apache/fop/fonts/Font.java java/org/apache/fop/fonts/MultiByteFont.java java/org/apache/fop/fonts/SingleByteFont.java java/org/apache/fop/fonts/Typeface.java

Author: maxberger
Date: Sun May 11 00:30:55 2008
New Revision: 655275

URL: http://svn.apache.org/viewvc?rev=655275&view=rev
Log:
made sure warning for missing glyphs is emitted in all cases

Modified:
    xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Font.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java

Modified: xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl?rev=655275&r1=655274&r2=655275&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl (original)
+++ xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl Sun May 11 00:30:55 2008
@@ -42,6 +42,7 @@
 import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.Base14Font;
 import org.apache.fop.fonts.CodePointMapping;
+import org.apache.fop.fonts.Typeface;;
 
 public class <xsl:value-of select="class-name"/> extends Base14Font {
     private final static String fontName = "<xsl:value-of select="font-name"/>";
@@ -169,7 +170,8 @@
         if (d != 0) {
             return d;
         } else {
-            return '#';
+            this.warnMissingGlyph(c);
+            return Typeface.NOT_FOUND;
         }
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Font.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Font.java?rev=655275&r1=655274&r2=655275&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Font.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Font.java Sun May 11 00:30:55 2008
@@ -212,7 +212,7 @@
             c = d;
         } else {
             log.warn("Glyph " + (int) c + " not available in font " + fontName);
-            c = '#';
+            c = Typeface.NOT_FOUND;
         }
 
         return c;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java?rev=655275&r1=655274&r2=655275&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java Sun May 11 00:30:55 2008
@@ -30,7 +30,7 @@
 
     private static int uniqueCounter = -1;
     private static final DecimalFormat COUNTER_FORMAT = new DecimalFormat("00000");
-
+    
     private String ttcName = null;
     private String encoding = "Identity-H";
 
@@ -158,7 +158,7 @@
      */
     private int findGlyphIndex(char c) {
         int idx = (int)c;
-        int retIdx = 0; //.notdef
+        int retIdx = SingleByteEncoding.NOT_FOUND_CODE_POINT;
 
         for (int i = 0; (i < bfentries.length) && retIdx == 0; i++) {
             if (bfentries[i].getUnicodeStart() <= idx
@@ -176,17 +176,19 @@
     public char mapChar(char c) {
         notifyMapOperation();
         int glyphIndex = findGlyphIndex(c);
-
+        if (glyphIndex == SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+            warnMissingGlyph(c);
+            glyphIndex = findGlyphIndex(Typeface.NOT_FOUND);
+        }
         if (isEmbeddable()) {
             glyphIndex = subset.mapSubsetChar(glyphIndex, c);
         }
-
         return (char)glyphIndex;
     }
 
     /** {@inheritDoc} */
     public boolean hasChar(char c) {
-        return (findGlyphIndex(c) > 0);
+        return (findGlyphIndex(c) != SingleByteEncoding.NOT_FOUND_CODE_POINT);
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=655275&r1=655274&r2=655275&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java Sun May 11 00:30:55 2008
@@ -21,21 +21,15 @@
 
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.xmlgraphics.fonts.Glyphs;
-
 /**
  * Generic SingleByte font
  */
 public class SingleByteFont extends CustomFont {
 
-    /** Code point that is used if no code point for a specific character has been found. */
-    public static final char NOT_FOUND = '#';
-
     /** logger */
     private  static Log log = LogFactory.getLog(SingleByteFont.class);
 
@@ -43,8 +37,6 @@
 
     private int[] width = null;
 
-    private Set warnedChars;
-
     private Map unencodedCharacters;
     //Map<Character, UnencodedCharacter>
     private List additionalEncodings;
@@ -115,27 +107,8 @@
         if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
             return d;
         }
-        
-        //Give up, character is not available
-        Character ch = new Character(c);
-        if (warnedChars == null) {
-            warnedChars = new java.util.HashSet();
-        }
-        if (warnedChars.size() < 8 && !warnedChars.contains(ch)) {
-            warnedChars.add(ch);
-            if (this.eventListener != null) {
-                this.eventListener.glyphNotAvailable(this, c, getFontName());
-            } else {
-                if (warnedChars.size() == 8) {
-                    log.warn("Many requested glyphs are not available in font " + getFontName());
-                } else {
-                    log.warn("Glyph " + (int)c + " (0x" + Integer.toHexString(c) 
-                            + ", " + Glyphs.charToGlyphName(c)
-                            + ") not available in font " + getFontName());
-                }
-            }
-        }
-        return NOT_FOUND;
+        this.warnMissingGlyph(c);
+        return Typeface.NOT_FOUND;
     }
 
     private char mapUnencodedChar(char ch) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java?rev=655275&r1=655274&r2=655275&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java Sun May 11 00:30:55 2008
@@ -19,20 +19,38 @@
  
 package org.apache.fop.fonts;
 
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.fonts.Glyphs;
+
 /**
  * Base class for font classes
  */
 public abstract class Typeface implements FontMetrics {
 
     /**
-     * Used to identify whether a font has been used (a character map operation is used as
-     * the trigger). This could just as well be a boolean but is a long out of statistical interest.
+     * Code point that is used if no code point for a specific character has
+     * been found.
+     */
+    public static final char NOT_FOUND = '#';
+
+    /** logger */
+    private static Log log = LogFactory.getLog(Typeface.class);
+
+    /**
+     * Used to identify whether a font has been used (a character map operation
+     * is used as the trigger). This could just as well be a boolean but is a
+     * long out of statistical interest.
      */
     private long charMapOps = 0;
     
     /** An optional event listener that receives events such as missing glyphs etc. */
     protected FontEventListener eventListener;
-    
+
+    private Set warnedChars;
+
     /**
      * Get the encoding of the font.
      * @return the encoding
@@ -92,5 +110,33 @@
         this.eventListener = listener;
     }
     
+    /**
+     * Provide proper warning if a glyph is not available.
+     * 
+     * @param c
+     *            the character which is missing.
+     */
+    protected void warnMissingGlyph(char c) {
+        // Give up, character is not available
+        Character ch = new Character(c);
+        if (warnedChars == null) {
+            warnedChars = new java.util.HashSet();
+        }
+        if (warnedChars.size() < 8 && !warnedChars.contains(ch)) {
+            warnedChars.add(ch);
+            if (this.eventListener != null) {
+                this.eventListener.glyphNotAvailable(this, c, getFontName());
+            } else {
+                if (warnedChars.size() == 8) {
+                    log.warn("Many requested glyphs are not available in font "
+                            + getFontName());
+                } else {
+                    log.warn("Glyph " + (int) c + " (0x"
+                            + Integer.toHexString(c) + ", "
+                            + Glyphs.charToGlyphName(c)
+                            + ") not available in font " + getFontName());
+                }
+            }
+        }
+    }
 }
-



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