]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Merged revisions 706272,706276 via svnmerge from
authorAdrian Cumiskey <acumiskey@apache.org>
Mon, 20 Oct 2008 13:42:28 +0000 (13:42 +0000)
committerAdrian Cumiskey <acumiskey@apache.org>
Mon, 20 Oct 2008 13:42:28 +0000 (13:42 +0000)
https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk

........
  r706272 | jeremias | 2008-10-20 14:14:03 +0100 (Mon, 20 Oct 2008) | 1 line

  Visually separated retroweaver part from hyphenation part.
........
  r706276 | jeremias | 2008-10-20 14:20:26 +0100 (Mon, 20 Oct 2008) | 3 lines

  Fixed size of images when vector graphic images are painted using fox:conversion-mode="bitmap" (for PDF output).
  Added support for fox:conversion-mode="bitmap" for PS output.
  Avoid "unsupported target ImageFlavor" error after the fix in XML Graphics Commons (rev 706270).
........

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@706282 13f79535-47bb-0310-9956-ffa450edef68

build.xml
src/java/org/apache/fop/image/loader/batik/ImageLoaderSVG.java
src/java/org/apache/fop/render/AbstractGenericSVGHandler.java
src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
src/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
src/java/org/apache/fop/render/ps/PSRenderer.java
src/java/org/apache/fop/render/ps/PSSVGHandler.java

index 32b27c82b97063d2fbafec97d52fd4ab002803e7..7ab83df21b6ac2abcaf8381bb208b11e60c43e4e 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -459,6 +459,9 @@ list of possible build targets.
       </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!" />
index c5c113b04be9f449db811eadb2cbda04bf0eb992..bb9c7d39595478800db6010f4295cbc9ce8f5c81 100644 (file)
@@ -23,6 +23,7 @@ import java.io.IOException;
 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;
@@ -45,8 +46,8 @@ public class ImageLoaderSVG extends AbstractImageLoader {
      * @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;
     }
index a72c3ccb06a84a38c628e2b29e1eef4ca7057f26..17b2b9d36b3bdbdfe2440b6e476579f5c3242044 100644 (file)
@@ -37,7 +37,9 @@ import org.apache.commons.logging.Log;
 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;
@@ -50,8 +52,9 @@ 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,
index f05a16f1a1d8a80f546f37f01e7212abf3391166..2aa11227abc8c3ba882a5fb3515e92883e1e5f4c 100644 (file)
@@ -66,8 +66,8 @@ public class PDFGraphics2DAdapter extends AbstractGraphics2DAdapter {
         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);
index c17fe9e56462e32a84a56e5c32a70c5265fc20ca..542a69a4a712c0827cac660b0aea7700429bc657 100644 (file)
@@ -22,21 +22,32 @@ package org.apache.fop.render.ps;
 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;
 
@@ -72,8 +83,15 @@ public class PSGraphics2DAdapter extends AbstractGraphics2DAdapter {
         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();
@@ -96,8 +114,19 @@ public class PSGraphics2DAdapter extends AbstractGraphics2DAdapter {
         // 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");
index 085ee8230277a6c9974709944f443a1d2938c92d..4ccb0bd520822c8b94d4b47db25998400f3259f7 100644 (file)
@@ -40,6 +40,36 @@ import javax.xml.transform.Source;
 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;
@@ -77,34 +107,6 @@ import org.apache.fop.render.ps.extensions.PSSetPageDevice;
 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.
@@ -1610,7 +1612,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
      * {@inheritDoc}
      */
     public void renderImage(Image image, Rectangle2D pos) {
-        drawImage(image.getURL(), pos);
+        drawImage(image.getURL(), pos, image.getForeignAttributes());
     }
 
     /**
index 1d293fa71c59ccdfb140ed539ec929362c229d6d..d4a478fa455d64beea730c8d3b29f7501dcba689 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.fop.render.ps;
 // Java
 import java.awt.geom.AffineTransform;
 import java.io.IOException;
+import java.util.Map;
 
 import org.w3c.dom.Document;
 
@@ -39,6 +40,7 @@ import org.apache.fop.fonts.FontInfo;
 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;
 
@@ -226,6 +228,23 @@ public class PSSVGHandler extends AbstractGenericSVGHandler
         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();