And the attached patch >_<
Index: src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFDocumentHandler.java	(revision 744954)
+++ src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFDocumentHandler.java	(working copy)
@@ -19,6 +19,7 @@
 
 package org.apache.fop.render.intermediate;
 
+import java.awt.Graphics2D;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -35,6 +36,8 @@
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.base14.Base14FontCollection;
+import org.apache.fop.render.java2d.InstalledFontCollection;
+import org.apache.fop.render.java2d.Java2DFontMetrics;
 
 /**
  * Abstract base class for binary-writing {...@code IFDocumentHandler} implementations.
@@ -94,26 +97,54 @@
     }
 
     /** {...@inheritdoc} */
-    public void setDefaultFontInfo(FontInfo fontInfo) {
+    public final void setDefaultFontInfo(FontInfo fontInfo) {
         FontManager fontManager = getUserAgent().getFactory().getFontManager();
+        FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo());
+        fi.setEventListener(new FontEventAdapter(getUserAgent().getEventBroadcaster()));
+        fontManager.setup(fi, getDefaultFontCollections(fontManager));
+        setFontInfo(fi);
+    }
+
+    protected abstract FontCollection[] getDefaultFontCollections(FontManager fontManager);
+
+    protected final FontCollection[] getBase14FontCollections(FontManager fontManager) {
         FontCollection[] fontCollections = new FontCollection[] {
                 new Base14FontCollection(fontManager.isBase14KerningEnabled())
         };
+        return fontCollections;
+    }
 
-        FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo());
-        fi.setEventListener(new FontEventAdapter(getUserAgent().getEventBroadcaster()));
-        fontManager.setup(fi, fontCollections);
-        setFontInfo(fi);
+    protected final FontCollection[] getJava2DFontCollections(FontManager fontManager) {
+        Graphics2D graphics2D = Java2DFontMetrics.createFontMetricsGraphics2D();
+        FontCollection[] fontCollections = new FontCollection[] {
+                new org.apache.fop.render.java2d.Base14FontCollection(graphics2D),
+                new InstalledFontCollection(graphics2D)
+        };
+        return fontCollections;
     }
 
     /** {...@inheritdoc} */
