From: Mehdi Houshmand
* FopFactory fopFactory = FopFactory.newInstance(); + * AWTRenderer renderer = new AWTRenderer(); * FOUserAgent agent = fopFactory.newFOUserAgent(); - * AWTRenderer renderer = new AWTRenderer(agent); * agent.setRendererOverride(renderer); + * renderer.setPreviewDialogDisplayed(false); + * renderer.setUserAgent(agent); + * renderer.setUserAgent(agent); * previewPanel = new PreviewPanel(agent, null, renderer); * previewPanel = new PreviewPanel(ua); * myGui.add(previewPanel); diff --git a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java index 1c6f2e33d..3733bf2f2 100644 --- a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java @@ -29,7 +29,6 @@ import org.apache.xmlgraphics.image.writer.ImageWriter; import org.apache.xmlgraphics.image.writer.ImageWriterParams; import org.apache.xmlgraphics.image.writer.ImageWriterRegistry; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; import org.apache.fop.area.PageViewport; import org.apache.fop.render.java2d.Java2DRenderer; @@ -41,10 +40,6 @@ import org.apache.fop.render.java2d.Java2DRenderer; */ public class PNGRenderer extends Java2DRenderer { - public PNGRenderer(FOUserAgent userAgent) { - super(userAgent); - } - /** The MIME type for png-Rendering */ public static final String MIME_TYPE = MimeConstants.MIME_PNG; diff --git a/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java b/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java index da19b2986..7d321791a 100644 --- a/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java +++ b/src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java @@ -36,7 +36,7 @@ public class PNGRendererMaker extends AbstractRendererMaker { /** {@inheritDoc} */ public Renderer makeRenderer(FOUserAgent ua) { - return new PNGRenderer(ua); + return new PNGRenderer(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java index 0e2364d35..5a9cfa21b 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java @@ -83,11 +83,19 @@ public class TIFFRenderer extends Java2DRenderer implements TIFFConstants { } /** Creates TIFF renderer. */ - public TIFFRenderer(FOUserAgent userAgent) { - super(userAgent); + public TIFFRenderer() { writerParams = new ImageWriterParams(); writerParams.setCompressionMethod(COMPRESSION_PACKBITS); + } + + /** + * {@inheritDoc} + * org.apache.fop.apps.FOUserAgent) + */ + public void setUserAgent(FOUserAgent foUserAgent) { + super.setUserAgent(foUserAgent); + //Set target resolution int dpi = Math.round(userAgent.getTargetResolution()); writerParams.setResolution(dpi); } diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java b/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java index 852e6ba04..e3c567995 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java @@ -34,7 +34,7 @@ public class TIFFRendererMaker extends AbstractRendererMaker { /** {@inheritDoc} */ public Renderer makeRenderer(FOUserAgent userAgent) { - return new TIFFRenderer(userAgent); + return new TIFFRenderer(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index d5d5a154a..24a2e8a75 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -51,7 +51,6 @@ import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema; import org.apache.fop.Version; import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; import org.apache.fop.area.Area; import org.apache.fop.area.AreaTreeObject; @@ -71,10 +70,10 @@ import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.InlineParent; -import org.apache.fop.area.inline.InlineViewport; import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.SpaceArea; import org.apache.fop.area.inline.TextArea; +import org.apache.fop.area.inline.InlineViewport; import org.apache.fop.area.inline.WordArea; import org.apache.fop.datatypes.URISpecification; import org.apache.fop.fo.extensions.ExtensionAttachment; @@ -159,8 +158,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer { /** * Main constructor */ - public IFRenderer(FOUserAgent userAgent) { - super(userAgent); + public IFRenderer() { } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 3c7006588..766aa081f 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -147,13 +147,15 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem private GeneralPath currentPath = null; /** Default constructor */ - public Java2DRenderer(FOUserAgent userAgent) { - super(userAgent); + public Java2DRenderer() { + } - // MH: necessary? the caller has access to FOUserAgent + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent foUserAgent) { + super.setUserAgent(foUserAgent); userAgent.setRendererOverride(this); // for document regeneration - String s = (String) userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND); + String s = (String)userAgent.getRendererOptions().get(JAVA2D_TRANSPARENT_PAGE_BACKGROUND); if (s != null) { this.transparentPageBackground = "true".equalsIgnoreCase(s); } diff --git a/src/java/org/apache/fop/render/print/PageableRenderer.java b/src/java/org/apache/fop/render/print/PageableRenderer.java index 08d5b0f04..89ab98071 100644 --- a/src/java/org/apache/fop/render/print/PageableRenderer.java +++ b/src/java/org/apache/fop/render/print/PageableRenderer.java @@ -73,11 +73,7 @@ public class PageableRenderer extends Java2DRenderer implements Pageable { /** * Creates a new PageableRenderer. */ - public PageableRenderer(FOUserAgent userAgent) { - super(userAgent); - Map rendererOptions = getUserAgent().getRendererOptions(); - processOptions(rendererOptions); - this.pageFilter = new DefaultPageFilter(); + public PageableRenderer() { } /** {@inheritDoc} */ @@ -85,6 +81,15 @@ public class PageableRenderer extends Java2DRenderer implements Pageable { return MimeConstants.MIME_FOP_PRINT; } + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent agent) { + super.setUserAgent(agent); + + Map rendererOptions = agent.getRendererOptions(); + processOptions(rendererOptions); + this.pageFilter = new DefaultPageFilter(); + } + private void processOptions(Map rendererOptions) { Object o = rendererOptions.get(PageableRenderer.PAGES_MODE); if (o != null) { diff --git a/src/java/org/apache/fop/render/print/PrintRenderer.java b/src/java/org/apache/fop/render/print/PrintRenderer.java index ea68bc9b2..2eb2b07a2 100644 --- a/src/java/org/apache/fop/render/print/PrintRenderer.java +++ b/src/java/org/apache/fop/render/print/PrintRenderer.java @@ -55,9 +55,19 @@ public class PrintRenderer extends PageableRenderer { * Creates a new PrintRenderer with the options set through the renderer options if a custom * PrinterJob is not given in FOUserAgent's renderer options. */ - public PrintRenderer(FOUserAgent userAgent) { - super(userAgent); - setRendererOptions(); + public PrintRenderer() { + } + + /** + * Creates a new PrintRenderer and allows you to pass in a specific PrinterJob instance + * that this renderer should work with. + * @param printerJob the PrinterJob instance + * @deprecated Please use the rendering options on the user agent to pass in the PrinterJob! + */ + public PrintRenderer(PrinterJob printerJob) { + this(); + this.printerJob = printerJob; + printerJob.setPageable(this); } private void initializePrinterJob() { @@ -75,8 +85,11 @@ public class PrintRenderer extends PageableRenderer { } } - private void setRendererOptions() { - Map rendererOptions = getUserAgent().getRendererOptions(); + /** {@inheritDoc} */ + public void setUserAgent(FOUserAgent agent) { + super.setUserAgent(agent); + + Map rendererOptions = agent.getRendererOptions(); Object printerJobO = rendererOptions.get(PrintRenderer.PRINTER_JOB); if (printerJobO != null) { diff --git a/src/java/org/apache/fop/render/print/PrintRendererMaker.java b/src/java/org/apache/fop/render/print/PrintRendererMaker.java index 63444a628..21eb4717a 100644 --- a/src/java/org/apache/fop/render/print/PrintRendererMaker.java +++ b/src/java/org/apache/fop/render/print/PrintRendererMaker.java @@ -35,7 +35,7 @@ public class PrintRendererMaker extends AbstractRendererMaker { /**{@inheritDoc} */ public Renderer makeRenderer(FOUserAgent userAgent) { - return new PrintRenderer(userAgent); + return new PrintRenderer(); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java index 74c5b84a8..386f95838 100644 --- a/src/java/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java @@ -32,7 +32,6 @@ import java.util.Map; import org.apache.xmlgraphics.util.UnitConv; import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.Area; import org.apache.fop.area.CTM; import org.apache.fop.area.PageViewport; @@ -111,8 +110,7 @@ public class TXTRenderer extends AbstractPathOrientedRenderer { /** * Constructs a newly allocatedTXTRenderer
object. */ - public TXTRenderer(FOUserAgent userAgent) { - super(userAgent); + public TXTRenderer() { } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java index 740866e0c..0db369ef2 100644 --- a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java +++ b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java @@ -34,7 +34,7 @@ public class TXTRendererMaker extends AbstractRendererMaker { /**{@inheritDoc} */ public Renderer makeRenderer(FOUserAgent userAgent) { - return new TXTRenderer(userAgent); + return new TXTRenderer(); } /**{@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java index 9c938199f..497e3c047 100644 --- a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java @@ -29,15 +29,6 @@ import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; -import org.xml.sax.helpers.AttributesImpl; - -import org.apache.xmlgraphics.util.QName; - -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.BookmarkData; import org.apache.fop.area.OffDocumentExtensionAttachment; import org.apache.fop.area.OffDocumentItem; @@ -45,14 +36,16 @@ import org.apache.fop.area.PageViewport; import org.apache.fop.fo.extensions.ExtensionAttachment; import org.apache.fop.render.PrintRenderer; import org.apache.fop.render.RendererContext; +import org.apache.xmlgraphics.util.QName; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.AttributesImpl; /** Abstract xml renderer base class. */ public abstract class AbstractXMLRenderer extends PrintRenderer { - public AbstractXMLRenderer(FOUserAgent userAgent) { - super(userAgent); - } - /** Main namespace in use. */ public static final String NS = ""; diff --git a/src/java/org/apache/fop/render/xml/XMLRenderer.java b/src/java/org/apache/fop/render/xml/XMLRenderer.java index 3ae49b121..21d28042d 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -37,6 +37,7 @@ import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; + import org.xml.sax.SAXException; import org.apache.xmlgraphics.util.QName; @@ -74,11 +75,11 @@ import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.InlineBlockParent; import org.apache.fop.area.inline.InlineParent; -import org.apache.fop.area.inline.InlineViewport; import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.Space; import org.apache.fop.area.inline.SpaceArea; import org.apache.fop.area.inline.TextArea; +import org.apache.fop.area.inline.InlineViewport; import org.apache.fop.area.inline.WordArea; import org.apache.fop.fo.Constants; import org.apache.fop.fo.extensions.ExtensionAttachment; @@ -112,9 +113,20 @@ public class XMLRenderer extends AbstractXMLRenderer { private int pageSequenceIndex; - public XMLRenderer(FOUserAgent userAgent) { - super(userAgent); + /** + * Creates a new XML renderer. + */ + public XMLRenderer() { context = new RendererContext(this, XML_MIME_TYPE); + } + + /** + * {@inheritDoc} + */ + @Override + public void setUserAgent(FOUserAgent agent) { + super.setUserAgent(agent); + XMLHandler xmlHandler = new XMLXMLHandler(); userAgent.getXMLHandlerRegistry().addXMLHandler(xmlHandler); Boolean b = (Boolean)userAgent.getRendererOptions().get("compact-format"); diff --git a/src/java/org/apache/fop/render/xml/XMLRendererMaker.java b/src/java/org/apache/fop/render/xml/XMLRendererMaker.java index f54c74b32..8526daa2a 100644 --- a/src/java/org/apache/fop/render/xml/XMLRendererMaker.java +++ b/src/java/org/apache/fop/render/xml/XMLRendererMaker.java @@ -35,7 +35,7 @@ public class XMLRendererMaker extends AbstractRendererMaker { /**{@inheritDoc} */ public Renderer makeRenderer(FOUserAgent userAgent) { - return new XMLRenderer(userAgent); + return new XMLRenderer(); } /**{@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java index 246062a32..63f486c07 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java @@ -26,22 +26,19 @@ import java.io.IOException; import java.io.OutputStream; import java.io.Writer; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; - import org.apache.batik.dom.GenericDOMImplementation; import org.apache.batik.svggen.SVGGeneratorContext; import org.apache.batik.svggen.SVGGraphics2D; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; import org.apache.fop.area.PageViewport; import org.apache.fop.render.bitmap.MultiFileRenderingUtil; import org.apache.fop.render.java2d.Java2DGraphicsState; import org.apache.fop.render.java2d.Java2DRenderer; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; /** *@@ -70,8 +67,8 @@ public class SVGRenderer extends Java2DRenderer { /** Helper class for generating multiple files */ private MultiFileRenderingUtil multiFileUtil; - public SVGRenderer(FOUserAgent userAgent) { - super(userAgent); + /** Default constructor. */ + public SVGRenderer() { } /** {@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java b/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java index 892d01711..f0da974e6 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java @@ -34,7 +34,7 @@ public class SVGRendererMaker extends AbstractRendererMaker { /** {@inheritDoc} */ public Renderer makeRenderer(FOUserAgent ua) { - return new SVGRenderer(ua); + return new SVGRenderer(); } /** {@inheritDoc} */ diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index 490486158..97d1c9c25 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -39,21 +39,19 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.junit.BeforeClass; -import org.junit.Test; -import org.w3c.dom.Document; - import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.xpath.XPathAPI; -import org.apache.xpath.objects.XObject; - import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.fop.apps.MimeConstants; import org.apache.fop.render.xml.XMLRenderer; +import org.apache.xpath.XPathAPI; +import org.apache.xpath.objects.XObject; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; /** * Tests URI resolution facilities. @@ -162,7 +160,8 @@ public class URIResolutionTestCase extends AbstractFOPTest { TransformerHandler athandler = tfactory.newTransformerHandler(); athandler.setResult(domres); - XMLRenderer atrenderer = new XMLRenderer(ua); + XMLRenderer atrenderer = new XMLRenderer(); + atrenderer.setUserAgent(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); diff --git a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java index 1f8abb9be..a0de2e8ab 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -97,9 +97,10 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTest { Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( userAgent, getTargetMIME()); - XMLRenderer renderer = new XMLRenderer(userAgent); + XMLRenderer renderer = new XMLRenderer(); renderer.mimicRenderer(targetRenderer); renderer.setContentHandler(handler); + renderer.setUserAgent(userAgent); userAgent.setRendererOverride(renderer); @@ -130,10 +131,12 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTest { TransformerHandler handler = testAssistant.getTransformerFactory().newTransformerHandler(); DOMResult domResult = new DOMResult(); handler.setResult(domResult); + XMLRenderer renderer = new XMLRenderer(); + renderer.setContentHandler(handler); + FOUserAgent userAgent = createUserAgent(); - XMLRenderer renderer = new XMLRenderer(userAgent); userAgent.setRendererOverride(renderer); - renderer.setContentHandler(handler); + renderer.setUserAgent(userAgent); FontInfo fontInfo = new FontInfo(); AreaTreeModel treeModel = new RenderPagesModel(userAgent, diff --git a/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java index 6a0d424e9..46908a448 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java @@ -150,7 +150,8 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - XMLRenderer atrenderer = new XMLRenderer(ua); + XMLRenderer atrenderer = new XMLRenderer(); + atrenderer.setUserAgent(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); fop = effFactory.newFop(ua); @@ -207,7 +208,8 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - IFRenderer ifRenderer = new IFRenderer(ua); + IFRenderer ifRenderer = new IFRenderer(); + ifRenderer.setUserAgent(ua); IFSerializer serializer = new IFSerializer(); serializer.setContext(new IFContext(ua));