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 3733bf2f2..1c6f2e33d 100644 --- a/src/java/org/apache/fop/render/bitmap/PNGRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/PNGRenderer.java @@ -29,6 +29,7 @@ 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; @@ -40,6 +41,10 @@ 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 7d321791a..da19b2986 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(); + return new PNGRenderer(ua); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java index 5a9cfa21b..0e2364d35 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFRenderer.java @@ -83,19 +83,11 @@ public class TIFFRenderer extends Java2DRenderer implements TIFFConstants { } /** Creates TIFF renderer. */ - public TIFFRenderer() { + public TIFFRenderer(FOUserAgent userAgent) { + super(userAgent); 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 e3c567995..852e6ba04 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(); + return new TIFFRenderer(userAgent); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index 24a2e8a75..d5d5a154a 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -51,6 +51,7 @@ 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; @@ -70,10 +71,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; @@ -158,7 +159,8 @@ public class IFRenderer extends AbstractPathOrientedRenderer { /** * Main constructor */ - public IFRenderer() { + public IFRenderer(FOUserAgent userAgent) { + super(userAgent); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 766aa081f..3c7006588 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -147,15 +147,13 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem private GeneralPath currentPath = null; /** Default constructor */ - public Java2DRenderer() { - } + public Java2DRenderer(FOUserAgent userAgent) { + super(userAgent); - /** {@inheritDoc} */ - public void setUserAgent(FOUserAgent foUserAgent) { - super.setUserAgent(foUserAgent); + // MH: necessary? the caller has access to 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 89ab98071..08d5b0f04 100644 --- a/src/java/org/apache/fop/render/print/PageableRenderer.java +++ b/src/java/org/apache/fop/render/print/PageableRenderer.java @@ -73,7 +73,11 @@ public class PageableRenderer extends Java2DRenderer implements Pageable { /** * Creates a new PageableRenderer. */ - public PageableRenderer() { + public PageableRenderer(FOUserAgent userAgent) { + super(userAgent); + Map rendererOptions = getUserAgent().getRendererOptions(); + processOptions(rendererOptions); + this.pageFilter = new DefaultPageFilter(); } /** {@inheritDoc} */ @@ -81,15 +85,6 @@ 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 2eb2b07a2..ea68bc9b2 100644 --- a/src/java/org/apache/fop/render/print/PrintRenderer.java +++ b/src/java/org/apache/fop/render/print/PrintRenderer.java @@ -55,19 +55,9 @@ 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() { - } - - /** - * 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); + public PrintRenderer(FOUserAgent userAgent) { + super(userAgent); + setRendererOptions(); } private void initializePrinterJob() { @@ -85,11 +75,8 @@ public class PrintRenderer extends PageableRenderer { } } - /** {@inheritDoc} */ - public void setUserAgent(FOUserAgent agent) { - super.setUserAgent(agent); - - Map rendererOptions = agent.getRendererOptions(); + private void setRendererOptions() { + Map rendererOptions = getUserAgent().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 21eb4717a..63444a628 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(); + return new PrintRenderer(userAgent); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java index 386f95838..74c5b84a8 100644 --- a/src/java/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java @@ -32,6 +32,7 @@ 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; @@ -110,7 +111,8 @@ public class TXTRenderer extends AbstractPathOrientedRenderer { /** * Constructs a newly allocatedTXTRenderer
object. */ - public TXTRenderer() { + public TXTRenderer(FOUserAgent userAgent) { + super(userAgent); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/txt/TXTRendererMaker.java b/src/java/org/apache/fop/render/txt/TXTRendererMaker.java index 0db369ef2..740866e0c 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(); + return new TXTRenderer(userAgent); } /**{@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java index 497e3c047..9c938199f 100644 --- a/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/AbstractXMLRenderer.java @@ -29,6 +29,15 @@ 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; @@ -36,16 +45,14 @@ 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 21d28042d..3ae49b121 100644 --- a/src/java/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/java/org/apache/fop/render/xml/XMLRenderer.java @@ -37,7 +37,6 @@ 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; @@ -75,11 +74,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; @@ -113,20 +112,9 @@ public class XMLRenderer extends AbstractXMLRenderer { private int pageSequenceIndex; - /** - * Creates a new XML renderer. - */ - public XMLRenderer() { + public XMLRenderer(FOUserAgent userAgent) { + super(userAgent); 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 8526daa2a..f54c74b32 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(); + return new XMLRenderer(userAgent); } /**{@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java index 63f486c07..246062a32 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGRenderer.java @@ -26,19 +26,22 @@ 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; /** *@@ -67,8 +70,8 @@ public class SVGRenderer extends Java2DRenderer { /** Helper class for generating multiple files */ private MultiFileRenderingUtil multiFileUtil; - /** Default constructor. */ - public SVGRenderer() { + public SVGRenderer(FOUserAgent userAgent) { + super(userAgent); } /** {@inheritDoc} */ diff --git a/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java b/src/sandbox/org/apache/fop/render/svg/SVGRendererMaker.java index f0da974e6..892d01711 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(); + return new SVGRenderer(ua); } /** {@inheritDoc} */ diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java index 97d1c9c25..490486158 100644 --- a/test/java/org/apache/fop/URIResolutionTestCase.java +++ b/test/java/org/apache/fop/URIResolutionTestCase.java @@ -39,19 +39,21 @@ 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. @@ -160,8 +162,7 @@ public class URIResolutionTestCase extends AbstractFOPTest { TransformerHandler athandler = tfactory.newTransformerHandler(); athandler.setResult(domres); - XMLRenderer atrenderer = new XMLRenderer(); - atrenderer.setUserAgent(ua); + XMLRenderer atrenderer = new XMLRenderer(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 a0de2e8ab..1f8abb9be 100644 --- a/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java @@ -97,10 +97,9 @@ public class AreaTreeParserTestCase extends AbstractIntermediateTest { Renderer targetRenderer = userAgent.getRendererFactory().createRenderer( userAgent, getTargetMIME()); - XMLRenderer renderer = new XMLRenderer(); + XMLRenderer renderer = new XMLRenderer(userAgent); renderer.mimicRenderer(targetRenderer); renderer.setContentHandler(handler); - renderer.setUserAgent(userAgent); userAgent.setRendererOverride(renderer); @@ -131,12 +130,10 @@ 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.setUserAgent(userAgent); + renderer.setContentHandler(handler); 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 46908a448..6a0d424e9 100644 --- a/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java +++ b/test/java/org/apache/fop/layoutengine/LayoutEngineTestCase.java @@ -150,8 +150,7 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - XMLRenderer atrenderer = new XMLRenderer(); - atrenderer.setUserAgent(ua); + XMLRenderer atrenderer = new XMLRenderer(ua); atrenderer.setContentHandler(athandler); ua.setRendererOverride(atrenderer); fop = effFactory.newFop(ua); @@ -208,8 +207,7 @@ public class LayoutEngineTestCase { ua.getEventBroadcaster().addEventListener( new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN)); - IFRenderer ifRenderer = new IFRenderer(); - ifRenderer.setUserAgent(ua); + IFRenderer ifRenderer = new IFRenderer(ua); IFSerializer serializer = new IFSerializer(); serializer.setContext(new IFContext(ua));