From 01ceb0032ead03d9c35abeee9075dabc3702fc7f Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 2 Jan 2009 14:29:30 +0000 Subject: [PATCH] Introduced IFContext to provide access to foreign attributes (as discussed on fop-dev). Removed the foreign attributes map from the drawImage methods as a consequence. Added support for foreign attributes on the page (PCL's paper-source and duplex-mode extensions). Fixed a couple of bugs parsing the document navigation elements. Build-time test suite now runs through. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@730740 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/RendererFactory.java | 2 +- .../render/bitmap/TIFFDocumentHandler.java | 10 +- .../bitmap/TIFFDocumentHandlerMaker.java | 3 +- .../AbstractIFDocumentHandler.java | 19 +-- .../intermediate/AbstractIFPainter.java | 10 +- .../fop/render/intermediate/IFContext.java | 111 ++++++++++++++++++ .../intermediate/IFDocumentHandler.java | 13 +- .../fop/render/intermediate/IFPainter.java | 8 +- .../fop/render/intermediate/IFParser.java | 19 ++- .../fop/render/intermediate/IFRenderer.java | 23 +++- .../fop/render/intermediate/IFSerializer.java | 39 +++--- .../extensions/DocumentNavigationHandler.java | 20 +++- .../fop/render/java2d/Java2DPainter.java | 27 ++--- .../fop/render/pcl/PCLDocumentHandler.java | 30 ++--- .../render/pcl/PCLDocumentHandlerMaker.java | 3 +- .../org/apache/fop/render/pcl/PCLPainter.java | 19 +-- .../apache/fop/render/pcl/PCLRenderer.java | 9 +- .../pcl/extensions/PCLElementMapping.java | 10 ++ .../fop/render/pdf/PDFDocumentHandler.java | 8 +- .../render/pdf/PDFDocumentHandlerMaker.java | 3 +- .../org/apache/fop/render/pdf/PDFPainter.java | 11 +- .../fop/render/ps/PSDocumentHandler.java | 8 +- .../fop/render/ps/PSDocumentHandlerMaker.java | 3 +- .../org/apache/fop/render/ps/PSPainter.java | 10 +- .../render/svg/SVGDocumentHandlerMaker.java | 3 +- .../org/apache/fop/render/svg/SVGPainter.java | 11 +- .../svg/SVGPrintDocumentHandlerMaker.java | 3 +- .../fop/intermediate/IFParserTestCase.java | 5 +- .../org/apache/fop/intermediate/IFTester.java | 3 +- .../fop/render/ps/ImageHandlingTestCase.java | 3 +- .../ps/ResourceOptimizationTestCase.java | 3 +- .../standard-testcases/pcl-extension_1.xml | 67 +++++++++++ 32 files changed, 379 insertions(+), 137 deletions(-) create mode 100644 src/java/org/apache/fop/render/intermediate/IFContext.java create mode 100644 test/layoutengine/standard-testcases/pcl-extension_1.xml diff --git a/src/java/org/apache/fop/render/RendererFactory.java b/src/java/org/apache/fop/render/RendererFactory.java index 19cf76931..2b26e4881 100644 --- a/src/java/org/apache/fop/render/RendererFactory.java +++ b/src/java/org/apache/fop/render/RendererFactory.java @@ -262,7 +262,7 @@ public class RendererFactory { private Renderer createRendererForDocumentHandler(IFDocumentHandler documentHandler) { IFRenderer rend = new IFRenderer(); - rend.setUserAgent(documentHandler.getUserAgent()); + rend.setUserAgent(documentHandler.getContext().getUserAgent()); rend.setDocumentHandler(documentHandler); return rend; } diff --git a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java index cdc350c9e..a7f0a185f 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandler.java @@ -32,11 +32,11 @@ import org.apache.xmlgraphics.image.writer.ImageWriter; 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; @@ -80,11 +80,11 @@ public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@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); } @@ -213,7 +213,7 @@ public class TIFFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler RenderingHints.VALUE_STROKE_PURE); graphics2D.scale(scale / 1000f, scale / 1000f); - return new Java2DPainter(graphics2D, getUserAgent(), getFontInfo()); + return new Java2DPainter(graphics2D, getContext(), getFontInfo()); } /** diff --git a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java index dd1cb10be..230ff49a3 100644 --- a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java +++ b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java @@ -22,6 +22,7 @@ package org.apache.fop.render.bitmap; 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; @@ -36,7 +37,7 @@ public class TIFFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker { /** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) { TIFFDocumentHandler handler = new TIFFDocumentHandler(); - handler.setUserAgent(ua); + handler.setContext(new IFContext(ua)); return handler; } diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java b/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java index a7b2757a8..2fb071e18 100644 --- a/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java +++ b/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandler.java @@ -32,7 +32,7 @@ public abstract class AbstractIFDocumentHandler implements IFDocumentHandler { /** logging instance */ private static Log log = LogFactory.getLog(AbstractIFDocumentHandler.class); - private FOUserAgent userAgent; + private IFContext ifContext; /** * Default constructor. @@ -41,16 +41,21 @@ public abstract class AbstractIFDocumentHandler implements IFDocumentHandler { } /** {@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} */ diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java index ea74a37c8..3fe7395f3 100644 --- a/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java @@ -72,11 +72,19 @@ public abstract class AbstractIFPainter implements IFPainter { 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. diff --git a/src/java/org/apache/fop/render/intermediate/IFContext.java b/src/java/org/apache/fop/render/intermediate/IFContext.java new file mode 100644 index 000000000..b05db1369 --- /dev/null +++ b/src/java/org/apache/fop/render/intermediate/IFContext.java @@ -0,0 +1,111 @@ +/* + * 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. + *

+ * 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 */ + 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 + */ + 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 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); + } + +} diff --git a/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java b/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java index ea07deee6..bfd31b5e2 100644 --- a/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java +++ b/src/java/org/apache/fop/render/intermediate/IFDocumentHandler.java @@ -23,7 +23,6 @@ import java.awt.Dimension; import javax.xml.transform.Result; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fonts.FontInfo; /** @@ -76,16 +75,16 @@ 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. diff --git a/src/java/org/apache/fop/render/intermediate/IFPainter.java b/src/java/org/apache/fop/render/intermediate/IFPainter.java index 2c704db8b..d60cd24d2 100644 --- a/src/java/org/apache/fop/render/intermediate/IFPainter.java +++ b/src/java/org/apache/fop/render/intermediate/IFPainter.java @@ -25,7 +25,6 @@ import java.awt.Paint; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.AffineTransform; -import java.util.Map; import org.w3c.dom.Document; @@ -164,21 +163,18 @@ public interface IFPainter { * 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) * @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) * @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 diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java index 6d037b0cf..c5c88ca78 100644 --- a/src/java/org/apache/fop/render/intermediate/IFParser.java +++ b/src/java/org/apache/fop/render/intermediate/IFParser.java @@ -151,6 +151,13 @@ public class IFParser implements IFConstants { 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) @@ -348,7 +355,11 @@ public class IFParser implements IFConstants { 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 { @@ -547,9 +558,10 @@ public class IFParser implements IFConstants { 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( @@ -557,8 +569,9 @@ public class IFParser implements IFConstants { 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; } diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index 50ef524b3..6ff96d18e 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -229,7 +229,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer { */ protected IFDocumentHandler createDefaultDocumentHandler() { IFSerializer serializer = new IFSerializer(); - serializer.setUserAgent(getUserAgent()); + serializer.setContext(new IFContext(getUserAgent())); return serializer; } @@ -554,8 +554,11 @@ public class IFRenderer extends AbstractPathOrientedRenderer { 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 @@ -584,12 +587,22 @@ public class IFRenderer extends AbstractPathOrientedRenderer { } 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); @@ -1108,7 +1121,9 @@ public class IFRenderer extends AbstractPathOrientedRenderer { (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); } @@ -1124,7 +1139,9 @@ public class IFRenderer extends AbstractPathOrientedRenderer { (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); } diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java index 1cc0e98d6..03f96c288 100644 --- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -229,6 +229,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler 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); @@ -278,7 +279,6 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler public void startPageTrailer() throws IFException { try { handler.startElement(EL_PAGE_TRAILER); - commitNavigation(); } catch (SAXException e) { throw new IFException("SAX error in startPageTrailer()", e); } @@ -287,6 +287,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler /** {@inheritDoc} */ public void endPageTrailer() throws IFException { try { + commitNavigation(); handler.endElement(EL_PAGE_TRAILER); } catch (SAXException e) { throw new IFException("SAX error in endPageTrailer()", e); @@ -375,7 +376,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler } /** {@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); @@ -383,34 +384,33 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler 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); @@ -499,7 +499,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler 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) { @@ -698,9 +698,8 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler 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. diff --git a/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java b/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java index 3351740e2..8516277c5 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java @@ -99,17 +99,27 @@ public class DocumentNavigationHandler extends DefaultHandler 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( diff --git a/src/java/org/apache/fop/render/java2d/Java2DPainter.java b/src/java/org/apache/fop/render/java2d/Java2DPainter.java index 34fbb3384..a3b7bb86e 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DPainter.java +++ b/src/java/org/apache/fop/render/java2d/Java2DPainter.java @@ -29,7 +29,6 @@ import java.awt.font.GlyphVector; 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; @@ -37,12 +36,12 @@ 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; @@ -56,8 +55,8 @@ public class Java2DPainter extends AbstractIFPainter { /** 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; @@ -71,23 +70,23 @@ public class Java2DPainter extends AbstractIFPainter { /** * 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 { @@ -99,8 +98,8 @@ public class Java2DPainter extends AbstractIFPainter { } /** {@inheritDoc} */ - public FOUserAgent getUserAgent() { - return this.userAgent; + public IFContext getContext() { + return this.ifContext; } /** @@ -155,7 +154,7 @@ public class Java2DPainter extends AbstractIFPainter { } /** {@inheritDoc} */ - public void drawImage(String uri, Rectangle rect, Map foreignAttributes) throws IFException { + public void drawImage(String uri, Rectangle rect) throws IFException { drawImageUsingURI(uri, rect); } @@ -167,7 +166,7 @@ public class Java2DPainter extends AbstractIFPainter { } /** {@inheritDoc} */ - public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException { + public void drawImage(Document doc, Rectangle rect) throws IFException { drawImageUsingDocument(doc, rect); } diff --git a/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java b/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java index 3e9201da4..d7011f112 100644 --- a/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java +++ b/src/java/org/apache/fop/render/pcl/PCLDocumentHandler.java @@ -32,14 +32,15 @@ import org.apache.commons.logging.LogFactory; 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. @@ -84,9 +85,9 @@ public class PCLDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@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} */ @@ -173,24 +174,23 @@ public class PCLDocumentHandler extends AbstractBinaryWritingIFDocumentHandler } /** {@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; @@ -240,7 +240,7 @@ public class PCLDocumentHandler extends AbstractBinaryWritingIFDocumentHandler 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) { diff --git a/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java b/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java index 4a937d7b1..62c2a4e77 100644 --- a/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java +++ b/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java @@ -22,6 +22,7 @@ package org.apache.fop.render.pcl; 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; @@ -36,7 +37,7 @@ public class PCLDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker { /** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) { PCLDocumentHandler handler = new PCLDocumentHandler(); - handler.setUserAgent(ua); + handler.setContext(new IFContext(ua)); return handler; } diff --git a/src/java/org/apache/fop/render/pcl/PCLPainter.java b/src/java/org/apache/fop/render/pcl/PCLPainter.java index 784aca941..28e8224a8 100644 --- a/src/java/org/apache/fop/render/pcl/PCLPainter.java +++ b/src/java/org/apache/fop/render/pcl/PCLPainter.java @@ -45,11 +45,11 @@ import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D; 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; @@ -83,6 +83,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { /** * 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; @@ -92,8 +93,8 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { } /** {@inheritDoc} */ - public FOUserAgent getUserAgent() { - return this.parent.getUserAgent(); + public IFContext getContext() { + return this.parent.getContext(); } PCLRenderingUtil getPCLUtil() { @@ -152,8 +153,8 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { } /** {@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} */ @@ -174,7 +175,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { } /** {@inheritDoc} */ - public void drawImage(Document doc, Rectangle rect, Map foreignAttributes) throws IFException { + public void drawImage(Document doc, Rectangle rect) throws IFException { drawImageUsingDocument(doc, rect); } @@ -225,7 +226,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { 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) { @@ -260,7 +261,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { 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) { @@ -458,7 +459,7 @@ public class PCLPainter extends AbstractIFPainter implements PCLConstants { 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) { diff --git a/src/java/org/apache/fop/render/pcl/PCLRenderer.java b/src/java/org/apache/fop/render/pcl/PCLRenderer.java index b492f1b07..eaccc523f 100644 --- a/src/java/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/java/org/apache/fop/render/pcl/PCLRenderer.java @@ -56,7 +56,6 @@ import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; 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; @@ -284,15 +283,13 @@ public class PCLRenderer extends PrintRenderer implements PCLConstants { 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)); } @@ -534,7 +531,7 @@ public class PCLRenderer extends PrintRenderer implements PCLConstants { public Dimension getImageSize() { return paintRect.getSize(); } - + }; g2a.paintImage(painter, rc, paintRect.x, paintRect.y, paintRect.width, paintRect.height); diff --git a/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java b/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java index 1c540718b..53931f671 100644 --- a/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java +++ b/src/java/org/apache/fop/render/pcl/extensions/PCLElementMapping.java @@ -21,6 +21,8 @@ package org.apache.fop.render.pcl.extensions; import java.util.HashMap; +import org.apache.xmlgraphics.util.QName; + import org.apache.fop.fo.ElementMapping; /** @@ -34,6 +36,14 @@ public class PCLElementMapping extends 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; diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index 32ab2fa7a..901dc4473 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory; 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; @@ -39,6 +38,7 @@ import org.apache.fop.pdf.PDFReference; 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; @@ -99,9 +99,9 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { } /** {@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} */ diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java index 88ae60d2c..fa0a49ee7 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java @@ -22,6 +22,7 @@ package org.apache.fop.render.pdf; 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; @@ -36,7 +37,7 @@ public class PDFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker { /** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) { PDFDocumentHandler handler = new PDFDocumentHandler(); - handler.setUserAgent(ua); + handler.setContext(new IFContext(ua)); return handler; } diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java index 278089d26..6386b8df6 100644 --- a/src/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java @@ -26,14 +26,12 @@ import java.awt.Point; 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; @@ -46,6 +44,7 @@ import org.apache.fop.pdf.PDFTextUtil; 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; @@ -80,8 +79,8 @@ public class PDFPainter extends AbstractIFPainter { } /** {@inheritDoc} */ - protected FOUserAgent getUserAgent() { - return this.documentHandler.getUserAgent(); + protected IFContext getContext() { + return this.documentHandler.getContext(); } PDFRenderingUtil getPDFUtil() { @@ -123,7 +122,7 @@ public class PDFPainter extends AbstractIFPainter { } /** {@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); @@ -161,7 +160,7 @@ public class PDFPainter extends AbstractIFPainter { } /** {@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(); diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java index 543a3e90d..7f86017c1 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java @@ -49,11 +49,11 @@ import org.apache.xmlgraphics.ps.dsc.ResourceTracker; 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; @@ -122,9 +122,9 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { } /** {@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} */ diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java b/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java index 635cd0720..e105ac836 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java @@ -22,6 +22,7 @@ package org.apache.fop.render.ps; 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; @@ -37,7 +38,7 @@ public class PSDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker { /** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) { PSDocumentHandler handler = new PSDocumentHandler(); - handler.setUserAgent(ua); + handler.setContext(new IFContext(ua)); return handler; } diff --git a/src/java/org/apache/fop/render/ps/PSPainter.java b/src/java/org/apache/fop/render/ps/PSPainter.java index a55d20739..02fb7292c 100644 --- a/src/java/org/apache/fop/render/ps/PSPainter.java +++ b/src/java/org/apache/fop/render/ps/PSPainter.java @@ -40,7 +40,6 @@ import org.apache.xmlgraphics.image.loader.ImageSessionContext; 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; @@ -49,6 +48,7 @@ import org.apache.fop.fonts.SingleByteFont; 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; @@ -80,8 +80,8 @@ public class PSPainter extends AbstractIFPainter { } /** {@inheritDoc} */ - protected FOUserAgent getUserAgent() { - return this.documentHandler.getUserAgent(); + protected IFContext getContext() { + return this.documentHandler.getContext(); } PSRenderingUtil getPSUtil() { @@ -176,7 +176,7 @@ public class PSPainter extends AbstractIFPainter { } /** {@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) { @@ -186,7 +186,7 @@ public class PSPainter extends AbstractIFPainter { } /** {@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) { diff --git a/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandlerMaker.java b/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandlerMaker.java index 0296135fd..c24a5af61 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandlerMaker.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandlerMaker.java @@ -21,6 +21,7 @@ package org.apache.fop.render.svg; 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; @@ -34,7 +35,7 @@ public class SVGDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker { /** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) { SVGDocumentHandler handler = new SVGDocumentHandler(); - handler.setUserAgent(ua); + handler.setContext(new IFContext(ua)); return handler; } diff --git a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java index df67971b8..e1626e6f9 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGPainter.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGPainter.java @@ -44,13 +44,13 @@ import org.apache.xmlgraphics.image.loader.ImageSessionContext; 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; @@ -93,8 +93,8 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants { } /** {@inheritDoc} */ - protected FOUserAgent getUserAgent() { - return parent.getUserAgent(); + protected IFContext getContext() { + return parent.getContext(); } /** {@inheritDoc} */ @@ -197,7 +197,7 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants { = 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); @@ -208,6 +208,7 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants { 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) @@ -245,7 +246,7 @@ public class SVGPainter extends AbstractIFPainter implements SVGConstants { } /** {@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); diff --git a/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java b/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java index 61993da13..8da7032aa 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGPrintDocumentHandlerMaker.java @@ -21,6 +21,7 @@ package org.apache.fop.render.svg; 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; @@ -34,7 +35,7 @@ public class SVGPrintDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker /** {@inheritDoc} */ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) { SVGPrintDocumentHandler handler = new SVGPrintDocumentHandler(); - handler.setUserAgent(ua); + handler.setContext(new IFContext(ua)); return handler; } diff --git a/test/java/org/apache/fop/intermediate/IFParserTestCase.java b/test/java/org/apache/fop/intermediate/IFParserTestCase.java index b61c252d7..76d72c804 100644 --- a/test/java/org/apache/fop/intermediate/IFParserTestCase.java +++ b/test/java/org/apache/fop/intermediate/IFParserTestCase.java @@ -36,6 +36,7 @@ import org.apache.fop.apps.FOUserAgent; 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; @@ -87,7 +88,7 @@ public class IFParserTestCase extends AbstractIntermediateTestCase { //Setup painter IFSerializer serializer = new IFSerializer(); - serializer.setUserAgent(userAgent); + serializer.setContext(new IFContext(userAgent)); serializer.mimicDocumentHandler(targetHandler); serializer.setResult(domResult); @@ -125,7 +126,7 @@ public class IFParserTestCase extends AbstractIntermediateTestCase { FOUserAgent userAgent = createUserAgent(); IFSerializer serializer = new IFSerializer(); - serializer.setUserAgent(userAgent); + serializer.setContext(new IFContext(userAgent)); DOMResult domResult = new DOMResult(); serializer.setResult(domResult); diff --git a/test/java/org/apache/fop/intermediate/IFTester.java b/test/java/org/apache/fop/intermediate/IFTester.java index 7f64ad489..a3291a373 100644 --- a/test/java/org/apache/fop/intermediate/IFTester.java +++ b/test/java/org/apache/fop/intermediate/IFTester.java @@ -51,6 +51,7 @@ import org.apache.fop.area.RenderPagesModel; 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; @@ -113,7 +114,7 @@ public class IFTester { 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); diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java index 51c4dc301..7f0462a75 100644 --- a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java +++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java @@ -35,6 +35,7 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCCommentTitle; 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. @@ -90,7 +91,7 @@ public class ImageHandlingTestCase extends AbstractPostScriptTestCase { 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); diff --git a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java index ace96e85d..e5b9a4d27 100644 --- a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java +++ b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java @@ -45,6 +45,7 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPage; 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 @@ -77,7 +78,7 @@ public class ResourceOptimizationTestCase extends AbstractPostScriptTestCase { 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); diff --git a/test/layoutengine/standard-testcases/pcl-extension_1.xml b/test/layoutengine/standard-testcases/pcl-extension_1.xml new file mode 100644 index 000000000..f75f1f695 --- /dev/null +++ b/test/layoutengine/standard-testcases/pcl-extension_1.xml @@ -0,0 +1,67 @@ + + + + + +

+ 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. +

+ + + + + + + + + + + + + + + + + + Text on page . + Text on page . + + + + + + + + + + + + + + + + + + + -- 2.39.5