]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Implement the cheaper mechanism to ensure correct rendering at differing resolutions...
authorJeremias Maerki <jeremias@apache.org>
Sun, 10 Oct 2004 12:20:56 +0000 (12:20 +0000)
committerJeremias Maerki <jeremias@apache.org>
Sun, 10 Oct 2004 12:20:56 +0000 (12:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198026 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java
src/java/org/apache/fop/render/ps/AbstractPSTranscoder.java
src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
src/java/org/apache/fop/svg/PDFTranscoder.java

index 4d447dba6674fc3515d85faa159ecbb63837bd6a..d970194c4eaad569838993ef2f5e9037b3d159b2 100644 (file)
@@ -45,6 +45,9 @@ public abstract class AbstractPSDocumentGraphics2D extends PSGraphics2D {
     
     protected int width;
     protected int height;
+    
+    protected float viewportWidth;
+    protected float viewportHeight;
 
     protected int pagecount;
     protected boolean pagePending;
@@ -126,9 +129,12 @@ public abstract class AbstractPSDocumentGraphics2D extends PSGraphics2D {
      * @throws IOException in case of an I/O problem
      */
     public void setSVGDimension(float w, float h) throws IOException {
+        this.viewportWidth = w;
+        this.viewportHeight = h;
+        /*
         if (w != this.width || h != this.height) {
             gen.concatMatrix(width / w, 0, 0, height / h, 0, 0);
-        }
+        }*/
     }
 
     /**
@@ -213,7 +219,15 @@ public abstract class AbstractPSDocumentGraphics2D extends PSGraphics2D {
           
         writePageHeader();
         gen.writeln("0.001 0.001 scale");
-        gen.concatMatrix(1, 0, 0, -1, 0, this.height * 1000);
+        if ((this.viewportWidth != this.width 
+                || this.viewportHeight != this.height)
+                && (this.viewportWidth > 0) && (this.viewportHeight > 0)){
+            gen.concatMatrix(this.width / this.viewportWidth, 0, 
+                       0, -1 * (this.height / this.viewportHeight), 
+                       0, this.height * 1000);
+        } else {
+            gen.concatMatrix(1, 0, 0, -1, 0, this.height * 1000);
+        }
         gen.writeDSCComment(DSCConstants.END_PAGE_SETUP);
         this.pagePending = true;
     }
index 68afbba3cb3157ef13228465d56a7581f9a3e94d..7ce111f339f38c07bc2ea2dc44d095b20710a3fb 100644 (file)
@@ -26,6 +26,7 @@ import java.io.IOException;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.UnitProcessor;
 import org.apache.batik.transcoder.TranscoderException;
 import org.apache.batik.transcoder.TranscoderOutput;
 
@@ -34,6 +35,7 @@ import org.apache.batik.transcoder.image.ImageTranscoder;
 import org.apache.fop.svg.AbstractFOPTranscoder;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.svg.SVGLength;
 
 /**
  * This class enables to transcode an input to a PostScript document.
@@ -77,21 +79,6 @@ public abstract class AbstractPSTranscoder extends AbstractFOPTranscoder {
 
     protected abstract AbstractPSDocumentGraphics2D createDocumentGraphics2D();
 
-    protected BridgeContext createBridgeContext() {
-        /*boolean stroke = true;
-        if (hints.containsKey(KEY_STROKE_TEXT)) {
-            stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
-        }*/
-
-        BridgeContext ctx = new BridgeContext(userAgent);
-        PSTextPainter textPainter = new PSTextPainter(graphics.getFontInfo());
-        ctx.setTextPainter(textPainter);
-        ctx.putBridge(new PSTextElementBridge(textPainter));
-
-        //ctx.putBridge(new PSImageElementBridge());
-        return ctx;
-    }
-
     /**
      * Transcodes the specified Document as an image in the specified output.
      *
@@ -118,9 +105,19 @@ public abstract class AbstractPSTranscoder extends AbstractFOPTranscoder {
 
         super.transcode(document, uri, output);
 
+        getLogger().trace("document size: " + width + " x " + height);
+        
         // prepare the image to be painted
-        int w = (int)(width + 0.5);
-        int h = (int)(height + 0.5);
+        UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, 
+                    document.getDocumentElement());
+        float widthInPt = UnitProcessor.userSpaceToSVG(width, SVGLength.SVG_LENGTHTYPE_PT, 
+                    UnitProcessor.HORIZONTAL_LENGTH, uctx);
+        int w = (int)(widthInPt + 0.5);
+        float heightInPt = UnitProcessor.userSpaceToSVG(height, SVGLength.SVG_LENGTHTYPE_PT, 
+                UnitProcessor.HORIZONTAL_LENGTH, uctx);
+        int h = (int)(heightInPt + 0.5);
+        getLogger().trace("document size: " + w + "pt x " + h + "pt");
+        
 
         try {
             graphics.setupDocument(output.getOutputStream(), w, h);
@@ -142,5 +139,20 @@ public abstract class AbstractPSTranscoder extends AbstractFOPTranscoder {
         }
     }
 
+    protected BridgeContext createBridgeContext() {
+        /*boolean stroke = true;
+        if (hints.containsKey(KEY_STROKE_TEXT)) {
+            stroke = ((Boolean)hints.get(KEY_STROKE_TEXT)).booleanValue();
+        }*/
+
+        BridgeContext ctx = new BridgeContext(userAgent);
+        PSTextPainter textPainter = new PSTextPainter(graphics.getFontInfo());
+        ctx.setTextPainter(textPainter);
+        ctx.putBridge(new PSTextElementBridge(textPainter));
+
+        //ctx.putBridge(new PSImageElementBridge());
+        return ctx;
+    }
+
 
 }
