You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2006/08/26 20:59:43 UTC

svn commit: r437210 - in /xmlgraphics/fop/trunk: ./ src/java/org/apache/fop/pdf/ src/java/org/apache/fop/render/pdf/ src/java/org/apache/fop/svg/

Author: jeremias
Date: Sat Aug 26 11:59:42 2006
New Revision: 437210

URL: http://svn.apache.org/viewvc?rev=437210&view=rev
Log:
My last attempt at fixing SVG gradients in PDF wasn't successful. This one is:
Improved resolution of transformation matrices in PDF patterns.
Renamed PDFState.setTransform() to PDFState.concatenate() because setTransform() does a concationation and is therefore misleading. The old method is still there (just in case) but it is deprecated.
Simplified the whole transformation tracking by including the basic page transformation in the stack.
Verified the changes with basic-links in FO, fixed block-containers, a-links in SVG and SVG gradients.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPattern.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFState.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPattern.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPattern.java?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPattern.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFPattern.java Sat Aug 26 11:59:42 2006
@@ -250,7 +250,8 @@
                 vectorSize = this.matrix.size();
                 p.append("/Matrix [ ");
                 for (tempInt = 0; tempInt < vectorSize; tempInt++) {
-                    p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt)));
+                    p.append(PDFNumber.doubleOut(
+                            ((Double)this.matrix.get(tempInt)).doubleValue(), 8));
                     p.append(" ");
                 }
                 p.append("] \n");
@@ -303,7 +304,8 @@
                 vectorSize = this.matrix.size();
                 p.append("/Matrix [ ");
                 for (tempInt = 0; tempInt < vectorSize; tempInt++) {
-                    p.append(PDFNumber.doubleOut((Double)this.matrix.get(tempInt)));
+                    p.append(PDFNumber.doubleOut(
+                            ((Double)this.matrix.get(tempInt)).doubleValue(), 8));
                     p.append(" ");
                 }
                 p.append("] \n");

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFState.java?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFState.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFState.java Sat Aug 26 11:59:42 2006
@@ -267,8 +267,17 @@
      * the current graphic state.
      *
      * @param tf the transform to concatonate to the current level transform
