//Set up a custom user agent so we can supply our own renderer instance
FOUserAgent userAgent = fopFactory.newFOUserAgent();
- PageableRenderer renderer = new PageableRenderer(userAgent);
+ PageableRenderer renderer = new PageableRenderer();
+ renderer.setUserAgent(userAgent);
userAgent.setRendererOverride(renderer);
// Construct FOP with desired output format
userAgent, MimeConstants.MIME_PDF);
//Create the XMLRenderer to create the area tree XML
- XMLRenderer xmlRenderer = new XMLRenderer(userAgent);
+ XMLRenderer xmlRenderer = new XMLRenderer();
+ xmlRenderer.setUserAgent(userAgent);
//Tell the XMLRenderer to mimic the target renderer
xmlRenderer.mimicRenderer(targetRenderer);
System.err.println("Couldn't set system look & feel!");
}
- AWTRenderer renderer = new AWTRenderer(foUserAgent, inputHandler, true, true);
+ AWTRenderer renderer = new AWTRenderer(true);
+ renderer.setRenderable(inputHandler); //set before user agent!
+ renderer.setUserAgent(foUserAgent);
foUserAgent.setRendererOverride(renderer);
} else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)
&& mimicRenderer != null) {
// render from FO to Intermediate Format
Renderer targetRenderer = foUserAgent.getRendererFactory().createRenderer(
foUserAgent, mimicRenderer);
- XMLRenderer xmlRenderer = new XMLRenderer(foUserAgent);
+ XMLRenderer xmlRenderer = new XMLRenderer();
+ xmlRenderer.setUserAgent(foUserAgent);
//Tell the XMLRenderer to mimic the target renderer
xmlRenderer.mimicRenderer(targetRenderer);
import org.apache.xmlgraphics.util.QName;
import org.apache.xmlgraphics.util.UnitConv;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
*/
public abstract class AbstractPathOrientedRenderer extends PrintRenderer {
- public AbstractPathOrientedRenderer(FOUserAgent userAgent) {
- super(userAgent);
- }
-
/**
* Handle block traits.
* The block could be any sort of block with any positioning
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.fonts.FontInfo;
/** {@inheritDoc} */
public abstract void setupFontInfo(FontInfo fontInfo) throws FOPException;
- /**
- *
- * @param userAgent the user agent that contains configuration details. This cannot be null.
- */
- public AbstractRenderer(FOUserAgent userAgent) {
- this.userAgent = userAgent;
+ /** {@inheritDoc} */
+ public void setUserAgent(FOUserAgent agent) {
+ userAgent = agent;
}
/** {@inheritDoc} */
public FOUserAgent getUserAgent() {
+ if (userAgent == null) {
+ throw new IllegalStateException("FOUserAgent has not been set on Renderer");
+ }
return userAgent;
}
import org.w3c.dom.Document;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.Area;
import org.apache.fop.area.Trait;
import org.apache.fop.fonts.CustomFontCollection;
/** Abstract base class of "Print" type renderers. */
public abstract class PrintRenderer extends AbstractRenderer {
- public PrintRenderer(FOUserAgent userAgent) {
- super(userAgent);
- }
-
/** Font configuration */
protected FontInfo fontInfo;
void stopRenderer()
throws IOException;
+ /**
+ * Set the User Agent.
+ *
+ * @param agent The User Agent
+ */
+ void setUserAgent(FOUserAgent agent);
+
/**
* Returns the associated user agent.
* @return the user agent
AbstractRendererMaker maker = getRendererMaker(outputFormat);
if (maker != null) {
Renderer rend = maker.makeRenderer(userAgent);
+ rend.setUserAgent(userAgent);
RendererConfigurator configurator = maker.getConfigurator(userAgent);
if (configurator != null) {
configurator.configure(rend);
}
private Renderer createRendererForDocumentHandler(IFDocumentHandler documentHandler) {
- IFRenderer rend = new IFRenderer(documentHandler.getContext().getUserAgent());
+ IFRenderer rend = new IFRenderer();
+ rend.setUserAgent(documentHandler.getContext().getUserAgent());
rend.setDocumentHandler(documentHandler);
return rend;
}
/** flag for debugging */
public boolean debug; // CSOK: VisibilityModifier
+ /** If true, preview dialog is shown. */
+ public boolean dialogDisplay = true; // CSOK: VisibilityModifier
+
+ /** true if the preview dialog should be the main window of the application */
+ private boolean previewAsMainWindow;
+
+ /**
+ * Renderable instance that can be used to reload and re-render a document after
+ * modifications.
+ */
+ protected Renderable renderable;
+
/**
* Will be notified when rendering progresses
*/
/**
* Creates a new AWTRenderer instance.
- *
- * @param userAgent the user agent that contains configuration data
*/
- public AWTRenderer(FOUserAgent userAgent) {
- this(userAgent, null, false, false);
+ public AWTRenderer() {
+ this(false);
}
/**
* Creates a new AWTRenderer instance.
- *
- * @param userAgent the user agent that contains configuration data
- * @param renderable a Renderable instance can be set so the Preview Dialog can enable the
- * "Reload" button which causes the current document to be reprocessed and redisplayed.
* @param previewAsMainWindow true if the preview dialog created by the renderer should be
- * the main window of the application.
- * @param show sets whether the preview dialog should be created and displayed when the
- * rendering has finished.
+ * the main window of the application.
*/
- public AWTRenderer(FOUserAgent userAgent, Renderable renderable, boolean previewAsMainWindow,
- boolean show) {
- super(userAgent);
- if (show) {
- // MH: Not sure about this??? If show is false, there's no way for this class
- // to create a preview dialog... Previously a "setUserAgent" could be called.
- setStatusListener(PreviewDialog.createPreviewDialog(userAgent, renderable,
- previewAsMainWindow));
+ public AWTRenderer(boolean previewAsMainWindow) {
+ this.previewAsMainWindow = previewAsMainWindow;
+ }
+
+ /** {@inheritDoc} */
+ public void setUserAgent(FOUserAgent foUserAgent) {
+ super.setUserAgent(foUserAgent);
+ if (dialogDisplay) {
+ setStatusListener(PreviewDialog.createPreviewDialog(userAgent, this.renderable,
+ this.previewAsMainWindow));
}
}
+ /**
+ * A Renderable instance can be set so the Preview Dialog can enable the "Reload" button
+ * which causes the current document to be reprocessed and redisplayed.
+ * @param renderable the Renderable instance.
+ */
+ public void setRenderable(Renderable renderable) {
+ this.renderable = renderable;
+ }
+
+ /**
+ * Sets whether the preview dialog should be created and displayed when
+ * the rendering is finished.
+ * @param show If false, preview dialog is not shown. True by default
+ */
+ public void setPreviewDialogDisplayed(boolean show) {
+ dialogDisplay = show;
+ }
+
/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public Renderer makeRenderer(FOUserAgent ua) {
- return new AWTRenderer(ua);
+ return new AWTRenderer();
}
/** {@inheritDoc} */
* </p>
* <pre>
* 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);
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;
*/
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;
/** {@inheritDoc} */
public Renderer makeRenderer(FOUserAgent ua) {
- return new PNGRenderer(ua);
+ return new PNGRenderer();
}
/** {@inheritDoc} */
}
/** 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);
}
/** {@inheritDoc} */
public Renderer makeRenderer(FOUserAgent userAgent) {
- return new TIFFRenderer(userAgent);
+ return new TIFFRenderer();
}
/** {@inheritDoc} */
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;
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;
/**
* Main constructor
*/
- public IFRenderer(FOUserAgent userAgent) {
- super(userAgent);
+ public IFRenderer() {
}
/** {@inheritDoc} */
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);
}
/**
* Creates a new PageableRenderer.
*/
- public PageableRenderer(FOUserAgent userAgent) {
- super(userAgent);
- Map rendererOptions = getUserAgent().getRendererOptions();
- processOptions(rendererOptions);
- this.pageFilter = new DefaultPageFilter();
+ public PageableRenderer() {
}
/** {@inheritDoc} */
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) {
* 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() {
}
}
- 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) {
/**{@inheritDoc} */
public Renderer makeRenderer(FOUserAgent userAgent) {
- return new PrintRenderer(userAgent);
+ return new PrintRenderer();
}
/** {@inheritDoc} */
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;
/**
* Constructs a newly allocated <code>TXTRenderer</code> object.
*/
- public TXTRenderer(FOUserAgent userAgent) {
- super(userAgent);
+ public TXTRenderer() {
}
/** {@inheritDoc} */
/**{@inheritDoc} */
public Renderer makeRenderer(FOUserAgent userAgent) {
- return new TXTRenderer(userAgent);
+ return new TXTRenderer();
}
/**{@inheritDoc} */
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;
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 = "";
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;
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;
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");
/**{@inheritDoc} */
public Renderer makeRenderer(FOUserAgent userAgent) {
- return new XMLRenderer(userAgent);
+ return new XMLRenderer();
}
/**{@inheritDoc} */
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;
/**
* <p>
/** Helper class for generating multiple files */
private MultiFileRenderingUtil multiFileUtil;
- public SVGRenderer(FOUserAgent userAgent) {
- super(userAgent);
+ /** Default constructor. */
+ public SVGRenderer() {
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public Renderer makeRenderer(FOUserAgent ua) {
- return new SVGRenderer(ua);
+ return new SVGRenderer();
}
/** {@inheritDoc} */
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.
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);
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);
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,
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);
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));