(page: Page, lnk: dict)
| 1611 | |
| 1612 | |
| 1613 | def getLinkText(page: Page, lnk: dict) -> str: |
| 1614 | # -------------------------------------------------------------------------- |
| 1615 | # define skeletons for /Annots object texts |
| 1616 | # -------------------------------------------------------------------------- |
| 1617 | ctm = page.transformation_matrix |
| 1618 | ictm = ~ctm |
| 1619 | r = lnk["from"] |
| 1620 | rect = "%g %g %g %g" % tuple(r * ictm) |
| 1621 | |
| 1622 | annot = "" |
| 1623 | if lnk["kind"] == LINK_GOTO: |
| 1624 | if lnk["page"] >= 0: |
| 1625 | txt = annot_skel["goto1"] # annot_goto |
| 1626 | pno = lnk["page"] |
| 1627 | xref = page.parent.page_xref(pno) |
| 1628 | pnt = lnk.get("to", Point(0, 0)) # destination point |
| 1629 | ipnt = pnt * ictm |
| 1630 | annot = txt % (xref, ipnt.x, ipnt.y, lnk.get("zoom", 0), rect) |
| 1631 | else: |
| 1632 | txt = annot_skel["goto2"] # annot_goto_n |
| 1633 | annot = txt % (get_pdf_str(lnk["to"]), rect) |
| 1634 | |
| 1635 | elif lnk["kind"] == LINK_GOTOR: |
| 1636 | if lnk["page"] >= 0: |
| 1637 | txt = annot_skel["gotor1"] # annot_gotor |
| 1638 | pnt = lnk.get("to", Point(0, 0)) # destination point |
| 1639 | if type(pnt) is not Point: |
| 1640 | pnt = Point(0, 0) |
| 1641 | annot = txt % ( |
| 1642 | lnk["page"], |
| 1643 | pnt.x, |
| 1644 | pnt.y, |
| 1645 | lnk.get("zoom", 0), |
| 1646 | lnk["file"], |
| 1647 | lnk["file"], |
| 1648 | rect, |
| 1649 | ) |
| 1650 | else: |
| 1651 | txt = annot_skel["gotor2"] # annot_gotor_n |
| 1652 | annot = txt % (get_pdf_str(lnk["to"]), lnk["file"], rect) |
| 1653 | |
| 1654 | elif lnk["kind"] == LINK_LAUNCH: |
| 1655 | txt = annot_skel["launch"] # annot_launch |
| 1656 | annot = txt % (lnk["file"], lnk["file"], rect) |
| 1657 | |
| 1658 | elif lnk["kind"] == LINK_URI: |
| 1659 | txt = annot_skel["uri"] # txt = annot_uri |
| 1660 | annot = txt % (lnk["uri"], rect) |
| 1661 | |
| 1662 | elif lnk["kind"] == LINK_NAMED: |
| 1663 | txt = annot_skel["named"] # annot_named |
| 1664 | annot = txt % (lnk["name"], rect) |
| 1665 | if not annot: |
| 1666 | return annot |
| 1667 | |
| 1668 | # add a /NM PDF key to the object definition |
| 1669 | link_names = dict( # existing ids and their xref |
| 1670 | [(x[0], x[2]) for x in page.annot_xrefs() if x[1] == PDF_ANNOT_LINK] |
no test coverage detected
searching dependent graphs…