+     * @deprecated This method name is misleading. Use concatenate(AffineTransform) instead!
      */
     public void setTransform(AffineTransform tf) {
+        concatenate(tf);
+    }
+    
+    /**
+     * Concatenates the given AffineTransform to the current one.
+     * @param tf the transform to concatenate to the current level transform
+     */
+    public void concatenate(AffineTransform tf) {
         getData().concatenate(tf);
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFGraphics2DAdapter.java Sat Aug 26 11:59:42 2006
@@ -94,7 +94,7 @@
         
         AffineTransform transform = new AffineTransform();
         transform.translate(fx, fy);
-        pdfInfo.pdfState.setTransform(transform);
+        pdfInfo.pdfState.concatenate(transform);
         graphics.setPDFState(pdfInfo.pdfState);
         graphics.setOutputStream(pdfInfo.outputStream);
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java Sat Aug 26 11:59:42 2006
@@ -208,9 +208,6 @@
     /** Optional URI to an output profile to be used. */
     protected String outputProfileURI; 
     
-    /** The current Transform */
-    protected AffineTransform currentBasicTransform;
-
     /** drawing state */
     protected PDFState currentState = null;
 
@@ -704,16 +701,11 @@
             .makeStream(PDFFilterList.CONTENT_FILTER, false);
 
         currentState = new PDFState();
-        /* This transform shouldn't affect PDFState as it only sets the basic
-         * coordinate system for the rendering process.
-         *
-        currentState.setTransform(new AffineTransform(1, 0, 0, -1, 0,
-                                   (int) Math.round(pageHeight / 1000)));
-        */
-        // Transform origin at top left to origin at bottom left
-        currentBasicTransform = new AffineTransform(1, 0, 0, -1, 0,
+        // Transform the PDF's default coordinate system (0,0 at lower left) to the PDFRenderer's
+        AffineTransform basicPageTransform = new AffineTransform(1, 0, 0, -1, 0,
                 pageHeight / 1000f);
-        currentStream.add(CTMHelper.toPDFString(currentBasicTransform, false) + " cm\n");
+        currentState.concatenate(basicPageTransform);
+        currentStream.add(CTMHelper.toPDFString(basicPageTransform, false) + " cm\n");
         
         
         currentFontName = "";
@@ -736,7 +728,7 @@
     protected void startVParea(CTM ctm, Rectangle2D clippingRect) {
         // Set the given CTM in the graphics state
         currentState.push();
-        currentState.setTransform(
+        currentState.concatenate(
                 new AffineTransform(CTMHelper.toPDFArray(ctm)));
 
         saveGraphicsState();
@@ -1069,7 +1061,7 @@
             saveGraphicsState();
             AffineTransform at = data.getTransform();
             if (!at.isIdentity()) {
-                currentState.setTransform(at);
+                currentState.concatenate(at);
                 at.getMatrix(matrix);
                 tempctm = new CTM(matrix[0], matrix[1], matrix[2], matrix[3], 
                                   matrix[4] * 1000, matrix[5] * 1000);
@@ -1130,7 +1122,6 @@
                 // transform rect to absolute coords
                 AffineTransform transform = currentState.getTransform();
                 rect = transform.createTransformedShape(rect).getBounds2D();
-                rect = currentBasicTransform.createTransformedShape(rect).getBounds2D();
 
                 int type = internal ? PDFLink.INTERNAL : PDFLink.EXTERNAL;
                 PDFLink pdflink = pdfDoc.getFactory().makeLink(

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFSVGHandler.java Sat Aug 26 11:59:42 2006
@@ -26,16 +26,12 @@
 import java.awt.geom.AffineTransform;
 
 import org.w3c.dom.Document;
-import org.w3c.dom.svg.SVGAElement;
-import org.w3c.dom.svg.SVGDocument;
-import org.w3c.dom.svg.SVGSVGElement;
 
 import org.apache.fop.render.AbstractGenericSVGHandler;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.RendererContext;
 import org.apache.fop.render.RendererContextConstants;
 import org.apache.fop.pdf.PDFDocument;
-import org.apache.fop.pdf.PDFNumber;
 import org.apache.fop.pdf.PDFPage;
 import org.apache.fop.pdf.PDFState;
 import org.apache.fop.pdf.PDFStream;
@@ -56,7 +52,6 @@
 
 import org.apache.batik.bridge.GVTBuilder;
 import org.apache.batik.bridge.BridgeContext;
-import org.apache.batik.bridge.ViewBox;
 import org.apache.batik.dom.svg.SVGDOMImplementation;
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.util.SVGConstants;
@@ -173,11 +168,6 @@
         AffineTransform resolutionScaling = new AffineTransform();
         resolutionScaling.scale(s, s);
         
-        //Transformation matrix that establishes the local coordinate system for the SVG graphic
-        //in relation to PDF's initial coordinate system.
-        AffineTransform baseTransform = (AffineTransform)renderer.currentBasicTransform.clone();
-        baseTransform.concatenate(pdfInfo.pdfState.getTransform());
-
         GVTBuilder builder = new GVTBuilder();
         
         //Controls whether text painted by Batik is generated using text or path operations
@@ -211,16 +201,12 @@
         AffineTransform scaling = new AffineTransform(
                 sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f);
 
-        //Finish the baseTransform, now that we know everything
-        baseTransform.concatenate(scaling);
-        baseTransform.concatenate(resolutionScaling);
+        //Transformation matrix that establishes the local coordinate system for the SVG graphic
+        //in relation to the current coordinate system
+        AffineTransform imageTransform = new AffineTransform();
+        imageTransform.concatenate(scaling);
+        imageTransform.concatenate(resolutionScaling);
         
-        //Now that we have the full baseTransform, we can update the transformation matrix for
-        //the AElementBridge.
-        PDFAElementBridge aBridge = (PDFAElementBridge)ctx.getBridge(
-                SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG);
-        aBridge.getCurrentTransform().setTransform(baseTransform);
-
         /*
          * Clip to the svg area.
          * Note: To have the svg overlay (under) a text area then use
@@ -236,7 +222,7 @@
             pdfInfo.currentStream.add(CTMHelper.toPDFString(scaling, false) + " cm\n");
         }
 
-        SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
+        //SVGSVGElement svg = ((SVGDocument)doc).getRootElement();
 
         if (pdfInfo.pdfContext == null) {
             pdfInfo.pdfContext = pdfInfo.pdfPage;
@@ -248,7 +234,8 @@
         graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
 
         if (!resolutionScaling.isIdentity()) {
-            pdfInfo.currentStream.add("%resolution scaling for " + uaResolution + " -> " + deviceResolution + "\n");
+            pdfInfo.currentStream.add("%resolution scaling for " + uaResolution 
+                        + " -> " + deviceResolution + "\n");
             pdfInfo.currentStream.add(
                     CTMHelper.toPDFString(resolutionScaling, false) + " cm\n");
             graphics.scale(1 / s, 1 / s);
@@ -256,8 +243,16 @@
         
         pdfInfo.currentStream.add("%SVG start\n");
 
+        //Save state and update coordinate system for the SVG image
         pdfInfo.pdfState.push();
-        pdfInfo.pdfState.setTransform(baseTransform);
+        pdfInfo.pdfState.concatenate(imageTransform);
+
+        //Now that we have the complete transformation matrix for the image, we can update the 
+        //transformation matrix for the AElementBridge.
+        PDFAElementBridge aBridge = (PDFAElementBridge)ctx.getBridge(
+                SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG);
+        aBridge.getCurrentTransform().setTransform(pdfInfo.pdfState.getTransform());
+
         graphics.setPDFState(pdfInfo.pdfState);
         graphics.setOutputStream(pdfInfo.outputStream);
         try {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java Sat Aug 26 11:59:42 2006
@@ -355,7 +355,7 @@
             scale(1 / s, 1 / s);
         }
         // Remember the transform we installed.
-        graphicsState.setTransform(at);
+        graphicsState.concatenate(at);
 
         pdfContext.increasePageCount();
     }

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=437210&r1=437209&r2=437210&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Sat Aug 26 11:59:42 2006
@@ -28,6 +28,10 @@
 
   <changes>
     <release version="FOP Trunk">
+      <action context="Code" dev="JM" type="fix">
+        Bugfix: Corrected painting of shading patterns and position of links for SVG images
+        inside FO documents.
+      </action>
       <action context="Code" dev="AD" type="update">
         Minor fix: correctly set negative values to zero.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org