You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/03/02 19:56:25 UTC

svn commit: r918150 - in /pdfbox/trunk/src/main/java/org/apache/pdfbox: pdmodel/graphics/xobject/PDXObjectForm.java util/operator/pagedrawer/Invoke.java

Author: lehmi
Date: Tue Mar  2 18:56:25 2010
New Revision: 918150

URL: http://svn.apache.org/viewvc?rev=918150&view=rev
Log:
PDFBOX-646: use the optional form matrix to map form the form space to the user space

Modified:
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectForm.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectForm.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectForm.java?rev=918150&r1=918149&r2=918150&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectForm.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDXObjectForm.java Tue Mar  2 18:56:25 2010
@@ -19,11 +19,13 @@
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * A form xobject.
@@ -111,7 +113,7 @@
     /**
      * An array of four numbers in the form coordinate system (see
      * below), giving the coordinates of the left, bottom, right, and top edges,
-     * respectively, of the form XObjectÂ’s bounding box. These boundaries are used
+     * respectively, of the form XObject's bounding box. These boundaries are used
      * to clip the form XObject and to determine its size for caching.
      *
      * @return The BBox of the form.
@@ -143,4 +145,27 @@
             getCOSStream().setItem( COSName.BBOX, bbox.getCOSArray() );
         }
     }
+    
+    /**
+     * This will get the optional Matrix of an XObjectForm.
+     * It maps the form space into the user space
+     * @return the form matrix
+     */
+    public Matrix getMatrix() 
+    {
+        Matrix retval = null;
+        COSArray array = (COSArray)getCOSStream().getDictionaryObject( COSName.MATRIX );
+        if( array != null )
+        {
+            retval = new Matrix();
+            retval.setValue(0, 0, ((COSNumber) array.get(0)).floatValue());
+            retval.setValue(0, 1, ((COSNumber) array.get(1)).floatValue());
+            retval.setValue(1, 0, ((COSNumber) array.get(2)).floatValue());
+            retval.setValue(1, 1, ((COSNumber) array.get(3)).floatValue());
+            retval.setValue(2, 0, ((COSNumber) array.get(4)).floatValue());
+            retval.setValue(2, 1, ((COSNumber) array.get(5)).floatValue());
+        }
+        return retval;
+    }
+    
 }

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java?rev=918150&r1=918149&r2=918150&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java Tue Mar  2 18:56:25 2010
@@ -138,7 +138,14 @@
             {
                 pdResources = page.findResources();
             }
-
+            // if there is an optional form matrix, we have to
+            // map the form space to the user space
+            Matrix matrix = form.getMatrix();
+            if (matrix != null) 
+            {
+                Matrix xobjectCTM = matrix.multiply( context.getGraphicsState().getCurrentTransformationMatrix());
+                context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
+            }
             getContext().processSubStream( page, pdResources, invoke );
         }
         else