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

(-)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 (-57 / +112 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
            // For overflow we need to paint the content from
991
            // all the tiles who's overflow will intersect one
992
            // tile (left->right, top->bottom).  Then we can
993
            // simply replicate that tile as normal.
994
            double gnMinX = gnBBox.getX();
995
            double gnMaxX = gnBBox.getX() + gnBBox.getWidth();
996
            double gnMinY = gnBBox.getY();
997
            double gnMaxY = gnBBox.getY() + gnBBox.getHeight();
998
            double patMaxX = rect.getX() + rect.getWidth();
999
            double patMaxY = rect.getY() + rect.getHeight();
1000
            double stepX = rect.getWidth();
1001
            double stepY = rect.getHeight();            
959
1002
960
        // this makes the pattern the right way up, since
1003
            int startX = (int)((rect.getX() - gnMaxX)/stepX);
961
        // it is outside the original transform around the
1004
            int startY = (int)((rect.getY() - gnMaxY)/stepY);
962
        // whole svg document
963
        pattStream.write("1 0 0 -1 0 " + (rect.getHeight() + rect.getY()) + " cm\n");
964
1005
965
        pattStream.write(pattGraphic.getString());
1006
            int endX   = (int)((patMaxX - gnMinX)/stepX);
966
        pattStream.write("Q");
1007
            int endY   = (int)((patMaxY - gnMinY)/stepY);
967
1008
1009
            pattGraphic.translate(startX*stepX, startY*stepY);
1010
            for (int yIdx=startY; yIdx<=endY; yIdx++) {
1011
                for (int xIdx=startX; xIdx<=endX; xIdx++) {
1012
                    gn.paint(pattGraphic);
1013
                    pattGraphic.translate(stepX,0);
1014
                }
1015
                pattGraphic.translate(-(endX-startX+1)*stepX, stepY);
1016
            }
1017
            
1018
        } else {
1019
            gn.paint(pattGraphic);
1020
        }
1021
1022
968
        List bbox = new java.util.ArrayList();
1023
        List bbox = new java.util.ArrayList();
969
        bbox.add(new Double(0));
1024
        bbox.add(new Double(rect.getX()));
970
        bbox.add(new Double(0));
1025
        bbox.add(new Double(rect.getHeight()+rect.getY()));
971
        bbox.add(new Double(rect.getWidth() + rect.getX()));
1026
        bbox.add(new Double(rect.getWidth() +rect.getX()));
972
        bbox.add(new Double(rect.getHeight() + rect.getY()));
1027
        bbox.add(new Double(rect.getY()));
973
1028
974
        List translate = new java.util.ArrayList();
1029
        AffineTransform transform;
975
        AffineTransform pattt = pp.getPatternTransform();
1030
        transform = new AffineTransform(graphicsState.getTransform());
976
        pattt.translate(rect.getWidth() + rect.getX(), rect.getHeight() + rect.getY());
1031
        transform.concatenate(getTransform());
977
        double[] flatmatrix = new double[6];
1032
        transform.concatenate(pp.getPatternTransform());
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
1033
1034
        List theMatrix = new java.util.ArrayList();
1035
        double [] mat = new double[6];
1036
        transform.getMatrix(mat);
1037
        for (int idx=0; idx<mat.length; idx++) 
1038
            theMatrix.add(new Double(mat[idx]));
1039
986
        /** @todo see if pdfDoc and res can be linked here,
1040
        /** @todo see if pdfDoc and res can be linked here,
987
        (currently res <> PDFDocument's resources) so addFonts() 
1041
        (currently res <> PDFDocument's resources) so addFonts() 
988
        can be moved to PDFDocument class */
1042
        can be moved to PDFDocument class */
