diff --git a/examples/index.php b/examples/index.php index a2158cc..266367c 100644 --- a/examples/index.php +++ b/examples/index.php @@ -933,17 +933,18 @@ $pdf->page->addContent($txt); // // get the coordinates of the box containing the last added text string. -// $bbox = $pdf->getLastTextBBox(); -// // set link -// $aoid = $pdf->setAnnotation( -// $bbox['llx'], -// $bbox['lly'], -// $bbox['urx'] - $bbox['llx'], -// $bbox['lly'] - $bbox['ury'], -// 'https://tcpdf.org', -// array('subtype'=>'Link') -// ); -// $pdf->page->addAnnotRef($aoid); +$bbox = $pdf->getLastTextBBox(); + +// set link +$aoid = $pdf->setAnnotation( + $bbox['x'], + $bbox['y'], + $bbox['width'], + $bbox['height'], + 'https://tcpdf.org', + array('subtype'=>'Link') +); +$pdf->page->addAnnotRef($aoid); // ---------- diff --git a/src/Output.php b/src/Output.php index 048b615..d2fa83a 100644 --- a/src/Output.php +++ b/src/Output.php @@ -818,12 +818,12 @@ protected function getOutAnnotations() $annot = $this->annotation[$oid]; $annot['opt'] = array_change_key_case($annot['opt'], CASE_LOWER); $out .= $this->getAnnotationRadiobuttonGroups($annot); - $orx = $this->userToPointsUnit($annot['x']); - $ory = $page['height'] - $this->userToPointsUnit(($annot['y'] + $annot['h'])); - $width = $this->userToPointsUnit($annot['w']); - $height = $this->userToPointsUnit($annot['h']); + $orx = ($annot['x'] * $this->kunit); + $ory = ($page['pheight'] - (($annot['y'] + $annot['h']) * $this->kunit)); + $width = ($annot['w'] * $this->kunit); + $height = ($annot['h'] * $this->kunit); $rect = sprintf('%F %F %F %F', $orx, $ory, $orx+$width, $ory+$height); - $out .= $oid.' 0 R'."\n" + $out .= $oid.' 0 obj'."\n" .'<<' .' /Type /Annot' .' /Subtype /'.$annot['opt']['subtype'] @@ -856,7 +856,6 @@ protected function getOutAnnotations() } } } - //var_dump($out); exit; //DEBUG return $out; } diff --git a/src/Text.php b/src/Text.php index 20083e2..df4ff95 100644 --- a/src/Text.php +++ b/src/Text.php @@ -36,15 +36,15 @@ abstract class Text { /** - * Last text bounding box [llx, lly, urx, ury]. + * Last text bounding box [x, y, width, height]. * * @var array */ protected $lasttxtbbox = array( - 'llx'=>0, - 'lly'=>0, - 'urx'=>0, - 'ury'=>0 + 'x'=>0, + 'y'=>0, + 'width'=>0, + 'height'=>0 ); /** @@ -82,10 +82,10 @@ public function getTextLine( $width = $width>0?$width:0; $curfont = $this->font->getCurrentFont(); $this->lasttxtbbox = array( - 'llx' => $posx, - 'lly' => ($posy + $this->userToPointsUnit($curfont['descent'])), - 'urx' => ($posx + $width), - 'ury' => ($posy - $this->userToPointsUnit($curfont['ascent'])) + 'x' => $posx, + 'y' => ($posy - $this->pointsToUserUnit($curfont['ascent'])), + 'width' => $width, + 'height' => ($this->pointsToUserUnit($curfont['ascent'] - $curfont['descent'])) ); $out = $this->getJustifiedString($txt, $width, $forcertl); $out = $this->getOutTextPosXY($out, $posx, $posy, 'Td'); @@ -98,8 +98,6 @@ public function getTextLine( $out = $this->getOutTextStateOperator($out, 'TL', $this->userToPointsUnit($leading)); $out = $this->getOutTextStateOperator($out, 'Ts', $this->userToPointsUnit($rise)); $out = $this->getOutTextObject($out); - //var_dump($out); //DEBUG - //var_dump($this->lasttxtbbox); return $out; } @@ -142,7 +140,7 @@ protected function getJustifiedString($txt, $width = 0, $forcertl = false) if ($width > 0) { return $this->getOutTextStateOperator($txt, 'Tw', $spacewidth * $this->kunit); } - $this->lasttxtbbox['urx'] += $this->pointsToUserUnit($dim['totwidth']); + $this->lasttxtbbox['width'] = $this->pointsToUserUnit($dim['totwidth']); return $txt; } if ($this->font->isCurrentByteFont()) { @@ -154,7 +152,7 @@ protected function getJustifiedString($txt, $width = 0, $forcertl = false) } $txt = $this->encrypt->escapeString($txt); if ($width <= 0) { - $this->lasttxtbbox['urx'] += $this->pointsToUserUnit($dim['totwidth']); + $this->lasttxtbbox['width'] = $this->pointsToUserUnit($dim['totwidth']); return $this->getOutTextShowing($txt, 'Tj'); } $fontsize = $this->font->getCurrentFont()['size']?$this->font->getCurrentFont()['size']:1;