Author: jeremias
Date: Sun Jan 4 04:59:29 2009
New Revision: 731248
URL: http://svn.apache.org/viewvc?rev=731248&view=rev
Log:
Added support for forcing single-byte encodings for TrueType fonts without
creating an XML font metric file (see "encoding-mode" attribute on "font"
element in updated documentation).
See also Acrobat PDF merge performance problem on fop-users:
http://markmail.org/message/dbbaaht4qshhqs3v
Added:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java
(with props)
Modified:
xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml
xmlgraphics/fop/trunk/src/foschema/fop-configuration.xsd
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
xmlgraphics/fop/trunk/status.xml
Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml
(original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/fonts.xml Sun
Jan 4 04:59:29 2009
@@ -367,7 +367,9 @@
<renderer mime="application/pdf">
<fonts>
<!-- register a particular font -->
- <font metrics-url="file:///C:/myfonts/FTL_____.xml" kerning="yes"
embed-url="file:///C:/myfonts/FTL_____.pfb">
+ <font metrics-url="file:///C:/myfonts/FTL_____.xml" kerning="yes"
+ embed-url="file:///C:/myfonts/FTL_____.pfb"
+ encoding-mode="single-byte">
<font-triplet name="FrutigerLight" style="normal" weight="normal"/>
</font>
@@ -393,6 +395,13 @@
<li>The font "kerning" attribute is optional. Default is "true".</li>
<li>If embedding is off (i.e. embed-url is not set), the output will
position the text correctly (from the metrics file), but it will not be
displayed or printed correctly unless the viewer has the applicable font
available to their local system.</li>
<li>When setting the "embed-url" attribute for Type 1 fonts, be sure
to specify the PFB (actual font data), not PFM (font metrics) file that you
used to generate the XML font metrics file.</li>
+ <li>The attribute "encoding-mode" is optional an may have the
following values:
+ <ul>
+ <li>auto: default font encoding mode ("cid" for Truetype,
"single-byte" for Type 1)</li>
+ <li>single-byte: use single-byte encodings in the target format
(if applicable)</li>
+ <li>cid: encode as CID-keyed font (currently only supported for
PDF output with TrueType fonts)</li>
+ </ul>
+ </li>
<li>The fonts "directory" tag can be used to register fonts
contained within a single or list of directory paths. The "recursive"
attribute can be specified to recursively add fonts from all sub
directories.</li>
<li>The fonts "auto-detect" tag can be used to automatically
register fonts that are found to be installed on the native operating
system.</li>
<li>Fonts registered with "font" tag configurations override fonts
found by means of "directory" tag definitions.</li>
Modified: xmlgraphics/fop/trunk/src/foschema/fop-configuration.xsd
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/foschema/fop-configuration.xsd?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/foschema/fop-configuration.xsd (original)
+++ xmlgraphics/fop/trunk/src/foschema/fop-configuration.xsd Sun Jan 4
04:59:29 2009
@@ -219,6 +219,15 @@
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
+ <xsd:attribute name="encoding-mode" use="optional" default="auto">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="auto"/>
+ <xsd:enumeration value="single-byte"/>
+ <xsd:enumeration value="cid"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
</xsd:complexType>
<xsd:complexType name="fontTripletType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java Sun
Jan 4 04:59:29 2009
@@ -29,7 +29,7 @@
public class EmbedFontInfo implements Serializable {
/** Serialization Version UID */
- private static final long serialVersionUID = 8755432068669997367L;
+ private static final long serialVersionUID = 8755432068669997368L;
/** filename of the metrics file */
protected String metricsFile;
@@ -37,6 +37,8 @@
protected String embedFile;
/** false, to disable kerning */
protected boolean kerning;
+ /** the requested encoding mode for the font */
+ protected EncodingMode encodingMode = EncodingMode.AUTO;
/** the PostScript name of the font */
protected String postScriptName = null;
@@ -142,6 +144,25 @@
this.embedded = value;
}
+ /**
+ * Returns the requested encoding mode for this font.
+ * @return the encoding mode
+ */
+ public EncodingMode getEncodingMode() {
+ return this.encodingMode;
+ }
+
+ /**
+ * Sets the requested encoding mode for this font.
+ * @param mode the new encoding mode
+ */
+ public void setEncodingMode(EncodingMode mode) {
+ if (mode == null) {
+ throw new NullPointerException("mode must not be null");
+ }
+ this.encodingMode = mode;
+ }
+
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
@@ -150,8 +171,10 @@
/** {...@inheritdoc} */
public String toString() {
- return "metrics-url=" + metricsFile + ",embed-url=" + embedFile
- + ", kerning=" + kerning + ", " + "font-triplet=" + fontTriplets
+ return "metrics-url=" + metricsFile + ", embed-url=" + embedFile
+ + ", kerning=" + kerning
+ + ", enc-mode=" + encodingMode
+ + ", font-triplet=" + fontTriplets
+ (getSubFontName() != null ? ", sub-font=" + getSubFontName() :
"")
+ (isEmbedded() ? "" : ", NOT embedded");
}
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java?rev=731248&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java
(added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java Sun
Jan 4 04:59:29 2009
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
+
+/**
+ * This class enumerates all supported encoding modes for fonts: auto,
single-byte and CID.
+ */
+public final class EncodingMode implements Serializable {
+
+ private static final long serialVersionUID = 8311486102457779529L;
+
+ /** Automatic selection of encoding mode. */
+ public static final EncodingMode AUTO = new EncodingMode("auto");
+
+ /** Single-byte encoding */
+ public static final EncodingMode SINGLE_BYTE = new
EncodingMode("single-byte");
+
+ /** CID encoding */
+ public static final EncodingMode CID = new EncodingMode("cid");
+
+ private String name;
+
+ private EncodingMode(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the encoding mode name.
+ * @return the encoding mode name
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Returns the {...@link EncodingMode} by name.
+ * @param name the name of the encoding mode to look up
+ * @return the encoding mode constant
+ */
+ public static EncodingMode valueOf(String name) {
+ if (name.equalsIgnoreCase(EncodingMode.AUTO.getName())) {
+ return EncodingMode.AUTO;
+ } else if (name.equalsIgnoreCase(EncodingMode.SINGLE_BYTE.getName())) {
+ return EncodingMode.SINGLE_BYTE;
+ } else if (name.equalsIgnoreCase(EncodingMode.CID.getName())) {
+ return EncodingMode.CID;
+ } else {
+ throw new IllegalArgumentException("Invalid encoding mode: " +
name);
+ }
+ }
+
+ private Object readResolve() throws ObjectStreamException {
+ return valueOf(getName());
+ }
+
+ /** {...@inheritdoc} */
+ public String toString() {
+ return "EncodingMode:" + getName();
+ }
+
+}
Propchange:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EncodingMode.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java Sun Jan
4 04:59:29 2009
@@ -75,13 +75,14 @@
* @param fontFile the File representation of the font
* @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 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(File fontFile, String subFontName,
- boolean embedded, FontResolver resolver) throws IOException {
- return loadFont(fontFile.getAbsolutePath(), subFontName, embedded,
resolver);
+ boolean embedded, EncodingMode encodingMode, FontResolver
resolver) throws IOException {
+ return loadFont(fontFile.getAbsolutePath(), subFontName, embedded,
encodingMode, resolver);
}
/**
@@ -89,13 +90,14 @@
* @param fontUrl the URL representation of the font
* @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 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(URL fontUrl, String subFontName,
- boolean embedded, FontResolver resolver) throws IOException {
- return loadFont(fontUrl.toExternalForm(), subFontName, embedded,
resolver);
+ boolean embedded, EncodingMode encodingMode, FontResolver
resolver) throws IOException {
+ return loadFont(fontUrl.toExternalForm(), subFontName, embedded,
encodingMode, resolver);
}
/**
@@ -103,19 +105,24 @@
* @param fontFileURI the URI to the font
* @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 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, FontResolver resolver) throws IOException {
+ boolean embedded, EncodingMode encodingMode, FontResolver
resolver) throws IOException {
fontFileURI = fontFileURI.trim();
boolean type1 = isType1(fontFileURI);
FontLoader loader;
if (type1) {
+ if (encodingMode == EncodingMode.CID) {
+ throw new IllegalArgumentException(
+ "CID encoding mode not supported for Type 1 fonts");
+ }
loader = new Type1FontLoader(fontFileURI, embedded, resolver);
} else {
- loader = new TTFFontLoader(fontFileURI, subFontName, embedded,
resolver);
+ loader = new TTFFontLoader(fontFileURI, subFontName, embedded,
encodingMode, resolver);
}
return loader.getFont();
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java Sun Jan
4 04:59:29 2009
@@ -44,6 +44,7 @@
private String metricsFileName = null;
private String fontEmbedPath = null;
private boolean useKerning = false;
+ private EncodingMode encodingMode = EncodingMode.AUTO;
private boolean embedded = true;
private String subFontName = null;
@@ -63,6 +64,7 @@
this.metricsFileName = fontInfo.getMetricsFile();
this.fontEmbedPath = fontInfo.getEmbedFile();
this.useKerning = fontInfo.getKerning();
+ this.encodingMode = fontInfo.getEncodingMode();
this.subFontName = fontInfo.getSubFontName();
this.embedded = fontInfo.isEmbedded();
this.resolver = resolver;
@@ -130,7 +132,7 @@
throw new RuntimeException("Cannot load font. No font
URIs available.");
}
realFont = FontLoader.loadFont(fontEmbedPath,
this.subFontName,
- this.embedded, resolver);
+ this.embedded, this.encodingMode, resolver);
}
if (realFont instanceof FontDescriptor) {
realFontDescriptor = (FontDescriptor) realFont;
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
Sun Jan 4 04:59:29 2009
@@ -33,6 +33,7 @@
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontCache;
import org.apache.fop.fonts.FontEventListener;
@@ -224,7 +225,7 @@
}
try {
TTFFontLoader ttfLoader = new TTFFontLoader(
- fontFileURI, fontName, true, resolver);
+ fontFileURI, fontName, true, EncodingMode.AUTO,
resolver);
customFont = ttfLoader.getFont();
if (this.eventListener != null) {
customFont.setEventListener(this.eventListener);
@@ -248,7 +249,7 @@
} else {
// The normal case
try {
- customFont = FontLoader.loadFont(fontUrl, null, true,
resolver);
+ customFont = FontLoader.loadFont(fontUrl, null, true,
EncodingMode.AUTO, resolver);
if (this.eventListener != null) {
customFont.setEventListener(this.eventListener);
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
Sun Jan 4 04:59:29 2009
@@ -31,6 +31,7 @@
import org.apache.fop.fonts.BFEntry;
import org.apache.fop.fonts.CIDFontType;
+import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.FontLoader;
import org.apache.fop.fonts.FontResolver;
import org.apache.fop.fonts.FontType;
@@ -46,6 +47,7 @@
private MultiByteFont multiFont;
private SingleByteFont singleFont;
private String subFontName;
+ private EncodingMode encodingMode;
/**
* Default constructor
@@ -53,7 +55,7 @@
* @param resolver the FontResolver for font URI resolution
*/
public TTFFontLoader(String fontFileURI, FontResolver resolver) {
- this(fontFileURI, null, true, resolver);
+ this(fontFileURI, null, true, EncodingMode.AUTO, resolver);
}
/**
@@ -62,12 +64,17 @@
* @param subFontName the sub-fontname of a font in a TrueType Collection
(or null for normal
* TrueType fonts)
* @param embedded indicates whether the font is embedded or referenced
+ * @param encodingMode the requested encoding mode
* @param resolver the FontResolver for font URI resolution
*/
public TTFFontLoader(String fontFileURI, String subFontName,
- boolean embedded, FontResolver resolver) {
+ boolean embedded, EncodingMode encodingMode, FontResolver
resolver) {
super(fontFileURI, embedded, resolver);
this.subFontName = subFontName;
+ this.encodingMode = encodingMode;
+ if (this.encodingMode == EncodingMode.AUTO) {
+ this.encodingMode = EncodingMode.CID; //Default to CID mode for
TrueType
+ }
}
/** {...@inheritdoc} */
@@ -105,6 +112,9 @@
}
boolean isCid = this.embedded;
+ if (this.encodingMode == EncodingMode.SINGLE_BYTE) {
+ isCid = false;
+ }
if (isCid) {
multiFont = new MultiByteFont();
@@ -156,7 +166,7 @@
copyKerning(ttf, isCid);
if (this.embedded && ttf.isEmbeddable()) {
- multiFont.setEmbedFileName(this.fontFileURI);
+ returnFont.setEmbedFileName(this.fontFileURI);
}
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
Sun Jan 4 04:59:29 2009
@@ -42,6 +42,7 @@
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.FontCache;
import org.apache.fop.fonts.FontEventAdapter;
import org.apache.fop.fonts.FontEventListener;
@@ -410,8 +411,11 @@
}
boolean useKerning = fontCfg.getAttributeAsBoolean("kerning", true);
+ EncodingMode encodingMode = EncodingMode.valueOf(
+ fontCfg.getAttribute("encoding-mode",
EncodingMode.AUTO.getName()));
EmbedFontInfo embedFontInfo
= new EmbedFontInfo(metricsUrl, useKerning, tripletList,
embedUrl, subFont);
+ embedFontInfo.setEncodingMode(encodingMode);
if (fontCache != null) {
if (!fontCache.containsFont(embedFontInfo)) {
fontCache.addFont(embedFontInfo);
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
Sun Jan 4 04:59:29 2009
@@ -28,6 +28,7 @@
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontLoader;
@@ -87,7 +88,7 @@
font = new CustomFontMetricsMapper(fontMetrics,
fontSource);
} else {
CustomFont fontMetrics = FontLoader.loadFont(
- fontFile, null, true, fontResolver);
+ fontFile, null, true, EncodingMode.AUTO,
fontResolver);
font = new CustomFontMetricsMapper(fontMetrics);
}
Modified: xmlgraphics/fop/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=731248&r1=731247&r2=731248&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Sun Jan 4 04:59:29 2009
@@ -53,6 +53,10 @@
<changes>
<release version="FOP Trunk" date="TBD">
+ <action context="Fonts" dev="JM" type="add">
+ Added support for forcing single-byte encodings for TrueType fonts
without
+ creating an XML font metric file (see "encoding-mode" attribute on
"font" element)
+ </action>
<action context="Layout" dev="JM" type="fix" fixes-bug="45306">
Fixed fo:instream-foreign-object inside fo:marker.
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]