Author: tilman
Date: Thu Aug 21 10:35:42 2025
New Revision: 1927942

Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #219

Modified:
   
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
  Thu Aug 21 09:59:44 2025        (r1927941)
+++ 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
  Thu Aug 21 10:35:42 2025        (r1927942)
@@ -859,18 +859,19 @@ class AppearanceGeneratorHelper {
                 // Acrobat defaults to 12 for multiline text with size 0
                 return DEFAULT_FONT_SIZE;
             } else {
-                float yScalingFactor = FONTSCALE * 
font.getFontMatrix().getScaleY();
-                float xScalingFactor = FONTSCALE * 
font.getFontMatrix().getScaleX();
+                Matrix fontMatrix = font.getFontMatrix();
+                float yScalingFactor = FONTSCALE * fontMatrix.getScaleY();
+                float xScalingFactor = FONTSCALE * fontMatrix.getScaleX();
 
                 // fit width
-                float width = font.getStringWidth(value) * 
font.getFontMatrix().getScaleX();
+                float width = font.getStringWidth(value) * 
fontMatrix.getScaleX();
                 float widthBasedFontSize = contentRect.getWidth() / width * 
xScalingFactor;
 
                 // fit height
                 float height = (font.getFontDescriptor().getCapHeight() + 
-font.getFontDescriptor().getDescent())
-                        * font.getFontMatrix().getScaleY();
+                        * fontMatrix.getScaleY();
                 if (height <= 0) {
-                    height = font.getBoundingBox().getHeight() * 
font.getFontMatrix().getScaleY();
+                    height = font.getBoundingBox().getHeight() * 
fontMatrix.getScaleY();
                 }
 
                 float heightBasedFontSize = contentRect.getHeight() / height * 
yScalingFactor;

Reply via email to