diff options
author | Maximilian Berger <maxberger@apache.org> | 2008-05-11 07:30:55 +0000 |
---|---|---|
committer | Maximilian Berger <maxberger@apache.org> | 2008-05-11 07:30:55 +0000 |
commit | 9526915ada1d579194a4b38a596d43f75921311c (patch) | |
tree | 7bbb67c894826b88ddf72c0f330de0e3f7b2298c | |
parent | dbc0c79b06fc75164dde3bb4bb26991b82fb676e (diff) | |
download | xmlgraphics-fop-9526915ada1d579194a4b38a596d43f75921311c.tar.gz xmlgraphics-fop-9526915ada1d579194a4b38a596d43f75921311c.zip |
made sure warning for missing glyphs is emitted in all cases
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@655275 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/codegen/fonts/font-file.xsl | 4 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/Font.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/MultiByteFont.java | 12 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/SingleByteFont.java | 31 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/Typeface.java | 54 |
5 files changed, 63 insertions, 40 deletions
diff --git a/src/codegen/fonts/font-file.xsl b/src/codegen/fonts/font-file.xsl index 21a6507b8..85b968808 100644 --- a/src/codegen/fonts/font-file.xsl +++ b/src/codegen/fonts/font-file.xsl @@ -42,6 +42,7 @@ import java.util.Set; 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 @@ public class <xsl:value-of select="class-name"/> extends Base14Font { if (d != 0) { return d; } else { - return '#'; + this.warnMissingGlyph(c); + return Typeface.NOT_FOUND; } } diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java index 90aced052..3a0d82046 100644 --- a/src/java/org/apache/fop/fonts/Font.java +++ b/src/java/org/apache/fop/fonts/Font.java @@ -212,7 +212,7 @@ public class Font { c = d; } else { log.warn("Glyph " + (int) c + " not available in font " + fontName); - c = '#'; + c = Typeface.NOT_FOUND; } return c; diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java index 5849379bd..2f3031646 100644 --- a/src/java/org/apache/fop/fonts/MultiByteFont.java +++ b/src/java/org/apache/fop/fonts/MultiByteFont.java @@ -30,7 +30,7 @@ public class MultiByteFont extends CIDFont { 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 @@ public class MultiByteFont extends CIDFont { */ 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 class MultiByteFont extends CIDFont { 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); } /** diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java index feb1b440c..f1b7b1b48 100644 --- a/src/java/org/apache/fop/fonts/SingleByteFont.java +++ b/src/java/org/apache/fop/fonts/SingleByteFont.java @@ -21,21 +21,15 @@ package org.apache.fop.fonts; 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 @@ public class SingleByteFont extends CustomFont { private int[] width = null; - private Set warnedChars; - private Map unencodedCharacters; //Map<Character, UnencodedCharacter> private List additionalEncodings; @@ -115,27 +107,8 @@ public class SingleByteFont extends CustomFont { 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) { diff --git a/src/java/org/apache/fop/fonts/Typeface.java b/src/java/org/apache/fop/fonts/Typeface.java index b6c78a3b0..4a434745c 100644 --- a/src/java/org/apache/fop/fonts/Typeface.java +++ b/src/java/org/apache/fop/fonts/Typeface.java @@ -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 @@ public abstract class Typeface implements FontMetrics { 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()); + } + } + } + } } - |