private Renderer createRendererForDocumentHandler(IFDocumentHandler documentHandler) {
IFRenderer rend = new IFRenderer();
- rend.setUserAgent(documentHandler.getUserAgent());
+ rend.setUserAgent(documentHandler.getContext().getUserAgent());
rend.setDocumentHandler(documentHandler);
return rend;
}
import org.apache.xmlgraphics.image.writer.ImageWriterRegistry;
import org.apache.xmlgraphics.image.writer.MultiImageWriter;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactoryConfigurator;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
}
/** {@inheritDoc} */
- public void setUserAgent(FOUserAgent ua) {
- super.setUserAgent(ua);
+ public void setContext(IFContext context) {
+ super.setContext(context);
//Set target resolution
- int dpi = Math.round(ua.getTargetResolution());
+ int dpi = Math.round(context.getUserAgent().getTargetResolution());
getSettings().getWriterParams().setResolution(dpi);
}
RenderingHints.VALUE_STROKE_PURE);
graphics2D.scale(scale / 1000f, scale / 1000f);
- return new Java2DPainter(graphics2D, getUserAgent(), getFontInfo());
+ return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}
/**
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/** {@inheritDoc} */
public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
TIFFDocumentHandler handler = new TIFFDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
return handler;
}
/** logging instance */
private static Log log = LogFactory.getLog(AbstractIFDocumentHandler.class);
- private FOUserAgent userAgent;
+ private IFContext ifContext;
/**
* Default constructor.
}
/** {@inheritDoc} */
- public void setUserAgent(FOUserAgent ua) {
- if (this.userAgent != null) {
- throw new IllegalStateException("The user agent was already set");
- }
- this.userAgent = ua;
+ public void setContext(IFContext context) {
+ this.ifContext = context;
}
/** {@inheritDoc} */
+ public IFContext getContext() {
+ return this.ifContext;
+ }
+
+ /**
+ * Returns the associated user agent.
+ * @return the user agent
+ */
public FOUserAgent getUserAgent() {
- return this.userAgent;
+ return getContext().getUserAgent();
}
/** {@inheritDoc} */
public AbstractIFPainter() {
}
+ /**
+ * Returns the intermediate format context object.
+ * @return the context object
+ */
+ protected abstract IFContext getContext();
+
/**
* Returns the user agent.
* @return the user agent
*/
- protected abstract FOUserAgent getUserAgent();
+ protected FOUserAgent getUserAgent() {
+ return getContext().getUserAgent();
+ }
/**
* Returns the FOP factory.
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.xmlgraphics.util.QName;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * This class provides a context object that is valid for a single processing run to create
+ * an output file using the intermediate format. It allows access to the user agent and other
+ * context information, such as foreign attributes for certain elements in the intermediate
+ * format.
+ * <p>
+ * Foreign attributes are usually specific to a particular output format implementation. Most
+ * implementations will just ignore all foreign attributes for most elements. That's why the
+ * main IF interfaces are not burdened with this.
+ */
+public class IFContext {
+
+ private FOUserAgent userAgent;
+
+ /** foreign attributes: Map<QName, Object> */
+ private Map foreignAttributes = Collections.EMPTY_MAP;
+
+ /**
+ * Main constructor.
+ * @param ua the user agent
+ */
+ public IFContext(FOUserAgent ua) {
+ setUserAgent(ua);
+ }
+
+ /**
+ * Set the user agent.
+ * @param ua the user agent
+ */
+ public void setUserAgent(FOUserAgent ua) {
+ if (this.userAgent != null) {
+ throw new IllegalStateException("The user agent was already set");
+ }
+ this.userAgent = ua;
+ }
+
+ /**
+ * Returns the associated user agent.
+ * @return the user agent
+ */
+ public FOUserAgent getUserAgent() {
+ return this.userAgent;
+ }
+
+ /**
+ * Returns the currently applicable foreign attributes.
+ * @return a Map<QName, Object>
+ */
+ public Map getForeignAttributes() {
+ return this.foreignAttributes;
+ }
+
+ /**
+ * Returns a foreign attribute.
+ * @param qName the qualified name of the foreign attribute
+ * @return the value of the foreign attribute or null if the attribute isn't specified
+ */
+ public Object getForeignAttribute(QName qName) {
+ return this.foreignAttributes.get(qName);
+ }
+
+ /**
+ * Sets the currently applicable foreign attributes.
+ * @param foreignAttributes a Map<QName, Object> or null to reset
+ */
+ public void setForeignAttributes(Map foreignAttributes) {
+ if (foreignAttributes != null) {
+ this.foreignAttributes = foreignAttributes;
+ } else {
+ //Make sure there is always at least an empty map so we don't have to check
+ //in the implementation code
+ this.foreignAttributes = Collections.EMPTY_MAP;
+ }
+ }
+
+ /**
+ * Resets the foreign attributes to "no foreign attributes".
+ */
+ public void resetForeignAttributes() {
+ setForeignAttributes(null);
+ }
+
+}
import javax.xml.transform.Result;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.FontInfo;
/**
public interface IFDocumentHandler {
/**
- * Set the user agent.
- * @param userAgent The user agent
+ * Sets the intermediate format context object.
+ * @param context the context object
*/
- void setUserAgent(FOUserAgent userAgent);
+ void setContext(IFContext context);
/**
- * Returns the associated user agent.
- * @return the user agent
+ * Returns the associated intermediate format context object.
+ * @return the context object
*/
- FOUserAgent getUserAgent();
+ IFContext getContext();
/**
* Sets the JAXP Result object to receive the generated content.
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
-import java.util.Map;
import org.w3c.dom.Document;
* an fo:external-graphic in XSL-FO.
* @param uri the image's URI
* @param rect the rectangle in which the image shall be painted
- * @param foreignAttributes a optional Map with foreign attributes (Map<QName,String>)
* @throws IFException if an error occurs while handling this event
*/
- void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException;
+ void drawImage(String uri, Rectangle rect) throws IFException;
/**
* Draws an image (represented by a DOM document) inside a given rectangle. This is the
* equivalent to an fo:instream-foreign-object in XSL-FO.
* @param doc the DOM document containing the foreign object
* @param rect the rectangle in which the image shall be painted
- * @param foreignAttributes a optional Map with foreign attributes (Map<QName,String>)
* @throws IFException if an error occurs while handling this event
*/
- void drawImage(Document doc, Rectangle rect, Map foreignAttributes)
- throws IFException;
+ void drawImage(Document doc, Rectangle rect) throws IFException;
//Note: For now, all foreign objects are handled as DOM documents. At the moment, all known
//implementations use a DOM anyway, so optimizing this to work with SAX wouldn't result in
//any performance benefits. The IFRenderer itself has a DOM anyway. Only the IFParser could
elementHandlers.put(EL_IMAGE, new ImageHandler());
}
+ private void establishForeignAttributes(Map foreignAttributes) {
+ documentHandler.getContext().setForeignAttributes(foreignAttributes);
+ }
+
+ private void resetForeignAttributes() {
+ documentHandler.getContext().resetForeignAttributes();
+ }
/** {@inheritDoc} */
public void startElement(String uri, String localName, String qName, Attributes attributes)
String pageMasterName = attributes.getValue("page-master-name");
int width = Integer.parseInt(attributes.getValue("width"));
int height = Integer.parseInt(attributes.getValue("height"));
- documentHandler.startPage(index, name, pageMasterName, new Dimension(width, height));
+ Map foreignAttributes = getForeignAttributes(lastAttributes);
+ establishForeignAttributes(foreignAttributes);
+ documentHandler.startPage(index, name, pageMasterName,
+ new Dimension(width, height));
+ resetForeignAttributes();
}
public void endElement() throws IFException {
int width = Integer.parseInt(lastAttributes.getValue("width"));
int height = Integer.parseInt(lastAttributes.getValue("height"));
Map foreignAttributes = getForeignAttributes(lastAttributes);
+ establishForeignAttributes(foreignAttributes);
if (foreignObject != null) {
painter.drawImage(foreignObject,
- new Rectangle(x, y, width, height), foreignAttributes);
+ new Rectangle(x, y, width, height));
foreignObject = null;
} else {
String uri = lastAttributes.getValue(
if (uri == null) {
throw new IFException("xlink:href is missing on image", null);
}
- painter.drawImage(uri, new Rectangle(x, y, width, height), foreignAttributes);
+ painter.drawImage(uri, new Rectangle(x, y, width, height));
}
+ resetForeignAttributes();
inForeignObject = false;
}
*/
protected IFDocumentHandler createDefaultDocumentHandler() {
IFSerializer serializer = new IFSerializer();
- serializer.setUserAgent(getUserAgent());
+ serializer.setContext(new IFContext(getUserAgent()));
return serializer;
}
Dimension dim = new Dimension(
(int)Math.ceil(viewArea.getWidth()),
(int)Math.ceil(viewArea.getHeight()));
+
+ establishForeignAttributes(page.getForeignAttributes());
documentHandler.startPage(page.getPageIndex(), page.getPageNumberString(),
page.getSimplePageMasterName(), dim);
+ resetForeignAttributes();
documentHandler.startPageHeader();
//Add page attachments to page header
}
documentHandler.endPageTrailer();
+ establishForeignAttributes(page.getForeignAttributes());
documentHandler.endPage();
+ resetForeignAttributes();
} catch (IFException e) {
handleIFException(e);
}
}
+ private void establishForeignAttributes(Map foreignAttributes) {
+ documentHandler.getContext().setForeignAttributes(foreignAttributes);
+ }
+
+ private void resetForeignAttributes() {
+ documentHandler.getContext().resetForeignAttributes();
+ }
+
/** {@inheritDoc} */
protected void saveGraphicsState() {
graphicContextStack.push(graphicContext);
(int)pos.getHeight());
uri = URISpecification.getURL(uri);
try {
- painter.drawImage(uri, posInt, foreignAttributes);
+ establishForeignAttributes(foreignAttributes);
+ painter.drawImage(uri, posInt);
+ resetForeignAttributes();
} catch (IFException ife) {
handleIFException(ife);
}
(int)pos.getHeight());
Document doc = fo.getDocument();
try {
- painter.drawImage(doc, posInt, fo.getForeignAttributes());
+ establishForeignAttributes(fo.getForeignAttributes());
+ painter.drawImage(doc, posInt);
+ resetForeignAttributes();
} catch (IFException ife) {
handleIFException(ife);
}
addAttribute(atts, "page-master-name", pageMasterName);
addAttribute(atts, "width", Integer.toString(size.width));
addAttribute(atts, "height", Integer.toString(size.height));
+ addForeignAttributes(atts);
handler.startElement(EL_PAGE, atts);
} catch (SAXException e) {
throw new IFException("SAX error in startPage()", e);
public void startPageTrailer() throws IFException {
try {
handler.startElement(EL_PAGE_TRAILER);
- commitNavigation();
} catch (SAXException e) {
throw new IFException("SAX error in startPageTrailer()", e);
}
/** {@inheritDoc} */
public void endPageTrailer() throws IFException {
try {
+ commitNavigation();
handler.endElement(EL_PAGE_TRAILER);
} catch (SAXException e) {
throw new IFException("SAX error in endPageTrailer()", e);
}
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(String uri, Rectangle rect) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
addAttribute(atts, XLINK_HREF, uri);
addAttribute(atts, "y", Integer.toString(rect.y));
addAttribute(atts, "width", Integer.toString(rect.width));
addAttribute(atts, "height", Integer.toString(rect.height));
- if (foreignAttributes != null) {
- Iterator iter = foreignAttributes.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry)iter.next();
- addAttribute(atts, (QName)entry.getKey(), entry.getValue().toString());
- }
- }
+ addForeignAttributes(atts);
handler.element(EL_IMAGE, atts);
} catch (SAXException e) {
throw new IFException("SAX error in startGroup()", e);
}
}
+ private void addForeignAttributes(AttributesImpl atts) {
+ Map foreignAttributes = getContext().getForeignAttributes();
+ if (!foreignAttributes.isEmpty()) {
+ Iterator iter = foreignAttributes.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ addAttribute(atts, (QName)entry.getKey(), entry.getValue().toString());
+ }
+ }
+ }
+
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
try {
AttributesImpl atts = new AttributesImpl();
addAttribute(atts, "x", Integer.toString(rect.x));
addAttribute(atts, "y", Integer.toString(rect.y));
addAttribute(atts, "width", Integer.toString(rect.width));
addAttribute(atts, "height", Integer.toString(rect.height));
- if (foreignAttributes != null) {
- Iterator iter = foreignAttributes.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry)iter.next();
- addAttribute(atts, (QName)entry.getKey(), entry.getValue().toString());
- }
- }
+ addForeignAttributes(atts);
handler.startElement(EL_IMAGE, atts);
new DOM2SAX(handler).writeDocument(doc, true);
handler.endElement(EL_IMAGE);
addAttribute(atts, "x2", Integer.toString(end.x));
addAttribute(atts, "y2", Integer.toString(end.y));
addAttribute(atts, "stroke-width", Integer.toString(width));
- addAttribute(atts, "color", Integer.toString(width));
+ addAttribute(atts, "color", ColorUtil.colorToString(color));
addAttribute(atts, "style", style.getName());
handler.element(EL_LINE, atts);
} catch (SAXException e) {
public void addResolvedAction(AbstractAction action) throws IFException {
assert action.isComplete();
assert action.hasID();
- AbstractAction noted = (AbstractAction)incompleteActions.get(action.getID());
+ AbstractAction noted = (AbstractAction)incompleteActions.remove(action.getID());
if (noted != null) {
- incompleteActions.remove(action.getID());
completeActions.add(action);
} else {
//ignore as it was already complete when it was first used.
Link link = new Link(null, targetRect);
objectStack.push(link);
} else if (GOTO_XY.getLocalName().equals(localName)) {
- String id = attributes.getValue("id");
- int pageIndex = XMLUtil.getAttributeAsInt(attributes, "page-index");
- int x = XMLUtil.getAttributeAsInt(attributes, "x");
- int y = XMLUtil.getAttributeAsInt(attributes, "y");
- GoToXYAction action = new GoToXYAction(id, pageIndex, new Point(x, y));
+ String idref = attributes.getValue("idref");
+ GoToXYAction action;
+ if (idref != null) {
+ action = new GoToXYAction(idref);
+ } else {
+ String id = attributes.getValue("id");
+ int pageIndex = XMLUtil.getAttributeAsInt(attributes, "page-index");
+ int x = XMLUtil.getAttributeAsInt(attributes, "x");
+ int y = XMLUtil.getAttributeAsInt(attributes, "y");
+ action = new GoToXYAction(id, pageIndex, new Point(x, y));
+ }
objectStack.push(action);
} else if (GOTO_URI.getLocalName().equals(localName)) {
+ String id = attributes.getValue("id");
String gotoURI = attributes.getValue("uri");
String showDestination = attributes.getValue("show-destination");
boolean newWindow = "new".equals(showDestination);
URIAction action = new URIAction(gotoURI, newWindow);
+ if (id != null) {
+ action.setID(id);
+ }
objectStack.push(action);
} else {
throw new SAXException(
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.io.IOException;
-import java.util.Map;
import java.util.Stack;
import org.w3c.dom.Document;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.traits.BorderProps;
/** logging instance */
private static Log log = LogFactory.getLog(Java2DPainter.class);
- /** the FO user agent */
- protected FOUserAgent userAgent;
+ /** the IF context */
+ protected IFContext ifContext;
/** The font information */
protected FontInfo fontInfo;
/**
* Main constructor.
* @param g2d the target Graphics2D instance
- * @param userAgent the user agent
+ * @param context the IF context
* @param fontInfo the font information
*/
- public Java2DPainter(Graphics2D g2d, FOUserAgent userAgent, FontInfo fontInfo) {
- this(g2d, userAgent, fontInfo, null);
+ public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo) {
+ this(g2d, context, fontInfo, null);
}
/**
* Special constructor for embedded use (when another painter uses Java2DPainter
* to convert part of a document into a bitmap, for example).
* @param g2d the target Graphics2D instance
- * @param userAgent the user agent
+ * @param context the IF context
* @param fontInfo the font information
*/
- public Java2DPainter(Graphics2D g2d, FOUserAgent userAgent, FontInfo fontInfo, IFState state) {
+ public Java2DPainter(Graphics2D g2d, IFContext context, FontInfo fontInfo, IFState state) {
super();
- this.userAgent = userAgent;
+ this.ifContext = context;
if (state != null) {
this.state = state.push();
} else {
}
/** {@inheritDoc} */
- public FOUserAgent getUserAgent() {
- return this.userAgent;
+ public IFContext getContext() {
+ return this.ifContext;
}
/**
}
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(String uri, Rectangle rect) throws IFException {
drawImageUsingURI(uri, rect);
}
}
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
drawImageUsingDocument(doc, rect);
}
import org.apache.xmlgraphics.util.UnitConv;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactoryConfigurator;
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.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
import org.apache.fop.render.java2d.Java2DPainter;
+import org.apache.fop.render.pcl.extensions.PCLElementMapping;
/**
* {@code IFDocumentHandler} implementation that produces PCL 5.
}
/** {@inheritDoc} */
- public void setUserAgent(FOUserAgent ua) {
- super.setUserAgent(ua);
- this.pclUtil = new PCLRenderingUtil(ua);
+ public void setContext(IFContext context) {
+ super.setContext(context);
+ this.pclUtil = new PCLRenderingUtil(context.getUserAgent());
}
/** {@inheritDoc} */
}
/** {@inheritDoc} */
- public void startPage(int index, String name, String pageMasterName, Dimension size) throws IFException {
+ public void startPage(int index, String name, String pageMasterName, Dimension size)
+ throws IFException {
try {
- //TODO Add support for paper-source and duplex-mode
- /*
//Paper source
- String paperSource = page.getForeignAttributeValue(
- new QName(PCLElementMapping.NAMESPACE, null, "paper-source"));
+ Object paperSource = getContext().getForeignAttribute(
+ PCLElementMapping.PCL_PAPER_SOURCE);
if (paperSource != null) {
- gen.selectPaperSource(Integer.parseInt(paperSource));
+ gen.selectPaperSource(Integer.parseInt(paperSource.toString()));
}
// Is Page duplex?
- String pageDuplex = page.getForeignAttributeValue(
- new QName(PCLElementMapping.NAMESPACE, null, "duplex-mode"));
+ Object pageDuplex = getContext().getForeignAttribute(
+ PCLElementMapping.PCL_DUPLEX_MODE);
if (pageDuplex != null) {
- gen.selectDuplexMode(Integer.parseInt(pageDuplex));
- }*/
+ gen.selectDuplexMode(Integer.parseInt(pageDuplex.toString()));
+ }
//Page size
final long pagewidth = size.width;
graphics2D.scale(scale / 1000f, scale / 1000f);
graphics2D.translate(-printArea.x, -printArea.y);
- return new Java2DPainter(graphics2D, getUserAgent(), getFontInfo());
+ return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}
private BufferedImage createBufferedImage(int bitmapWidth, int bitmapHeight) {
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/** {@inheritDoc} */
public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
PCLDocumentHandler handler = new PCLDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
return handler;
}
import org.apache.xmlgraphics.java2d.GraphicContext;
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.render.java2d.FontMetricsMapper;
/**
* Main constructor.
* @param parent the parent document handler
+ * @param pageDefinition the page definition describing the page to be rendered
*/
public PCLPainter(PCLDocumentHandler parent, PCLPageDefinition pageDefinition) {
this.parent = parent;
}
/** {@inheritDoc} */
- public FOUserAgent getUserAgent() {
- return this.parent.getUserAgent();
+ public IFContext getContext() {
+ return this.parent.getContext();
}
PCLRenderingUtil getPCLUtil() {
}
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
- drawImageUsingURI(uri, rect/*, foreignAttributes*/);
+ public void drawImage(String uri, Rectangle rect) throws IFException {
+ drawImageUsingURI(uri, rect);
}
/** {@inheritDoc} */
}
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
drawImageUsingDocument(doc, rect);
}
g2d.translate(-rect.x, -rect.y);
Java2DPainter painter = new Java2DPainter(g2d,
- getUserAgent(), parent.getFontInfo(), state);
+ getContext(), parent.getFontInfo(), state);
try {
painter.drawBorderRect(rect, before, after, start, end);
} catch (IFException e) {
g2d.translate(-boundingBox.x, -boundingBox.y);
Java2DPainter painter = new Java2DPainter(g2d,
- getUserAgent(), parent.getFontInfo(), state);
+ getContext(), parent.getFontInfo(), state);
try {
painter.drawLine(start, end, width, color, style);
} catch (IFException e) {
g2d.draw(rect);
}
Java2DPainter painter = new Java2DPainter(g2d,
- getUserAgent(), parent.getFontInfo(), state);
+ getContext(), parent.getFontInfo(), state);
try {
painter.drawText(x, y, dx, dy, text);
} catch (IFException e) {
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
import org.apache.xmlgraphics.java2d.GraphicContext;
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.apache.xmlgraphics.util.QName;
import org.apache.xmlgraphics.util.UnitConv;
import org.apache.fop.apps.FOPException;
saveGraphicsState();
//Paper source
- String paperSource = page.getForeignAttributeValue(
- new QName(PCLElementMapping.NAMESPACE, null, "paper-source"));
+ String paperSource = page.getForeignAttributeValue(PCLElementMapping.PCL_PAPER_SOURCE);
if (paperSource != null) {
gen.selectPaperSource(Integer.parseInt(paperSource));
}
// Is Page duplex?
- String pageDuplex = page.getForeignAttributeValue(
- new QName(PCLElementMapping.NAMESPACE, null, "duplex-mode"));
+ String pageDuplex = page.getForeignAttributeValue(PCLElementMapping.PCL_DUPLEX_MODE);
if (pageDuplex != null) {
gen.selectDuplexMode(Integer.parseInt(pageDuplex));
}
public Dimension getImageSize() {
return paintRect.getSize();
}
-
+
};
g2a.paintImage(painter, rc,
paintRect.x, paintRect.y, paintRect.width, paintRect.height);
import java.util.HashMap;
+import org.apache.xmlgraphics.util.QName;
+
import org.apache.fop.fo.ElementMapping;
/**
/** The usual namespace prefix used for PCL extensions */
public static final String NAMESPACE_PREFIX = "pcl";
+ /** The extension attribute for the PCL paper source */
+ public static final QName PCL_PAPER_SOURCE
+ = new QName(PCLElementMapping.NAMESPACE, null, "paper-source");
+
+ /** The extension attribute for the PCL duplex mode */
+ public static final QName PCL_DUPLEX_MODE
+ = new QName(PCLElementMapping.NAMESPACE, null, "duplex-mode");
+
/** Main constructor */
public PCLElementMapping() {
this.namespaceURI = NAMESPACE;
import org.apache.xmlgraphics.xmp.Metadata;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fo.extensions.xmp.XMPMetadata;
import org.apache.fop.pdf.PDFAnnotList;
import org.apache.fop.pdf.PDFResourceContext;
import org.apache.fop.pdf.PDFResources;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
import org.apache.fop.render.intermediate.IFException;
}
/** {@inheritDoc} */
- public void setUserAgent(FOUserAgent ua) {
- super.setUserAgent(ua);
- this.pdfUtil = new PDFRenderingUtil(ua);
+ public void setContext(IFContext context) {
+ super.setContext(context);
+ this.pdfUtil = new PDFRenderingUtil(context.getUserAgent());
}
/** {@inheritDoc} */
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/** {@inheritDoc} */
public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
PDFDocumentHandler handler = new PDFDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
return handler;
}
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.io.IOException;
-import java.util.Map;
import org.w3c.dom.Document;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.pdf.PDFXObject;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.traits.BorderProps;
}
/** {@inheritDoc} */
- protected FOUserAgent getUserAgent() {
- return this.documentHandler.getUserAgent();
+ protected IFContext getContext() {
+ return this.documentHandler.getContext();
}
PDFRenderingUtil getPDFUtil() {
}
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(String uri, Rectangle rect) throws IFException {
PDFXObject xobject = getPDFDoc().getXObject(uri);
if (xobject != null) {
placeImage(rect, xobject);
}
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
drawImageUsingDocument(doc, rect);
flushPDFDoc();
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.fonts.LazyFont;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
}
/** {@inheritDoc} */
- public void setUserAgent(FOUserAgent ua) {
- super.setUserAgent(ua);
- this.psUtil = new PSRenderingUtil(ua);
+ public void setContext(IFContext context) {
+ super.setContext(context);
+ this.psUtil = new PSRenderingUtil(context.getUserAgent());
}
/** {@inheritDoc} */
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/** {@inheritDoc} */
public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
PSDocumentHandler handler = new PSDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
return handler;
}
import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSResource;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.traits.BorderProps;
}
/** {@inheritDoc} */
- protected FOUserAgent getUserAgent() {
- return this.documentHandler.getUserAgent();
+ protected IFContext getContext() {
+ return this.documentHandler.getContext();
}
PSRenderingUtil getPSUtil() {
}
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(String uri, Rectangle rect) throws IFException {
try {
endTextObject();
} catch (IOException ioe) {
}
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
try {
endTextObject();
} catch (IOException ioe) {
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/** {@inheritDoc} */
public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
SVGDocumentHandler handler = new SVGDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
return handler;
}
import org.apache.xmlgraphics.util.QName;
import org.apache.xmlgraphics.xmp.Metadata;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.events.ResourceEventProducer;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.AbstractIFPainter;
import org.apache.fop.render.intermediate.IFConstants;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFState;
import org.apache.fop.render.intermediate.IFUtil;
}
/** {@inheritDoc} */
- protected FOUserAgent getUserAgent() {
- return parent.getUserAgent();
+ protected IFContext getContext() {
+ return parent.getContext();
}
/** {@inheritDoc} */
= new QName(ExtensionElementMapping.URI, null, "conversion-mode");
/** {@inheritDoc} */
- public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(String uri, Rectangle rect) throws IFException {
try {
establish(MODE_NORMAL);
info = manager.getImageInfo(uri, sessionContext);
String mime = info.getMimeType();
+ Map foreignAttributes = getContext().getForeignAttributes();
String conversionMode = (String)foreignAttributes.get(CONVERSION_MODE);
if ("reference".equals(conversionMode)
&& (MimeConstants.MIME_GIF.equals(mime)
}
/** {@inheritDoc} */
- public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException {
+ public void drawImage(Document doc, Rectangle rect) throws IFException {
try {
establish(MODE_NORMAL);
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/** {@inheritDoc} */
public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
SVGPrintDocumentHandler handler = new SVGPrintDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
return handler;
}
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFParser;
import org.apache.fop.render.intermediate.IFRenderer;
//Setup painter
IFSerializer serializer = new IFSerializer();
- serializer.setUserAgent(userAgent);
+ serializer.setContext(new IFContext(userAgent));
serializer.mimicDocumentHandler(targetHandler);
serializer.setResult(domResult);
FOUserAgent userAgent = createUserAgent();
IFSerializer serializer = new IFSerializer();
- serializer.setUserAgent(userAgent);
+ serializer.setContext(new IFContext(userAgent));
DOMResult domResult = new DOMResult();
serializer.setResult(domResult);
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.layoutengine.EvalCheck;
import org.apache.fop.layoutengine.TrueCheck;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFRenderer;
import org.apache.fop.render.intermediate.IFSerializer;
import org.apache.fop.util.DelegatingContentHandler;
ifRenderer.setUserAgent(ua);
IFSerializer serializer = new IFSerializer();
- serializer.setUserAgent(ua);
+ serializer.setContext(new IFContext(ua));
DOMResult result = new DOMResult();
serializer.setResult(result);
ifRenderer.setDocumentHandler(serializer);
import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.intermediate.IFContext;
/**
* Tests the image handling in PostScript output.
private void innerTestJPEGImageWithIF(int level) throws Exception {
FOUserAgent ua = fopFactory.newFOUserAgent();
PSDocumentHandler handler = new PSDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
PSRenderingUtil psUtil = handler.getPSUtil();
psUtil.setLanguageLevel(level);
psUtil.setOptimizeResources(true);
import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.intermediate.IFContext;
/**
* Tests the PostScript resource optimization (selective de-duplication of
public void testResourceOptimizationWithIF() throws Exception {
FOUserAgent ua = fopFactory.newFOUserAgent();
PSDocumentHandler handler = new PSDocumentHandler();
- handler.setUserAgent(ua);
+ handler.setContext(new IFContext(ua));
// This is the important part: we're enabling resource optimization
handler.getPSUtil().setOptimizeResources(true);
ua.setDocumentHandlerOverride(handler);
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+ <info>
+ <p>
+ This test checks the PostScript extension for custom setup code. The extension attachments need to show
+ up in the area tree XML so the AreaTreeParser can fully restore the area tree.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:pcl="http://xmlgraphics.apache.org/fop/extensions/pcl">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="first"
+ page-width="148mm" page-height="210mm" margin="20mm"
+ pcl:paper-source="2" pcl:duplex-mode="1">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ <fo:simple-page-master master-name="second"
+ page-width="148mm" page-height="210mm" margin="20mm"
+ pcl:paper-source="1">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ <fo:page-sequence-master master-name="complex">
+ <fo:repeatable-page-master-reference master-reference="first" maximum-repeats="1"/>
+ <fo:repeatable-page-master-reference master-reference="second"/>
+ </fo:page-sequence-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="complex">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block>Text on page <fo:page-number/>.</fo:block>
+ <fo:block break-before="page">Text on page <fo:page-number/>.</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks xmlns:pcl="http://xmlgraphics.apache.org/fop/extensions/pcl">
+ <eval expected="2" xpath="//pageViewport[@nr=1]/@pcl:paper-source"/>
+ <eval expected="1" xpath="//pageViewport[@nr=1]/@pcl:duplex-mode"/>
+
+ <eval expected="1" xpath="//pageViewport[@nr=2]/@pcl:paper-source"/>
+ <true xpath="not(boolean(//pageViewport[@nr=2]/@pcl:duplex-mode))"/>
+ </checks>
+ <if-checks xmlns:if="http://xmlgraphics.apache.org/fop/intermediate" xmlns:pcl="http://xmlgraphics.apache.org/fop/extensions/pcl">
+ <eval expected="2" xpath="//if:page[@index=0]/@pcl:paper-source"/>
+ <eval expected="1" xpath="//if:page[@index=0]/@pcl:duplex-mode"/>
+
+ <eval expected="1" xpath="//if:page[@index=1]/@pcl:paper-source"/>
+ <true xpath="not(boolean(//if:page[@index=1]/@pcl:duplex-mode))"/>
+ </if-checks>
+</testcase>