xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject svn commit: r1356161 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/ src/java/org/apache/fop/render/ src/java/org/apache/fop/render/afp/ src/java/org/apache/fop/render/intermediate/ src/java/org/apache/fop/render/java2d/ src/java/org/apache...
Date Mon, 02 Jul 2012 10:13:57 GMT
Author: mehdi
Date: Mon Jul  2 10:13:54 2012
New Revision: 1356161

URL: http://svn.apache.org/viewvc?rev=1356161&view=rev
Log:
Changed the exception message when internal font key == null, also some clean up and encapsulation to *Painter classes

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java   (with props)
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontTriplet.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFException.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
    xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontTriplet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontTriplet.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontTriplet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontTriplet.java Mon Jul  2 10:13:54 2012
@@ -27,6 +27,8 @@ import java.io.Serializable;
  */
 public class FontTriplet implements Comparable<FontTriplet>, Serializable {
 
+    public static final FontTriplet DEFAULT_FONT_TRIPLET = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
+
     /** serial version UID */
     private static final long serialVersionUID = 1168991106658033508L;
 
@@ -143,6 +145,5 @@ public class FontTriplet implements Comp
          */
         boolean matches(FontTriplet triplet);
     }
-
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java Mon Jul  2 10:13:54 2012
@@ -107,7 +107,7 @@ public abstract class PrintRenderer exte
         String key = fontInfo.getInternalFontKey(triplet);
         if (key == null) {
             //Find a default fallback font as last resort
-            triplet = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
+            triplet = FontTriplet.DEFAULT_FONT_TRIPLET;
             key = fontInfo.getInternalFontKey(triplet);
         }
         return key;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java Mon Jul  2 10:13:54 2012
