You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2007/05/28 16:31:33 UTC
svn commit: r542237 [2/5] - in /xmlgraphics/fop/trunk: ./ lib/
src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/
src/java/org/apache/fop/area/ src/java/org/apache/fop/cli/
src/java/org/apache/fop/fonts/ src/java/org/apache/fop/fonts/...
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java Mon May 28 07:31:24 2007
@@ -0,0 +1,330 @@
+/*
+ * 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.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * Fop cache (currently only used for font info caching)
+ */
+public final class FontCache implements Serializable {
+
+ /** Serialization Version UID */
+ private static final long serialVersionUID = 605232520271754717L;
+
+ /** logging instance */
+ private static Log log = LogFactory.getLog(FontCache.class);
+
+ /** FOP's user directory name */
+ private static final String FOP_USER_DIR = ".fop";
+
+ /** font cache file path */
+ private static final String DEFAULT_CACHE_FILENAME = "fop-fonts.cache";
+
+ /** has this cache been changed since it was last read? */
+ private transient boolean changed = false;
+
+ /** change lock */
+ private transient Object changeLock = new Object();
+
+ /** master mapping of font url -> font info */
+ private Map fontMap = new java.util.HashMap();
+
+ /** mapping of font url -> file modified date */
+ private Map failedFontMap = new java.util.HashMap();
+
+ /**
+ * Default constructor
+ */
+ public FontCache() {
+ //nop
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ this.changeLock = new Object(); //Initialize transient field
+ }
+
+ private static File getUserHome() {
+ String s = System.getProperty("user.home");
+ if (s != null) {
+ File userDir = new File(s);
+ if (userDir.exists()) {
+ return userDir;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the default font cache file.
+ * @param forWriting true if the user directory should be created
+ * @return the default font cache file
+ */
+ public static File getDefaultCacheFile(boolean forWriting) {
+ File userHome = getUserHome();
+ if (userHome != null) {
+ File fopUserDir = new File(userHome, FOP_USER_DIR);
+ if (forWriting) {
+ fopUserDir.mkdir();
+ }
+ return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
+ }
+ return new File(FOP_USER_DIR);
+ }
+
+ /**
+ * Reads the default font cache file and returns its contents.
+ * @return the font cache deserialized from the file (or null if no cache file exists or if
+ * it could not be read)
+ */
+ public static FontCache load() {
+ return loadFrom(getDefaultCacheFile(false));
+ }
+
+ /**
+ * Reads a font cache file and returns its contents.
+ * @param cacheFile the cache file
+ * @return the font cache deserialized from the file (or null if no cache file exists or if
+ * it could not be read)
+ */
+ public static FontCache loadFrom(File cacheFile) {
+ if (cacheFile.exists()) {
+ try {
+ if (log.isTraceEnabled()) {
+ log.trace("Loading font cache from " + cacheFile.getCanonicalPath());
+ }
+ InputStream in = new java.io.FileInputStream(cacheFile);
+ in = new java.io.BufferedInputStream(in);
+ ObjectInputStream oin = new ObjectInputStream(in);
+ try {
+ return (FontCache)oin.readObject();
+ } finally {
+ IOUtils.closeQuietly(oin);
+ }
+ } catch (ClassNotFoundException e) {
+ //We don't really care about the exception since it's just a cache file
+ log.warn("Could not read font cache. Discarding font cache file. Reason: "
+ + e.getMessage());
+ } catch (IOException ioe) {
+ //We don't really care about the exception since it's just a cache file
+ log.warn("I/O exception while reading font cache (" + ioe.getMessage()
+ + "). Discarding font cache file.");
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Writes the font cache to disk.
+ * @throws FOPException fop exception
+ */
+ public void save() throws FOPException {
+ saveTo(getDefaultCacheFile(true));
+ }
+
+ /**
+ * Writes the font cache to disk.
+ * @param cacheFile the file to write to
+ * @throws FOPException fop exception
+ */
+ public void saveTo(File cacheFile) throws FOPException {
+ synchronized (changeLock) {
+ if (changed) {
+ try {
+ if (log.isTraceEnabled()) {
+ log.trace("Writing font cache to " + cacheFile.getCanonicalPath());
+ }
+ OutputStream out = new java.io.FileOutputStream(cacheFile);
+ out = new java.io.BufferedOutputStream(out);
+ ObjectOutputStream oout = new ObjectOutputStream(out);
+ try {
+ oout.writeObject(this);
+ } finally {
+ IOUtils.closeQuietly(oout);
+ }
+ } catch (IOException ioe) {
+ LogUtil.handleException(log, ioe, true);
+ }
+ changed = false;
+ log.trace("Cache file written.");
+ }
+ }
+ }
+
+ /**
+ * creates a key given a font info for the font mapping
+ * @param fontInfo font info
+ * @return font cache key
+ */
+ protected static String getCacheKey(EmbedFontInfo fontInfo) {
+ if (fontInfo != null) {
+ String embedFile = fontInfo.getEmbedFile();
+ String metricsFile = fontInfo.getMetricsFile();
+ return (embedFile != null) ? embedFile : metricsFile;
+ }
+ return null;
+ }
+
+ /**
+ * cache has been updated since it was read
+ * @return if this cache has changed
+ */
+ public boolean hasChanged() {
+ return this.changed;
+ }
+
+ /**
+ * is this font in the cache?
+ * @param embedUrl font info
+ * @return boolean
+ */
+ public boolean containsFont(String embedUrl) {
+ if (embedUrl != null) {
+ return fontMap.containsKey(embedUrl);
+ }
+ return false;
+ }
+
+ /**
+ * is this font info in the cache?
+ * @param fontInfo font info
+ * @return font
+ */
+ public boolean containsFont(EmbedFontInfo fontInfo) {
+ if (fontInfo != null) {
+ return fontMap.containsKey(getCacheKey(fontInfo));
+ }
+ return false;
+ }
+
+ /**
+ * adds a font info to cache
+ * @param fontInfo font info
+ */
+ public void addFont(EmbedFontInfo fontInfo) {
+ String cacheKey = getCacheKey(fontInfo);
+ synchronized (changeLock) {
+ if (!containsFont(cacheKey)) {
+ if (log.isTraceEnabled()) {
+ log.trace("Font added to cache: " + cacheKey);
+ }
+ if (fontInfo instanceof CachedFontInfo) {
+ fontMap.put(cacheKey, fontInfo);
+ } else {
+ fontMap.put(cacheKey, new CachedFontInfo(fontInfo));
+ }
+ changed = true;
+ }
+ }
+ }
+
+ /**
+ * returns a font from the cache
+ * @param embedUrl font info
+ * @return boolean
+ */
+ public CachedFontInfo getFont(String embedUrl) {
+ if (containsFont(embedUrl)) {
+ return (CachedFontInfo)fontMap.get(embedUrl);
+ }
+ return null;
+ }
+
+ /**
+ * removes font from cache
+ * @param embedUrl embed url
+ */
+ public void removeFont(String embedUrl) {
+ synchronized (changeLock) {
+ if (containsFont(embedUrl)) {
+ if (log.isTraceEnabled()) {
+ log.trace("Font removed from cache: " + embedUrl);
+ }
+ fontMap.remove(embedUrl);
+ changed = true;
+ }
+ }
+ }
+
+ /**
+ * has this font previously failed to load?
+ * @param embedUrl embed url
+ * @param lastModified last modified
+ * @return whether this is a failed font
+ */
+ public boolean isFailedFont(String embedUrl, long lastModified) {
+ if (failedFontMap.containsKey(embedUrl)) {
+ synchronized (changeLock) {
+ long failedLastModified = ((Long)failedFontMap.get(embedUrl)).longValue();
+ if (lastModified != failedLastModified) {
+ // this font has been changed so lets remove it
+ // from failed font map for now
+ failedFontMap.remove(embedUrl);
+ changed = true;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * registers a failed font with the cache
+ * @param embedUrl embed url
+ * @param lastModified time last modified
+ */
+ public void registerFailedFont(String embedUrl, long lastModified) {
+ synchronized (changeLock) {
+ if (!failedFontMap.containsKey(embedUrl)) {
+ failedFontMap.put(embedUrl, new Long(lastModified));
+ changed = true;
+ }
+ }
+ }
+
+ /**
+ * Clears font cache
+ */
+ public void clear() {
+ synchronized (changeLock) {
+ if (log.isTraceEnabled()) {
+ log.trace("Font cache cleared.");
+ }
+ fontMap.clear();
+ failedFontMap.clear();
+ changed = true;
+ }
+ }
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java Mon May 28 07:31:24 2007
@@ -130,6 +130,9 @@
*/
private FontTriplet fontLookup(String family, String style,
int weight, boolean substFont) {
+ if (log.isTraceEnabled()) {
+ log.trace("Font lookup: " + family + " " + style + " " + weight);
+ }
FontTriplet startKey = createFontKey(family, style, weight);
FontTriplet key = startKey;
// first try given parameters
@@ -146,13 +149,13 @@
// only if the font may be substituted
// fallback 1: try the same font-family and weight with default style
if (f == null) {
- key = createFontKey(family, "normal", weight);
+ key = createFontKey(family, Font.STYLE_NORMAL, weight);
f = getInternalFontKey(key);
}
// fallback 2: try the same font-family with default style and weight
if (f == null) {
- key = createFontKey(family, "normal", 400);
+ key = createFontKey(family, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
f = getInternalFontKey(key);
}
@@ -426,8 +429,4 @@
return 0;
}
}
-
}
-
-
-
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?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontLoader.java Mon May 28 07:31:24 2007
@@ -19,6 +19,7 @@
package org.apache.fop.fonts;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -28,6 +29,8 @@
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.fop.fonts.truetype.TTFFontLoader;
import org.apache.fop.fonts.type1.Type1FontLoader;
@@ -37,6 +40,51 @@
public abstract class FontLoader {
/**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog(FontLoader.class);
+
+ /** URI representing the font file */
+ protected String fontFileURI = null;
+ /** the InputStream to load the font from */
+ protected InputStream in = null;
+ /** the FontResolver to use for font URI resolution */
+ protected FontResolver resolver = null;
+ /** the loaded font */
+ protected CustomFont returnFont = null;
+
+ /** true if the font has been loaded */
+ protected boolean loaded = false;
+
+ /**
+ * Default constructor.
+ * @param fontFileURI the URI to the PFB file of a Type 1 font
+ * @param in the InputStream reading the PFM file of a Type 1 font
+ * @param resolver the font resolver used to resolve URIs
+ */
+ public FontLoader(String fontFileURI, InputStream in, FontResolver resolver) {
+ this.fontFileURI = fontFileURI;
+ this.in = in;
+ this.resolver = resolver;
+ }
+
+ private static boolean isType1(String fontURI) {
+ return fontURI.toLowerCase().endsWith(".pfb");
+ }
+
+ /**
+ * Loads a custom font from a File. In the case of Type 1 fonts, the PFB file must be specified.
+ * @param fontFile the File representation of the font
+ * @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, FontResolver resolver)
+ throws IOException {
+ return loadFont(fontFile.getAbsolutePath(), resolver);
+ }
+
+ /**
* Loads a custom font from a URI. In the case of Type 1 fonts, the PFB file must be specified.
* @param fontFileURI the URI to the font
* @param resolver the font resolver to use when resolving URIs
@@ -45,21 +93,38 @@
*/
public static CustomFont loadFont(String fontFileURI, FontResolver resolver)
throws IOException {
- FontLoader loader;
fontFileURI = fontFileURI.trim();
String name = fontFileURI.toLowerCase();
String effURI;
- boolean type1 = false;
- if (name.endsWith(".pfb")) {
- type1 = true;
+ boolean type1 = isType1(fontFileURI);
+ if (type1) {
effURI = name.substring(0, fontFileURI.length() - 4) + ".pfm";
} else {
effURI = fontFileURI;
}
-
+ if (log.isDebugEnabled()) {
+ log.debug("opening " + effURI);
+ }
InputStream in = openFontFile(resolver, effURI);
+ return loadFontFromInputStream(fontFileURI, resolver, type1, in);
+ }
+
+ /**
+ * Loads and returns a font given an input stream.
+ * @param fontFileURI font file uri
+ * @param resolver font resolver
+ * @param isType1 is it a type1 font?
+ * @param in input stream
+ * @return the loaded font.
+ * @throws IOException In case of an I/O error
+ */
+ protected static CustomFont loadFontFromInputStream(
+ String fontFileURI, FontResolver resolver, boolean isType1,
+ InputStream in)
+ throws IOException {
+ FontLoader loader;
try {
- if (type1) {
+ if (isType1) {
loader = new Type1FontLoader(fontFileURI, in, resolver);
} else {
loader = new TTFFontLoader(fontFileURI, in, resolver);
@@ -70,6 +135,14 @@
}
}
+ /**
+ * Opens a font file and returns an input stream.
+ * @param resolver the FontResolver to use for font URI resolution
+ * @param uri the URI representing the font
+ * @return the InputStream to read the font from.
+ * @throws IOException In case of an I/O error
+ * @throws MalformedURLException If an invalid URL is built
+ */
private static InputStream openFontFile(FontResolver resolver, String uri)
throws IOException, MalformedURLException {
InputStream in = null;
@@ -96,11 +169,18 @@
}
return in;
}
-
+
/**
- * @return the font loaded by this loader
+ * Reads/parses the font data.
+ * @throws IOException In case of an I/O error
*/
- public abstract CustomFont getFont();
+ protected abstract void read() throws IOException;
-
+ /** @see org.apache.fop.fonts.FontLoader#getFont() */
+ public CustomFont getFont() throws IOException {
+ if (!loaded) {
+ read();
+ }
+ return this.returnFont;
+ }
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontSetup.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontSetup.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontSetup.java Mon May 28 07:31:24 2007
@@ -34,16 +34,11 @@
import org.apache.fop.fonts.base14.CourierBoldOblique;
import org.apache.fop.fonts.base14.Symbol;
import org.apache.fop.fonts.base14.ZapfDingbats;
-import org.apache.fop.render.PrintRenderer;
// commons logging
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-// Avalon
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
// Java
import java.util.List;
@@ -62,8 +57,8 @@
/**
* logging instance
*/
- protected static Log log = LogFactory.getLog("org.apache.fop.fonts");
-
+ protected static Log log = LogFactory.getLog(FontSetup.class);
+
/**
* Sets up the font info object.
*
@@ -113,52 +108,52 @@
// fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
/* any is treated as serif */
- fontInfo.addFontProperties("F5", "any", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "any", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F6", "any", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F7", "any", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "any", "italic", Font.BOLD);
- fontInfo.addFontProperties("F8", "any", "oblique", Font.BOLD);
-
- fontInfo.addFontProperties("F1", "sans-serif", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F2", "sans-serif", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F2", "sans-serif", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F3", "sans-serif", "normal", Font.BOLD);
- fontInfo.addFontProperties("F4", "sans-serif", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F4", "sans-serif", "italic", Font.BOLD);
- fontInfo.addFontProperties("F5", "serif", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "serif", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "serif", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "serif", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "serif", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "serif", "italic", Font.BOLD);
- fontInfo.addFontProperties("F9", "monospace", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F10", "monospace", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F10", "monospace", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F11", "monospace", "normal", Font.BOLD);
- fontInfo.addFontProperties("F12", "monospace", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F12", "monospace", "italic", Font.BOLD);
-
- fontInfo.addFontProperties("F1", "Helvetica", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F2", "Helvetica", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F2", "Helvetica", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F3", "Helvetica", "normal", Font.BOLD);
- fontInfo.addFontProperties("F4", "Helvetica", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F4", "Helvetica", "italic", Font.BOLD);
- fontInfo.addFontProperties("F5", "Times", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "Times", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times", "italic", Font.BOLD);
- fontInfo.addFontProperties("F9", "Courier", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F10", "Courier", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F10", "Courier", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F11", "Courier", "normal", Font.BOLD);
- fontInfo.addFontProperties("F12", "Courier", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F12", "Courier", "italic", Font.BOLD);
- fontInfo.addFontProperties("F13", "Symbol", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", Font.NORMAL);
+ fontInfo.addFontProperties("F5", "any", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "any", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "any", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "any", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "any", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "any", "oblique", Font.WEIGHT_BOLD);
+
+ fontInfo.addFontProperties("F1", "sans-serif", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F3", "sans-serif", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F5", "serif", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "serif", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "serif", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "serif", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F9", "monospace", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F11", "monospace", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "italic", Font.WEIGHT_BOLD);
+
+ fontInfo.addFontProperties("F1", "Helvetica", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F3", "Helvetica", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F5", "Times", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "Times", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F9", "Courier", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F11", "Courier", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F13", "Symbol", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", Font.WEIGHT_NORMAL);
// Custom type 1 fonts step 2/2
// fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL);
@@ -166,20 +161,20 @@
// fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD);
/* for compatibility with PassiveTex */
- fontInfo.addFontProperties("F5", "Times-Roman", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times-Roman", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times-Roman", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "Times-Roman", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times-Roman", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times-Roman", "italic", Font.BOLD);
- fontInfo.addFontProperties("F5", "Times Roman", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times Roman", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times Roman", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "Times Roman", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times Roman", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times Roman", "italic", Font.BOLD);
+ fontInfo.addFontProperties("F5", "Times-Roman", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "Times-Roman", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F5", "Times Roman", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "Times Roman", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "italic", Font.WEIGHT_BOLD);
fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
- "normal", Font.NORMAL);
+ "normal", Font.WEIGHT_NORMAL);
/* Add configured fonts */
addConfiguredFonts(fontInfo, embedList, 15, resolver);
@@ -218,10 +213,7 @@
reader.setFontEmbedPath(configFontInfo.getEmbedFile());
fontInfo.addMetrics(internalName, reader.getFont());
*/
- LazyFont font = new LazyFont(configFontInfo.getEmbedFile(),
- metricsFile,
- configFontInfo.getKerning(),
- resolver);
+ LazyFont font = new LazyFont(configFontInfo, resolver);
fontInfo.addMetrics(internalName, font);
List triplets = configFontInfo.getFontTriplets();
@@ -237,7 +229,7 @@
}
/** @return a new FontResolver to be used by the font subsystem */
- private static FontResolver createMinimalFontResolver() {
+ public static FontResolver createMinimalFontResolver() {
return new FontResolver() {
/** @see org.apache.fop.fonts.FontResolver#resolve(java.lang.String) */
@@ -245,135 +237,6 @@
//Minimal functionality here
return new StreamSource(href);
}
-
};
- }
-
- /**
- * Builds a list of EmbedFontInfo objects for use with the setup() method.
- *
- * @param cfg Configuration object
- * @param renderer calling Renderer object
- * @return List the newly created list of fonts
- * @throws ConfigurationException if something's wrong with the config data
- */
- public static List buildFontListFromConfiguration(Configuration cfg, PrintRenderer renderer)
- throws ConfigurationException {
- List fontList = new java.util.ArrayList();
-
- FontResolver fontResolver = (renderer != null ? renderer.getFontResolver() : null);
- if (fontResolver == null) {
- //Ensure that we have minimal font resolution capabilities
- fontResolver = FontSetup.createMinimalFontResolver();
- }
-
- boolean strict = false;
- if (renderer != null) {
- strict = renderer.getUserAgent().getFactory().validateUserConfigStrictly();
- }
-
- Configuration[] fonts = cfg.getChildren("fonts");
- for (int f = 0; f < fonts.length; f++) {
-
- Configuration[] font = fonts[f].getChildren("font");
- for (int i = 0; i < font.length; i++) {
-
- String metricsUrl = font[i].getAttribute("metrics-url", null);
- String embedUrl = font[i].getAttribute("embed-url", null);
-
- if (metricsUrl == null && embedUrl == null) {
- if (strict) {
- throw new ConfigurationException(
- "Font configuration without metric-url or embed-url");
- }
- log.error("Font configuration without metric-url or embed-url");
- continue;
- }
-
- if (metricsUrl != null && fontResolver.resolve(metricsUrl) == null) {
- if (strict) {
- throw new ConfigurationException("Failed to resolve font metric-url '"
- + metricsUrl + "'");
- }
- log.error("Failed to resolve font metric-url '" + metricsUrl + "'");
- continue;
- }
-
- if (embedUrl != null && fontResolver.resolve(embedUrl) == null) {
- if (strict) {
- throw new ConfigurationException("Failed to resolve font with embed-url '"
- + embedUrl + "'");
- }
- log.error("Failed to resolve font with embed-url '" + embedUrl + "'");
- continue;
- }
-
- boolean useKerning = font[i].getAttributeAsBoolean("kerning", false);
-
- Configuration[] triple = font[i].getChildren("font-triplet");
- List tripleList = new java.util.ArrayList();
- for (int j = 0; j < triple.length; j++) {
- String name = triple[j].getAttribute("name");
- if (name == null) {
- if (strict) {
- throw new ConfigurationException("font-triplet without name");
- }
- log.error("font-triplet without name");
- continue;
- }
-
- String weightStr = triple[j].getAttribute("weight");
- if (weightStr == null) {
- if (strict) {
- throw new ConfigurationException("font-triplet without weight");
- }
- log.error("font-triplet without weight");
- continue;
- }
- int weight = FontUtil.parseCSS2FontWeight(weightStr);
-
- String style = triple[j].getAttribute("style");
- if (style == null) {
- if (strict) {
- throw new ConfigurationException("font-triplet without style");
- }
- log.error("font-triplet without style");
- continue;
- }
-
- tripleList.add(FontInfo.createFontKey(name,
- style, weight));
- }
-
- EmbedFontInfo configFontInfo = new EmbedFontInfo(metricsUrl,
- useKerning, tripleList, embedUrl);
-
- if (log.isDebugEnabled()) {
- log.debug("Adding font " + configFontInfo.getEmbedFile()
- + ", metric file " + configFontInfo.getMetricsFile());
- for (int j = 0; j < tripleList.size(); ++j) {
- FontTriplet triplet = (FontTriplet) tripleList.get(j);
- log.debug("Font triplet "
- + triplet.getName() + ", "
- + triplet.getStyle() + ", "
- + triplet.getWeight());
- }
- }
- fontList.add(configFontInfo);
- }
- }
- return fontList;
- }
-
- /**
- * Builds a list of EmbedFontInfo objects for use with the setup() method.
- *
- * @param cfg Configuration object
- * @return List the newly created list of fonts
- * @throws ConfigurationException if something's wrong with the config data
- */
- public static List buildFontListFromConfiguration(Configuration cfg)
- throws ConfigurationException {
- return buildFontListFromConfiguration(cfg, null);
- }
+ }
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontUtil.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontUtil.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontUtil.java Mon May 28 07:31:24 2007
@@ -57,4 +57,24 @@
return weight;
}
+ /**
+ * Removes all white space from a string (used primarily for font names)
+ * @param s the string
+ * @return the processed result
+ */
+ public static String stripWhiteSpace(String s) {
+ StringBuffer sb = new StringBuffer(s.length());
+ for (int i = 0, c = s.length(); i < c; i++) {
+ final char ch = s.charAt(i);
+ if (ch != ' '
+ && ch != '\r'
+ && ch != '\n'
+ && ch != '\t') {
+ sb.append(ch);
+ }
+ }
+ return sb.toString();
+ }
+
+
}
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?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java Mon May 28 07:31:24 2007
@@ -54,14 +54,21 @@
* @param useKerning True, if kerning should be enabled
* @param resolver the font resolver to handle font URIs
*/
- public LazyFont(String fontEmbedPath, String metricsFileName
- , boolean useKerning, FontResolver resolver) {
- this.metricsFileName = metricsFileName;
- this.fontEmbedPath = fontEmbedPath;
- this.useKerning = useKerning;
+ public LazyFont(EmbedFontInfo fontInfo, FontResolver resolver) {
+
+ this.metricsFileName = fontInfo.getMetricsFile();
+ this.fontEmbedPath = fontInfo.getEmbedFile();
+ this.useKerning = fontInfo.getKerning();
this.resolver = resolver;
}
+ /**
+ * String representation of LazyFont
+ */
+ public String toString() {
+ return ( "metrics-url=" + metricsFileName + ", embed-url=" + fontEmbedPath + ", kerning=" + useKerning );
+ }
+
private void load(boolean fail) {
if (!isMetricsLoaded) {
try {
@@ -327,6 +334,5 @@
load(true);
return realFontDescriptor.isEmbeddable();
}
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java Mon May 28 07:31:24 2007
@@ -108,28 +108,9 @@
public void setCIDType(CIDFontType cidType) {
this.cidType = cidType;
}
-
- /**
- * Removes all white space from a string (used primarily for font names)
- * @param s the string
- * @return the processed result
- */
- public static String stripWhiteSpace(String s) {
- StringBuffer sb = new StringBuffer(s.length());
- for (int i = 0, c = s.length(); i < c; i++) {
- final char ch = s.charAt(i);
- if (ch != ' '
- && ch != '\r'
- && ch != '\n'
- && ch != '\t') {
- sb.append(ch);
- }
- }
- return sb.toString();
- }
private String getPrefixedFontName() {
- return namePrefix + stripWhiteSpace(super.getFontName());
+ return namePrefix + FontUtil.stripWhiteSpace(super.getFontName());
}
/**
@@ -147,7 +128,7 @@
* @see org.apache.fop.fonts.FontDescriptor#isEmbeddable()
*/
public boolean isEmbeddable() {
- return !(getEmbedFileName() == null && embedResourceName == null);
+ return !(getEmbedFileName() == null && getEmbedResourceName() == null);
}
/**
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/apps/TTFReader.java Mon May 28 07:31:24 2007
@@ -27,6 +27,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.fop.Version;
+import org.apache.fop.fonts.FontUtil;
import org.apache.fop.fonts.truetype.FontFileReader;
import org.apache.fop.fonts.truetype.TTFCmapEntry;
import org.apache.fop.fonts.truetype.TTFFile;
@@ -258,10 +259,10 @@
// "Perpetua-Bold", but the TrueType spec says that in the ttf file
// it should be "Perpetua,Bold".
- String s = stripWhiteSpace(ttf.getPostScriptName());
+ String s = FontUtil.stripWhiteSpace(ttf.getPostScriptName());
if (fontName != null) {
- el.appendChild(doc.createTextNode(stripWhiteSpace(fontName)));
+ el.appendChild(doc.createTextNode(FontUtil.stripWhiteSpace(fontName)));
} else {
el.appendChild(doc.createTextNode(s));
}
@@ -450,22 +451,6 @@
}
- private String stripWhiteSpace(String s) {
- char[] ch = new char[s.length()];
- s.getChars(0, s.length(), ch, 0);
- StringBuffer stb = new StringBuffer();
- for (int i = 0; i < ch.length; i++) {
- if (ch[i] != ' '
- && ch[i] != '\r'
- && ch[i] != '\n'
- && ch[i] != '\t') {
- stb.append(ch[i]);
- }
- }
-
- return stb.toString();
- }
-
/**
* Bugzilla 40739, check that attr has a metrics-version attribute
* compatible with ours.
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,158 @@
+/*
+ * 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.autodetect;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.io.DirectoryWalker;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Helps to autodetect/locate available operating system fonts.
+ */
+public class FontFileFinder extends DirectoryWalker implements FontFinder {
+
+ /** logging instance */
+ private final Log log = LogFactory.getLog(FontFileFinder.class);
+
+ /** default depth limit of recursion when searching for font files **/
+ public static final int DEFAULT_DEPTH_LIMIT = -1;
+
+ /**
+ * Default constructor
+ */
+ public FontFileFinder() {
+ super(getDirectoryFilter(), getFileFilter(), DEFAULT_DEPTH_LIMIT);
+ }
+
+ /**
+ * Constructor
+ * @param depthLimit recursion depth limit
+ */
+ public FontFileFinder(int depthLimit) {
+ super(getDirectoryFilter(), getFileFilter(), depthLimit);
+ }
+
+ /**
+ * Font directory filter. Currently ignores hidden directories.
+ * @return IOFileFilter font directory filter
+ */
+ protected static IOFileFilter getDirectoryFilter() {
+ return FileFilterUtils.andFileFilter(
+ FileFilterUtils.directoryFileFilter(),
+ FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter("."))
+ );
+ }
+
+ /**
+ * Font file filter. Currently searches for files with .ttf and .pfb extensions.
+ * @return IOFileFilter font file filter
+ */
+ protected static IOFileFilter getFileFilter() {
+ return FileFilterUtils.andFileFilter(
+ FileFilterUtils.fileFileFilter(),
+ FileFilterUtils.orFileFilter(
+ FileFilterUtils.suffixFileFilter(".ttf"),
+ FileFilterUtils.suffixFileFilter(".pfb")
+ )
+ );
+ }
+
+ /**
+ * @param directory directory to handle
+ * @param depth recursion depth
+ * @param results collection
+ * @return whether directory should be handled
+ * @see org.apache.commons.io.DirectoryWalker#handleDirectory(File, int, Collection)
+ */
+ protected boolean handleDirectory(File directory, int depth, Collection results) {
+ return true;
+ }
+
+ /**
+ * @param file file to handle
+ * @param depth recursion depth
+ * @param results collection
+ * @see org.apache.commons.io.DirectoryWalker#handleFile(File, int, Collection)
+ */
+ protected void handleFile(File file, int depth, Collection results) {
+ results.add(file);
+ }
+
+ /**
+ * @param directory the directory being processed
+ * @param depth the current directory level
+ * @param results the colleciton of results objects
+ * @see org.apache.commons.io.DirectoryWalker.handleDirectoryEnd
+ */
+ protected void handleDirectoryEnd(File directory, int depth, Collection results) {
+ if (log.isDebugEnabled()) {
+ log.debug(directory + ": found " + results.size() + " font"
+ + ((results.size() == 1) ? "" : "s"));
+ }
+ }
+
+ /**
+ * Automagically finds a list of font files on local system
+ *
+ * @return list of font files
+ * @throws IOException io exception
+ * @see org.apache.fop.fonts.autodetect.FontFinder#find()
+ */
+ public List find() throws IOException {
+ final FontFinder fontDirFinder;
+ final String osName = System.getProperty("os.name");
+ if (osName.startsWith("Windows")) {
+ fontDirFinder = new WindowsFontDirFinder();
+ } else {
+ if (osName.startsWith("Mac")) {
+ fontDirFinder = new MacFontDirFinder();
+ } else {
+ fontDirFinder = new UnixFontDirFinder();
+ }
+ }
+ List fontDirs = fontDirFinder.find();
+ List results = new java.util.ArrayList();
+ for (Iterator iter = fontDirs.iterator(); iter.hasNext();) {
+ super.walk((File)iter.next(), results);
+ }
+ return results;
+ }
+
+ /**
+ * Searches a given directory for font files
+ *
+ * @param dir directory to search
+ * @return list of font files
+ * @throws IOException io exception
+ */
+ public List find(String dir) throws IOException {
+ List results = new java.util.ArrayList();
+ super.walk(new File(dir), results);
+ return results;
+ }
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFinder.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.autodetect;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Implementers provide find method for searching native operating system
+ * for available fonts.
+ */
+public interface FontFinder {
+
+ /**
+ * Finds a list of font files.
+ * @return list of font files
+ * @throws IOException In case of an I/O problem
+ */
+ List find() throws IOException;
+
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,171 @@
+/*
+ * 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.autodetect;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fonts.CachedFontInfo;
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontCache;
+import org.apache.fop.fonts.FontLoader;
+import org.apache.fop.fonts.FontResolver;
+import org.apache.fop.fonts.FontTriplet;
+
+/**
+ * Attempts to determine correct FontInfo
+ */
+public class FontInfoFinder {
+
+ /** logging instance */
+ private Log log = LogFactory.getLog(FontInfoFinder.class);
+
+ /** font constituent names which identify a font as being of "italic" style */
+ private static final String[] ITALIC_WORDS = {"italic", "oblique"};
+
+ /** font constituent names which identify a font as being of "bold" weight */
+ private static final String[] BOLD_WORDS = {"bold", "black", "heavy", "ultra", "super"};
+
+ /**
+ * Attempts to determine FontTriplet from a given CustomFont.
+ * It seems to be fairly accurate but will probably require some tweaking over time
+ *
+ * @param customFont CustomFont
+ * @return newly created font triplet
+ */
+ private FontTriplet tripletFromFont(CustomFont customFont) {
+ // default style and weight triplet vales (fallback)
+ String name = customFont.getStrippedFontName();
+ String subName = customFont.getFontSubName();
+ String searchName = name.toLowerCase();
+ if (subName != null) {
+ searchName += subName.toLowerCase();
+ }
+
+ // style
+ String style = Font.STYLE_NORMAL;
+ if (customFont.getItalicAngle() > 0) {
+ style = Font.STYLE_ITALIC;
+ } else {
+ for (int i = 0; i < ITALIC_WORDS.length; i++) {
+ if (searchName.indexOf(ITALIC_WORDS[i]) != -1) {
+ style = Font.STYLE_ITALIC;
+ break;
+ }
+ }
+ }
+
+ // weight
+ int weight = Font.WEIGHT_NORMAL;
+ for (int i = 0; i < BOLD_WORDS.length; i++) {
+ if (searchName.indexOf(BOLD_WORDS[i]) != -1) {
+ weight = Font.WEIGHT_BOLD;
+ break;
+ }
+ }
+ return new FontTriplet(name, style, weight);
+ }
+
+ /**
+ * Attempts to determine FontInfo from a given custom font
+ * @param fontFile the font file
+ * @param customFont the custom font
+ * @param fontCache font cache (may be null)
+ * @return
+ */
+ private EmbedFontInfo fontInfoFromCustomFont(
+ File fontFile, CustomFont customFont, FontCache fontCache) {
+ FontTriplet fontTriplet = tripletFromFont(customFont);
+ List fontTripletList = new java.util.ArrayList();
+ fontTripletList.add(fontTriplet);
+ String embedUrl;
+ try {
+ embedUrl = fontFile.toURL().toExternalForm();
+ } catch (MalformedURLException e) {
+ embedUrl = fontFile.getAbsolutePath();
+ }
+ EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(),
+ fontTripletList, embedUrl);
+ if (fontCache != null) {
+ fontCache.addFont(fontInfo);
+ }
+ return fontInfo;
+ }
+
+ /**
+ * Attempts to determine EmbedFontInfo from a given font file.
+ *
+ * @param fontFile font file
+ * @param resolver font resolver used to resolve font
+ * @param fontCache font cache (may be null)
+ * @return newly created embed font info
+ */
+ public EmbedFontInfo find(File fontFile, FontResolver resolver, FontCache fontCache) {
+ String embedUrl = null;
+ try {
+ embedUrl = fontFile.toURL().toExternalForm();
+ } catch (MalformedURLException mfue) {
+ // should never happen
+ log.error("Failed to convert '" + fontFile + "' to URL: " + mfue.getMessage() );
+ }
+
+ long fileLastModified = -1;
+ if (fontCache != null) {
+ fileLastModified = fontFile.lastModified();
+ // firstly try and fetch it from cache before loading/parsing the font file
+ if (fontCache.containsFont(embedUrl)) {
+ CachedFontInfo fontInfo = fontCache.getFont(embedUrl);
+ if (fontInfo.lastModified() == fileLastModified) {
+ return fontInfo;
+ } else {
+ // out of date cache item
+ fontCache.removeFont(embedUrl);
+ }
+ // is this a previously failed parsed font?
+ } else if (fontCache.isFailedFont(embedUrl, fileLastModified)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Skipping font file that failed to load previously: " + embedUrl);
+ }
+ return null;
+ }
+ }
+
+ // try to determine triplet information from font file
+ CustomFont customFont = null;
+ try {
+ customFont = FontLoader.loadFont(fontFile, resolver);
+ } catch (Exception e) {
+ //TODO Too verbose (it's an error but we don't care if some fonts can't be loaded)
+ if (log.isErrorEnabled()) {
+ log.error("Unable to load font file: " + embedUrl + ". Reason: " + e.getMessage());
+ }
+ if (fontCache != null) {
+ fontCache.registerFailedFont(embedUrl, fileLastModified);
+ }
+ return null;
+ }
+ return fontInfoFromCustomFont(fontFile, customFont, fontCache);
+ }
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.autodetect;
+
+/**
+ * Mac font directory finder
+ */
+public class MacFontDirFinder extends NativeFontDirFinder {
+
+ /**
+ * Some guesses at possible unix font directory locations
+ * @return a array of possible font directory locations
+ */
+ protected String[] getSearchableDirectories() {
+ return new String[] {
+ System.getProperty("user.home") + "/Library/Fonts/", // user
+ "/Library/Fonts/", // local
+ "/System/Library/Fonts/", // system
+ "/Network/Library/Fonts/" // network
+ };
+ }
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.autodetect;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Native font finder base class
+ */
+public abstract class NativeFontDirFinder implements FontFinder {
+
+ /**
+ * Generic method used by Mac and Unix font finders.
+ * @return list of natively existing font directories
+ * @see FontFinder#find()
+ */
+ public List find() {
+ List fontDirList = new java.util.ArrayList();
+ String[] searchableDirectories = getSearchableDirectories();
+ if (searchableDirectories != null) {
+ for (int i = 0; i < searchableDirectories.length; i++) {
+ File fontDir = new File(searchableDirectories[i]);
+ if (fontDir.exists() && fontDir.canRead()) {
+ fontDirList.add(fontDir);
+ }
+ }
+ }
+ return fontDirList;
+ }
+
+ /**
+ * Returns an array of directories to search for fonts in.
+ * @return an array of directories
+ */
+ protected abstract String[] getSearchableDirectories();
+
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/NativeFontDirFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.autodetect;
+
+/**
+ * Unix font directory finder
+ */
+public class UnixFontDirFinder extends NativeFontDirFinder {
+
+ /**
+ * Some guesses at possible unix font directory locations
+ * @return a list of possible font locations
+ */
+ protected String[] getSearchableDirectories() {
+ return new String[] {
+ System.getProperty("user.home") + "/.fonts", // user
+ "/usr/local/fonts", // local
+ "/usr/share/fonts", // system
+ "/usr/X11R6/lib/X11/fonts" // X
+ };
+ }
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/UnixFontDirFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java Mon May 28 07:31:24 2007
@@ -0,0 +1,108 @@
+/*
+ * 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.autodetect;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.List;
+
+/**
+ * FontFinder for native Windows platforms
+ */
+public class WindowsFontDirFinder implements FontFinder {
+
+ /**
+ * Attempts to read windir environment variable on windows
+ * (disclaimer: This is a bit dirty but seems to work nicely)
+ */
+ private String getWinDir(String osName) throws IOException {
+ Process process = null;
+ Runtime runtime = Runtime.getRuntime();
+ if (osName.startsWith("Windows 9")) {
+ process = runtime.exec("command.com /c echo %windir%");
+ } else {
+ process = runtime.exec("cmd.exe /c echo %windir%");
+ }
+ BufferedReader bufferedReader = new BufferedReader(
+ new InputStreamReader(process.getInputStream()));
+ return bufferedReader.readLine();
+ }
+
+ /**
+ * @see FontFinder#find()
+ * @return a list of detected font files
+ */
+ public List find() {
+ List fontDirList = new java.util.ArrayList();
+ String windir = null;
+ try {
+ windir = System.getProperty("env.windir");
+ } catch (SecurityException e) {
+ // should continue if this fails
+ }
+ String osName = System.getProperty("os.name");
+ if (windir == null) {
+ try {
+ windir = getWinDir(osName);
+ } catch (IOException e) {
+ // should continue if this fails
+ }
+ }
+ File osFontsDir = null, psFontsDir = null;
+ if (windir != null) {
+ // remove any trailing '/'
+ if (windir.endsWith("/")) {
+ windir = windir.substring(0, windir.length() - 1);
+ }
+ osFontsDir = new File(windir + File.separator + "FONTS");
+ if (osFontsDir.exists() && osFontsDir.canRead()) {
+ fontDirList.add(osFontsDir);
+ }
+ psFontsDir = new File(windir.substring(0, 2) + File.separator + "PSFONTS");
+ if (psFontsDir.exists() && psFontsDir.canRead()) {
+ fontDirList.add(psFontsDir);
+ }
+ } else {
+ String windowsDirName = osName.endsWith("NT") ? "WINNT" : "WINDOWS";
+ // look for true type font folder
+ for (char driveLetter = 'C'; driveLetter <= 'E'; driveLetter++) {
+ osFontsDir = new File(
+ driveLetter + ":"
+ + File.separator + windowsDirName
+ + File.separator + "FONTS");
+ if (osFontsDir.exists() && osFontsDir.canRead()) {
+ fontDirList.add(osFontsDir);
+ break;
+ }
+ }
+ // look for type 1 font folder
+ for (char driveLetter = 'C'; driveLetter <= 'E'; driveLetter++) {
+ psFontsDir = new File(driveLetter + ":" + File.separator + "PSFONTS");
+ if (psFontsDir.exists() && psFontsDir.canRead()) {
+ fontDirList.add(psFontsDir);
+ break;
+ }
+ }
+ }
+ return fontDirList;
+ }
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/package.html?view=auto&rev=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/package.html (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/package.html Mon May 28 07:31:24 2007
@@ -0,0 +1,23 @@
+<!--
+ 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: $ -->
+<HTML>
+<TITLE>org.apache.fop.fonts.autodetect Package</TITLE>
+<BODY>
+<P>A collection of classes that aid in the autodetection of installed system fonts.</P>
+</BODY>
+</HTML>
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/autodetect/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/truetype/TTFFile.java Mon May 28 07:31:24 2007
@@ -567,6 +567,14 @@
}
/**
+ * Returns the font sub family name of the font.
+ * @return String The sub family name
+ */
+ public String getSubFamilyName() {
+ return subFamilyName;
+ }
+
+ /**
* Returns the name of the character set used.
* @return String The caracter set
*/
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?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- 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 Mon May 28 07:31:24 2007
@@ -27,7 +27,6 @@
import org.apache.fop.fonts.BFEntry;
import org.apache.fop.fonts.CIDFontType;
-import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.FontLoader;
import org.apache.fop.fonts.FontResolver;
import org.apache.fop.fonts.MultiByteFont;
@@ -37,18 +36,23 @@
*/
public class TTFFontLoader extends FontLoader {
- private String fontFileURI;
- private TTFFile ttf;
private MultiByteFont multiFont;
- private CustomFont returnFont;
- private FontResolver resolver;
- public TTFFontLoader(String fontFileURI, InputStream in, FontResolver resolver)
- throws IOException {
- this.fontFileURI = fontFileURI;
- this.resolver = resolver;
-
- this.ttf = new TTFFile();
+ /**
+ * Default constructor
+ * @param fontFileURI the URI representing the font file
+ * @param in the InputStream to load the font from
+ * @param resolver the FontResolver for font URI resolution
+ */
+ public TTFFontLoader(String fontFileURI, InputStream in, FontResolver resolver) {
+ super(fontFileURI, in, resolver);
+ }
+
+ /**
+ * @see FontLoader#read()
+ */
+ protected void read() throws IOException {
+ TTFFile ttf = new TTFFile();
FontFileReader reader = new FontFileReader(in);
boolean supported = ttf.readFont(reader, null);
if (!supported) {
@@ -61,11 +65,9 @@
multiFont = new MultiByteFont();
multiFont.setResolver(this.resolver);
returnFont = multiFont;
- read();
- }
-
- private void read() throws IOException {
+
returnFont.setFontName(ttf.getFamilyName());
+ returnFont.setFontSubFamilyName(ttf.getSubFamilyName());
//multiFont.setTTCName(ttcName)
returnFont.setCapHeight(ttf.getCapHeight());
returnFont.setXHeight(ttf.getXHeight());
@@ -77,6 +79,7 @@
returnFont.setStemV(Integer.parseInt(ttf.getStemV())); //not used for TTF
returnFont.setItalicAngle(Integer.parseInt(ttf.getItalicAngle()));
returnFont.setMissingWidth(0);
+
multiFont.setCIDType(CIDFontType.CIDTYPE2);
int[] wx = ttf.getWidths();
multiFont.setWidthArray(wx);
@@ -93,9 +96,12 @@
multiFont.setBFEntries(bfentries);
copyKerning(ttf, true);
multiFont.setEmbedFileName(this.fontFileURI);
-
+ loaded = true;
}
+ /**
+ * Copy kerning information.
+ */
private void copyKerning(TTFFile ttf, boolean isCid) {
// Get kerning
@@ -115,15 +121,7 @@
} else {
h2 = (Map)ttf.getAnsiKerning().get(kpx1);
}
-
returnFont.putKerningEntry(kpx1, h2);
}
- }
-
-
- /** @see org.apache.fop.fonts.FontLoader#getFont() */
- public CustomFont getFont() {
- return this.returnFont;
- }
-
+ }
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java Mon May 28 07:31:24 2007
@@ -22,7 +22,6 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.FontLoader;
import org.apache.fop.fonts.FontResolver;
import org.apache.fop.fonts.FontType;
@@ -33,11 +32,8 @@
*/
public class Type1FontLoader extends FontLoader {
- private String fontFileURI;
private PFMFile pfm;
private SingleByteFont singleFont;
- private CustomFont returnFont;
- private FontResolver resolver;
/**
* Constructs a new Type 1 font loader.
@@ -48,19 +44,19 @@
*/
public Type1FontLoader(String fontFileURI, InputStream in, FontResolver resolver)
throws IOException {
- this.fontFileURI = fontFileURI;
- this.resolver = resolver;
+ super(fontFileURI, in, resolver);
+ }
+ /**
+ * @see FontLoader#read()
+ */
+ protected void read() throws IOException {
pfm = new PFMFile();
pfm.load(in);
singleFont = new SingleByteFont();
singleFont.setFontType(FontType.TYPE1);
singleFont.setResolver(this.resolver);
returnFont = singleFont;
- read();
- }
-
- private void read() throws IOException {
returnFont.setFontName(pfm.getPostscriptName());
returnFont.setCapHeight(pfm.getCapHeight());
returnFont.setXHeight(pfm.getXHeight());
@@ -77,12 +73,5 @@
singleFont.setWidth(i, pfm.getCharWidth(i));
}
singleFont.setEmbedFileName(this.fontFileURI);
-
- }
-
- /** @see org.apache.fop.fonts.FontLoader#getFont() */
- public CustomFont getFont() {
- return this.returnFont;
}
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFilterList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFilterList.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFilterList.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFilterList.java Mon May 28 07:31:24 2007
@@ -24,14 +24,6 @@
import java.util.List;
import java.util.Map;
-// commons logging
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-// Avalon
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
/**
* This class represents a list of PDF filters to be applied when serializing
* the output of a PDF object.
@@ -56,12 +48,7 @@
private List filters = new java.util.ArrayList();
private boolean ignoreASCIIFilters = false;
-
- /**
- * logging instance
- */
- protected static Log logger = LogFactory.getLog("org.apache.fop.render");
-
+
/**
* Default constructor.
* <p>
@@ -290,53 +277,4 @@
}
return out;
}
-
- /**
- * Builds a filter map from an Avalon Configuration object.
- * @param cfg the Configuration object
- * @return Map the newly built filter map
- * @throws ConfigurationException if a filter list is defined twice
- */
- public static Map buildFilterMapFromConfiguration(Configuration cfg)
- throws ConfigurationException {
- Map filterMap = new java.util.HashMap();
- Configuration[] filterLists = cfg.getChildren("filterList");
- for (int i = 0; i < filterLists.length; i++) {
- Configuration filters = filterLists[i];
- String type = filters.getAttribute("type", null);
- Configuration[] filt = filters.getChildren("value");
- List filterList = new java.util.ArrayList();
- for (int j = 0; j < filt.length; j++) {
- String name = filt[j].getValue();
- filterList.add(name);
- }
-
- if (type == null) {
- type = PDFFilterList.DEFAULT_FILTER;
- }
-
- if (!filterList.isEmpty() && logger.isDebugEnabled()) {
- StringBuffer debug = new StringBuffer("Adding PDF filter");
- if (filterList.size() != 1) {
- debug.append("s");
- }
- debug.append(" for type ").append(type).append(": ");
- for (int j = 0; j < filterList.size(); j++) {
- if (j != 0) {
- debug.append(", ");
- }
- debug.append(filterList.get(j));
- }
- logger.debug(debug.toString());
- }
-
- if (filterMap.get(type) != null) {
- throw new ConfigurationException("A filterList of type '"
- + type + "' has already been defined");
- }
- filterMap.put(type, filterList);
- }
- return filterMap;
- }
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java?view=diff&rev=542237&r1=542236&r2=542237
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRenderer.java Mon May 28 07:31:24 2007
@@ -69,18 +69,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-// Avalon
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
/**
* Abstract base class for all renderers. The Abstract renderer does all the
* top level processing of the area tree and adds some abstract methods to
* handle viewports. This keeps track of the current block and inline position.
*/
public abstract class AbstractRenderer
- implements Renderer, Configurable, Constants {
+ implements Renderer, Constants {
/** logging instance */
protected static Log log = LogFactory.getLog("org.apache.fop.render");
@@ -118,12 +113,6 @@
private Set warnedXMLHandlers;
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration conf) throws ConfigurationException {
- }
-
- /**
* @see org.apache.fop.render.Renderer#setupFontInfo(FontInfo)
*/
public abstract void setupFontInfo(FontInfo fontInfo);
@@ -805,39 +794,6 @@
}
/**
- * Returns the configuration subtree for a specific renderer.
- * @param cfg the renderer configuration
- * @param namespace the namespace (i.e. the XMLHandler) for which the configuration should
- * be returned
- * @return the requested configuration subtree, null if there's no configuration
- */
- public static Configuration getHandlerConfig(Configuration cfg, String namespace) {
-
- if (cfg == null || namespace == null) {
- return null;
- }
-
- Configuration handlerConfig = null;
-
- Configuration[] children = cfg.getChildren("xml-handler");
- for (int i = 0; i < children.length; ++i) {
- try {
- if (children[i].getAttribute("namespace").equals(namespace)) {
- handlerConfig = children[i];
- break;
- }
- } catch (ConfigurationException e) {
- // silently pass over configurations without namespace
- }
- }
- if (log.isDebugEnabled()) {
- log.debug((handlerConfig == null ? "No" : "")
- + "XML handler configuration found for namespace " + namespace);
- }
- return handlerConfig;
- }
-
- /**
* Render the xml document with the given xml namespace.
* The Render Context is by the handle to render into the current
* rendering target.
@@ -851,15 +807,9 @@
this, namespace);
if (handler != null) {
try {
- //Optional XML handler configuration
- Configuration cfg = userAgent.getFactory().getUserRendererConfig(getMimeType());
- if (cfg != null) {
- cfg = getHandlerConfig(cfg, namespace);
- if (cfg != null) {
- ctx.setProperty(RendererContextConstants.HANDLER_CONFIGURATION, cfg);
- }
- }
-
+ XMLHandlerConfigurator configurator
+ = new XMLHandlerConfigurator(userAgent);
+ configurator.configure(ctx, namespace);
handler.handleXML(ctx, doc, namespace);
} catch (Throwable t) {
// could not handle document
@@ -887,6 +837,4 @@
public String getMimeType() {
return null;
}
-
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org