From commits-return-15257-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Thu Aug 1 16:49:17 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id C4720180644 for ; Thu, 1 Aug 2019 18:49:16 +0200 (CEST) Received: (qmail 5617 invoked by uid 500); 1 Aug 2019 16:49:16 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 5608 invoked by uid 99); 1 Aug 2019 16:49:16 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2019 16:49:16 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 1557F3A0A32 for ; Thu, 1 Aug 2019 16:49:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1864165 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java Date: Thu, 01 Aug 2019 16:49:15 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190801164915.1557F3A0A32@svn01-us-west.apache.org> 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> buildPagesWidgetsMap(List fields)