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 2025/08/19 09:42:57 UTC
svn commit: r1927877 - pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form
Author: tilman
Date: Tue Aug 19 09:42:57 2025
New Revision: 1927877
Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #217
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java Tue Aug 19 09:42:53 2025 (r1927876)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java Tue Aug 19 09:42:57 2025 (r1927877)
@@ -502,13 +502,16 @@ class AppearanceGeneratorHelper
}
float padding = Math.max(1f, borderWidth);
PDRectangle clipRect = applyPadding(bbox, padding);
+ float clipRectLowerLeftY = clipRect.getLowerLeftY();
+ float clipRectHeight = clipRect.getHeight();
+
PDRectangle contentRect = applyPadding(clipRect, padding);
contents.saveGraphicsState();
// Acrobat always adds a clipping path
- contents.addRect(clipRect.getLowerLeftX(), clipRect.getLowerLeftY(),
- clipRect.getWidth(), clipRect.getHeight());
+ contents.addRect(clipRect.getLowerLeftX(), clipRectLowerLeftY,
+ clipRect.getWidth(), clipRectHeight);
contents.clip();
// get the font
@@ -579,21 +582,22 @@ class AppearanceGeneratorHelper
else
{
// Adobe shows the text 'shifted up' in case the caps don't fit into the clipping area
- if (fontCapAtSize > clipRect.getHeight())
+ if (fontCapAtSize > clipRectHeight)
{
- y = clipRect.getLowerLeftY() + -fontDescentAtSize;
+ y = clipRectLowerLeftY + -fontDescentAtSize;
}
else
{
// calculate the position based on the content rectangle
- y = clipRect.getLowerLeftY() + (clipRect.getHeight() - fontCapAtSize) / 2;
-
+ y = clipRectLowerLeftY + (clipRectHeight - fontCapAtSize) / 2;
+
// check to ensure that ascents and descents fit
- if (y - clipRect.getLowerLeftY() < -fontDescentAtSize) {
-
- float fontDescentBased = -fontDescentAtSize + contentRect.getLowerLeftY();
- float fontCapBased = contentRect.getHeight() - contentRect.getLowerLeftY() - fontCapAtSize;
-
+ if (y - clipRectLowerLeftY < -fontDescentAtSize)
+ {
+ float contentRectLowerLeftY = contentRect.getLowerLeftY();
+ float fontDescentBased = -fontDescentAtSize + contentRectLowerLeftY;
+ float fontCapBased = contentRect.getHeight() - contentRectLowerLeftY - fontCapAtSize;
+
y = Math.min(fontDescentBased, Math.max(y, fontCapBased));
}
}