(ln, document=None)
| 508 | |
| 509 | |
| 510 | def getLinkDict(ln, document=None) -> dict: |
| 511 | if isinstance(ln, pymupdf.Outline): |
| 512 | dest = ln.destination(document) |
| 513 | elif isinstance(ln, pymupdf.Link): |
| 514 | dest = ln.dest |
| 515 | else: |
| 516 | assert 0, f'Unexpected {type(ln)=}.' |
| 517 | nl = {"kind": dest.kind, "xref": 0} |
| 518 | try: |
| 519 | if hasattr(ln, 'rect'): |
| 520 | nl["from"] = ln.rect |
| 521 | except Exception: |
| 522 | # This seems to happen quite often in PyMuPDF/tests. |
| 523 | if g_exceptions_verbose >= 2: pymupdf.exception_info() |
| 524 | pass |
| 525 | pnt = pymupdf.Point(0, 0) |
| 526 | if dest.flags & pymupdf.LINK_FLAG_L_VALID: |
| 527 | pnt.x = dest.lt.x |
| 528 | if dest.flags & pymupdf.LINK_FLAG_T_VALID: |
| 529 | pnt.y = dest.lt.y |
| 530 | |
| 531 | if dest.kind == pymupdf.LINK_URI: |
| 532 | nl["uri"] = dest.uri |
| 533 | |
| 534 | elif dest.kind == pymupdf.LINK_GOTO: |
| 535 | nl["page"] = dest.page |
| 536 | nl["to"] = pnt |
| 537 | if dest.flags & pymupdf.LINK_FLAG_R_IS_ZOOM: |
| 538 | nl["zoom"] = dest.rb.x |
| 539 | else: |
| 540 | nl["zoom"] = 0.0 |
| 541 | |
| 542 | elif dest.kind == pymupdf.LINK_GOTOR: |
| 543 | nl["file"] = dest.file_spec.replace("\\", "/") |
| 544 | nl["page"] = dest.page |
| 545 | if dest.page < 0: |
| 546 | nl["to"] = dest.dest |
| 547 | else: |
| 548 | nl["to"] = pnt |
| 549 | if dest.flags & pymupdf.LINK_FLAG_R_IS_ZOOM: |
| 550 | nl["zoom"] = dest.rb.x |
| 551 | else: |
| 552 | nl["zoom"] = 0.0 |
| 553 | |
| 554 | elif dest.kind == pymupdf.LINK_LAUNCH: |
| 555 | nl["file"] = dest.file_spec.replace("\\", "/") |
| 556 | |
| 557 | elif dest.kind == pymupdf.LINK_NAMED: |
| 558 | # The dicts should not have same key(s). |
| 559 | assert not (dest.named.keys() & nl.keys()) |
| 560 | nl.update(dest.named) |
| 561 | if 'to' in nl: |
| 562 | nl['to'] = pymupdf.Point(nl['to']) |
| 563 | |
| 564 | else: |
| 565 | nl["page"] = dest.page |
| 566 | return nl |
| 567 |
nothing calls this directly
no test coverage detected
searching dependent graphs…