You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/08/01 16:49:05 UTC

svn commit: r1864163 - /pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java

Author: tilman
Date: Thu Aug  1 16:49:04 2019
New Revision: 1864163

URL: http://svn.apache.org/viewvc?rev=1864163&view=rev
Log:
PDFBOX-4615: scale if rectangle and BBox have different width or height

Modified:
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1864163&r1=1864162&r2=1864163&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java (original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java Thu Aug  1 16:49:04 2019
@@ -339,7 +339,7 @@ public final class PDAcroForm implements
                                         
                     // scale the appearance stream - mainly needed for images
                     // in buttons and signatures
-                    boolean needsScaling = resolveNeedsScaling(appearanceStream);
+                    boolean needsScaling = resolveNeedsScaling(annotation);
                     
                     Matrix transformationMatrix = new Matrix();
                     boolean transformed = false;
@@ -352,19 +352,15 @@ public final class PDAcroForm implements
                     }
 
                     if (needsScaling)
-                    {                    
+                    {
                         PDRectangle bbox = appearanceStream.getBBox();
                         PDRectangle fieldRect = annotation.getRectangle();
-                        
-                        if (Float.compare(bbox.getWidth() - fieldRect.getWidth(), 0) != 0 && 
-                            Float.compare(bbox.getHeight() - fieldRect.getHeight(), 0) != 0)
-                        {
-                            float xScale = fieldRect.getWidth() / bbox.getWidth();
-                            float yScale = fieldRect.getHeight() / bbox.getHeight();
-                            Matrix scalingMatrix = Matrix.getScaleInstance(xScale, yScale);
-                            transformationMatrix.concatenate(scalingMatrix);
-                            transformed = true;
-                        }
+
+                        float xScale = fieldRect.getWidth() / bbox.getWidth();
+                        float yScale = fieldRect.getHeight() / bbox.getHeight();
+                        Matrix scalingMatrix = Matrix.getScaleInstance(xScale, yScale);
+                        transformationMatrix.concatenate(scalingMatrix);
+                        transformed = true;
                     }
 
                     if (transformed)
@@ -786,14 +782,22 @@ public final class PDAcroForm implements
     /**
      * Check if there needs to be a scaling transformation applied.
      * 
-     * @param appearanceStream
+     * @param annotation
      * @return the need for a scaling transformation.
      */    
-    private boolean resolveNeedsScaling(PDAppearanceStream appearanceStream)
+    private boolean resolveNeedsScaling(PDAnnotation annotation)
     {
+        PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
         // Check if there is a transformation within the XObjects content
         PDResources resources = appearanceStream.getResources();
-        return resources != null && resources.getXObjectNames().iterator().hasNext();
+        if (resources != null && resources.getXObjectNames().iterator().hasNext())
+        {
+            return true;
+        }
+        PDRectangle bbox = appearanceStream.getBBox();
+        PDRectangle fieldRect = annotation.getRectangle();
+        return Float.compare(bbox.getWidth(),  fieldRect.getWidth()) != 0 ||
+               Float.compare(bbox.getHeight(), fieldRect.getHeight()) != 0;
     }
     
     private Map<COSDictionary,Map<COSDictionary,PDAnnotationWidget>> buildPagesWidgetsMap(List<PDField> fields)