</manifest>
</jar>
</target>
+ <!-- =================================================================== -->
+ <!-- Retroweaver -->
+ <!-- =================================================================== -->
<target name="retro-unavail" unless="java14.rt.lib">
<echo message="Please set the path to a JDK 1.4 installation in your build-local.properties" />
<echo message="to allow for verification!" />
import java.util.Map;
import org.apache.batik.dom.svg.SVGDOMImplementation;
+
import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageException;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
* @param targetFlavor the target flavor
*/
public ImageLoaderSVG(ImageFlavor targetFlavor) {
- if (!(XMLNamespaceEnabledImageFlavor.SVG_DOM.equals(targetFlavor))) {
- throw new IllegalArgumentException("Unsupported target ImageFlavor: " + targetFlavor);
+ if (!(XMLNamespaceEnabledImageFlavor.SVG_DOM.isCompatible(targetFlavor))) {
+ throw new IllegalArgumentException("Incompatible target ImageFlavor: " + targetFlavor);
}
this.targetFlavor = targetFlavor;
}
import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.util.QName;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.render.RendererContext.RendererContextWrapper;
import org.apache.fop.svg.SVGEventProducer;
import org.apache.fop.svg.SVGUserAgent;
*/
public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererContextConstants {
- /** logging instance */
- protected static Log log = LogFactory.getLog(AbstractGenericSVGHandler.class);
+ /** Qualified name for the "conversion-mode" extension attribute. */
+ protected static final QName CONVERSION_MODE = new QName(
+ ExtensionElementMapping.URI, null, "conversion-mode");
/** {@inheritDoc} */
public void handleXML(RendererContext context,
float imw = (float)dim.getWidth() / 1000f;
float imh = (float)dim.getHeight() / 1000f;
- float sx = fwidth / (float)imw;
- float sy = fheight / (float)imh;
+ float sx = pdfInfo.paintAsBitmap ? 1.0f : (fwidth / (float)imw);
+ float sy = pdfInfo.paintAsBitmap ? 1.0f : (fheight / (float)imh);
renderer.saveGraphicsState();
renderer.setColor(Color.black, false, null);
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
import java.io.IOException;
+import java.util.Map;
import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.util.QName;
+import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.render.AbstractGraphics2DAdapter;
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RendererContextConstants;
+import org.apache.fop.render.RendererContext.RendererContextWrapper;
+import org.apache.fop.render.pdf.PDFRenderer;
/**
* Graphics2DAdapter implementation for PostScript.
*/
public class PSGraphics2DAdapter extends AbstractGraphics2DAdapter {
+ /** Qualified name for the "conversion-mode" extension attribute. */
+ protected static final QName CONVERSION_MODE = new QName(
+ ExtensionElementMapping.URI, null, "conversion-mode");
+
private PSGenerator gen;
private boolean clip = true;
float imw = (float)dim.getWidth() / 1000f;
float imh = (float)dim.getHeight() / 1000f;
- float sx = fwidth / (float)imw;
- float sy = fheight / (float)imh;
+ boolean paintAsBitmap = false;
+ if (context != null) {
+ Map foreign = (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
+ paintAsBitmap = (foreign != null
+ && "bitmap".equalsIgnoreCase((String)foreign.get(CONVERSION_MODE)));
+ }
+
+ float sx = paintAsBitmap ? 1.0f : (fwidth / (float)imw);
+ float sy = paintAsBitmap ? 1.0f : (fheight / (float)imh);
gen.commentln("%FOPBeginGraphics2D");
gen.saveGraphicsState();
// scale to viewbox
transform.translate(fx, fy);
gen.getCurrentState().concatMatrix(transform);
- Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
- painter.paint(graphics, area);
+ if (paintAsBitmap) {
+ //Fallback solution: Paint to a BufferedImage
+ int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
+ RendererContextWrapper ctx = RendererContext.wrapRendererContext(context);
+ BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false);
+
+ float scale = PDFRenderer.NORMAL_PDF_RESOLUTION
+ / context.getUserAgent().getTargetResolution();
+ graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null);
+ } else {
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(graphics, area);
+ }
gen.restoreGraphicsState();
gen.commentln("%FOPEndGraphics2D");
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
+import org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline;
+import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.ImageEncoder;
+import org.apache.xmlgraphics.ps.PSDictionary;
+import org.apache.xmlgraphics.ps.PSDictionaryFormatException;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSImageUtils;
+import org.apache.xmlgraphics.ps.PSPageDeviceDictionary;
+import org.apache.xmlgraphics.ps.PSProcSets;
+import org.apache.xmlgraphics.ps.PSResource;
+import org.apache.xmlgraphics.ps.PSState;
+import org.apache.xmlgraphics.ps.dsc.DSCException;
+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.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.Area;
import org.apache.fop.render.ps.extensions.PSSetupCode;
import org.apache.fop.util.CharUtilities;
import org.apache.fop.util.ColorUtil;
-import org.apache.xmlgraphics.image.loader.ImageException;
-import org.apache.xmlgraphics.image.loader.ImageFlavor;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.ImageManager;
-import org.apache.xmlgraphics.image.loader.ImageSessionContext;
-import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
-import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
-import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
-import org.apache.xmlgraphics.image.loader.pipeline.ImageProviderPipeline;
-import org.apache.xmlgraphics.image.loader.util.ImageUtil;
-import org.apache.xmlgraphics.ps.DSCConstants;
-import org.apache.xmlgraphics.ps.ImageEncoder;
-import org.apache.xmlgraphics.ps.PSDictionary;
-import org.apache.xmlgraphics.ps.PSDictionaryFormatException;
-import org.apache.xmlgraphics.ps.PSGenerator;
-import org.apache.xmlgraphics.ps.PSImageUtils;
-import org.apache.xmlgraphics.ps.PSPageDeviceDictionary;
-import org.apache.xmlgraphics.ps.PSProcSets;
-import org.apache.xmlgraphics.ps.PSResource;
-import org.apache.xmlgraphics.ps.PSState;
-import org.apache.xmlgraphics.ps.dsc.DSCException;
-import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
-import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
-import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
/**
* Renderer that renders to PostScript.
* {@inheritDoc}
*/
public void renderImage(Image image, Rectangle2D pos) {
- drawImage(image.getURL(), pos);
+ drawImage(image.getURL(), pos, image.getForeignAttributes());
}
/**
// Java
import java.awt.geom.AffineTransform;
import java.io.IOException;
+import java.util.Map;
import org.w3c.dom.Document;
import org.apache.fop.render.AbstractGenericSVGHandler;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.RendererContext;
+import org.apache.fop.render.RendererContextConstants;
import org.apache.fop.svg.SVGEventProducer;
import org.apache.fop.svg.SVGUserAgent;
int yOffset = psInfo.currentYPosition;
PSGenerator gen = psInfo.psGenerator;
+ boolean paintAsBitmap = false;
+ if (context != null) {
+ Map foreign = (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
+ paintAsBitmap = (foreign != null
+ && "bitmap".equalsIgnoreCase((String)foreign.get(CONVERSION_MODE)));
+ }
+ if (paintAsBitmap) {
+ try {
+ super.renderSVGDocument(context, doc);
+ } catch (IOException ioe) {
+ SVGEventProducer eventProducer = SVGEventProducer.Provider.get(
+ context.getUserAgent().getEventBroadcaster());
+ eventProducer.svgRenderingError(this, ioe, getDocumentURI(doc));
+ }
+ return;
+ }
+
//Controls whether text painted by Batik is generated using text or path operations
boolean strokeText = false;
Configuration cfg = psInfo.getHandlerConfiguration();