pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1465396 [3/3] - in /pdfbox/branches/1.8: ./ fontbox/src/main/java/org/apache/fontbox/ttf/ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/ pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/...
Date Sun, 07 Apr 2013 13:29:13 GMT
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java Sun
Apr  7 13:29:12 2013
@@ -124,7 +124,7 @@ public class PageDrawer extends PDFStrea
             PDResources resources = page.findResources();
             processStream( page, resources, page.getContents().getStream() );
         }
-        List annotations = page.getAnnotations();
+        List<PDAnnotation> annotations = page.getAnnotations();
         for( int i=0; i<annotations.size(); i++ )
         {
             PDAnnotation annot = (PDAnnotation)annotations.get( i );
@@ -137,16 +137,24 @@ public class PageDrawer extends PDFStrea
                 {
                     appearanceName = "default";
                 }
-                Map appearanceMap = appearDictionary.getNormalAppearance();
+                Map<String, PDAppearanceStream> appearanceMap = appearDictionary.getNormalAppearance();
                 if (appearanceMap != null) 
                 { 
                     PDAppearanceStream appearance = 
                         (PDAppearanceStream)appearanceMap.get( appearanceName ); 
                     if( appearance != null ) 
                     { 
-                        g.translate( (int)rect.getLowerLeftX(), (int)-rect.getLowerLeftY()
); 
+                        Point2D point = new Point2D.Float(rect.getLowerLeftX(), rect.getLowerLeftY());
+                        Matrix matrix = appearance.getMatrix();
+                        if (matrix != null) 
+                        {
+                            // transform the rectangle using the given matrix 
+                            AffineTransform at = matrix.createAffineTransform();
+                            at.transform(point, point);
+                        }
+                        g.translate( (int)point.getX(), -(int)point.getY() );
                         processSubStream( page, appearance.getResources(), appearance.getStream()
); 
-                        g.translate( (int)-rect.getLowerLeftX(), (int)+rect.getLowerLeftY()
); 
+                        g.translate( -(int)point.getX(), (int)point.getY() ); 
                     }
                 }
             }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Sun
Apr  7 13:29:12 2013
@@ -1139,7 +1139,7 @@ public class COSWriter implements ICOSVi
             }
             
             // the trailer section should only be used for xref tables not for xref streams
