From cad1cea3b08a4ffba6ae5242fe82ae3ff8fd0b53 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 12 Nov 2007 09:40:16 +0000 Subject: [PATCH] Avoid null values in generated Font classes so the encoding can be inspected. 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 | 3 +- .../fop/fo/properties/CommonHyphenation.java | 33 ++++++++++++++++--- src/java/org/apache/fop/fonts/Font.java | 8 +++++ .../org/apache/fop/fonts/SingleByteFont.java | 4 +-- .../org/apache/fop/render/ps/PSFontUtils.java | 7 ++-- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/codegen/fonts/font-file.xsl b/src/codegen/fonts/font-file.xsl index 17d6de2e3..dbca3eba5 100644 --- a/src/codegen/fonts/font-file.xsl +++ b/src/codegen/fonts/font-file.xsl @@ -30,7 +30,6 @@ - @@ -48,7 +47,7 @@ public class extends Typeface { private final static String fontName = ""; private final static String fullName = ""; private final static Set familyNames; - private final static String encoding = ""null; + private final static String encoding = ""; private final static int capHeight = ; private final static int xHeight = ; private final static int ascender = ; diff --git a/src/java/org/apache/fop/fo/properties/CommonHyphenation.java b/src/java/org/apache/fop/fo/properties/CommonHyphenation.java index 28f44fbce..abb242f45 100644 --- a/src/java/org/apache/fop/fo/properties/CommonHyphenation.java +++ b/src/java/org/apache/fop/fo/properties/CommonHyphenation.java @@ -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) diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java index 96aaf80d2..e123513c2 100644 --- a/src/java/org/apache/fop/fonts/Font.java +++ b/src/java/org/apache/fop/fonts/Font.java @@ -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 diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java index 1baee3f98..1df44b3a2 100644 --- a/src/java/org/apache/fop/fonts/SingleByteFont.java +++ b/src/java/org/apache/fop/fonts/SingleByteFont.java @@ -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 '#'; } } diff --git a/src/java/org/apache/fop/render/ps/PSFontUtils.java b/src/java/org/apache/fop/render/ps/PSFontUtils.java index c568fe826..8fb29d302 100644 --- a/src/java/org/apache/fop/render/ps/PSFontUtils.java +++ b/src/java/org/apache/fop/render/ps/PSFontUtils.java @@ -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 { -- 2.39.5