Skip to content

Commit 17fcfd3

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #217
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1927877 13f79535-47bb-0310-9956-ffa450edef68
1 parent e655c03 commit 17fcfd3

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,16 @@ private void insertGeneratedAppearance(PDAnnotationWidget widget,
502502
}
503503
float padding = Math.max(1f, borderWidth);
504504
PDRectangle clipRect = applyPadding(bbox, padding);
505+
float clipRectLowerLeftY = clipRect.getLowerLeftY();
506+
float clipRectHeight = clipRect.getHeight();
507+
505508
PDRectangle contentRect = applyPadding(clipRect, padding);
506509

507510
contents.saveGraphicsState();
508511

509512
// Acrobat always adds a clipping path
510-
contents.addRect(clipRect.getLowerLeftX(), clipRect.getLowerLeftY(),
511-
clipRect.getWidth(), clipRect.getHeight());
513+
contents.addRect(clipRect.getLowerLeftX(), clipRectLowerLeftY,
514+
clipRect.getWidth(), clipRectHeight);
512515
contents.clip();
513516

514517
// get the font
@@ -579,21 +582,22 @@ private void insertGeneratedAppearance(PDAnnotationWidget widget,
579582
else
580583
{
581584
// Adobe shows the text 'shifted up' in case the caps don't fit into the clipping area
582-
if (fontCapAtSize > clipRect.getHeight())
585+
if (fontCapAtSize > clipRectHeight)
583586
{
584-
y = clipRect.getLowerLeftY() + -fontDescentAtSize;
587+
y = clipRectLowerLeftY + -fontDescentAtSize;
585588
}
586589
else
587590
{
588591
// calculate the position based on the content rectangle
589-
y = clipRect.getLowerLeftY() + (clipRect.getHeight() - fontCapAtSize) / 2;
590-
592+
y = clipRectLowerLeftY + (clipRectHeight - fontCapAtSize) / 2;
593+
591594
// check to ensure that ascents and descents fit
592-
if (y - clipRect.getLowerLeftY() < -fontDescentAtSize) {
593-
594-
float fontDescentBased = -fontDescentAtSize + contentRect.getLowerLeftY();
595-
float fontCapBased = contentRect.getHeight() - contentRect.getLowerLeftY() - fontCapAtSize;
596-
595+
if (y - clipRectLowerLeftY < -fontDescentAtSize)
596+
{
597+
float contentRectLowerLeftY = contentRect.getLowerLeftY();
598+
float fontDescentBased = -fontDescentAtSize + contentRectLowerLeftY;
599+
float fontCapBased = contentRect.getHeight() - contentRectLowerLeftY - fontCapAtSize;
600+
597601
y = Math.min(fontDescentBased, Math.max(y, fontCapBased));
598602
}
599603
}

0 commit comments

Comments
 (0)