diff options
Diffstat (limited to 'src/java/org/apache/fop/fonts/FontSetup.java')
-rw-r--r-- | src/java/org/apache/fop/fonts/FontSetup.java | 265 |
1 files changed, 64 insertions, 201 deletions
diff --git a/src/java/org/apache/fop/fonts/FontSetup.java b/src/java/org/apache/fop/fonts/FontSetup.java index 9659398ba..0028f3281 100644 --- a/src/java/org/apache/fop/fonts/FontSetup.java +++ b/src/java/org/apache/fop/fonts/FontSetup.java @@ -34,16 +34,11 @@ import org.apache.fop.fonts.base14.CourierOblique; 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 @@ public class FontSetup { /** * 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 @@ public class FontSetup { // 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 @@ public class FontSetup { // 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 @@ public class FontSetup { 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 @@ public class FontSetup { } /** @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 @@ public class FontSetup { //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); - } + } } |