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/02 18:18:43 UTC

svn commit: r1864270 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java

Author: tilman
Date: Fri Aug  2 18:18:43 2019
New Revision: 1864270

URL: http://svn.apache.org/viewvc?rev=1864270&view=rev
Log:
PDFBOX-4615: different scale if page is rotated by 90 or 270 degrees

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1864270&r1=1864269&r2=1864270&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java Fri Aug  2 18:18:43 2019
@@ -336,11 +336,11 @@ public final class PDAcroForm implements
                     // translate the appearance stream to the widget location if there is 
                     // not already a transformation in place
                     boolean needsTranslation = resolveNeedsTranslation(appearanceStream);
-                                        
+
                     // scale the appearance stream - mainly needed for images
                     // in buttons and signatures
-                    boolean needsScaling = resolveNeedsScaling(annotation);
-                    
+                    boolean needsScaling = resolveNeedsScaling(annotation, page.getRotation());
+
                     Matrix transformationMatrix = new Matrix();
                     boolean transformed = false;
                     
@@ -356,8 +356,18 @@ public final class PDAcroForm implements
                         PDRectangle bbox = appearanceStream.getBBox();
                         PDRectangle fieldRect = annotation.getRectangle();
 
-                        float xScale = fieldRect.getWidth() / bbox.getWidth();
-                        float yScale = fieldRect.getHeight() / bbox.getHeight();
+                        float xScale;
+                        float yScale;
+                        if (page.getRotation() == 90 || page.getRotation() == 270)
+                        {
+                            xScale = fieldRect.getWidth() / bbox.getHeight();
+                            yScale = fieldRect.getHeight() / bbox.getWidth();
+                        }
+                        else
+                        {
+                            xScale = fieldRect.getWidth() / bbox.getWidth();
+                            yScale = fieldRect.getHeight() / bbox.getHeight();
+                        }
                         Matrix scalingMatrix = Matrix.getScaleInstance(xScale, yScale);
                         transformationMatrix.concatenate(scalingMatrix);
                         transformed = true;
@@ -783,9 +793,10 @@ public final class PDAcroForm implements
      * Check if there needs to be a scaling transformation applied.
      * 
      * @param annotation
+     * @param rotation 
      * @return the need for a scaling transformation.
      */    
-    private boolean resolveNeedsScaling(PDAnnotation annotation)
+    private boolean resolveNeedsScaling(PDAnnotation annotation, int rotation)
     {
         PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream();
         // Check if there is a transformation within the XObjects content
@@ -796,8 +807,16 @@ public final class PDAcroForm implements
         }
         PDRectangle bbox = appearanceStream.getBBox();
         PDRectangle fieldRect = annotation.getRectangle();
-        return Float.compare(bbox.getWidth(),  fieldRect.getWidth()) != 0 ||
-               Float.compare(bbox.getHeight(), fieldRect.getHeight()) != 0;
+        if (rotation == 90 || rotation == 270)
+        {
+            return Float.compare(bbox.getWidth(),  fieldRect.getHeight()) != 0 ||
+                   Float.compare(bbox.getHeight(), fieldRect.getWidth()) != 0;
+        }
+        else
+        {
+            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)