diff options
author | Mehdi Houshmand <mehdi@apache.org> | 2012-07-02 13:23:46 +0000 |
---|---|---|
committer | Mehdi Houshmand <mehdi@apache.org> | 2012-07-02 13:23:46 +0000 |
commit | ab426a49d46ec69b80e6accccd537522477df5b3 (patch) | |
tree | a4a4550b9d329c7a7eae6a8d00861f373911c081 /src/java/org/apache/fop/render/afp | |
parent | c9f6e74ddf229f879ea7df1b389d6018286ca1aa (diff) | |
parent | f5a033d38f700d70bbf679d87d535b37438c9ebb (diff) | |
download | xmlgraphics-fop-ab426a49d46ec69b80e6accccd537522477df5b3.tar.gz xmlgraphics-fop-ab426a49d46ec69b80e6accccd537522477df5b3.zip |
Merged in trunk@1356161
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1356212 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/afp')
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPDocumentHandler.java | 4 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/afp/AFPPainter.java | 63 |
2 files changed, 32 insertions, 35 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java index b94f396b6..fb6c89ce4 100644 --- a/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java @@ -61,8 +61,8 @@ import org.apache.fop.render.intermediate.IFException; 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 { diff --git a/src/java/org/apache/fop/render/afp/AFPPainter.java b/src/java/org/apache/fop/render/afp/AFPPainter.java index 86858c3c8..7d659a8b4 100644 --- a/src/java/org/apache/fop/render/afp/AFPPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPPainter.java @@ -30,7 +30,13 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; +import org.w3c.dom.Document; + +import org.apache.xmlgraphics.image.loader.ImageProcessingHints; +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; @@ -47,27 +53,22 @@ import org.apache.fop.afp.ptoca.PtocaBuilder; import org.apache.fop.afp.ptoca.PtocaProducer; import org.apache.fop.afp.util.AFPResourceAccessor; 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; import org.apache.fop.traits.BorderProps; import org.apache.fop.traits.RuleStyle; import org.apache.fop.util.CharUtilities; -import org.apache.xmlgraphics.image.loader.ImageProcessingHints; -import org.apache.xmlgraphics.image.loader.ImageSessionContext; -import org.w3c.dom.Document; /** * 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); @@ -75,8 +76,6 @@ public class AFPPainter extends AbstractIFPainter { 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 */ @@ -85,36 +84,38 @@ public class AFPPainter extends AbstractIFPainter { /** 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} */ @@ -180,7 +181,7 @@ public class AFPPainter extends AbstractIFPainter { protected RenderingContext createRenderingContext() { AFPRenderingContext psContext = new AFPRenderingContext( getUserAgent(), - documentHandler.getResourceManager(), + getDocumentHandler().getResourceManager(), getPaintingState(), getFontInfo(), getContext().getForeignAttributes()); @@ -189,7 +190,7 @@ public class AFPPainter extends AbstractIFPainter { /** {@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}; @@ -203,10 +204,10 @@ public class AFPPainter extends AbstractIFPainter { //Do we need to embed an external page segment? if (pageSegment.getURI() != null) { AFPResourceAccessor accessor = new AFPResourceAccessor( - documentHandler.getUserAgent().getResourceResolver()); + getDocumentHandler().getUserAgent().getResourceResolver()); try { URI resourceUri = new URI(pageSegment.getURI()); - documentHandler.getResourceManager().createIncludedResourceFromExternal( + getDocumentHandler().getResourceManager().createIncludedResourceFromExternal( pageSegment.getName(), resourceUri, accessor); } catch (URISyntaxException urie) { @@ -362,14 +363,10 @@ public class AFPPainter extends AbstractIFPainter { 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(); @@ -383,7 +380,7 @@ public class AFPPainter extends AbstractIFPainter { 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); } |