1 17 18 19 20 package org.apache.fop.render.pdf; 21 22 import java.awt.geom.AffineTransform ; 23 24 import org.apache.fop.area.CTM; 25 import org.apache.fop.pdf.PDFNumber; 26 27 37 public final class CTMHelper { 38 52 public static String toPDFString(CTM sourceMatrix) { 53 if (null == sourceMatrix) { 54 throw new NullPointerException ("sourceMatrix must not be null"); 55 } 56 57 final double[] matrix = toPDFArray(sourceMatrix); 58 59 return constructPDFArray(matrix); 60 } 61 62 71 public static String toPDFString(AffineTransform transform, boolean convertMillipoints) { 72 if (null == transform) { 73 throw new NullPointerException ("transform must not be null"); 74 } 75 76 final double[] matrix = new double[6]; 77 transform.getMatrix(matrix); 78 if (convertMillipoints) { 79 matrix[4] /= 1000; 81 matrix[5] /= 1000; 82 } 83 84 return constructPDFArray(matrix); 85 } 86 87 private static String constructPDFArray(double[] matrix) { 88 return PDFNumber.doubleOut(matrix[0], 8) + " " 89 + PDFNumber.doubleOut(matrix[1], 8) + " " 90 + PDFNumber.doubleOut(matrix[2], 8) + " " 91 + PDFNumber.doubleOut(matrix[3], 8) + " " 92 + PDFNumber.doubleOut(matrix[4], 8) + " " 93 + PDFNumber.doubleOut(matrix[5], 8); 94 } 95 96 111 public static CTM toPDFCTM(CTM sourceMatrix) { 112 if (null == sourceMatrix) { 113 throw new NullPointerException ("sourceMatrix must not be null"); 114 } 115 116 final double[] matrix = toPDFArray(sourceMatrix); 117 118 return new CTM(matrix[0], matrix[1], matrix[2], matrix[3], 119 matrix[4], matrix[5]); 120 } 121 122 137 public static double[] toPDFArray(CTM sourceMatrix) { 138 if (null == sourceMatrix) { 139 throw new NullPointerException ("sourceMatrix must not be null"); 140 } 141 142 final double[] matrix = sourceMatrix.toArray(); 143 144 return new double[]{matrix[0], matrix[1], matrix[2], matrix[3], 145 matrix[4] / 1000.0, matrix[5] / 1000.0}; 146 } 147 148 } 149 150 | Popular Tags |