-    public void startDocument() throws IFException {
+    public final void startDocument() throws IFException {
         super.startDocument();
         if (this.outputStream == null) {
             throw new IllegalStateException("OutputStream hasn't been set through setResult()");
         }
+        try {
+            doStartDocument();
+        } catch (IOException e) {
+            throw new IFException("I/O error in startDocument()", e);
+        }
     }
 
+    /**
+     * Actually implements the actions that are specific to the output format.
+     * {...@link #startDocument()} contains the common stuff and calls this method.
+     *
+     * @throws IOException in case an I/O error occurs when writing to the
+     * output stream
+     */
+    abstract protected void doStartDocument() throws IOException;
+
     /** {...@inheritdoc} */
     public void endDocument() throws IFException {
         if (this.ownOutputStream) {
Index: src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java	(revision 744954)
+++ src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java	(working copy)
@@ -34,14 +34,14 @@
 
 import org.apache.fop.apps.FopFactoryConfigurator;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontManager;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFPainter;
 import org.apache.fop.render.java2d.Java2DPainter;
-import org.apache.fop.render.java2d.Java2DUtil;
 
 /**
  * {...@code IFDocumentHandler} implementation that produces PCL 5.
@@ -102,17 +102,14 @@
     }
 
     /** {...@inheritdoc} */
-    public void setDefaultFontInfo(FontInfo fontInfo) {
-        FontInfo fi = Java2DUtil.buildDefaultJava2DBasedFontInfo(fontInfo, getUserAgent());
-        setFontInfo(fi);
+    protected FontCollection[] getDefaultFontCollections(FontManager fontManager) {
+        return getJava2DFontCollections(fontManager);
     }
 
     //----------------------------------------------------------------------------------------------
 
     /** {...@inheritdoc} */
-    public void startDocument() throws IFException {
-        super.startDocument();
-        try {
+    protected void doStartDocument() throws IOException {
             // Creates writer
             this.imageWriter = ImageWriterRegistry.getInstance().getWriterFor(getMimeType());
             if (this.imageWriter == null) {
@@ -125,9 +122,6 @@
                 this.multiImageWriter = this.imageWriter.createMultiImageWriter(outputStream);
             }
             this.pageCount = 0;
-        } catch (IOException e) {
-            throw new IFException("I/O error in startDocument()", e);
-        }
     }
 
     /** {...@inheritdoc} */
Index: src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java	(revision 744954)
+++ src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java	(working copy)
@@ -34,14 +34,14 @@
 
 import org.apache.fop.apps.FopFactoryConfigurator;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontManager;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFPainter;
 import org.apache.fop.render.java2d.Java2DPainter;
-import org.apache.fop.render.java2d.Java2DUtil;
 import org.apache.fop.render.pcl.extensions.PCLElementMapping;
 
 /**
@@ -98,9 +98,8 @@
     }
 
     /** {...@inheritdoc} */
-    public void setDefaultFontInfo(FontInfo fontInfo) {
-        FontInfo fi = Java2DUtil.buildDefaultJava2DBasedFontInfo(fontInfo, getUserAgent());
-        setFontInfo(fi);
+    protected FontCollection[] getDefaultFontCollections(FontManager fontManager) {
+        return getJava2DFontCollections(fontManager);
     }
 
     PCLRenderingUtil getPCLUtil() {
@@ -124,9 +123,7 @@
     //----------------------------------------------------------------------------------------------
 
     /** {...@inheritdoc} */
-    public void startDocument() throws IFException {
-        super.startDocument();
-        try {
+    protected void doStartDocument() throws IOException {
             this.gen = new PCLGenerator(this.outputStream, getResolution());
 
             if (!pclUtil.isPJLDisabled()) {
@@ -141,9 +138,6 @@
             gen.resetPrinter();
             gen.setUnitOfMeasure(getResolution());
             gen.setRasterGraphicsResolution(getResolution());
-        } catch (IOException e) {
-            throw new IFException("I/O error in startDocument()", e);
-        }
     }
 
     /** {...@inheritdoc} */
Index: src/java/org/apache/fop/render/ps/PSDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSDocumentHandler.java	(revision 744954)
+++ src/java/org/apache/fop/render/ps/PSDocumentHandler.java	(working copy)
@@ -50,6 +50,8 @@
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
 
 import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
@@ -132,14 +134,17 @@
         return new PSRendererConfigurator(getUserAgent());
     }
 
+    /** {...@inheritdoc} */
+    protected FontCollection[] getDefaultFontCollections(FontManager fontManager) {
+        return getBase14FontCollections(fontManager);
+    }
+
     PSRenderingUtil getPSUtil() {
         return this.psUtil;
     }
 
     /** {...@inheritdoc} */
-    public void startDocument() throws IFException {
-        super.startDocument();
-        try {
+    protected void doStartDocument() throws IOException {
             OutputStream out;
             if (psUtil.isOptimizeResources()) {
                 this.tempFile = File.createTempFile("fop", null);
@@ -164,9 +169,6 @@
             this.pageDeviceDictionary = new PSPageDeviceDictionary();
             pageDeviceDictionary.setFlushOnRetrieval(!psUtil.isDSCComplianceEnabled());
             pageDeviceDictionary.put("/ImagingBBox", "null");
-        } catch (IOException e) {
-            throw new IFException("I/O error in startDocument()", e);
-        }
     }
 
     private void writeHeader() throws IOException {
Index: src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/afp/AFPDocumentHandler.java	(revision 744954)
+++ src/java/org/apache/fop/render/afp/AFPDocumentHandler.java	(working copy)
@@ -34,8 +34,6 @@
 import org.apache.fop.afp.fonts.AFPPageFonts;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.fonts.FontCollection;
-import org.apache.fop.fonts.FontEventAdapter;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.render.afp.extensions.AFPElementMapping;
 import org.apache.fop.render.afp.extensions.AFPPageSetup;
@@ -102,16 +100,11 @@
     }
 
     /** {...@inheritdoc} */
-    public void setDefaultFontInfo(FontInfo fontInfo) {
-        FontManager fontManager = getUserAgent().getFactory().getFontManager();
+    protected FontCollection[] getDefaultFontCollections(FontManager fontManager) {
         FontCollection[] fontCollections = new FontCollection[] {
             new AFPFontCollection(getUserAgent().getEventBroadcaster(), null)
         };
-
-        FontInfo fi = (fontInfo != null ? fontInfo : new FontInfo());
-        fi.setEventListener(new FontEventAdapter(getUserAgent().getEventBroadcaster()));
-        fontManager.setup(fi, fontCollections);
-        setFontInfo(fi);
+        return fontCollections;
     }
 
     AFPPaintingState getPaintingState() {
@@ -127,17 +120,12 @@
     }
 
     /** {...@inheritdoc} */
-    public void startDocument() throws IFException {
-        super.startDocument();
-        try {
+    protected void doStartDocument() throws IOException {
             paintingState.setColor(Color.WHITE);
 
             this.dataStream = resourceManager.createDataStream(paintingState, outputStream);
 
             this.dataStream.startDocument();
-        } catch (IOException e) {
-            throw new IFException("I/O error in startDocument()", e);
-        }
     }
 
     /** {...@inheritdoc} */
Index: src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
===================================================================
--- src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java	(revision 744954)
+++ src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java	(working copy)
@@ -31,6 +31,8 @@
 
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.fo.extensions.xmp.XMPMetadata;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontManager;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFPage;
@@ -110,6 +112,11 @@
     }
 
     /** {...@inheritdoc} */
+    protected FontCollection[] getDefaultFontCollections(FontManager fontManager) {
+        return getBase14FontCollections(fontManager);
+    }
+
+    /** {...@inheritdoc} */
     public IFDocumentNavigationHandler getDocumentNavigationHandler() {
         return this.documentNavigationHandler;
     }
@@ -119,13 +126,8 @@
     }
 
     /** {...@inheritdoc} */
-    public void startDocument() throws IFException {
-        super.startDocument();
-        try {
+    protected void doStartDocument() throws IOException {
             this.pdfDoc = pdfUtil.setupPDFDocument(this.outputStream);
-        } catch (IOException e) {
-            throw new IFException("I/O error in startDocument()", e);
-        }
     }
 
     /** {...@inheritdoc} */

Reply via email to