View | Details | Raw Unified | Return to bug 37236
Collapse All | Expand All

(-)src/java/org/apache/fop/render/ps/PSGraphics2D.java (+9 lines)
Lines 134-139 Link Here
134
     */
134
     */
135
    public PSGraphics2D(PSGraphics2D g) {
135
    public PSGraphics2D(PSGraphics2D g) {
136
        super(g);
136
        super(g);
137
138
        setPSGenerator(g.gen);
139
        this.clippingDisabled = g.clippingDisabled;
140
        this.font             = g.font;
141
        this.overrideFont     = g.overrideFont;
142
        this.currentFontName  = g.currentFontName;
143
        this.currentFontSize  = g.currentFontSize;
144
        this.currentColour    = g.currentColour;
145
        this.fontInfo         = g.fontInfo;
137
    }
146
    }
138
147
139
    /**
148
    /**
(-)src/java/org/apache/fop/render/pdf/PDFRenderer.java (-11 / +8 lines)
Lines 926-946 Link Here
926
        comment("------ restoring context after break-out...");
926
        comment("------ restoring context after break-out...");
927
        PDFState.Data data;
927
        PDFState.Data data;
928
        Iterator i = breakOutList.iterator();
928
        Iterator i = breakOutList.iterator();
929
        double[] matrix = new double[6];
929
        while (i.hasNext()) {
930
        while (i.hasNext()) {
930
            data = (PDFState.Data)i.next();
931
            data = (PDFState.Data)i.next();
931
            currentState.push();
932
            currentState.push();
932
            saveGraphicsState();
933
            saveGraphicsState();
933
            if (data.concatenations != null) {
934
            AffineTransform at = data.getTransform();
934
                Iterator tr = data.concatenations.iterator();
935
            if (!at.isIdentity()) {
935
                while (tr.hasNext()) {
936
                currentState.setTransform(at);
936
                    AffineTransform at = (AffineTransform)tr.next();
937
                at.getMatrix(matrix);
937
                    currentState.setTransform(at);
938
                tempctm = new CTM(matrix[0], matrix[1], matrix[2], matrix[3], 
938
                    double[] matrix = new double[6];
939
                                  matrix[4] * 1000, matrix[5] * 1000);
939
                    at.getMatrix(matrix);
940
                currentStream.add(CTMHelper.toPDFString(tempctm) + " cm\n");
940
                    tempctm = new CTM(matrix[0], matrix[1], matrix[2], matrix[3], 
941
                            matrix[4] * 1000, matrix[5] * 1000);
942
                    currentStream.add(CTMHelper.toPDFString(tempctm) + " cm\n");
943
                }
944
            }
941
            }
945
            //TODO Break-out: Also restore items such as line width and color
942
            //TODO Break-out: Also restore items such as line width and color
946
            //Left out for now because all this painting stuff is very
943
            //Left out for now because all this painting stuff is very
(-)src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (-3 / +10 lines)
Lines 305-316 Link Here
305
        resourceContext = page;
305
        resourceContext = page;
306
        pdfContext.setCurrentPage(page);
306
        pdfContext.setCurrentPage(page);
307
        pageRef = page.referencePDF();
307
        pageRef = page.referencePDF();
308
        graphicsState.setTransform(new AffineTransform(1.0, 0.0, 0.0, -1.0, 0.0, (double)height));
308
309
        AffineTransform at = new AffineTransform(1.0, 0.0, 0.0, -1.0, 
310
                                                 0.0, (double)height);
309
        currentStream.write("1 0 0 -1 0 " + height + " cm\n");
311
        currentStream.write("1 0 0 -1 0 " + height + " cm\n");
310
        if (svgWidth != 0) {
312
        if (svgWidth != 0) {
311
            currentStream.write("" + PDFNumber.doubleOut(width / svgWidth) + " 0 0 "
313
            double scaleX = width / svgWidth;
312
                    + PDFNumber.doubleOut(height / svgHeight) + " 0 0 cm\n");
314
            double scaleY = height / svgHeight;
315
            at.scale(scaleX, scaleY);
316
            currentStream.write("" + PDFNumber.doubleOut(scaleX) + " 0 0 "
317
                                + PDFNumber.doubleOut(scaleY) + " 0 0 cm\n");
313
        }
318
        }
319
        // Remember the transform we installed.
320
        graphicsState.setTransform(at);
314
321
315
        pdfContext.increasePageCount();
322
        pdfContext.increasePageCount();
316
    }
323
    }
(-)src/java/org/apache/fop/svg/PDFGraphics2D.java (-59 / +113 lines)
Lines 279-284 Link Here
279
    }
279
    }
280
280
281
    /**
281
    /**
282
     * Get the string buffer from the currentStream, containing all
283
     * the commands written into this Grpahics so far.
284
     * @return the StringBuffer containing the PDF markup
285
     */
