You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/08/29 16:13:53 UTC

svn commit: r264145 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf: CTMHelper.java PDFRenderer.java

Author: jeremias
Date: Mon Aug 29 07:13:48 2005
New Revision: 264145

URL: http://svn.apache.org/viewcvs?rev=264145&view=rev
Log:
Fixed the page coordinate system for the PDF Renderer (Defect: Rounding and rounding errors).

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/CTMHelper.java   (contents, props changed)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/CTMHelper.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/CTMHelper.java?rev=264145&r1=264144&r2=264145&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/CTMHelper.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/CTMHelper.java Mon Aug 29 07:13:48 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,12 +18,14 @@
  
 package org.apache.fop.render.pdf;
 
+import java.awt.geom.AffineTransform;
+
 import org.apache.fop.area.CTM;
 import org.apache.fop.pdf.PDFNumber;
 
 /**
- * CTMHelper converts FOP transformation matrixis to those
- * suitable for use by the PDFRender. The e and f elements
+ * CTMHelper converts FOP transformation matrices to those
+ * suitable for use by the PDFRenderer. The e and f elements
  * of the matrix will be divided by 1000 as FOP uses millipoints
  * as it's default user space and PDF uses points.
  *
@@ -33,7 +35,7 @@
  */
 public final class CTMHelper {
     /**
-     * <p>Converts the sourceMatrix to a string for use in the PDFRender cm operations.</p>
+     * <p>Converts the sourceMatrix to a string for use in the PDFRenderer cm operations.</p>
      * <p>For example:
      * <pre>
      *    org.apache.fop.area.CTM ctm = 
@@ -51,16 +53,45 @@
             throw new NullPointerException("sourceMatrix must not be null");
         }
 
-        final double matrix[] = toPDFArray(sourceMatrix);
+        final double[] matrix = toPDFArray(sourceMatrix);
+
+        return constructPDFArray(matrix);
+    }
+
+    /**
+     * <p>Converts the AffineTransform instance to a string for use in the PDFRenderer 
+     * cm operations.</p>
+     *
+     * @param transform The matrix to convert.
+     * @param convertMillipoints Indicates that the matrix needs to be converted from millipoints
+     *                           to points.
+     * @return  a space seperated string containing the matrix elements.
+     */
+    public static String toPDFString(AffineTransform transform, boolean convertMillipoints) {
+        if (null == transform) {
+            throw new NullPointerException("transform must not be null");
+        }
+
+        final double[] matrix = new double[6];
+        transform.getMatrix(matrix);
+        if (convertMillipoints) {
+            //Convert from millipoints to points
+            matrix[4] /= 1000;
+            matrix[5] /= 1000;
+        }
 
-        return PDFNumber.doubleOut(matrix[0], 8) + " " + 
-               PDFNumber.doubleOut(matrix[1], 8) + " " + 
-               PDFNumber.doubleOut(matrix[2], 8) + " " + 
-               PDFNumber.doubleOut(matrix[3], 8) + " " + 
-               PDFNumber.doubleOut(matrix[4], 8) + " " + 
-               PDFNumber.doubleOut(matrix[5], 8);
+        return constructPDFArray(matrix);
     }
 
+    private static String constructPDFArray(double[] matrix) {
+        return PDFNumber.doubleOut(matrix[0], 8) + " " 
+                + PDFNumber.doubleOut(matrix[1], 8) + " " 
+                + PDFNumber.doubleOut(matrix[2], 8) + " " 
+                + PDFNumber.doubleOut(matrix[3], 8) + " " 
+                + PDFNumber.doubleOut(matrix[4], 8) + " " 
+                + PDFNumber.doubleOut(matrix[5], 8);
+    }
+    
     /**
      * <p>Creates a new CTM based in the sourceMatrix.</p>
      * <p>For example:
@@ -81,7 +112,7 @@
             throw new NullPointerException("sourceMatrix must not be null");
         }
 
-        final double matrix[] = toPDFArray(sourceMatrix);
+        final double[] matrix = toPDFArray(sourceMatrix);
 
         return new CTM(matrix[0], matrix[1], matrix[2], matrix[3],
                        matrix[4], matrix[5]);
@@ -107,7 +138,7 @@
             throw new NullPointerException("sourceMatrix must not be null");
         }
 
-        final double matrix[] = sourceMatrix.toArray();
+        final double[] matrix = sourceMatrix.toArray();
 
         return new double[]{matrix[0], matrix[1], matrix[2], matrix[3],
                             matrix[4] / 1000.0, matrix[5] / 1000.0};

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/CTMHelper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=264145&r1=264144&r2=264145&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java Mon Aug 29 07:13:48 2005
@@ -38,9 +38,6 @@
 // FOP
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.area.Area;
-import org.apache.fop.area.Block;
-import org.apache.fop.area.BlockViewport;
 import org.apache.fop.area.CTM;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.area.Page;
@@ -50,10 +47,8 @@
 import org.apache.fop.area.OffDocumentItem;
 import org.apache.fop.area.BookmarkData;
 import org.apache.fop.area.inline.Character;
-import org.apache.fop.area.inline.InlineArea;
 import org.apache.fop.area.inline.InlineBlockParent;
 import org.apache.fop.area.inline.TextArea;
-import org.apache.fop.area.inline.Viewport;
 import org.apache.fop.area.inline.ForeignObject;
 import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.Leader;
@@ -82,12 +77,9 @@
 import org.apache.fop.pdf.PDFText;
 import org.apache.fop.pdf.PDFXObject;
 import org.apache.fop.render.AbstractPathOrientedRenderer;
-import org.apache.fop.render.PrintRenderer;
 import org.apache.fop.render.RendererContext;
-import org.apache.fop.traits.BorderProps;
 import org.apache.fop.fo.Constants;
 
-
 /*
 todo:
 
@@ -464,10 +456,9 @@
                                    (int) Math.round(pageHeight / 1000)));
         */
         // Transform origin at top left to origin at bottom left
-        currentStream.add("1 0 0 -1 0 "
-                           + (int) Math.round(pageHeight / 1000) + " cm\n");
         currentBasicTransform = new AffineTransform(1, 0, 0, -1, 0,
-                (int) Math.round(pageHeight / 1000));
+                pageHeight / 1000f);
+        currentStream.add(CTMHelper.toPDFString(currentBasicTransform, false) + " cm\n");
         
         
         currentFontName = "";



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org