diff options
author | Glen Mazza <gmazza@apache.org> | 2003-12-12 22:37:39 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2003-12-12 22:37:39 +0000 |
commit | e7341ee4f08a1784d84eb7b88b6d1f647f530f46 (patch) | |
tree | 3c7ebb8913c0ab9d721ee28228b8160a6f72732b | |
parent | 49cb7713f146e028a55a85014a681e53712d6864 (diff) | |
download | xmlgraphics-fop-e7341ee4f08a1784d84eb7b88b6d1f647f530f46.tar.gz xmlgraphics-fop-e7341ee4f08a1784d84eb7b88b6d1f647f530f46.zip |
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
14 files changed, 62 insertions, 62 deletions
diff --git a/src/java/org/apache/fop/render/pdf/EmbedFontInfo.java b/src/java/org/apache/fop/fonts/EmbedFontInfo.java index a78dbd8e0..55689c6a7 100644 --- a/src/java/org/apache/fop/render/pdf/EmbedFontInfo.java +++ b/src/java/org/apache/fop/fonts/EmbedFontInfo.java @@ -1,5 +1,5 @@ /* - * $Id: EmbedFontInfo.java,v 1.4 2003/03/07 09:46:32 jeremias Exp $ + * $Id$ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ @@ -48,7 +48,7 @@ * James Tauber <jtauber@jtauber.com>. For more information on the Apache * Software Foundation, please see <http://www.apache.org/>. */ -package org.apache.fop.render.pdf; +package org.apache.fop.fonts; import java.util.List; diff --git a/src/java/org/apache/fop/render/pdf/FontSetup.java b/src/java/org/apache/fop/fonts/FontSetup.java index 74caf1592..c6e0bee45 100644 --- a/src/java/org/apache/fop/render/pdf/FontSetup.java +++ b/src/java/org/apache/fop/fonts/FontSetup.java @@ -1,5 +1,5 @@ /* - * $Id: FontSetup.java,v 1.22 2003/03/07 09:46:32 jeremias Exp $ + * $Id$ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ @@ -48,19 +48,11 @@ * James Tauber <jtauber@jtauber.com>. For more information on the Apache * Software Foundation, please see <http://www.apache.org/>. */ -package org.apache.fop.render.pdf; +package org.apache.fop.fonts; // 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; @@ -77,13 +69,17 @@ 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; /** - * sets up the PDF fonts. + * 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 @@ -243,30 +239,6 @@ public class FontSetup { } /** - * 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 diff --git a/src/java/org/apache/fop/render/pdf/FontTriplet.java b/src/java/org/apache/fop/fonts/FontTriplet.java index be999d2b1..b95f2aa90 100644 --- a/src/java/org/apache/fop/render/pdf/FontTriplet.java +++ b/src/java/org/apache/fop/fonts/FontTriplet.java @@ -1,5 +1,5 @@ /* - * $Id: FontTriplet.java,v 1.2 2003/03/07 09:46:32 jeremias Exp $ + * $Id$ * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ @@ -48,7 +48,7 @@ * James Tauber <jtauber@jtauber.com>. For more information on the Apache * Software Foundation, please see <http://www.apache.org/>. */ -package org.apache.fop.render.pdf; +package org.apache.fop.fonts; /** * FontTriplet contains information on name, weight, style of one font 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; @@ -111,6 +115,27 @@ public class PDFResources extends PDFObject { } /** + * 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. * * @param gs the PDFGState to add 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/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 <tt>PSGraphics2D</tt> 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 <tt>PSGraphics2D</tt> 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, |