286
    public StringBuffer getBuffer() {
287
        return currentStream.getBuffer();
288
    }
289
290
    /**
282
     * Set the Grpahics context.
291
     * Set the Grpahics context.
283
     * @param c the graphics context to use
292
     * @param c the graphics context to use
284
     */
293
     */
Lines 829-845 Link Here
829
            LinearGradientPaint gp = (LinearGradientPaint)paint;
838
            LinearGradientPaint gp = (LinearGradientPaint)paint;
830
            Color[] cols = gp.getColors();
839
            Color[] cols = gp.getColors();
831
            float[] fractions = gp.getFractions();
840
            float[] fractions = gp.getFractions();
832
            Point2D p1 = gp.getStartPoint();
841
833
            Point2D p2 = gp.getEndPoint();
834
            //MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod();
842
            //MultipleGradientPaint.CycleMethodEnum cycenum = gp.getCycleMethod();
835
            //boolean cyclic = (cycenum == MultipleGradientPaint.REPEAT);
843
            //boolean cyclic = (cycenum == MultipleGradientPaint.REPEAT);
836
            AffineTransform transform = graphicsState.getTransform();
844
            // This code currently doesn't support 'repeat' as PDF has
845
            // no way to support this (we need to rasterize).
846
847
            // Build proper transform from gradient space to page space
848
            // ('Patterns' don't get userspace transform).
849
            AffineTransform transform;
850
            transform = new AffineTransform(graphicsState.getTransform());
851
            transform.concatenate(getTransform());
837
            transform.concatenate(gp.getTransform());
852
            transform.concatenate(gp.getTransform());
838
            transform.concatenate(getTransform());
839
853
840
            p1 = transform.transform(p1, null);
854
            List theMatrix = new java.util.ArrayList();
841
            p2 = transform.transform(p2, null);
855
            double [] mat = new double[6];
856
            transform.getMatrix(mat);
857
            for (int idx=0; idx<mat.length; idx++) 
858
                theMatrix.add(new Double(mat[idx]));
842
859
860
            Point2D p1 = gp.getStartPoint();
861
            Point2D p2 = gp.getEndPoint();
843
            List theCoords = new java.util.ArrayList();
862
            List theCoords = new java.util.ArrayList();
844
            theCoords.add(new Double(p1.getX()));
863
            theCoords.add(new Double(p1.getX()));
845
            theCoords.add(new Double(p1.getY()));
864
            theCoords.add(new Double(p1.getY()));
Lines 874-919 Link Here
874
                }
893
                }
875
            }
894
            }
876
895
877
            PDFColorSpace aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
896
            PDFColorSpace aColorSpace;
897
            aColorSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
878
            PDFPattern myPat = pdfDoc.getFactory().makeGradient(
898
            PDFPattern myPat = pdfDoc.getFactory().makeGradient(
879
                    resourceContext, false, aColorSpace,
899
                    resourceContext, false, aColorSpace,
880
                    someColors, theBounds, theCoords);
900
                    someColors, theBounds, theCoords, theMatrix);
881
            currentStream.write(myPat.getColorSpaceOut(fill));
901
            currentStream.write(myPat.getColorSpaceOut(fill));
