aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-08-29 14:13:48 +0000
committerJeremias Maerki <jeremias@apache.org>2005-08-29 14:13:48 +0000
commitaa4d68d3f3d33ec409e6d1fbb166fc0402d4de4b (patch)
tree3b08e859dd4e9c1ad033d30bdea931d67a216ddc
parentf8376cbe95b55975476e6e0b7385518dcd7c2c17 (diff)
downloadxmlgraphics-fop-aa4d68d3f3d33ec409e6d1fbb166fc0402d4de4b.tar.gz
xmlgraphics-fop-aa4d68d3f3d33ec409e6d1fbb166fc0402d4de4b.zip
Fixed the page coordinate system for the PDF Renderer (Defect: Rounding and rounding errors).
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@264145 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/render/pdf/CTMHelper.java57
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderer.java13
2 files changed, 46 insertions, 24 deletions
diff --git a/src/java/org/apache/fop/render/pdf/CTMHelper.java b/src/java/org/apache/fop/render/pdf/CTMHelper.java
index 3a263fc25..1dafa4d8b 100644
--- a/src/java/org/apache/fop/render/pdf/CTMHelper.java
+++ b/src/java/org/apache/fop/render/pdf/CTMHelper.java
@@ -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 @@ import org.apache.fop.pdf.PDFNumber;
*/
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 @@ public final class CTMHelper {
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 @@ public final class CTMHelper {
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 @@ public final class CTMHelper {
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};
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
index a5cb4e38b..07a5ea7d7 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java
@@ -38,9 +38,6 @@ import org.apache.avalon.framework.configuration.ConfigurationException;
// 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.Trait;
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.PDFStream;
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 @@ public class PDFRenderer extends AbstractPathOrientedRenderer {
(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 = "";