(page: pymupdf.Page, lnk: dict)
| 625 | |
| 626 | |
| 627 | def getLinkText(page: pymupdf.Page, lnk: dict) -> str: |
| 628 | # -------------------------------------------------------------------------- |
| 629 | # define skeletons for /Annots object texts |
| 630 | # -------------------------------------------------------------------------- |
| 631 | ctm = page.transformation_matrix |
| 632 | ictm = ~ctm |
| 633 | r = lnk["from"] |
| 634 | rect = _format_g(tuple(r * ictm)) |
| 635 | |
| 636 | annot = "" |
| 637 | if lnk["kind"] == pymupdf.LINK_GOTO: |
| 638 | if lnk["page"] >= 0: |
| 639 | txt = pymupdf.annot_skel["goto1"] # annot_goto |
| 640 | pno = lnk["page"] |
| 641 | xref = page.parent.page_xref(pno) |
| 642 | pnt = lnk.get("to", pymupdf.Point(0, 0)) # destination point |
| 643 | dest_page = page.parent[pno] |
| 644 | dest_ctm = dest_page.transformation_matrix |
| 645 | dest_ictm = ~dest_ctm |
| 646 | ipnt = pnt * dest_ictm |
| 647 | annot = txt(xref, ipnt.x, ipnt.y, lnk.get("zoom", 0), rect) |
| 648 | else: |
| 649 | txt = pymupdf.annot_skel["goto2"] # annot_goto_n |
| 650 | annot = txt(pymupdf.get_pdf_str(lnk["to"]), rect) |
| 651 | |
| 652 | elif lnk["kind"] == pymupdf.LINK_GOTOR: |
| 653 | if lnk["page"] >= 0: |
| 654 | txt = pymupdf.annot_skel["gotor1"] # annot_gotor |
| 655 | pnt = lnk.get("to", pymupdf.Point(0, 0)) # destination point |
| 656 | if type(pnt) is not pymupdf.Point: |
| 657 | pnt = pymupdf.Point(0, 0) |
| 658 | annot = txt( |
| 659 | lnk["page"], |
| 660 | pnt.x, |
| 661 | pnt.y, |
| 662 | lnk.get("zoom", 0), |
| 663 | lnk["file"], |
| 664 | lnk["file"], |
| 665 | rect, |
| 666 | ) |
| 667 | else: |
| 668 | txt = pymupdf.annot_skel["gotor2"] # annot_gotor_n |
| 669 | annot = txt(pymupdf.get_pdf_str(lnk["to"]), lnk["file"], rect) |
| 670 | |
| 671 | elif lnk["kind"] == pymupdf.LINK_LAUNCH: |
| 672 | txt = pymupdf.annot_skel["launch"] # annot_launch |
| 673 | annot = txt(lnk["file"], lnk["file"], rect) |
| 674 | |
| 675 | elif lnk["kind"] == pymupdf.LINK_URI: |
| 676 | txt = pymupdf.annot_skel["uri"] # txt = annot_uri |
| 677 | annot = txt(lnk["uri"], rect) |
| 678 | |
| 679 | elif lnk["kind"] == pymupdf.LINK_NAMED: |
| 680 | txt = pymupdf.annot_skel["named"] # annot_named |
| 681 | lname = lnk.get("name") # check presence of key |
| 682 | if lname is None: # if missing, fall back to alternative |
| 683 | lname = lnk["nameddest"] |
| 684 | annot = txt(lname, rect) |
nothing calls this directly
no test coverage detected
searching dependent graphs…