882
902
883
        } else if (paint instanceof RadialGradientPaint) {
903
        } else if (paint instanceof RadialGradientPaint) {
884
            RadialGradientPaint rgp = (RadialGradientPaint)paint;
904
            RadialGradientPaint rgp = (RadialGradientPaint)paint;
885
905
906
            AffineTransform transform;
907
            transform = new AffineTransform(graphicsState.getTransform());
908
            transform.concatenate(getTransform());
909
            transform.concatenate(rgp.getTransform());
910
911
            List theMatrix = new java.util.ArrayList();
912
            double [] mat = new double[6];
913
            transform.getMatrix(mat);
914
            for (int idx=0; idx<mat.length; idx++) 
915
                theMatrix.add(new Double(mat[idx]));
916
886
            double ar = rgp.getRadius();
917
            double ar = rgp.getRadius();
887
            Point2D ac = rgp.getCenterPoint();
918
            Point2D ac = rgp.getCenterPoint();
888
            Point2D af = rgp.getFocusPoint();
919
            Point2D af = rgp.getFocusPoint();
889
            AffineTransform transform = graphicsState.getTransform();
890
            AffineTransform gradt = rgp.getTransform();
891
            transform.concatenate(gradt);
892
920
893
            // find largest scaling for the radius
921
            List theCoords = new java.util.ArrayList();
894
            double scale = gradt.getScaleX();
922
            double dx = af.getX()-ac.getX();
895
            if (gradt.getScaleY() > scale) {
923
            double dy = af.getY()-ac.getY();
896
                scale = gradt.getScaleY();
924
            double d = Math.sqrt(dx*dx+dy*dy);
925
            if (d > ar) {
926
                // the center point af must be within the circle with
927
                // radius ar centered at ac so limit it to that.
928
                double scale = (ar*.9999)/d;
929
                dx = dx*scale;
930
                dy = dy*scale;
897
            }
931
            }
898
            ar = ar * scale;
899
            ac = transform.transform(ac, null);
900
            af = transform.transform(af, null);
901
932
902
            List theCoords = new java.util.ArrayList();
933
            theCoords.add(new Double(ac.getX()+dx)); // Fx
903
            // the center point af must be within the circle with
934
            theCoords.add(new Double(ac.getY()+dy)); // Fy
904
            // radius ar centered at ac
905
            theCoords.add(new Double(af.getX()));
906
            theCoords.add(new Double(af.getY()));
907
            theCoords.add(new Double(0));
935
            theCoords.add(new Double(0));
908
            theCoords.add(new Double(ac.getX())); // Fx
936
            theCoords.add(new Double(ac.getX()));
909
            theCoords.add(new Double(ac.getY())); // Fy
937
            theCoords.add(new Double(ac.getY()));
910
            theCoords.add(new Double(ar));
938
            theCoords.add(new Double(ar));
911
939
912
            Color[] cols = rgp.getColors();
940
            Color[] cols = rgp.getColors();
913
            List someColors = new java.util.ArrayList();
941
            List someColors = new java.util.ArrayList();
914
            for (int count = 0; count < cols.length; count++) {
942
            for (int count = 0; count < cols.length; count++) {
915
                Color cc = cols[count];
943
                Color cc = cols[count];
916
                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), cc.getBlue()));
944
                someColors.add(new PDFColor(cc.getRed(), cc.getGreen(), 
945
                                            cc.getBlue()));
917
            }
946
            }
918
947
919
            float[] fractions = rgp.getFractions();
948
            float[] fractions = rgp.getFractions();
Lines 922-932 Link Here
922
                float offset = fractions[count];
951
                float offset = fractions[count];
923
                theBounds.add(new Double(offset));
952
                theBounds.add(new Double(offset));
924
            }
953
            }
925
            PDFColorSpace colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
954
            PDFColorSpace colSpace;
926
            PDFPattern myPat = pdfDoc.getFactory().makeGradient(
955
            colSpace = new PDFColorSpace(PDFColorSpace.DEVICE_RGB);
927
                                    resourceContext, true, colSpace,
928
                                    someColors, theBounds, theCoords);
929
956
957
            PDFPattern myPat = pdfDoc.getFactory().makeGradient
958
                (resourceContext, true, colSpace,
959
                 someColors, theBounds, theCoords, theMatrix);
