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:15 UTC
svn commit: r1864165 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Author: tilman
Date: Thu Aug 1 16:49:14 2019
New Revision: 1864165
URL: http://svn.apache.org/viewvc?rev=1864165&view=rev
Log:
PDFBOX-4615: scale if rectangle and BBox have different width or height
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=1864165&r1=1864164&r2=1864165&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 Thu Aug 1 16:49:14 2019
@@ -341,7 +341,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;
@@ -354,18 +354,15 @@ public final class PDAcroForm implements
}
if (needsScaling)
- {
+ {
PDRectangle bbox = appearanceStream.getBBox();
PDRectangle fieldRect = annotation.getRectangle();
-
- if (bbox.getWidth() - fieldRect.getWidth() != 0 && bbox.getHeight() - fieldRect.getHeight() != 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)
@@ -784,14 +781,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)