From e7341ee4f08a1784d84eb7b88b6d1f647f530f46 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Fri, 12 Dec 2003 22:37:39 +0000 Subject: Moved FontSetup and two helper classes from render.pdf to fonts package. FontSetup has the PDF fonts as the default, but this class can be extended if/when another renderer needs its own font setups. (Cannot do this, however, for AWT's FontSetup at the moment, because its setup() has a different signature.) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197031 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fonts/EmbedFontInfo.java | 112 ++++++++ src/java/org/apache/fop/fonts/FontSetup.java | 270 +++++++++++++++++++ src/java/org/apache/fop/fonts/FontTriplet.java | 103 +++++++ src/java/org/apache/fop/pdf/PDFResources.java | 25 ++ src/java/org/apache/fop/render/PrintRenderer.java | 2 +- src/java/org/apache/fop/render/mif/MIFHandler.java | 4 +- .../org/apache/fop/render/pdf/EmbedFontInfo.java | 112 -------- src/java/org/apache/fop/render/pdf/FontSetup.java | 298 --------------------- .../org/apache/fop/render/pdf/FontTriplet.java | 103 ------- .../org/apache/fop/render/pdf/PDFRenderer.java | 5 +- .../render/ps/AbstractPSDocumentGraphics2D.java | 2 +- .../apache/fop/render/ps/PSDocumentGraphics2D.java | 2 +- src/java/org/apache/fop/render/ps/PSRenderer.java | 6 +- src/java/org/apache/fop/render/rtf/RTFHandler.java | 4 +- .../org/apache/fop/render/xml/XMLRenderer.java | 5 +- .../org/apache/fop/svg/PDFDocumentGraphics2D.java | 4 +- src/java/org/apache/fop/svg/PDFGraphics2D.java | 13 +- 17 files changed, 535 insertions(+), 535 deletions(-) create mode 100644 src/java/org/apache/fop/fonts/EmbedFontInfo.java create mode 100644 src/java/org/apache/fop/fonts/FontSetup.java create mode 100644 src/java/org/apache/fop/fonts/FontTriplet.java delete mode 100644 src/java/org/apache/fop/render/pdf/EmbedFontInfo.java delete mode 100644 src/java/org/apache/fop/render/pdf/FontSetup.java delete mode 100644 src/java/org/apache/fop/render/pdf/FontTriplet.java diff --git a/src/java/org/apache/fop/fonts/EmbedFontInfo.java b/src/java/org/apache/fop/fonts/EmbedFontInfo.java new file mode 100644 index 000000000..55689c6a7 --- /dev/null +++ b/src/java/org/apache/fop/fonts/EmbedFontInfo.java @@ -0,0 +1,112 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.fonts; + +import java.util.List; + +/** + * FontInfo contains meta information on fonts (where is the metrics file etc.) + */ +public class EmbedFontInfo { + + private String metricsFile, embedFile; + private boolean kerning; + private List fontTriplets; + + /** + * Main constructor + * @param metricsFile Path to the xml file containing font metrics + * @param kerning True if kerning should be enabled + * @param fontTriplets List of font triplets to associate with this font + * @param embedFile Path to the embeddable font file (may be null) + */ + public EmbedFontInfo(String metricsFile, boolean kerning, + List fontTriplets, String embedFile) { + this.metricsFile = metricsFile; + this.embedFile = embedFile; + this.kerning = kerning; + this.fontTriplets = fontTriplets; + } + + /** + * Returns the path to the metrics file + * @return the metrics file path + */ + public String getMetricsFile() { + return metricsFile; + } + + /** + * Returns the path to the embeddable font file + * @return the font file path + */ + public String getEmbedFile() { + return embedFile; + } + + /** + * Determines if kerning is enabled + * @return True if enabled + */ + public boolean getKerning() { + return kerning; + } + + /** + * Returns the list of font triplets associated with this font. + * @return List of font triplets + */ + public List getFontTriplets() { + return fontTriplets; + } + +} + diff --git a/src/java/org/apache/fop/fonts/FontSetup.java b/src/java/org/apache/fop/fonts/FontSetup.java new file mode 100644 index 000000000..c6e0bee45 --- /dev/null +++ b/src/java/org/apache/fop/fonts/FontSetup.java @@ -0,0 +1,270 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.fonts; + +// FOP +import org.apache.fop.apps.Document; + +// FOP (base 14 fonts) +import org.apache.fop.fonts.base14.Helvetica; +import org.apache.fop.fonts.base14.HelveticaBold; +import org.apache.fop.fonts.base14.HelveticaOblique; +import org.apache.fop.fonts.base14.HelveticaBoldOblique; +import org.apache.fop.fonts.base14.TimesRoman; +import org.apache.fop.fonts.base14.TimesBold; +import org.apache.fop.fonts.base14.TimesItalic; +import org.apache.fop.fonts.base14.TimesBoldItalic; +import org.apache.fop.fonts.base14.Courier; +import org.apache.fop.fonts.base14.CourierBold; +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.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; + +// Java +import java.util.Map; +import java.util.Iterator; +import java.util.List; + +/** + * Default fonts for FOP application; currently this uses PDF's fonts + * by default. + * + * Assigns the font (with metrics) to internal names like "F1" and + * assigns family-style-weight triplets to the fonts + */ +public class FontSetup { + + /** + * Sets up the font info object. + * + * Adds metrics for basic fonts and useful family-style-weight + * triplets for lookup. + * + * @param fontInfo the font info object to set up + * @param embedList ??? + */ + public static void setup(Document fontInfo, List embedList) { + + fontInfo.addMetrics("F1", new Helvetica()); + fontInfo.addMetrics("F2", new HelveticaOblique()); + fontInfo.addMetrics("F3", new HelveticaBold()); + fontInfo.addMetrics("F4", new HelveticaBoldOblique()); + fontInfo.addMetrics("F5", new TimesRoman()); + fontInfo.addMetrics("F6", new TimesItalic()); + fontInfo.addMetrics("F7", new TimesBold()); + fontInfo.addMetrics("F8", new TimesBoldItalic()); + fontInfo.addMetrics("F9", new Courier()); + fontInfo.addMetrics("F10", new CourierOblique()); + fontInfo.addMetrics("F11", new CourierBold()); + fontInfo.addMetrics("F12", new CourierBoldOblique()); + fontInfo.addMetrics("F13", new Symbol()); + fontInfo.addMetrics("F14", new ZapfDingbats()); + + // Custom type 1 fonts step 1/2 + // fontInfo.addMetrics("F15", new OMEP()); + // fontInfo.addMetrics("F16", new GaramondLightCondensed()); + // 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); + + // Custom type 1 fonts step 2/2 + // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL); + // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL); + // 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("F9", "Computer-Modern-Typewriter", + "normal", Font.NORMAL); + + /* Add configured fonts */ + addConfiguredFonts(fontInfo, embedList, 15); + } + + /** + * Add fonts from configuration file starting with + * internalnames F + * @param fontInfo the font info object to set up + * @param fontInfos ??? + * @param num starting index for internal font numbering + */ + public static void addConfiguredFonts(Document fontInfo, List fontInfos, int num) { + if (fontInfos == null) { + return; //No fonts to process + } + + String internalName = null; + //FontReader reader = null; + + for (int i = 0; i < fontInfos.size(); i++) { + EmbedFontInfo configFontInfo = (EmbedFontInfo)fontInfos.get(i); + + String metricsFile = configFontInfo.getMetricsFile(); + if (metricsFile != null) { + internalName = "F" + num; + num++; + /* + reader = new FontReader(metricsFile); + reader.useKerning(configFontInfo.getKerning()); + reader.setFontEmbedPath(configFontInfo.getEmbedFile()); + fontInfo.addMetrics(internalName, reader.getFont()); + */ + LazyFont font = new LazyFont(configFontInfo.getEmbedFile(), + metricsFile, + configFontInfo.getKerning()); + fontInfo.addMetrics(internalName, font); + + List triplets = configFontInfo.getFontTriplets(); + for (int c = 0; c < triplets.size(); c++) { + FontTriplet triplet = (FontTriplet)triplets.get(c); + + int weight = FontUtil.parseCSS2FontWeight(triplet.getWeight()); + //System.out.println("Registering: "+triplet+" weight="+weight); + fontInfo.addFontProperties(internalName, + triplet.getName(), + triplet.getStyle(), + weight); + } + } + } + } + + /** + * 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 { + List fontList = new java.util.ArrayList(); + Configuration[] font = cfg.getChildren("font"); + for (int i = 0; i < font.length; i++) { + Configuration[] triple = font[i].getChildren("font-triplet"); + List tripleList = new java.util.ArrayList(); + for (int j = 0; j < triple.length; j++) { + tripleList.add(new FontTriplet(triple[j].getAttribute("name"), + triple[j].getAttribute("weight"), + triple[j].getAttribute("style"))); + } + + EmbedFontInfo efi; + efi = new EmbedFontInfo(font[i].getAttribute("metrics-url"), + font[i].getAttributeAsBoolean("kerning", false), + tripleList, font[i].getAttribute("embed-url", null)); + + fontList.add(efi); + } + return fontList; + } +} + diff --git a/src/java/org/apache/fop/fonts/FontTriplet.java b/src/java/org/apache/fop/fonts/FontTriplet.java new file mode 100644 index 000000000..b95f2aa90 --- /dev/null +++ b/src/java/org/apache/fop/fonts/FontTriplet.java @@ -0,0 +1,103 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.fonts; + +/** + * FontTriplet contains information on name, weight, style of one font + */ +public class FontTriplet { + + private String name, weight, style; + + /** + * Creates a new font triplet. + * @param name font name + * @param weight font weight (normal, bold etc.) + * @param style font style (normal, italic etc.) + */ + public FontTriplet(String name, String weight, String style) { + this.name = name; + this.weight = weight; + this.style = style; + } + + /** + * Returns the font name. + * @return the font name + */ + public String getName() { + return name; + } + + /** + * Returns the font weight. + * @return the font weight + */ + public String getWeight() { + return weight; + } + + /** + * Returns the font style. + * @return the font style + */ + public String getStyle() { + return style; + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + return getName() + "," + getStyle() + "," + getWeight(); + } +} + diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java index 76f303113..ead46edaa 100644 --- a/src/java/org/apache/fop/pdf/PDFResources.java +++ b/src/java/org/apache/fop/pdf/PDFResources.java @@ -50,6 +50,10 @@ */ package org.apache.fop.pdf; +import org.apache.fop.apps.Document; +import org.apache.fop.fonts.Typeface; +import org.apache.fop.fonts.FontDescriptor; + // Java import java.util.Iterator; import java.util.Map; @@ -110,6 +114,27 @@ public class PDFResources extends PDFObject { this.fonts.put(font.getName(), font); } + /** + * Add the fonts in the font info to this PDF document's Font Resources. + * + * @param doc PDF document to add fonts to + * @param fontInfo font info object to get font information from + */ + public void addFonts(PDFDocument doc, Document fontInfo) { + Map fonts = fontInfo.getUsedFonts(); + Iterator e = fonts.keySet().iterator(); + while (e.hasNext()) { + String f = (String)e.next(); + Typeface font = (Typeface)fonts.get(f); + FontDescriptor desc = null; + if (font instanceof FontDescriptor) { + desc = (FontDescriptor)font; + } + addFont(doc.getFactory().makeFont( + f, font.getFontName(), font.getEncoding(), font, desc)); + } + } + /** * Add a PDFGState to the resources. * diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java index 59ffda9d5..04b49b362 100644 --- a/src/java/org/apache/fop/render/PrintRenderer.java +++ b/src/java/org/apache/fop/render/PrintRenderer.java @@ -51,9 +51,9 @@ package org.apache.fop.render; // FOP -import org.apache.fop.render.pdf.FontSetup; import org.apache.fop.apps.Document; import org.apache.fop.fo.FOTreeControl; +import org.apache.fop.fonts.FontSetup; // Java import java.util.List; diff --git a/src/java/org/apache/fop/render/mif/MIFHandler.java b/src/java/org/apache/fop/render/mif/MIFHandler.java index 0f7cf75f8..a7cf15117 100644 --- a/src/java/org/apache/fop/render/mif/MIFHandler.java +++ b/src/java/org/apache/fop/render/mif/MIFHandler.java @@ -74,6 +74,7 @@ import org.apache.fop.fo.pagination.Flow; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.PageSequenceMaster; import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.fonts.FontSetup; import org.xml.sax.SAXException; // TODO: do we really want every method throwing a SAXException @@ -102,8 +103,7 @@ public class MIFHandler extends FOInputHandler { public MIFHandler(Document doc, OutputStream os) { super(doc); outStream = os; - // use pdf fonts for now, this is only for resolving names - org.apache.fop.render.pdf.FontSetup.setup(doc, null); + FontSetup.setup(doc, null); } /** diff --git a/src/java/org/apache/fop/render/pdf/EmbedFontInfo.java b/src/java/org/apache/fop/render/pdf/EmbedFontInfo.java deleted file mode 100644 index a78dbd8e0..000000000 --- a/src/java/org/apache/fop/render/pdf/EmbedFontInfo.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * $Id: EmbedFontInfo.java,v 1.4 2003/03/07 09:46:32 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.render.pdf; - -import java.util.List; - -/** - * FontInfo contains meta information on fonts (where is the metrics file etc.) - */ -public class EmbedFontInfo { - - private String metricsFile, embedFile; - private boolean kerning; - private List fontTriplets; - - /** - * Main constructor - * @param metricsFile Path to the xml file containing font metrics - * @param kerning True if kerning should be enabled - * @param fontTriplets List of font triplets to associate with this font - * @param embedFile Path to the embeddable font file (may be null) - */ - public EmbedFontInfo(String metricsFile, boolean kerning, - List fontTriplets, String embedFile) { - this.metricsFile = metricsFile; - this.embedFile = embedFile; - this.kerning = kerning; - this.fontTriplets = fontTriplets; - } - - /** - * Returns the path to the metrics file - * @return the metrics file path - */ - public String getMetricsFile() { - return metricsFile; - } - - /** - * Returns the path to the embeddable font file - * @return the font file path - */ - public String getEmbedFile() { - return embedFile; - } - - /** - * Determines if kerning is enabled - * @return True if enabled - */ - public boolean getKerning() { - return kerning; - } - - /** - * Returns the list of font triplets associated with this font. - * @return List of font triplets - */ - public List getFontTriplets() { - return fontTriplets; - } - -} - diff --git a/src/java/org/apache/fop/render/pdf/FontSetup.java b/src/java/org/apache/fop/render/pdf/FontSetup.java deleted file mode 100644 index 74caf1592..000000000 --- a/src/java/org/apache/fop/render/pdf/FontSetup.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * $Id: FontSetup.java,v 1.22 2003/03/07 09:46:32 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.render.pdf; - -// FOP -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.avalon.framework.configuration.ConfigurationException; -import org.apache.fop.fonts.Font; -import org.apache.fop.fonts.Typeface; -import org.apache.fop.fonts.FontDescriptor; -import org.apache.fop.fonts.FontUtil; -import org.apache.fop.fonts.LazyFont; -import org.apache.fop.apps.Document; -import org.apache.fop.pdf.PDFDocument; -import org.apache.fop.pdf.PDFResources; -// FOP (base 14 fonts) -import org.apache.fop.fonts.base14.Helvetica; -import org.apache.fop.fonts.base14.HelveticaBold; -import org.apache.fop.fonts.base14.HelveticaOblique; -import org.apache.fop.fonts.base14.HelveticaBoldOblique; -import org.apache.fop.fonts.base14.TimesRoman; -import org.apache.fop.fonts.base14.TimesBold; -import org.apache.fop.fonts.base14.TimesItalic; -import org.apache.fop.fonts.base14.TimesBoldItalic; -import org.apache.fop.fonts.base14.Courier; -import org.apache.fop.fonts.base14.CourierBold; -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; - -// Java -import java.util.Map; -import java.util.Iterator; -import java.util.List; - -/** - * sets up the PDF fonts. - * - * Assigns the font (with metrics) to internal names like "F1" and - * assigns family-style-weight triplets to the fonts - */ -public class FontSetup { - - /** - * Sets up the font info object. - * - * Adds metrics for basic fonts and useful family-style-weight - * triplets for lookup. - * - * @param fontInfo the font info object to set up - * @param embedList ??? - */ - public static void setup(Document fontInfo, List embedList) { - - fontInfo.addMetrics("F1", new Helvetica()); - fontInfo.addMetrics("F2", new HelveticaOblique()); - fontInfo.addMetrics("F3", new HelveticaBold()); - fontInfo.addMetrics("F4", new HelveticaBoldOblique()); - fontInfo.addMetrics("F5", new TimesRoman()); - fontInfo.addMetrics("F6", new TimesItalic()); - fontInfo.addMetrics("F7", new TimesBold()); - fontInfo.addMetrics("F8", new TimesBoldItalic()); - fontInfo.addMetrics("F9", new Courier()); - fontInfo.addMetrics("F10", new CourierOblique()); - fontInfo.addMetrics("F11", new CourierBold()); - fontInfo.addMetrics("F12", new CourierBoldOblique()); - fontInfo.addMetrics("F13", new Symbol()); - fontInfo.addMetrics("F14", new ZapfDingbats()); - - // Custom type 1 fonts step 1/2 - // fontInfo.addMetrics("F15", new OMEP()); - // fontInfo.addMetrics("F16", new GaramondLightCondensed()); - // 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); - - // Custom type 1 fonts step 2/2 - // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL); - // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL); - // 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("F9", "Computer-Modern-Typewriter", - "normal", Font.NORMAL); - - /* Add configured fonts */ - addConfiguredFonts(fontInfo, embedList, 15); - } - - /** - * Add fonts from configuration file starting with - * internalnames F - * @param fontInfo the font info object to set up - * @param fontInfos ??? - * @param num starting index for internal font numbering - */ - public static void addConfiguredFonts(Document fontInfo, List fontInfos, int num) { - if (fontInfos == null) { - return; //No fonts to process - } - - String internalName = null; - //FontReader reader = null; - - for (int i = 0; i < fontInfos.size(); i++) { - EmbedFontInfo configFontInfo = (EmbedFontInfo)fontInfos.get(i); - - String metricsFile = configFontInfo.getMetricsFile(); - if (metricsFile != null) { - internalName = "F" + num; - num++; - /* - reader = new FontReader(metricsFile); - reader.useKerning(configFontInfo.getKerning()); - reader.setFontEmbedPath(configFontInfo.getEmbedFile()); - fontInfo.addMetrics(internalName, reader.getFont()); - */ - LazyFont font = new LazyFont(configFontInfo.getEmbedFile(), - metricsFile, - configFontInfo.getKerning()); - fontInfo.addMetrics(internalName, font); - - List triplets = configFontInfo.getFontTriplets(); - for (int c = 0; c < triplets.size(); c++) { - FontTriplet triplet = (FontTriplet)triplets.get(c); - - int weight = FontUtil.parseCSS2FontWeight(triplet.getWeight()); - //System.out.println("Registering: "+triplet+" weight="+weight); - fontInfo.addFontProperties(internalName, - triplet.getName(), - triplet.getStyle(), - weight); - } - } - } - } - - /** - * Add the fonts in the font info to the PDF document - * - * @param doc PDF document to add fonts to - * @param resources PDFResources object to attach the font to - * @param fontInfo font info object to get font information from - */ - public static void addToResources(PDFDocument doc, PDFResources resources, - Document fontInfo) { - Map fonts = fontInfo.getUsedFonts(); - Iterator e = fonts.keySet().iterator(); - while (e.hasNext()) { - String f = (String)e.next(); - Typeface font = (Typeface)fonts.get(f); - FontDescriptor desc = null; - if (font instanceof FontDescriptor) { - desc = (FontDescriptor)font; - } - resources.addFont(doc.getFactory().makeFont( - f, font.getFontName(), font.getEncoding(), font, desc)); - } - } - - - /** - * 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 { - List fontList = new java.util.ArrayList(); - Configuration[] font = cfg.getChildren("font"); - for (int i = 0; i < font.length; i++) { - Configuration[] triple = font[i].getChildren("font-triplet"); - List tripleList = new java.util.ArrayList(); - for (int j = 0; j < triple.length; j++) { - tripleList.add(new FontTriplet(triple[j].getAttribute("name"), - triple[j].getAttribute("weight"), - triple[j].getAttribute("style"))); - } - - EmbedFontInfo efi; - efi = new EmbedFontInfo(font[i].getAttribute("metrics-url"), - font[i].getAttributeAsBoolean("kerning", false), - tripleList, font[i].getAttribute("embed-url", null)); - - fontList.add(efi); - } - return fontList; - } -} - diff --git a/src/java/org/apache/fop/render/pdf/FontTriplet.java b/src/java/org/apache/fop/render/pdf/FontTriplet.java deleted file mode 100644 index be999d2b1..000000000 --- a/src/java/org/apache/fop/render/pdf/FontTriplet.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * $Id: FontTriplet.java,v 1.2 2003/03/07 09:46:32 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.render.pdf; - -/** - * FontTriplet contains information on name, weight, style of one font - */ -public class FontTriplet { - - private String name, weight, style; - - /** - * Creates a new font triplet. - * @param name font name - * @param weight font weight (normal, bold etc.) - * @param style font style (normal, italic etc.) - */ - public FontTriplet(String name, String weight, String style) { - this.name = name; - this.weight = weight; - this.style = style; - } - - /** - * Returns the font name. - * @return the font name - */ - public String getName() { - return name; - } - - /** - * Returns the font weight. - * @return the font weight - */ - public String getWeight() { - return weight; - } - - /** - * Returns the font style. - * @return the font style - */ - public String getStyle() { - return style; - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - return getName() + "," + getStyle() + "," + getWeight(); - } -} - diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 7327960fb..c885c324a 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -94,6 +94,7 @@ import org.apache.fop.fo.properties.BackgroundRepeat; import org.apache.fop.fo.properties.RuleStyle; import org.apache.fop.fonts.Typeface; import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontSetup; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.image.FopImage; import org.apache.fop.image.ImageFactory; @@ -295,8 +296,8 @@ public class PDFRenderer extends PrintRenderer { * @see org.apache.fop.render.Renderer#stopRenderer() */ public void stopRenderer() throws IOException { - FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), - (org.apache.fop.apps.Document)fontInfo); + pdfDoc.getResources().addFonts(pdfDoc, + (org.apache.fop.apps.Document) fontInfo); pdfDoc.outputTrailer(ostream); this.pdfDoc = null; diff --git a/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java b/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java index f28061249..09600a85c 100644 --- a/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java @@ -61,7 +61,7 @@ import java.io.IOException; //FOP import org.apache.fop.apps.Document; import org.apache.fop.fonts.Font; -import org.apache.fop.render.pdf.FontSetup; +import org.apache.fop.fonts.FontSetup; /** * This class is a wrapper for the PSGraphics2D that diff --git a/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java b/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java index 3c811d476..59db67df3 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java @@ -57,7 +57,7 @@ import java.io.IOException; //FOP import org.apache.fop.apps.Document; -import org.apache.fop.render.pdf.FontSetup; +import org.apache.fop.fonts.FontSetup; /** * This class is a wrapper for the PSGraphics2D that diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java index 3f216c921..c46959832 100644 --- a/src/java/org/apache/fop/render/ps/PSRenderer.java +++ b/src/java/org/apache/fop/render/ps/PSRenderer.java @@ -72,6 +72,7 @@ import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.TextArea; import org.apache.fop.datatypes.ColorType; import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fonts.FontSetup; import org.apache.fop.fonts.Typeface; import org.apache.fop.apps.Document; import org.apache.fop.render.AbstractRenderer; @@ -262,9 +263,8 @@ public class PSRenderer extends AbstractRenderer { * @param foTreeControl the font info object to set up */ public void setupFontInfo(FOTreeControl foTreeControl) { - /* use PDF's font setup to get PDF metrics */ - org.apache.fop.render.pdf.FontSetup.setup((Document)foTreeControl, null); - this.fontInfo = (Document)foTreeControl; + FontSetup.setup((Document) foTreeControl, null); + this.fontInfo = (Document) foTreeControl; } /** diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index a112061d4..493a612a7 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -103,6 +103,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell; import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTableContainer; +import org.apache.fop.fonts.FontSetup; import org.xml.sax.SAXException; /** @@ -143,8 +144,7 @@ public class RTFHandler extends FOInputHandler { public RTFHandler(Document doc, OutputStream os) { super(doc); this.os = os; - // use pdf fonts for now, this is only for resolving names - org.apache.fop.render.pdf.FontSetup.setup(doc, null); + FontSetup.setup(doc, null); log.warn(ALPHA_WARNING); } diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 32eef5f45..03c63543b 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -92,6 +92,7 @@ import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.Space; import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.TextArea; +import org.apache.fop.fonts.FontSetup; import org.apache.fop.fo.properties.RuleStyle; import org.apache.fop.fo.FOTreeControl; import org.apache.fop.fo.pagination.Region; @@ -211,9 +212,7 @@ public class XMLRenderer extends AbstractRenderer { * @param fontInfo the font info object to set up */ public void setupFontInfo(FOTreeControl foTreeControl) { - - /* use PDF's font setup to get PDF metrics */ - org.apache.fop.render.pdf.FontSetup.setup((Document)foTreeControl, null); + FontSetup.setup((Document) foTreeControl, null); } private boolean isCoarseXml() { diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java index 4f2ec8d93..43e585aa1 100644 --- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -59,7 +59,7 @@ import org.apache.fop.pdf.PDFNumber; import org.apache.fop.pdf.PDFResources; import org.apache.fop.pdf.PDFColor; import org.apache.fop.pdf.PDFAnnotList; -import org.apache.fop.render.pdf.FontSetup; +import org.apache.fop.fonts.FontSetup; import org.apache.avalon.framework.CascadingRuntimeException; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configurable; @@ -308,7 +308,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D } this.pdfDoc.addObject(currentPage); if (fontInfo != null) { - FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo); + pdfDoc.getResources().addFonts(pdfDoc, fontInfo); } this.pdfDoc.output(outputStream); pdfDoc.outputTrailer(outputStream); diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index dc4523d17..90e7f91a0 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -66,7 +66,7 @@ import org.apache.fop.pdf.PDFAnnotList; import org.apache.fop.pdf.BitmapImage; import org.apache.fop.apps.Document; import org.apache.fop.fonts.Font; -import org.apache.fop.render.pdf.FontSetup; +import org.apache.fop.fonts.FontSetup; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.fonts.LazyFont; import org.apache.fop.image.JpegImage; @@ -964,12 +964,12 @@ public class PDFGraphics2D extends AbstractGraphics2D { private void createPattern(PatternPaint pp, boolean fill) { Rectangle2D rect = pp.getPatternRect(); - Document fi = new Document(null); - FontSetup.setup(fi, null); + Document fontInfo = new Document(null); + FontSetup.setup(fontInfo, null); PDFResources res = pdfDoc.getFactory().makeResources(); PDFResourceContext context = new PDFResourceContext(res); - PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fi, + PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo, pdfDoc, context, pageRef, "", 0); pattGraphic.gc = (GraphicContext)this.gc.clone(); @@ -1008,7 +1008,10 @@ public class PDFGraphics2D extends AbstractGraphics2D { translate.add(new Double(flatmatrix[4])); translate.add(new Double(flatmatrix[5])); - FontSetup.addToResources(pdfDoc, res, fi); + /** @todo see if pdfDoc and res can be linked here, + (currently res <> PDFDocument's resources) so addFonts() + can be moved to PDFDocument class */ + res.addFonts(pdfDoc, fontInfo); PDFPattern myPat = pdfDoc.getFactory().makePattern( resourceContext, 1, res, 1, 1, bbox, -- cgit v1.2.3