MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / getDestStr

Function getDestStr

src/utils.py:569–624  ·  view source on GitHub ↗

Calculate the PDF action string. Notes: Supports Link annotations and outline items (bookmarks).

(xref: int, ddict: dict)

Source from the content-addressed store, hash-verified

567
568
569def getDestStr(xref: int, ddict: dict) -> str:
570 """Calculate the PDF action string.
571
572 Notes:
573 Supports Link annotations and outline items (bookmarks).
574 """
575 if not ddict:
576 return ""
577 str_goto = lambda a, b, c, d: f"/A<</S/GoTo/D[{a} 0 R/XYZ {_format_g((b, c, d))}]>>"
578 str_gotor1 = lambda a, b, c, d, e, f: f"/A<</S/GoToR/D[{a} /XYZ {_format_g((b, c, d))}]/F<</F{e}/UF{f}/Type/Filespec>>>>"
579 str_gotor2 = lambda a, b, c: f"/A<</S/GoToR/D{a}/F<</F{b}/UF{c}/Type/Filespec>>>>"
580 str_launch = lambda a, b: f"/A<</S/Launch/F<</F{a}/UF{b}/Type/Filespec>>>>"
581 str_uri = lambda a: f"/A<</S/URI/URI{a}>>"
582
583 if type(ddict) in (int, float):
584 dest = str_goto(xref, 0, ddict, 0)
585 return dest
586 d_kind = ddict.get("kind", pymupdf.LINK_NONE)
587
588 if d_kind == pymupdf.LINK_NONE:
589 return ""
590
591 if ddict["kind"] == pymupdf.LINK_GOTO:
592 d_zoom = ddict.get("zoom", 0)
593 to = ddict.get("to", pymupdf.Point(0, 0))
594 d_left, d_top = to
595 dest = str_goto(xref, d_left, d_top, d_zoom)
596 return dest
597
598 if ddict["kind"] == pymupdf.LINK_URI:
599 dest = str_uri(pymupdf.get_pdf_str(ddict["uri"]),)
600 return dest
601
602 if ddict["kind"] == pymupdf.LINK_LAUNCH:
603 fspec = pymupdf.get_pdf_str(ddict["file"])
604 dest = str_launch(fspec, fspec)
605 return dest
606
607 if ddict["kind"] == pymupdf.LINK_GOTOR and ddict["page"] < 0:
608 fspec = pymupdf.get_pdf_str(ddict["file"])
609 dest = str_gotor2(pymupdf.get_pdf_str(ddict["to"]), fspec, fspec)
610 return dest
611
612 if ddict["kind"] == pymupdf.LINK_GOTOR and ddict["page"] >= 0:
613 fspec = pymupdf.get_pdf_str(ddict["file"])
614 dest = str_gotor1(
615 ddict["page"],
616 ddict["to"].x,
617 ddict["to"].y,
618 ddict["zoom"],
619 fspec,
620 fspec,
621 )
622 return dest
623
624 return ""
625
626

Callers

nothing calls this directly

Calls 2

_format_gFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…