@@ -58,8 +58,8 @@ import org.apache.fop.render.intermediat
 import org.apache.fop.render.intermediate.IFPainter;
 
 /**
- * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that
- * produces AFP (MO:DCA).
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that produces AFP
+ * (MO:DCA).
  */
 public class AFPDocumentHandler extends AbstractBinaryWritingIFDocumentHandler
             implements AFPCustomizable {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java Mon Jul  2 10:13:54 2012
@@ -36,6 +36,7 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.image.loader.ImageSessionContext;
 
 import org.apache.fop.afp.AFPBorderPainter;
+import org.apache.fop.afp.AFPEventProducer;
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPUnitConverter;
 import org.apache.fop.afp.AbstractAFPPainter;
@@ -53,13 +54,11 @@ import org.apache.fop.afp.ptoca.PtocaPro
 import org.apache.fop.afp.util.DefaultFOPResourceAccessor;
 import org.apache.fop.afp.util.ResourceAccessor;
 import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.AbstractIFPainter;
 import org.apache.fop.render.intermediate.BorderPainter;
-import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.render.intermediate.IFUtil;
@@ -70,7 +69,7 @@ import org.apache.fop.util.CharUtilities
 /**
  * IFPainter implementation that produces AFP (MO:DCA).
  */
-public class AFPPainter extends AbstractIFPainter {
+public class AFPPainter extends AbstractIFPainter<AFPDocumentHandler> {
 
     //** logging instance */
     //private static Log log = LogFactory.getLog(AFPPainter.class);
@@ -78,8 +77,6 @@ public class AFPPainter extends Abstract
     private static final int X = 0;
     private static final int Y = 1;
 
-    private final AFPDocumentHandler documentHandler;
-
     /** the border painter */
     private final AFPBorderPainterAdapter borderPainter;
     /** the rectangle painter */
@@ -88,36 +85,38 @@ public class AFPPainter extends Abstract
     /** unit converter */
     private final AFPUnitConverter unitConv;
 
+    private final AFPEventProducer eventProducer;
+
     /**
      * Default constructor.
      * @param documentHandler the parent document handler
      */
     public AFPPainter(AFPDocumentHandler documentHandler) {
-        super();
-        this.documentHandler = documentHandler;
+        super(documentHandler);
         this.state = IFState.create();
         this.borderPainter = new AFPBorderPainterAdapter(
                 new AFPBorderPainter(getPaintingState(), getDataStream()));
         this.rectanglePainter = documentHandler.createRectanglePainter();
         this.unitConv = getPaintingState().getUnitConverter();
+        this.eventProducer = AFPEventProducer.Provider.get(getUserAgent().getEventBroadcaster());
     }
 
-    /** {@inheritDoc} */
-    @Override
-    protected IFContext getContext() {
-        return this.documentHandler.getContext();
-    }
-
-    FontInfo getFontInfo() {
-        return this.documentHandler.getFontInfo();
+    private AFPPaintingState getPaintingState() {
+        return getDocumentHandler().getPaintingState();
     }
 
-    AFPPaintingState getPaintingState() {
-        return this.documentHandler.getPaintingState();
+    private DataStream getDataStream() {
+        return getDocumentHandler().getDataStream();
     }
 
-    DataStream getDataStream() {
-        return this.documentHandler.getDataStream();
+    @Override
+    public String getFontKey(FontTriplet triplet) throws IFException {
+        try {
+            return super.getFontKey(triplet);
+        } catch (IFException e) {
+            eventProducer.invalidConfiguration(null, e);
+            return super.getFontKey(FontTriplet.DEFAULT_FONT_TRIPLET);
+        }
     }
 
     /** {@inheritDoc} */
@@ -183,7 +182,7 @@ public class AFPPainter extends Abstract
     protected RenderingContext createRenderingContext() {
         AFPRenderingContext psContext = new AFPRenderingContext(
                 getUserAgent(),
-                documentHandler.getResourceManager(),
+                getDocumentHandler().getResourceManager(),
                 getPaintingState(),
                 getFontInfo(),
                 getContext().getForeignAttributes());
@@ -192,7 +191,7 @@ public class AFPPainter extends Abstract
 
     /** {@inheritDoc} */
     public void drawImage(String uri, Rectangle rect) throws IFException {
-        PageSegmentDescriptor pageSegment = documentHandler.getPageSegmentNameFor(uri);
+        PageSegmentDescriptor pageSegment = getDocumentHandler().getPageSegmentNameFor(uri);
 
         if (pageSegment != null) {
             float[] srcPts = {rect.x, rect.y};
@@ -206,10 +205,10 @@ public class AFPPainter extends Abstract
             //Do we need to embed an external page segment?
             if (pageSegment.getURI() != null) {
                 ResourceAccessor accessor = new DefaultFOPResourceAccessor (
-                        documentHandler.getUserAgent(), null, null);
+                        getUserAgent(), null, null);
                 try {
                     URI resourceUri = new URI(pageSegment.getURI());
-                    documentHandler.getResourceManager().createIncludedResourceFromExternal(
+                    getDocumentHandler().getResourceManager().createIncludedResourceFromExternal(
                             pageSegment.getName(), resourceUri, accessor);
 
                 } catch (URISyntaxException urie) {
@@ -365,14 +364,10 @@ public class AFPPainter extends Abstract
         FontTriplet triplet = new FontTriplet(
                 state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
         //TODO Ignored: state.getFontVariant()
-        String fontKey = getFontInfo().getInternalFontKey(triplet);
-        if (fontKey == null) {
-            triplet = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontKey = getFontInfo().getInternalFontKey(triplet);
-        }
+        String fontKey = getFontKey(triplet);
 
         // register font as necessary
-        Map<String, Typeface> fontMetricMap = documentHandler.getFontInfo().getFonts();
+        Map<String, Typeface> fontMetricMap = getFontInfo().getFonts();
         final AFPFont afpFont = (AFPFont)fontMetricMap.get(fontKey);
         final Font font = getFontInfo().getFontInstance(triplet, fontSize);
         AFPPageFonts pageFonts = getPaintingState().getPageFonts();
@@ -386,7 +381,7 @@ public class AFPPainter extends Abstract
 
         if (afpFont.isEmbeddable()) {
             try {
-                documentHandler.getResourceManager().embedFont(afpFont, charSet);
+                getDocumentHandler().getResourceManager().embedFont(afpFont, charSet);
             } catch (IOException ioe) {
                 throw new IFException("Error while embedding font resources", ioe);
             }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Mon Jul  2 10:13:54 2012
@@ -47,6 +47,8 @@ import org.apache.fop.ResourceEventProdu
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.fo.Constants;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.render.ImageHandler;
 import org.apache.fop.render.ImageHandlerRegistry;
 import org.apache.fop.render.ImageHandlerUtil;
@@ -57,7 +59,7 @@ import org.apache.fop.traits.RuleStyle;
 /**
  * Abstract base class for IFPainter implementations.
  */
-public abstract class AbstractIFPainter implements IFPainter {
+public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements IFPainter {
 
     /** logging instance */
     private static Log log = LogFactory.getLog(AbstractIFPainter.class);
@@ -68,18 +70,39 @@ public abstract class AbstractIFPainter 
     /** Holds the intermediate format state */
     protected IFState state;
 
+    private final T documentHandler;
 
     /**
      * Default constructor.
      */
-    public AbstractIFPainter() {
+    public AbstractIFPainter(T documentHandler) {
+        this.documentHandler = documentHandler;
+    }
+
+    protected String getFontKey(FontTriplet triplet) throws IFException {
+        String key = getFontInfo().getInternalFontKey(triplet);
+        if (key == null) {
+            throw new IFException("The font triplet is not available: \"" + triplet + "\" "
+                    + "for the MIME type: \"" + documentHandler.getMimeType() + "\"");
+        }
+        return key;
     }
 
     /**
      * Returns the intermediate format context object.
      * @return the context object
      */
-    protected abstract IFContext getContext();
+    protected IFContext getContext() {
+        return documentHandler.getContext();
+    }
+
+    protected FontInfo getFontInfo() {
+        return documentHandler.getFontInfo();
+    }
+
+    protected T getDocumentHandler() {
+        return documentHandler;
+    }
 
     /**
      * Returns the user agent.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFException.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFException.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/IFException.java Mon Jul  2 10:13:54 2012
@@ -27,20 +27,27 @@ public class IFException extends Excepti
     private static final long serialVersionUID = 0L;
 
     /**
-     * Constructs a new exception with the specified detail message and
-     * cause.  <p>Note that the detail message associated with
-     * <code>cause</code> is <i>not</i> automatically incorporated in
+     * Constructs a new exception with the specified detail message and cause.  <p>Note that the
+     * detail message associated with <code>cause</code> is <i>not</i> automatically incorporated in
      * this exception's detail message.
      *
-     * @param  message the detail message (which is saved for later retrieval
-     *         by the {@link #getMessage()} method).
-     * @param  cause the cause (which is saved for later retrieval by the
-     *         {@link #getCause()} method).  (A <code>null</code> value is
-     *         permitted, and indicates that the cause is nonexistent or
-     *         unknown.)
+     * @param  message the detail message (which is saved for later retrieval by the
+     * {@link #getMessage()} method).
+     * @param  cause the cause (which is saved for later retrieval by the {@link #getCause()}
+     * method).  (A <code>null</code> value is permitted, and indicates that the cause is
+     * nonexistent or unknown.)
      */
     public IFException(String message, Exception cause) {
         super(message, cause);
     }
 
+    /**
+     * Constructs a new exception with the specified detail message.
+     *
+     * @param  message the detail message (which is saved for later retrieval by the
+     * {@link #getMessage()} method).
+     */
+    public IFException(String message) {
+        super(message);
+    }
 }

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java?rev=1356161&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java Mon Jul  2 10:13:54 2012
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fop.render.java2d;
+
+import java.awt.Dimension;
+import java.util.Locale;
+
+import javax.xml.transform.Result;
+
+import org.apache.fop.accessibility.StructureTreeEventHandler;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
+import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFPainter;
+
+/**
+ * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation that produces
+ * Graphics2D instance.
+ */
+public class Java2DDocumentHandler implements IFDocumentHandler {
+
+    public void setContext(IFContext context) {
+        throw new UnsupportedOperationException();
+    }
+
+    public IFContext getContext() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setResult(Result result) throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setFontInfo(FontInfo fontInfo) {
+        throw new UnsupportedOperationException();
+    }
+
+    public FontInfo getFontInfo() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setDefaultFontInfo(FontInfo fontInfo) {
+        throw new UnsupportedOperationException();
+    }
+
+    public IFDocumentHandlerConfigurator getConfigurator() {
+        throw new UnsupportedOperationException();
+    }
+
+    public StructureTreeEventHandler getStructureTreeEventHandler() {
+        throw new UnsupportedOperationException();
+    }
+
+    public IFDocumentNavigationHandler getDocumentNavigationHandler() {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean supportsPagesOutOfOrder() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getMimeType() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startDocument() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endDocument() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setDocumentLocale(Locale locale) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startDocumentHeader() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endDocumentHeader() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startDocumentTrailer() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endDocumentTrailer() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startPageSequence(String id) throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endPageSequence() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startPage(int index, String name, String pageMasterName, Dimension size)
+            throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endPage() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startPageHeader() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endPageHeader() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public IFPainter startPageContent() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endPageContent() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void startPageTrailer() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void endPageTrailer() throws IFException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void handleExtensionObject(Object extension) throws IFException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DDocumentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DPainter.java Mon Jul  2 10:13:54 2012
@@ -47,10 +47,10 @@ import org.apache.fop.traits.RuleStyle;
 import org.apache.fop.util.CharUtilities;
 
 /**
- * {@link org.apache.fop.render.intermediate.IFPainter} implementation
- * that paints on a Graphics2D instance.
+ * {@link org.apache.fop.render.intermediate.IFPainter} implementation that paints on a Graphics2D
+ * instance.
  */
-public class Java2DPainter extends AbstractIFPainter {
+public class Java2DPainter extends AbstractIFPainter<Java2DDocumentHandler> {
 
     /** the IF context */
     protected IFContext ifContext;
@@ -62,7 +62,7 @@ public class Java2DPainter extends Abstr
 
     /** The current state, holds a Graphics2D and its context */
     protected Java2DGraphicsState g2dState;
-    private Stack g2dStateStack = new Stack();
+    private Stack<Java2DGraphicsState> g2dStateStack = new Stack<Java2DGraphicsState>();
 
     /**
      * Main constructor.
@@ -83,7 +83,7 @@ public class Java2DPainter extends Abstr
      * @param state the IF state object
      */
     public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state) {
-        super();
+        super(new Java2DDocumentHandler());
         this.ifContext = context;
         if (state != null) {
             this.state = state.push();
@@ -256,7 +256,7 @@ public class Java2DPainter extends Abstr
     /** Restores the last graphics state from the stack. */
     protected void restoreGraphicsState() {
         g2dState.dispose();
-        g2dState = (Java2DGraphicsState)g2dStateStack.pop();
+        g2dState = g2dStateStack.pop();
     }
 
     private void concatenateTransformationMatrix(AffineTransform transform) throws IOException {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pcl/PCLPainter.java Mon Jul  2 10:13:54 2012
@@ -47,7 +47,6 @@ import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.render.ImageHandlerUtil;
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.AbstractIFPainter;
-import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.render.intermediate.IFUtil;
@@ -58,15 +57,12 @@ import org.apache.fop.traits.RuleStyle;
 import org.apache.fop.util.CharUtilities;
 
 /**
- * {@link org.apache.fop.render.intermediate.IFPainter} implementation
- * that produces PCL 5.
+ * {@link org.apache.fop.render.intermediate.IFPainter} implementation that produces PCL 5.
  */
-public class PCLPainter extends AbstractIFPainter implements PCLConstants {
+public class PCLPainter extends AbstractIFPainter<PCLDocumentHandler> implements PCLConstants {
 
     private static final boolean DEBUG = false;
 
-    private PCLDocumentHandler parent;
-
     /** The PCL generator */
     private PCLGenerator gen;
 
@@ -74,7 +70,7 @@ public class PCLPainter extends Abstract
     private int currentPrintDirection = 0;
     //private GeneralPath currentPath = null;
 
-    private Stack graphicContextStack = new Stack();
+    private Stack<GraphicContext> graphicContextStack = new Stack<GraphicContext>();
     private GraphicContext graphicContext = new GraphicContext();
 
     /**
@@ -83,24 +79,19 @@ public class PCLPainter extends Abstract
      * @param pageDefinition the page definition describing the page to be rendered
      */
     public PCLPainter(PCLDocumentHandler parent, PCLPageDefinition pageDefinition) {
-        this.parent = parent;
+        super(parent);
         this.gen = parent.getPCLGenerator();
         this.state = IFState.create();
         this.currentPageDefinition = pageDefinition;
     }
 
-    /** {@inheritDoc} */
-    public IFContext getContext() {
-        return this.parent.getContext();
-    }
-
     PCLRenderingUtil getPCLUtil() {
-        return this.parent.getPCLUtil();
+        return getDocumentHandler().getPCLUtil();
     }
 
     /** @return the target resolution */
     protected int getResolution() {
-        int resolution = (int)Math.round(getUserAgent().getTargetResolution());
+        int resolution = Math.round(getUserAgent().getTargetResolution());
         if (resolution <= 300) {
             return 300;
         } else {
@@ -223,7 +214,7 @@ public class PCLPainter extends Abstract
                     g2d.translate(-rect.x, -rect.y);
 
                     Java2DPainter painter = new Java2DPainter(g2d,
-                            getContext(), parent.getFontInfo(), state);
+                            getContext(), getFontInfo(), state);
                     try {
                         painter.drawBorderRect(rect, top, bottom, left, right);
                     } catch (IFException e) {
@@ -258,7 +249,7 @@ public class PCLPainter extends Abstract
                 g2d.translate(-boundingBox.x, -boundingBox.y);
 
                 Java2DPainter painter = new Java2DPainter(g2d,
-                        getContext(), parent.getFontInfo(), state);
+                        getContext(), getFontInfo(), state);
                 try {
                     painter.drawLine(start, end, width, color, style);
                 } catch (IFException e) {
@@ -315,9 +306,8 @@ public class PCLPainter extends Abstract
                     state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
             //TODO Ignored: state.getFontVariant()
             //TODO Opportunity for font caching if font state is more heavily used
-            String fontKey = parent.getFontInfo().getInternalFontKey(triplet);
-            boolean pclFont = getPCLUtil().isAllTextAsBitmaps()
-                        ? false
+            String fontKey = getFontKey(triplet);
+            boolean pclFont = getPCLUtil().isAllTextAsBitmaps() ? false
                         : HardcodedFonts.setFont(gen, fontKey, state.getFontSize(), text);
             if (pclFont) {
                 drawTextNative(x, y, letterSpacing, wordSpacing, dp, text, triplet);
@@ -346,7 +336,7 @@ public class PCLPainter extends Abstract
         setCursorPos(x, y);
 
         float fontSize = state.getFontSize() / 1000f;
-        Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());
+        Font font = getFontInfo().getFontInstance(triplet, state.getFontSize());
         int l = text.length();
         int[] dx = IFUtil.convertDPToDX ( dp );
         int dxl = (dx != null ? dx.length : 0);
@@ -438,10 +428,10 @@ public class PCLPainter extends Abstract
             final int letterSpacing, final int wordSpacing, final int[][] dp,
             final String text, FontTriplet triplet) throws IFException {
         //Use Java2D to paint different fonts via bitmap
-        final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize());
+        final Font font = getFontInfo().getFontInstance(triplet, state.getFontSize());
 
         //for cursive fonts, so the text isn't clipped
-        final FontMetricsMapper mapper = (FontMetricsMapper)parent.getFontInfo().getMetricsFor(
+        final FontMetricsMapper mapper = (FontMetricsMapper) getFontInfo().getMetricsFor(
                 font.getFontName());
         final int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
         final int ascent = mapper.getAscender(font.getFontSize()) / 1000;
@@ -470,8 +460,7 @@ public class PCLPainter extends Abstract
                     rect = new Rectangle(x, y, 1000, -descent);
                     g2d.draw(rect);
                 }
-                Java2DPainter painter = new Java2DPainter(g2d,
-                        getContext(), parent.getFontInfo(), state);
+                Java2DPainter painter = new Java2DPainter(g2d, getContext(), getFontInfo(), state);
                 try {
                     painter.drawText(x, y, letterSpacing, wordSpacing, dp, text);
                 } catch (IFException e) {
@@ -496,7 +485,7 @@ public class PCLPainter extends Abstract
 
     /** Restores the last graphics state from the stack. */
     private void restoreGraphicsState() {
-        graphicContext = (GraphicContext)graphicContextStack.pop();
+        graphicContext = graphicContextStack.pop();
     }
 
     private void concatenateTransformationMatrix(AffineTransform transform) throws IOException {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java Mon Jul  2 10:13:54 2012
@@ -40,7 +40,6 @@ import org.apache.fop.fo.extensions.xmp.
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFPage;
-import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.render.extensions.prepress.PageBoundaries;
 import org.apache.fop.render.extensions.prepress.PageScale;
@@ -67,31 +66,28 @@ public class PDFDocumentHandler extends 
     private PDFStructureTreeBuilder structureTreeBuilder;
 
     /** the PDF Document being created */
-    protected PDFDocument pdfDoc;
+    private PDFDocument pdfDoc;
 
     /**
      * Utility class which enables all sorts of features that are not directly connected to the
      * normal rendering process.
      */
-    protected PDFRenderingUtil pdfUtil;
+    private PDFRenderingUtil pdfUtil;
 
     /** the /Resources object of the PDF document being created */
-    protected PDFResources pdfResources;
+    private PDFResources pdfResources;
 
     /** The current content generator */
-    protected PDFContentGenerator generator;
-
-    /** the current annotation list to add annotations to */
-    protected PDFResourceContext currentContext;
+    private PDFContentGenerator generator;
 
     /** the current page to add annotations to */
-    protected PDFPage currentPage;
+    private PDFPage currentPage;
 
     /** the current page's PDF reference */
-    protected PageReference currentPageRef;
+    private PageReference currentPageRef;
 
     /** Used for bookmarks/outlines. */
-    protected Map<Integer, PageReference> pageReferences = new HashMap<Integer, PageReference>();
+    private Map<Integer, PageReference> pageReferences = new HashMap<Integer, PageReference>();
 
     private final PDFDocumentNavigationHandler documentNavigationHandler
             = new PDFDocumentNavigationHandler(this);
@@ -136,6 +132,22 @@ public class PDFDocumentHandler extends 
         return logicalStructureHandler;
     }
 
+    PDFDocument getPDFDocument() {
+        return pdfDoc;
+    }
+
+    PDFPage getCurrentPage() {
+        return currentPage;
+    }
+
+    PageReference getCurrentPageRef() {
+        return currentPageRef;
+    }
+
+    PDFContentGenerator getGenerator() {
+        return generator;
+    }
+
     /** {@inheritDoc} */
     public void startDocument() throws IFException {
         super.startDocument();
@@ -174,7 +186,6 @@ public class PDFDocumentHandler extends 
 
             pdfResources = null;
             this.generator = null;
-            currentContext = null;
             currentPage = null;
         } catch (IOException ioe) {
             throw new IFException("I/O error in endDocument()", ioe);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java Mon Jul  2 10:13:54 2012
@@ -63,7 +63,7 @@ public class PDFDocumentNavigationHandle
     }
 
     PDFDocument getPDFDoc() {
-        return this.documentHandler.pdfDoc;
+        return this.documentHandler.getPDFDocument();
     }
 
     /** {@inheritDoc} */
@@ -100,7 +100,7 @@ public class PDFDocumentNavigationHandle
     /** {@inheritDoc} */
     public void renderLink(Link link) throws IFException {
         Rectangle targetRect = link.getTargetRect();
-        int pageHeight = documentHandler.currentPageRef.getPageDimension().height;
+        int pageHeight = documentHandler.getCurrentPageRef().getPageDimension().height;
         Rectangle2D targetRect2D = new Rectangle2D.Double(
                 targetRect.getMinX() / 1000.0,
                 (pageHeight - targetRect.getMinY() - targetRect.getHeight()) / 1000.0,
@@ -116,7 +116,7 @@ public class PDFDocumentNavigationHandle
             if (documentHandler.getUserAgent().isAccessibilityEnabled() && structure != null) {
                 documentHandler.getLogicalStructureHandler().addLinkContentItem(pdfLink, structure);
             }
-            documentHandler.currentPage.addAnnotation(pdfLink);
+            documentHandler.getCurrentPage().addAnnotation(pdfLink);
         }
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFPainter.java Mon Jul  2 10:13:54 2012
@@ -30,19 +30,16 @@ import java.io.IOException;
 import org.w3c.dom.Document;
 
 import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.fonts.SingleByteFont;
 import org.apache.fop.fonts.Typeface;
-import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFNumber;
 import org.apache.fop.pdf.PDFStructElem;
 import org.apache.fop.pdf.PDFTextUtil;
 import org.apache.fop.pdf.PDFXObject;
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.AbstractIFPainter;
-import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.render.intermediate.IFUtil;
@@ -55,9 +52,7 @@ import org.apache.fop.util.CharUtilities
 /**
  * IFPainter implementation that produces PDF.
  */
-public class PDFPainter extends AbstractIFPainter {
-
-    private final PDFDocumentHandler documentHandler;
+public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
 
     /** The current content generator */
     protected PDFContentGenerator generator;
@@ -77,34 +72,15 @@ public class PDFPainter extends Abstract
      */
     public PDFPainter(PDFDocumentHandler documentHandler,
             PDFLogicalStructureHandler logicalStructureHandler) {
-        super();
-        this.documentHandler = documentHandler;
+        super(documentHandler);
         this.logicalStructureHandler = logicalStructureHandler;
-        this.generator = documentHandler.generator;
+        this.generator = documentHandler.getGenerator();
         this.borderPainter = new PDFBorderPainter(this.generator);
         this.state = IFState.create();
         accessEnabled = this.getUserAgent().isAccessibilityEnabled();
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected IFContext getContext() {
-        return this.documentHandler.getContext();
-    }
-
-    PDFRenderingUtil getPDFUtil() {
-        return this.documentHandler.pdfUtil;
-    }
-
-    PDFDocument getPDFDoc() {
-        return this.documentHandler.pdfDoc;
-    }
-
-    FontInfo getFontInfo() {
-        return this.documentHandler.getFontInfo();
-    }
-
-    /** {@inheritDoc} */
     public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
             throws IFException {
         generator.saveGraphicsState();
@@ -133,7 +109,7 @@ public class PDFPainter extends Abstract
     /** {@inheritDoc} */
     public void drawImage(String uri, Rectangle rect)
             throws IFException {
-        PDFXObject xobject = getPDFDoc().getXObject(uri);
+        PDFXObject xobject = getDocumentHandler().getPDFDocument().getXObject(uri);
         if (xobject != null) {
             if (accessEnabled) {
                 PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement();
@@ -160,7 +136,7 @@ public class PDFPainter extends Abstract
     @Override
     protected RenderingContext createRenderingContext() {
         PDFRenderingContext pdfContext = new PDFRenderingContext(
-                getUserAgent(), generator, this.documentHandler.currentPage, getFontInfo());
+                getUserAgent(), generator, getDocumentHandler().getCurrentPage(), getFontInfo());
         pdfContext.setMarkedContentInfo(imageMCI);
         return pdfContext;
     }
@@ -321,12 +297,11 @@ public class PDFPainter extends Abstract
         }
     }
 
-    private void drawTextWithDX ( int x, int y, String text, FontTriplet triplet,
-                                  int letterSpacing, int wordSpacing, int[] dx ) {
-
+    private void drawTextWithDX(int x, int y, String text, FontTriplet triplet,
+            int letterSpacing, int wordSpacing, int[] dx) throws IFException {
         //TODO Ignored: state.getFontVariant()
         //TODO Opportunity for font caching if font state is more heavily used
-        String fontKey = getFontInfo().getInternalFontKey(triplet);
+        String fontKey = getFontKey(triplet);
         int sizeMillipoints = state.getFontSize();
         float fontSize = sizeMillipoints / 1000f;
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentHandler.java Mon Jul  2 10:13:54 2012
@@ -54,6 +54,7 @@ import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
 import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFPainter;
@@ -76,10 +77,10 @@ public class PSDocumentHandler extends A
      * Utility class which enables all sorts of features that are not directly connected to the
      * normal rendering process.
      */
-    protected PSRenderingUtil psUtil;
+    private PSRenderingUtil psUtil;
 
     /** The PostScript generator used to output the PostScript */
-    protected PSGenerator gen;
+    PSGenerator gen;
 
     /** the temporary file in case of two-pass processing */
     private File tempFile;
@@ -126,6 +127,10 @@ public class PSDocumentHandler extends A
         return MimeConstants.MIME_POSTSCRIPT;
     }
 
+    PSGenerator getGenerator() {
+        return gen;
+    }
+
     /** {@inheritDoc} */
     public void setContext(IFContext context) {
         super.setContext(context);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSPainter.java Mon Jul  2 10:13:54 2012
@@ -41,7 +41,6 @@ import org.apache.xmlgraphics.ps.PSGener
 import org.apache.xmlgraphics.ps.PSResource;
 
 import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.LazyFont;
 import org.apache.fop.fonts.MultiByteFont;
@@ -49,7 +48,6 @@ import org.apache.fop.fonts.SingleByteFo
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.AbstractIFPainter;
-import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.render.intermediate.IFUtil;
@@ -61,12 +59,11 @@ import org.apache.fop.util.HexEncoder;
 /**
  * IFPainter implementation that produces PostScript.
  */
-public class PSPainter extends AbstractIFPainter {
+public class PSPainter extends AbstractIFPainter<PSDocumentHandler> {
 
     /** logging instance */
     private static Log log = LogFactory.getLog(PSPainter.class);
 
-    private PSDocumentHandler documentHandler;
     private PSBorderPainter borderPainter;
 
     private boolean inTextMode = false;
@@ -80,27 +77,13 @@ public class PSPainter extends AbstractI
     }
 
     protected PSPainter(PSDocumentHandler documentHandler, IFState state) {
-        super();
-        this.documentHandler = documentHandler;
-        this.borderPainter = new PSBorderPainter(documentHandler.gen);
+        super(documentHandler);
+        this.borderPainter = new PSBorderPainter(getGenerator());
         this.state = state;
     }
 
-    /** {@inheritDoc} */
-    protected IFContext getContext() {
-        return this.documentHandler.getContext();
-    }
-
-    PSRenderingUtil getPSUtil() {
-        return this.documentHandler.psUtil;
-    }
-
-    FontInfo getFontInfo() {
-        return this.documentHandler.getFontInfo();
-    }
-
     private PSGenerator getGenerator() {
-        return this.documentHandler.gen;
+        return getDocumentHandler().getGenerator();
     }
 
     /** {@inheritDoc} */
@@ -168,7 +151,7 @@ public class PSPainter extends AbstractI
     /** {@inheritDoc} */
     protected void drawImageUsingImageHandler(ImageInfo info, Rectangle rect)
             throws ImageException, IOException {
-        if (!getPSUtil().isOptimizeResources()
+        if (!getDocumentHandler().getPSUtil().isOptimizeResources()
                 || PSImageUtils.isImageInlined(info,
                         (PSRenderingContext)createRenderingContext())) {
             super.drawImageUsingImageHandler(info, rect);
@@ -177,7 +160,7 @@ public class PSPainter extends AbstractI
                 log.debug("Image " + info + " is embedded as a form later");
             }
             //Don't load image at this time, just put a form placeholder in the stream
-            PSResource form = documentHandler.getFormForImage(info.getOriginalURI());
+            PSResource form = getDocumentHandler().getFormForImage(info.getOriginalURI());
             PSImageUtils.drawForm(form, info, rect, getGenerator());
         }
     }
@@ -246,7 +229,7 @@ public class PSPainter extends AbstractI
         if (top != null || bottom != null || left != null || right != null) {
             try {
                 endTextObject();
-                if (getPSUtil().getRenderingMode() == PSRenderingMode.SIZE
+                if (getDocumentHandler().getPSUtil().getRenderingMode() == PSRenderingMode.SIZE
                     && hasOnlySolidBorders(top, bottom, left, right)) {
                     super.drawBorderRect(rect, top, bottom, left, right);
                 } else {
@@ -273,7 +256,7 @@ public class PSPainter extends AbstractI
         if (fontName == null) {
             throw new NullPointerException("fontName must not be null");
         }
-        Typeface tf = (Typeface)getFontInfo().getFonts().get(fontName);
+        Typeface tf = getFontInfo().getFonts().get(fontName);
         if (tf instanceof LazyFont) {
             tf = ((LazyFont)tf).getRealFont();
         }
@@ -363,10 +346,7 @@ public class PSPainter extends AbstractI
                     state.getFontFamily(), state.getFontStyle(), state.getFontWeight());
             //TODO Ignored: state.getFontVariant()
             //TODO Opportunity for font caching if font state is more heavily used
-            String fontKey = getFontInfo().getInternalFontKey(triplet);
-            if (fontKey == null) {
-                throw new IFException("Font not available: " + triplet, null);
-            }
+            String fontKey = getFontKey(triplet);
             int sizeMillipoints = state.getFontSize();
 
             // This assumes that *all* CIDFonts use a /ToUnicode mapping
@@ -529,10 +509,9 @@ public class PSPainter extends AbstractI
     }
 
     private void useFont(String key, int size) throws IOException {
-        PSFontResource res = this.documentHandler.getPSResourceForFontKey(key);
+        PSFontResource res = getDocumentHandler().getPSResourceForFontKey(key);
         PSGenerator generator = getGenerator();
         generator.useFont("/" + res.getName(), size / 1000f);
         res.notifyResourceUsageOnPage(generator.getResourceTracker());
     }
-
 }

Modified: xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java?rev=1356161&r1=1356160&r2=1356161&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java (original)
+++ xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGPainter.java Mon Jul  2 10:13:54 2012
@@ -30,7 +30,6 @@ import java.io.IOException;
 import java.util.Map;
 
 import org.w3c.dom.Document;
-
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
@@ -46,7 +45,6 @@ import org.apache.fop.render.ImageHandle
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.intermediate.AbstractIFPainter;
 import org.apache.fop.render.intermediate.IFConstants;
-import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFException;
 import org.apache.fop.render.intermediate.IFState;
 import org.apache.fop.render.intermediate.IFUtil;
@@ -60,12 +58,11 @@ import org.apache.fop.util.XMLUtil;
 /**
  * IFPainter implementation that writes SVG.
  */
-public class SVGPainter extends AbstractIFPainter implements SVGConstants {
-
-    private AbstractSVGDocumentHandler parent;
+public class SVGPainter extends AbstractIFPainter<AbstractSVGDocumentHandler>
+        implements SVGConstants {
 
     /** The SAX content handler that receives the generated XML events. */
-    protected GenerationHelperContentHandler handler;
+    private GenerationHelperContentHandler handler;
 
     private static final int MODE_NORMAL = 0;
     private static final int MODE_TEXT = 1;
@@ -79,18 +76,12 @@ public class SVGPainter extends Abstract
      */
     public SVGPainter(AbstractSVGDocumentHandler parent,
             GenerationHelperContentHandler contentHandler) {
-        super();
-        this.parent = parent;
+        super(parent);
         this.handler = contentHandler;
         this.state = IFState.create();
     }
 
     /** {@inheritDoc} */
-    protected IFContext getContext() {
-        return parent.getContext();
-    }
-
-    /** {@inheritDoc} */
     public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
             throws IFException {
         startViewport(SVGUtil.formatAffineTransformMptToPt(transform), size, clipRect);

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java?rev=1356161&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java Mon Jul  2 10:13:54 2012
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fop.render.intermediate;
+
+import java.awt.Dimension;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.render.RenderingContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AbstractIFPainterTestCase {
+
+    private AbstractIFPainter<?> sut;
+    private IFDocumentHandler handler;
+
+    @Before
+    public void setUp() {
+        handler = mock(IFDocumentHandler.class);
+        sut = new AbstractIFPainter<IFDocumentHandler>(handler) {
+            public void startViewport(AffineTransform transform, Dimension size, Rectangle clipRect)
+                    throws IFException {
+            }
+
+            public void endViewport() throws IFException {
+            }
+
+            public void startGroup(AffineTransform transform) throws IFException {
+            }
+
+            public void endGroup() throws IFException {
+            }
+
+            public void clipRect(Rectangle rect) throws IFException {
+            }
+
+            public void fillRect(Rectangle rect, Paint fill) throws IFException {
+            }
+
+            public void drawImage(String uri, Rectangle rect) throws IFException {
+            }
+
+            public void drawImage(Document doc, Rectangle rect) throws IFException {
+            }
+
+            @Override
+            protected RenderingContext createRenderingContext() {
+                return null;
+            }
+
+            public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[][] dp,
+                    String text) throws IFException {
+            }
+        };
+        FontInfo fontInfo = mock(FontInfo.class);
+        when(handler.getFontInfo()).thenReturn(fontInfo);
+    }
+
+    @Test
+    public void testGetFontKey() throws IFException {
+        String expected = "the expected string";
+        FontTriplet triplet = mock(FontTriplet.class);
+        FontInfo fontInfo = handler.getFontInfo();
+        when(fontInfo.getInternalFontKey(triplet)).thenReturn(expected);
+        assertEquals(expected, sut.getFontKey(triplet));
+    }
+
+    @Test(expected = IFException.class)
+    public void testGetFontKeyMissingFont() throws IFException {
+        FontTriplet triplet = mock(FontTriplet.class);
+        when(handler.getFontInfo().getInternalFontKey(triplet)).thenReturn(null);
+        sut.getFontKey(triplet);
+    }
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/intermediate/AbstractIFPainterTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message