From: Vincent Hennebert Date: Thu, 10 Jul 2014 17:34:27 +0000 (+0000) Subject: Factorized creation of gradient transform X-Git-Tag: fop-2_0~97^2~44 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=291a0f78402d4b2077edfd9ef284b2ab94e959ef;p=xmlgraphics-fop.git Factorized creation of gradient transform git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609515 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index 25534b3b1..804ba10b1 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -844,19 +844,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand return false; } - // Build proper transform from gradient space to page space - // ('Patterns' don't get userspace transform). - AffineTransform transform; - transform = new AffineTransform(getBaseTransform()); - transform.concatenate(getTransform()); - transform.concatenate(gp.getTransform()); - - List theMatrix = new java.util.ArrayList(); - double [] mat = new double[6]; - transform.getMatrix(mat); - for (int idx = 0; idx < mat.length; idx++) { - theMatrix.add(new Double(mat[idx])); - } + List matrix = createGradientTransform(gp); Point2D p1 = gp.getStartPoint(); Point2D p2 = gp.getEndPoint(); @@ -909,7 +897,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB); PDFGradientFactory gradientFactory = new PDFGradientFactory(this); PDFPattern myPat = gradientFactory.createGradient(false, colSpace, someColors, theBounds, - theCoords, theMatrix); + theCoords, matrix); currentStream.write(myPat.getColorSpaceOut(fill)); return true; @@ -930,19 +918,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand return false; } - // Build proper transform from gradient space to page space - // ('Patterns' don't get userspace transform). - AffineTransform transform; - transform = new AffineTransform(getBaseTransform()); - transform.concatenate(getTransform()); - transform.concatenate(gp.getTransform()); - - List theMatrix = new java.util.ArrayList(); - double [] mat = new double[6]; - transform.getMatrix(mat); - for (int idx = 0; idx < mat.length; idx++) { - theMatrix.add(new Double(mat[idx])); - } + List matrix = createGradientTransform(gp); double ar = gp.getRadius(); Point2D ac = gp.getCenterPoint(); @@ -996,12 +972,27 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB); PDFGradientFactory gradientFactory = new PDFGradientFactory(this); PDFPattern myPat = gradientFactory.createGradient(true, colSpace, someColors, theBounds, - theCoords, theMatrix); + theCoords, matrix); currentStream.write(myPat.getColorSpaceOut(fill)); return true; } + private List createGradientTransform(MultipleGradientPaint gp) { + // Build proper transform from gradient space to page space + // ('Patterns' don't get userspace transform). + AffineTransform transform = new AffineTransform(getBaseTransform()); + transform.concatenate(getTransform()); + transform.concatenate(gp.getTransform()); + List matrix = new java.util.ArrayList(6); + double[] m = new double[6]; + transform.getMatrix(m); + for (double d : m) { + matrix.add(Double.valueOf(d)); + } + return matrix; + } + private boolean createPattern(PatternPaint pp, boolean fill) { preparePainting();