@@ -78,12 +78,7 @@ private Rectangle2D calcTotalLinkArea(RenderingContext c, Box box, float pageHei
7878 }
7979
8080 private Rectangle2D add (Rectangle2D r1 , Rectangle2D r2 ) {
81- float llx = (float ) Math .min (r1 .getMinX (), r2 .getMinX ());
82- float urx = (float ) Math .max (r1 .getMaxX (), r2 .getMaxX ());
83- float lly = (float ) Math .min (r1 .getMaxY (), r2 .getMaxY ());
84- float ury = (float ) Math .max (r1 .getMinY (), r2 .getMinY ());
85-
86- return new Rectangle2D .Float (llx , lly , urx , ury );
81+ return r1 .createUnion (r2 );
8782 }
8883
8984 private String createRectKey (Rectangle2D rect , Shape linkShape , AffineTransform transform ) {
@@ -366,14 +361,14 @@ private PDPageXYZDestination createDestination(RenderingContext c, Box box) {
366361 public static Rectangle2D createTargetArea (RenderingContext c , Box box , float pageHeight , AffineTransform transform ,
367362 Box _root , PdfBoxOutputDevice _od ) {
368363 Rectangle bounds = box .getContentAreaEdge (box .getAbsX (), box .getAbsY (), c );
369- PageBox page = _root . getLayer (). getPage ( c , bounds . y );
370-
371- float bottom = _od . getDeviceLength (
372- page . getBottom () - ( bounds . y + bounds . height ) + page . getMarginBorderPadding ( c , CalculatedStyle . BOTTOM ));
373- float left = _od . getDeviceLength ( page . getMarginBorderPadding ( c , CalculatedStyle . LEFT ) + bounds . x );
374-
375- return new Rectangle2D . Float ( left , bottom , _od .getDeviceLength (bounds .width ),
376- _od .getDeviceLength (bounds .height ));
364+
365+ Point2D pt = new Point2D . Float ( bounds . x , ( float ) bounds . getMaxY ());
366+ Point2D ptTransformed = transform . transform ( pt , null );
367+
368+ return new Rectangle2D . Float (( float ) ptTransformed . getX (),
369+ _od . normalizeY (( float ) ptTransformed . getY (), pageHeight ),
370+ _od .getDeviceLength (bounds .width ),
371+ _od .getDeviceLength (bounds .height ));
377372 }
378373
379374 public static class LinkDetails {
@@ -387,14 +382,20 @@ public static class LinkDetails {
387382
388383 public void processLinkLater (RenderingContext c , Box box , PDPage page , float pageHeight ,
389384 AffineTransform transform ) {
385+
386+ if ((box instanceof BlockBox &&
387+ ((BlockBox ) box ).getReplacedElement () != null ) ||
388+ (box .getElement () != null && box .getElement ().getNodeName ().equals ("a" ))) {
389+
390390 LinkDetails link = new LinkDetails ();
391391 link .c = c ;
392392 link .box = box ;
393393 link .page = page ;
394394 link .pageHeight = pageHeight ;
395- link .transform = transform ;
395+ link .transform = ( AffineTransform ) transform . clone () ;
396396
397397 _links .add (link );
398+ }
398399 }
399400
400401 public void processLinks () {
0 commit comments