diff options
author | Peter Hancock <phancock@apache.org> | 2012-06-29 11:22:42 +0000 |
---|---|---|
committer | Peter Hancock <phancock@apache.org> | 2012-06-29 11:22:42 +0000 |
commit | 3e31e071ea47f37ef7f8749b324dfdfe76745d18 (patch) | |
tree | 7d3b646c521349634592b62556a8832ec082cc9c /src/java/org/apache/fop/render/ps/PSDocumentHandler.java | |
parent | ae8a5035235e1262e412e1eacd0eb3adfaef83ef (diff) | |
parent | 015538e0f11f031e3d7bd05db8c29e2a40365678 (diff) | |
download | xmlgraphics-fop-3e31e071ea47f37ef7f8749b324dfdfe76745d18.tar.gz xmlgraphics-fop-3e31e071ea47f37ef7f8749b324dfdfe76745d18.zip |
Merged trunk@1354651
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_RoundedCorners@1355321 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/ps/PSDocumentHandler.java')
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSDocumentHandler.java | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java index d55e0724b..0fe564827 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -49,20 +50,22 @@ import org.apache.xmlgraphics.ps.dsc.ResourceTracker; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox; +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; import org.apache.fop.render.ps.extensions.PSCommentAfter; import org.apache.fop.render.ps.extensions.PSCommentBefore; +import org.apache.fop.render.ps.extensions.PSPageTrailerCodeBefore; import org.apache.fop.render.ps.extensions.PSSetPageDevice; import org.apache.fop.render.ps.extensions.PSSetupCode; /** - * {@link IFDocumentHandler} implementation that produces PostScript. + * {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation + * that produces PostScript. */ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { @@ -99,10 +102,13 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { private PSPageDeviceDictionary pageDeviceDictionary; /** This is a collection holding all document header comments */ - private Collection[] comments = new Collection[3]; + private Collection[] comments = new Collection[4]; private static final int COMMENT_DOCUMENT_HEADER = 0; private static final int COMMENT_DOCUMENT_TRAILER = 1; private static final int COMMENT_PAGE_TRAILER = 2; + private static final int PAGE_TRAILER_CODE_BEFORE = 3; + + private PSEventProducer eventProducer; /** * Default constructor. @@ -123,7 +129,9 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { /** {@inheritDoc} */ public void setContext(IFContext context) { super.setContext(context); - this.psUtil = new PSRenderingUtil(context.getUserAgent()); + FOUserAgent userAgent = context.getUserAgent(); + this.psUtil = new PSRenderingUtil(userAgent); + eventProducer = PSEventProducer.Provider.get(userAgent.getEventBroadcaster()); } /** {@inheritDoc} */ @@ -142,7 +150,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { try { OutputStream out; if (psUtil.isOptimizeResources()) { - this.tempFile = File.createTempFile("fop", null); + this.tempFile = File.createTempFile("fop", ".ps"); out = new java.io.FileOutputStream(this.tempFile); out = new java.io.BufferedOutputStream(out); } else { @@ -200,7 +208,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { gen.writeDSCComment(DSCConstants.BEGIN_SETUP); PSRenderingUtil.writeSetupCodeList(gen, setupCodeList, "SetupCode"); if (!psUtil.isOptimizeResources()) { - this.fontResources.addAll(PSFontUtils.writeFontDict(gen, fontInfo)); + this.fontResources.addAll(PSFontUtils.writeFontDict(gen, fontInfo, eventProducer)); } else { gen.commentln("%FOPFontSetup"); //Place-holder, will be replaced in the second pass } @@ -255,8 +263,8 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { in = new java.io.BufferedInputStream(in); try { try { - ResourceHandler handler = new ResourceHandler(getUserAgent(), this.fontInfo, - resTracker, this.formResources); + ResourceHandler handler = new ResourceHandler(getUserAgent(), eventProducer, + this.fontInfo, resTracker, this.formResources); handler.process(in, this.outputStream, this.currentPageNumber, this.documentBoundingBox); this.outputStream.flush(); @@ -444,8 +452,9 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { /** {@inheritDoc} */ public void startPageTrailer() throws IFException { - super.startPageTrailer(); try { + writeExtensions(PAGE_TRAILER_CODE_BEFORE); + super.startPageTrailer(); gen.writeDSCComment(DSCConstants.PAGE_TRAILER); } catch (IOException ioe) { throw new IFException("I/O error in startPageTrailer()", ioe); @@ -527,6 +536,11 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { comments[targetCollection] = new java.util.ArrayList(); } comments[targetCollection].add(extension); + } else if (extension instanceof PSPageTrailerCodeBefore) { + if (comments[PAGE_TRAILER_CODE_BEFORE] == null) { + comments[PAGE_TRAILER_CODE_BEFORE] = new ArrayList(); + } + comments[PAGE_TRAILER_CODE_BEFORE].add(extension); } } catch (IOException ioe) { throw new IFException("I/O error in handleExtensionObject()", ioe); @@ -538,8 +552,8 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { * @param key the font key ("F*") * @return the matching PSResource */ - protected PSResource getPSResourceForFontKey(String key) { - return this.fontResources.getPSResourceForFontKey(key); + protected PSFontResource getPSResourceForFontKey(String key) { + return this.fontResources.getFontResourceForFontKey(key); } /** |