/*
- * 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.
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.
*
*/
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 =
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:
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]);
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};
// 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;
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;
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:
(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 = "";