diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-02-05 16:27:08 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-02-05 16:27:08 +0000 |
commit | 4e27a1c9dd7246dff9d9380755171f179e3fcb8a (patch) | |
tree | 93817887ac0a99f6a3c1b736cae9ce5688eb4bab /src/java/org/apache/fop/fonts | |
parent | 7fbf442044c42fce773c36cd9aea80694abf007d (diff) | |
download | xmlgraphics-fop-4e27a1c9dd7246dff9d9380755171f179e3fcb8a.tar.gz xmlgraphics-fop-4e27a1c9dd7246dff9d9380755171f179e3fcb8a.zip |
Performance improvements and file-size reductions by introducing letter-spacing and word-spacing attributes in new IF (as mentioned on fop-dev).
Allow to control whether kerning information is loaded from fonts.
Started support for AFP font embedding (incomplete and currently disabled)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@741165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fonts')
5 files changed, 39 insertions, 18 deletions
diff --git a/src/java/org/apache/fop/fonts/FontLoader.java b/src/java/org/apache/fop/fonts/FontLoader.java index b3d32e38d..aaca5b3fd 100644 --- a/src/java/org/apache/fop/fonts/FontLoader.java +++ b/src/java/org/apache/fop/fonts/FontLoader.java @@ -53,16 +53,21 @@ public abstract class FontLoader { protected boolean loaded = false; /** true if the font will be embedded, false if it will be referenced only. */ protected boolean embedded = true; + /** true if kerning information shall be loaded if available. */ + protected boolean useKerning = true; /** * Default constructor. * @param fontFileURI the URI to the PFB file of a Type 1 font * @param embedded indicates whether the font is embedded or referenced + * @param useKerning indicates whether kerning information shall be loaded if available * @param resolver the font resolver used to resolve URIs */ - public FontLoader(String fontFileURI, boolean embedded, FontResolver resolver) { + public FontLoader(String fontFileURI, boolean embedded, boolean useKerning, + FontResolver resolver) { this.fontFileURI = fontFileURI; this.embedded = embedded; + this.useKerning = useKerning; this.resolver = resolver; } @@ -82,7 +87,8 @@ public abstract class FontLoader { */ public static CustomFont loadFont(File fontFile, String subFontName, boolean embedded, EncodingMode encodingMode, FontResolver resolver) throws IOException { - return loadFont(fontFile.getAbsolutePath(), subFontName, embedded, encodingMode, resolver); + return loadFont(fontFile.getAbsolutePath(), subFontName, + embedded, encodingMode, true, resolver); } /** @@ -96,8 +102,11 @@ public abstract class FontLoader { * @throws IOException In case of an I/O error */ public static CustomFont loadFont(URL fontUrl, String subFontName, - boolean embedded, EncodingMode encodingMode, FontResolver resolver) throws IOException { - return loadFont(fontUrl.toExternalForm(), subFontName, embedded, encodingMode, resolver); + boolean embedded, EncodingMode encodingMode, + FontResolver resolver) throws IOException { + return loadFont(fontUrl.toExternalForm(), subFontName, + embedded, encodingMode, true, + resolver); } /** @@ -106,12 +115,14 @@ public abstract class FontLoader { * @param subFontName the sub-fontname of a font (for TrueType Collections, null otherwise) * @param embedded indicates whether the font is embedded or referenced * @param encodingMode the requested encoding mode + * @param useKerning indicates whether kerning information should be loaded if available * @param resolver the font resolver to use when resolving URIs * @return the newly loaded font * @throws IOException In case of an I/O error */ public static CustomFont loadFont(String fontFileURI, String subFontName, - boolean embedded, EncodingMode encodingMode, FontResolver resolver) throws IOException { + boolean embedded, EncodingMode encodingMode, boolean useKerning, + FontResolver resolver) throws IOException { fontFileURI = fontFileURI.trim(); boolean type1 = isType1(fontFileURI); FontLoader loader; @@ -120,9 +131,10 @@ public abstract class FontLoader { throw new IllegalArgumentException( "CID encoding mode not supported for Type 1 fonts"); } - loader = new Type1FontLoader(fontFileURI, embedded, resolver); + loader = new Type1FontLoader(fontFileURI, embedded, useKerning, resolver); } else { - loader = new TTFFontLoader(fontFileURI, subFontName, embedded, encodingMode, resolver); + loader = new TTFFontLoader(fontFileURI, subFontName, + embedded, encodingMode, useKerning, resolver); } return loader.getFont(); } diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index c18ed6965..e5d111d38 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -132,7 +132,7 @@ public class LazyFont extends Typeface implements FontDescriptor { throw new RuntimeException("Cannot load font. No font URIs available."); } realFont = FontLoader.loadFont(fontEmbedPath, this.subFontName, - this.embedded, this.encodingMode, resolver); + this.embedded, this.encodingMode, useKerning, resolver); } if (realFont instanceof FontDescriptor) { realFontDescriptor = (FontDescriptor) realFont; diff --git a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java index 951ebdcff..03a3e1018 100644 --- a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java +++ b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java @@ -225,7 +225,7 @@ public class FontInfoFinder { } try { TTFFontLoader ttfLoader = new TTFFontLoader( - fontFileURI, fontName, true, EncodingMode.AUTO, resolver); + fontFileURI, fontName, true, EncodingMode.AUTO, true, resolver); customFont = ttfLoader.getFont(); if (this.eventListener != null) { customFont.setEventListener(this.eventListener); diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java index cbf9c9d17..405a25f9e 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java @@ -55,7 +55,7 @@ public class TTFFontLoader extends FontLoader { * @param resolver the FontResolver for font URI resolution */ public TTFFontLoader(String fontFileURI, FontResolver resolver) { - this(fontFileURI, null, true, EncodingMode.AUTO, resolver); + this(fontFileURI, null, true, EncodingMode.AUTO, true, resolver); } /** @@ -65,11 +65,13 @@ public class TTFFontLoader extends FontLoader { * TrueType fonts) * @param embedded indicates whether the font is embedded or referenced * @param encodingMode the requested encoding mode + * @param useKerning true to enable loading kerning info if available, false to disable * @param resolver the FontResolver for font URI resolution */ public TTFFontLoader(String fontFileURI, String subFontName, - boolean embedded, EncodingMode encodingMode, FontResolver resolver) { - super(fontFileURI, embedded, resolver); + boolean embedded, EncodingMode encodingMode, boolean useKerning, + FontResolver resolver) { + super(fontFileURI, embedded, true, resolver); this.subFontName = subFontName; this.encodingMode = encodingMode; if (this.encodingMode == EncodingMode.AUTO) { @@ -164,7 +166,9 @@ public class TTFFontLoader extends FontLoader { copyWidthsSingleByte(ttf); } - copyKerning(ttf, isCid); + if (useKerning) { + copyKerning(ttf, isCid); + } if (this.embedded && ttf.isEmbeddable()) { returnFont.setEmbedFileName(this.fontFileURI); } diff --git a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java index 981f3ad69..1d0c75605 100644 --- a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java +++ b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java @@ -45,12 +45,13 @@ public class Type1FontLoader extends FontLoader { * Constructs a new Type 1 font loader. * @param fontFileURI the URI to the PFB file of a Type 1 font * @param embedded indicates whether the font is embedded or referenced + * @param useKerning indicates whether to load kerning information if available * @param resolver the font resolver used to resolve URIs * @throws IOException In case of an I/O error */ - public Type1FontLoader(String fontFileURI, boolean embedded, FontResolver resolver) - throws IOException { - super(fontFileURI, embedded, resolver); + public Type1FontLoader(String fontFileURI, boolean embedded, boolean useKerning, + FontResolver resolver) throws IOException { + super(fontFileURI, embedded, useKerning, resolver); } private String getPFMURI(String pfbURI) { @@ -321,7 +322,9 @@ public class Type1FontLoader extends FontLoader { singleFont.setWidth(chm.getCharCode(), (int)Math.round(chm.getWidthX())); } } - returnFont.replaceKerningMap(afm.createXKerningMapEncoded()); + if (useKerning) { + returnFont.replaceKerningMap(afm.createXKerningMapEncoded()); + } } else { returnFont.setFlags(pfm.getFlags()); returnFont.setFirstChar(pfm.getFirstChar()); @@ -329,7 +332,9 @@ public class Type1FontLoader extends FontLoader { for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) { singleFont.setWidth(i, pfm.getCharWidth(i)); } - returnFont.replaceKerningMap(pfm.getKerning()); + if (useKerning) { + returnFont.replaceKerningMap(pfm.getKerning()); + } } } |