960
930
            currentStream.write(myPat.getColorSpaceOut(fill));
961
            currentStream.write(myPat.getColorSpaceOut(fill));
931
962
932
        } else if (paint instanceof PatternPaint) {
963
        } else if (paint instanceof PatternPaint) {
Lines 937-943 Link Here
937
968
938
    private void createPattern(PatternPaint pp, boolean fill) {
969
    private void createPattern(PatternPaint pp, boolean fill) {
939
        preparePainting();
970
        preparePainting();
940
        Rectangle2D rect = pp.getPatternRect();
941
971
942
        FontInfo fontInfo = new FontInfo();
972
        FontInfo fontInfo = new FontInfo();
943
        FontSetup.setup(fontInfo, null);
973
        FontSetup.setup(fontInfo, null);
Lines 947-988 Link Here
947
        PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo,
977
        PDFGraphics2D pattGraphic = new PDFGraphics2D(textAsShapes, fontInfo,
948
                                        pdfDoc, context, pageRef,
978
                                        pdfDoc, context, pageRef,
949
                                        "", 0);
979
                                        "", 0);
950
        pattGraphic.gc = (GraphicContext)this.gc.clone();
980
        pattGraphic.setGraphicContext(new GraphicContext());
951
        pattGraphic.gc.validateTransformStack();
981
        pattGraphic.gc.validateTransformStack();
982
        pattGraphic.setRenderingHints(this.getRenderingHints());
952
        pattGraphic.setOutputStream(outputStream);
983
        pattGraphic.setOutputStream(outputStream);
953
984
954
        GraphicsNode gn = pp.getGraphicsNode();
985
        GraphicsNode gn = pp.getGraphicsNode();
955
        gn.paint(pattGraphic);
986
        Rectangle2D gnBBox = gn.getBounds();
987
        Rectangle2D rect = pp.getPatternRect();
956
988
957
        StringWriter pattStream = new StringWriter();
989
        // if (!pp.getOverflow()) {
958
        pattStream.write("q\n");
990
            gn.paint(pattGraphic);
991
        // } else {
992
        // /* Commented out until SVN version of Batik is included */
993
        //     // For overflow we need to paint the content from
994
        //     // all the tiles who's overflow will intersect one
995
        //     // tile (left->right, top->bottom).  Then we can
996
        //     // simply replicate that tile as normal.
997
        //     double gnMinX = gnBBox.getX();
998
        //     double gnMaxX = gnBBox.getX() + gnBBox.getWidth();
999
        //     double gnMinY = gnBBox.getY();
1000
        //     double gnMaxY = gnBBox.getY() + gnBBox.getHeight();
1001
        //     double patMaxX = rect.getX() + rect.getWidth();
1002
        //     double patMaxY = rect.getY() + rect.getHeight();
1003
        //     double stepX = rect.getWidth();
1004
        //     double stepY = rect.getHeight();            
1005
        // 
1006
        //     int startX = (int)((rect.getX() - gnMaxX)/stepX);
1007
        //     int startY = (int)((rect.getY() - gnMaxY)/stepY);
1008
        // 
1009
        //     int endX   = (int)((patMaxX - gnMinX)/stepX);
1010
        //     int endY   = (int)((patMaxY - gnMinY)/stepY);
1011
        // 
1012
        //     pattGraphic.translate(startX*stepX, startY*stepY);
1013
        //     for (int yIdx=startY; yIdx<=endY; yIdx++) {
1014
        //         for (int xIdx=startX; xIdx<=endX; xIdx++) {
1015
        //             gn.paint(pattGraphic);
1016
        //             pattGraphic.translate(stepX,0);
1017
        //         }
1018
        //         pattGraphic.translate(-(endX-startX+1)*stepX, stepY);
1019
        //     }
1020
        // }
959
1021
960
        // this makes the pattern the right way up, since
1022
        List bbox = new java.util.ArrayList();
961
        // it is outside the original transform around the
1023
        bbox.add(new Double(rect.getX()));
962
        // whole svg document
1024
        bbox.add(new Double(rect.getHeight()+rect.getY()));
963
        pattStream.write("1 0 0 -1 0 " + (rect.getHeight() + rect.getY()) + " cm\n");
1025
        bbox.add(new Double(rect.getWidth() +rect.getX()));
1026
        bbox.add(new Double(rect.getY()));
964
1027
965
        pattStream.write(pattGraphic.getString());
1028
        AffineTransform transform;
966
        pattStream.write("Q");
1029
        transform = new AffineTransform(graphicsState.getTransform());
1030
        transform.concatenate(getTransform());
1031
        transform.concatenate(pp.getPatternTransform());
967
1032
968
        List bbox = new java.util.ArrayList();
1033
        List theMatrix = new java.util.ArrayList();
969
        bbox.add(new Double(0));
1034
        double [] mat = new double[6];
970
        bbox.add(new Double(0));
1035
        transform.getMatrix(mat);
971
        bbox.add(new Double(rect.getWidth() + rect.getX()));
1036
        for (int idx=0; idx<mat.length; idx++) 
972
        bbox.add(new Double(rect.getHeight() + rect.getY()));
1037
            theMatrix.add(new Double(mat[idx]));
973
1038
974
        List translate = new java.util.ArrayList();
975
        AffineTransform pattt = pp.getPatternTransform();
976
        pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY());
977
        double[] flatmatrix = new double[6];
978
        pattt.getMatrix(flatmatrix);
979
        translate.add(new Double(flatmatrix[0]));
980
        translate.add(new Double(flatmatrix[1]));
981
        translate.add(new Double(flatmatrix[2]));
982
        translate.add(new Double(flatmatrix[3]));
983
        translate.add(new Double(flatmatrix[4]));
984
        translate.add(new Double(flatmatrix[5]));
985
986
        /** @todo see if pdfDoc and res can be linked here,
1039
        /** @todo see if pdfDoc and res can be linked here,
987
        (currently res <> PDFDocument's resources) so addFonts() 
1040
        (currently res <> PDFDocument's resources) so addFonts() 
988
        can be moved to PDFDocument class */
1041
        can be moved to PDFDocument class */
Lines 991-997 Link Here
991
        PDFPattern myPat = pdfDoc.getFactory().makePattern(
1044
        PDFPattern myPat = pdfDoc.getFactory().makePattern(
992
                                resourceContext, 1, res, 1, 1, bbox,
1045
                                resourceContext, 1, res, 1, 1, bbox,
993
                                rect.getWidth(), rect.getHeight(),
1046
                                rect.getWidth(), rect.getHeight(),
994
                                translate, null, pattStream.getBuffer());
1047
                                theMatrix, null, 
1048
                                pattGraphic.getBuffer());
995
1049
996
        currentStream.write(myPat.getColorSpaceOut(fill));
1050
        currentStream.write(myPat.getColorSpaceOut(fill));
997
1051
(-)src/java/org/apache/fop/pdf/PDFState.java (-25 / +19 lines)
Lines 68-78 Link Here
68
        Data copy;
68
        Data copy;
69
        try {
69
        try {
70
            copy = (Data)getData().clone();
70
            copy = (Data)getData().clone();
71
            getData().resetTransform();
71
        } catch (CloneNotSupportedException e) {
72
        } catch (CloneNotSupportedException e) {
72
            throw new RuntimeException(e.getMessage());
73
            throw new RuntimeException(e.getMessage());
73
        }
74
        }
74
        stateStack.add(copy);
75
        stateStack.add(copy);
75
        data.resetConcatenations();
76
    }
