diff options
author | Glen Mazza <gmazza@apache.org> | 2004-07-07 01:51:50 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-07-07 01:51:50 +0000 |
commit | 18a28ab107b07c5ba0fee9a57ede8fb00b2fbaa3 (patch) | |
tree | f3bab32fe9ddd90178a592971bbe905d3f9ddf3b /src/java/org/apache/fop/area/RenderPagesModel.java | |
parent | a0e92b3059b2ecf27506bcb4ee2eae099adec7c9 (diff) | |
download | xmlgraphics-fop-18a28ab107b07c5ba0fee9a57ede8fb00b2fbaa3.tar.gz xmlgraphics-fop-18a28ab107b07c5ba0fee9a57ede8fb00b2fbaa3.zip |
1.) Moved the Renderer creation further down from AreaTree to RenderPagesModel (subclass of AreaTreeModel). Still have the issue of the four-param constructor a bit messy, also some of the exceptions I have to declare to be thrown may not be necessary.
2.) Removed encapsulation-breaking methods from AreaTree; dropped the AreaTreeBuilder class as it wasn't conformant with our API and required too many objects to expose internal functionality.
3.) Validity checking added for fo:title, however still won't work as #PCDATA needs <fo:blocks> around it within FOP, but the Recommendation bans those for fo:title.
4.) isInlineItem() added to FObj, as a quick check for the %inline; parameter entity as defined in spec.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197763 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/area/RenderPagesModel.java')
-rw-r--r-- | src/java/org/apache/fop/area/RenderPagesModel.java | 84 |
1 files changed, 77 insertions, 7 deletions
diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java index 3ad65a8f6..96fcb8a7e 100644 --- a/src/java/org/apache/fop/area/RenderPagesModel.java +++ b/src/java/org/apache/fop/area/RenderPagesModel.java @@ -18,13 +18,22 @@ package org.apache.fop.area; -// FOP -import org.apache.fop.render.Renderer; - // Java +import java.io.IOException; +import java.io.OutputStream; import java.util.List; import java.util.Iterator; +// XML +import org.xml.sax.SAXException; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.Constants; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.render.Renderer; + /** * This uses the store pages model to store the pages * each page is either rendered if ready or prepared @@ -38,6 +47,7 @@ public class RenderPagesModel extends StorePagesModel { * The renderer that will render the pages. */ protected Renderer renderer; + /** * Pages that have been prepared but not rendered yet. */ @@ -47,10 +57,64 @@ public class RenderPagesModel extends StorePagesModel { /** * Create a new render pages model with the given renderer. - * @param rend the renderer to render pages to + * @param userAgent FOUserAgent object for process + * @param renderType Desired fo.Constants output type (RENDER_PDF, + * RENDER_PS, etc.) + * @param fontInfo FontInfo object + * @param stream OutputStream */ - public RenderPagesModel(Renderer rend) { - renderer = rend; + public RenderPagesModel (FOUserAgent userAgent, int renderType, + FontInfo fontInfo, OutputStream stream) throws FOPException { + + if (userAgent.getRendererOverride() != null) { + renderer = userAgent.getRendererOverride(); + } else { + renderer = createRenderer(renderType); + renderer.setUserAgent(userAgent); + } + + try { + renderer.setupFontInfo(fontInfo); + // check that the "any,normal,400" font exists + if (!fontInfo.isSetupValid()) { + throw new FOPException( + "No default font defined by OutputConverter"); + } + renderer.startRenderer(stream); + } catch (IOException e) { + throw new FOPException(e); + } + } + + /** + * Creates a Renderer object based on render-type desired + * @param renderType the type of renderer to use + * @return Renderer the new Renderer instance + * @throws IllegalArgumentException if an unsupported renderer type was requested + */ + private Renderer createRenderer(int renderType) throws IllegalArgumentException { + + switch (renderType) { + case Constants.RENDER_PDF: + return new org.apache.fop.render.pdf.PDFRenderer(); + case Constants.RENDER_AWT: + return new org.apache.fop.render.awt.AWTRenderer(); + case Constants.RENDER_PRINT: + return new org.apache.fop.render.awt.AWTPrintRenderer(); + case Constants.RENDER_PCL: + return new org.apache.fop.render.pcl.PCLRenderer(); + case Constants.RENDER_PS: + return new org.apache.fop.render.ps.PSRenderer(); + case Constants.RENDER_TXT: + return new org.apache.fop.render.txt.TXTRenderer(); + case Constants.RENDER_XML: + return new org.apache.fop.render.xml.XMLRenderer(); + case Constants.RENDER_SVG: + return new org.apache.fop.render.svg.SVGRenderer(); + default: + throw new IllegalArgumentException("Invalid renderer type " + + renderType); + } } /** @@ -178,7 +242,7 @@ public class RenderPagesModel extends StorePagesModel { /** * End the document. Render any end document extensions. */ - public void endDocument() { + public void endDocument() throws SAXException { // render any pages that had unresolved ids checkPreparedPages(null); @@ -186,6 +250,12 @@ public class RenderPagesModel extends StorePagesModel { pendingExt.clear(); renderExtensions(endDocExt); + + try { + renderer.stopRenderer(); + } catch (IOException ex) { + throw new SAXException(ex); + } } } |