Lines 991-997 Link Here
991
        PDFPattern myPat = pdfDoc.getFactory().makePattern(
1045
        PDFPattern myPat = pdfDoc.getFactory().makePattern(
992
                                resourceContext, 1, res, 1, 1, bbox,
1046
                                resourceContext, 1, res, 1, 1, bbox,
993
                                rect.getWidth(), rect.getHeight(),
1047
                                rect.getWidth(), rect.getHeight(),
994
                                translate, null, pattStream.getBuffer());
1048
                                theMatrix, null, 
1049
                                pattGraphic.getBuffer());
995
1050
996
        currentStream.write(myPat.getColorSpaceOut(fill));
1051
        currentStream.write(myPat.getColorSpaceOut(fill));
997
1052
(-)src/java/org/apache/fop/pdf/PDFState.java (-28 / +2 lines)
Lines 72-78 Link Here
72
            throw new RuntimeException(e.getMessage());
72
            throw new RuntimeException(e.getMessage());
73
        }
73
        }
74
        stateStack.add(copy);
74
        stateStack.add(copy);
75
        data.resetConcatenations();
76
    }
75
    }
77
76
78
    /**
77
    /**
Lines 280-295 Link Here
280
     * @return the calculate combined transform for the current state
279
     * @return the calculate combined transform for the current state
281
     */
280
     */
282
    public AffineTransform getTransform() {
281
    public AffineTransform getTransform() {
283
        AffineTransform tf;
282
        return new AffineTransform(getData().transform);
284
        AffineTransform at = new AffineTransform();
285
        for (Iterator iter = stateStack.iterator(); iter.hasNext();) {
286
            Data d = (Data)iter.next();
287
            tf = d.transform;
288
            at.concatenate(tf);
289
        }
290
        at.concatenate(getData().transform);
291
292
        return at;
293
    }
283
    }
294
284
295
    /**
285
    /**
Lines 339-346 Link Here
339
        public String fontName = "";
329
        public String fontName = "";
340
        public Shape clip = null;
330
        public Shape clip = null;
341
        public PDFGState gstate = null;
331
        public PDFGState gstate = null;
342
        /** Log of all concatenation operations */
343
        public List concatenations = null;
344
332
345
        
333
        
346
        /** @see java.lang.Object#clone() */
334
        /** @see java.lang.Object#clone() */
Lines 362-381 Link Here
362
            obj.fontName = this.fontName;
350
            obj.fontName = this.fontName;
363
            obj.clip = this.clip;
351
            obj.clip = this.clip;
364
            obj.gstate = this.gstate;
352
            obj.gstate = this.gstate;
365
            if (this.concatenations != null) {
366
                obj.concatenations = new java.util.ArrayList(this.concatenations);
367
            }
368
            return obj;
353
            return obj;
369
        }
354
        }
370
        
355
        
371
        /**
356
        /**
372
         * Forgets the previously made AffineTransform concatenations.
373
         */
374
        public void resetConcatenations() {
375
            this.concatenations = null;
376
        }
377
        
378
        /**
379
         * Concatenate the given AffineTransform with the current thus creating
357
         * Concatenate the given AffineTransform with the current thus creating
380
         * a new viewport. Note that all concatenation operations are logged
358
         * a new viewport. Note that all concatenation operations are logged
381
         * so they can be replayed if necessary (ex. for block-containers with
359
         * so they can be replayed if necessary (ex. for block-containers with
Lines 383-398 Link Here
383
         * @param at Transformation to perform
361
         * @param at Transformation to perform
384
         */
362
         */
385
        public void concatenate(AffineTransform at) {
363
        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);
364
            transform.concatenate(at);
391
        }
365
        }
392
        
366
        
393
        /** @see java.lang.Object#toString() */
367
        /** @see java.lang.Object#toString() */
394
        public String toString() {
368
        public String toString() {
395
            return super.toString() + ", " + this.transform + " | " + this.concatenations;
369
            return super.toString() + ", " + this.transform;
396
        }
370
        }
397
    }
371
    }
398
}
372
}
(-)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