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-ffa450edef68tags/fop-1_0
@@ -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; | |||
} |
@@ -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()); | |||
} | |||
/** |
@@ -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; | |||
} | |||
@@ -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} */ |
@@ -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. |
@@ -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. | |||
* <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); | |||
} | |||
} |
@@ -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. |
@@ -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<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 |
@@ -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; | |||
} | |||
@@ -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); | |||
} |
@@ -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. |
@@ -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( |
@@ -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); | |||
} | |||
@@ -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) { |
@@ -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; | |||
} | |||
@@ -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) { |
@@ -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); |
@@ -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; |
@@ -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} */ |
@@ -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; | |||
} | |||
@@ -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(); |
@@ -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} */ |
@@ -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; | |||
} | |||
@@ -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) { |
@@ -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; | |||
} | |||
@@ -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); | |||
@@ -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; | |||
} | |||
@@ -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); | |||
@@ -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); |
@@ -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); |
@@ -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); |
@@ -0,0 +1,67 @@ | |||
<?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> |