76
    }
77
77
78
    /**
78
    /**
Lines 280-295 Link Here
280
     * @return the calculate combined transform for the current state
280
     * @return the calculate combined transform for the current state
281
     */
281
     */
282
    public AffineTransform getTransform() {
282
    public AffineTransform getTransform() {
283
        AffineTransform tf;
283
       AffineTransform tf;
284
        AffineTransform at = new AffineTransform();
284
       AffineTransform at = new AffineTransform();
285
        for (Iterator iter = stateStack.iterator(); iter.hasNext();) {
285
       for (Iterator iter = stateStack.iterator(); iter.hasNext();) {
286
            Data d = (Data)iter.next();
286
           Data d = (Data)iter.next();
287
            tf = d.transform;
287
           tf = d.transform;
288
            at.concatenate(tf);
288
           at.concatenate(tf);
289
        }
289
       }
290
        at.concatenate(getData().transform);
290
       at.concatenate(getData().transform);
291
291
       return at;
292
        return at;
293
    }
292
    }
294
293
295
    /**
294
    /**
Lines 339-346 Link Here
339
        public String fontName = "";
338
        public String fontName = "";
340
        public Shape clip = null;
339
        public Shape clip = null;
341
        public PDFGState gstate = null;
340
        public PDFGState gstate = null;
342
        /** Log of all concatenation operations */
