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:38 UTC
svn commit: r1864269 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Author: tilman
Date: Fri Aug 2 18:18:38 2019
New Revision: 1864269
URL: http://svn.apache.org/viewvc?rev=1864269&view=rev
Log:
PDFBOX-4615: different scale if page is rotated by 90 or 270 degrees
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1864269&r1=1864268&r2=1864269&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java Fri Aug 2 18:18:38 2019
@@ -338,11 +338,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;
@@ -358,8 +358,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;
@@ -782,9 +792,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
@@ -795,8 +806,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)