@@ -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