343
        public List concatenations = null;
344
341
345
        
342
        
346
        /** @see java.lang.Object#clone() */
343
        /** @see java.lang.Object#clone() */
Lines 362-380 Link Here
362
            obj.fontName = this.fontName;
359
            obj.fontName = this.fontName;
363
            obj.clip = this.clip;
360
            obj.clip = this.clip;
364
            obj.gstate = this.gstate;
361
            obj.gstate = this.gstate;
365
            if (this.concatenations != null) {
366
                obj.concatenations = new java.util.ArrayList(this.concatenations);
367
            }
368
            return obj;
362
            return obj;
369
        }
363
        }
370
        
364
        
371
        /**
365
        /**
372
         * Forgets the previously made AffineTransform concatenations.
366
         * Get the current Transform.
373
         */
367
         */
374
        public void resetConcatenations() {
368
        public AffineTransform getTransform() {
375
            this.concatenations = null;
369
            return transform;
376
        }
370
        }
377
        
371
372
        public void resetTransform() {
373
            transform = new AffineTransform();
374
        }
375
378
        /**
376
        /**
379
         * Concatenate the given AffineTransform with the current thus creating
377
         * Concatenate the given AffineTransform with the current thus creating
380
         * a new viewport. Note that all concatenation operations are logged
378
         * a new viewport. Note that all concatenation operations are logged
Lines 383-398 Link Here
383
         * @param at Transformation to perform
381
         * @param at Transformation to perform
384
         */
382
         */
385
        public void concatenate(AffineTransform at) {
383
        public void concatenate(AffineTransform at) {
386
            if (this.concatenations == null) {
387
                this.concatenations = new java.util.ArrayList();
388
            }
389
            concatenations.add(at);
390
            transform.concatenate(at);
384
            transform.concatenate(at);
391
        }
385
        }
392
        
386
        
393
        /** @see java.lang.Object#toString() */
387
        /** @see java.lang.Object#toString() */
394
        public String toString() {
388
        public String toString() {
395
            return super.toString() + ", " + this.transform + " | " + this.concatenations;
389
            return super.toString() + ", " + this.transform;
396
        }
390
        }
397
    }
391
    }
398
}
392
}
(-)src/java/org/apache/fop/pdf/PDFFactory.java (-2 / +2 lines)
Lines 688-694 Link Here
688
    public PDFPattern makeGradient(PDFResourceContext res, boolean radial,
688
    public PDFPattern makeGradient(PDFResourceContext res, boolean radial,
689
                                   PDFColorSpace theColorspace,
689
                                   PDFColorSpace theColorspace,
690
                                   List theColors, List theBounds,
690
                                   List theColors, List theBounds,
691
                                   List theCoords) {
691
                                   List theCoords, List theMatrix) {
692
        PDFShading myShad;
692
        PDFShading myShad;
693
        PDFFunction myfunky;
693
        PDFFunction myfunky;
694
        PDFFunction myfunc;
694
        PDFFunction myfunc;
Lines 770-776 Link Here
770
770
771
        }
771
        }
772
772
773
        myPattern = makePattern(res, 2, myShad, null, null, null);
773
        myPattern = makePattern(res, 2, myShad, null, null, theMatrix);
774
774
775
        return (myPattern);
775
        return (myPattern);
776
    }
776
    }

Return to bug 37236