git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@655275 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_0
@@ -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; | |||
} | |||
} | |||
@@ -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; |
@@ -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); | |||
} | |||
/** |
@@ -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) { |
@@ -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()); | |||
} | |||
} | |||
} | |||
} | |||
} | |||