index 4eccb87a5300552e01aa989c059a6e6adc94f38a..a94a4eec7752aed541bfcb78e03ec99b03f22977 100644 (file)
@@ -62,8 +62,10 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
 
     private PDFPage currentPage;
     private PDFStream pdfStream;
+
     private int width;
     private int height;
+    
     private List fontList;
 
     private Log logger;
index dc10bc7c6f807bae745fa1a5a607ce3b429ff9e5..2ac0153ac671f372c633b7640718bd67597901b0 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.batik.bridge.BridgeContext;
+import org.apache.batik.bridge.UnitProcessor;
 import org.apache.batik.bridge.UserAgent;
 import org.apache.batik.gvt.TextPainter;
 import org.apache.batik.gvt.renderer.StrokingTextPainter;
@@ -34,6 +35,7 @@ import org.apache.batik.transcoder.TranscoderException;
 import org.apache.batik.transcoder.TranscoderOutput;
 import org.apache.batik.transcoder.image.ImageTranscoder;
 import org.w3c.dom.Document;
+import org.w3c.dom.svg.SVGLength;
 
 /**
  * This class enables to transcode an input to a pdf document.
@@ -83,8 +85,8 @@ public class PDFTranscoder extends AbstractFOPTranscoder
         return new AbstractFOPTranscoder.FOPTranscoderUserAgent() {
             // The PDF stuff wants everything at 72dpi
             public float getPixelUnitToMillimeter() {
-                //return super.getPixelUnitToMillimeter();
-                return 25.4f / 72; //72dpi = 0.352778f;
+                return super.getPixelUnitToMillimeter();
+                //return 25.4f / 72; //72dpi = 0.352778f;
             }
         };
     }
@@ -126,12 +128,23 @@ public class PDFTranscoder extends AbstractFOPTranscoder
         getLogger().trace("document size: " + width + " x " + height);
         
         // prepare the image to be painted
-        int w = (int)(width + 0.5);
-        int h = (int)(height + 0.5);
+        UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, 
+                    document.getDocumentElement());
+        float widthInPt = UnitProcessor.userSpaceToSVG(width, SVGLength.SVG_LENGTHTYPE_PT, 
+                    UnitProcessor.HORIZONTAL_LENGTH, uctx);
+        int w = (int)(widthInPt + 0.5);
+        float heightInPt = UnitProcessor.userSpaceToSVG(height, SVGLength.SVG_LENGTHTYPE_PT, 
+                UnitProcessor.HORIZONTAL_LENGTH, uctx);
+        int h = (int)(heightInPt + 0.5);
+        getLogger().trace("document size: " + w + "pt x " + h + "pt");
+
+        // prepare the image to be painted
+        //int w = (int)(width + 0.5);
+        //int h = (int)(height + 0.5);
 
         try {
             graphics.setupDocument(output.getOutputStream(), w, h);
-            graphics.setSVGDimension(w, h);
+            graphics.setSVGDimension(width, height);
 
             if (hints.containsKey(ImageTranscoder.KEY_BACKGROUND_COLOR)) {
                 graphics.setBackgroundColor