-            if (!doc.isXRefStream() || hybridPrev != -1)
+            if (!incrementalUpdate || !doc.isXRefStream() || hybridPrev != -1)
             {
                 doWriteTrailer(doc);
             }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java Sun Apr
 7 13:29:12 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.pdfbox.pdmodel;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -62,6 +64,11 @@ import java.util.List;
 public class PDPage implements COSObjectable, Printable
 {
 
+    /**
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(PDPage.class);
+
     private static final int DEFAULT_USER_SPACE_UNIT_DPI = 72;
 
     private static final float MM_TO_UNITS = 1/(10*2.54f)*DEFAULT_USER_SPACE_UNIT_DPI;
@@ -311,6 +318,11 @@ public class PDPage implements COSObject
         {
             retval = getParent().findMediaBox();
         }
+        if (retval == null)
+        {
+            LOG.debug("Can't find MediaBox, using LETTER as default pagesize!");
+            retval = PDPage.PAGE_SIZE_LETTER;
+        }
         return retval;
     }
 

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
Sun Apr  7 13:29:12 2013
@@ -380,6 +380,9 @@ public class PDTrueTypeFont extends PDSi
             
             HorizontalMetricsTable hMet = ttf.getHorizontalMetrics();
             int[] widthValues = hMet.getAdvanceWidth();
+            // some monospaced fonts provide only one value for the width 
+            // instead of an array containing the same value for every glyphid 
+            boolean isMonospaced = widthValues.length == 1;
             int nWidths=lastChar-firstChar+1;
             List<Float> widths = new ArrayList<Float>(nWidths);
             // width of the .notdef character.
@@ -406,7 +409,14 @@ public class PDTrueTypeFont extends PDSi
                 int gid = uniMap.getGlyphId(charCode);
                 if (gid != 0) 
                 {
-                    widths.set( e.getKey().intValue()-firstChar,widthValues[gid]*scaling
);
+                    if (isMonospaced)
+                    {
+                        widths.set( e.getKey().intValue()-firstChar,widthValues[0]*scaling
);
+                    }
+                    else
+                    {
+                        widths.set( e.getKey().intValue()-firstChar,widthValues[gid]*scaling
);
+                    }
                 }
             }
             setWidths( widths );

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceStream.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceStream.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceStream.java
Sun Apr  7 13:29:12 2013
@@ -16,16 +16,21 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.annotation;
 
+import java.awt.geom.AffineTransform;
+
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSFloat;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 
 import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.util.Matrix;
 
 
 /**
@@ -76,7 +81,7 @@ public class PDAppearanceStream implemen
     public PDRectangle getBoundingBox()
     {
         PDRectangle box = null;
-        COSArray bbox = (COSArray)stream.getDictionaryObject( COSName.getPDFName( "BBox"
) );
+        COSArray bbox = (COSArray)stream.getDictionaryObject( COSName.BBOX );
         if( bbox != null )
         {
             box = new PDRectangle( bbox );
@@ -96,7 +101,7 @@ public class PDAppearanceStream implemen
         {
             array = rectangle.getCOSArray();
         }
-        stream.setItem( COSName.getPDFName( "BBox" ), array );
+        stream.setItem( COSName.BBOX, array );
     }
 
     /**
@@ -129,4 +134,50 @@ public class PDAppearanceStream implemen
         }
         stream.setItem( COSName.RESOURCES, dict );
     }
+
+    /**
+     * Gets the optional matrix for this appearance.  This may return null.
+     *
+     * @return The matrix of this appearance.
+     */
+    public Matrix getMatrix()
+    {
+        Matrix retval = null;
+        COSArray array = (COSArray)stream.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;
+    }
+
+    /**
+     * Sets the optional Matrix entry for this appearance.
+     * @param transform the transformation matrix
+     */
+    public void setMatrix(AffineTransform transform)
+    {
+        if (transform != null)
+        {
+            COSArray matrix = new COSArray();
+            double[] values = new double[6];
+            transform.getMatrix(values);
+            for (double v : values)
+            {
+                matrix.add(new COSFloat((float)v));
+            }
+            stream.setItem(COSName.MATRIX, matrix);
+        }
+        else
+        {
+            stream.removeItem(COSName.MATRIX);
+        }
+    }
+
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignature.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignature.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignature.java
Sun Apr  7 13:29:12 2013
@@ -25,6 +25,8 @@ import java.io.IOException;
  *
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.5 $
+ * 
+ * @deprecated Use {@link PDSignatureField} instead (see PDFBOX-1513).
  */
 public class PDSignature extends PDField
 {
@@ -38,6 +40,8 @@ public class PDSignature extends PDField
     public PDSignature( PDAcroForm theAcroForm, COSDictionary field)
     {
         super(theAcroForm,field);
+        throw new RuntimeException( "The usage of " + getClass().getName() 
+                + " is deprecated. Please use " + PDSignatureField.class.getName() + " instead
(see PDFBOX-1513)" );
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1465396&r1=1465395&r2=1465396&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Sun
Apr  7 13:29:12 2013
@@ -375,8 +375,8 @@ public class PDFStreamEngine
         textStateParameters.setValue(2,1, riseText);
 
         int pageRotation = page.findRotation();
-        float pageHeight = page.findMediaBox().getHeight();
-        float pageWidth = page.findMediaBox().getWidth();
+        float pageHeight = page.findCropBox().getHeight();
+        float pageWidth = page.findCropBox().getWidth();
 
         Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
         Matrix textXctm = new Matrix();



Mime
View raw message