Mercurial > hgrepos > Python2 > PyMuPDF
comparison src_classic/helper-select.i @ 1:1d09e1dec1d9 upstream
ADD: PyMuPDF v1.26.4: the original sdist.
It does not yet contain MuPDF. This normally will be downloaded when
building PyMuPDF.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:37:51 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 1:1d09e1dec1d9 |
|---|---|
| 1 %{ | |
| 2 /* | |
| 3 # ------------------------------------------------------------------------ | |
| 4 # Copyright 2020-2022, Harald Lieder, mailto:harald.lieder@outlook.com | |
| 5 # License: GNU AFFERO GPL 3.0, https://www.gnu.org/licenses/agpl-3.0.html | |
| 6 # | |
| 7 # Part of "PyMuPDF", a Python binding for "MuPDF" (http://mupdf.com), a | |
| 8 # lightweight PDF, XPS, and E-book viewer, renderer and toolkit which is | |
| 9 # maintained and developed by Artifex Software, Inc. https://artifex.com. | |
| 10 # ------------------------------------------------------------------------ | |
| 11 */ | |
| 12 void remove_dest_range(fz_context *ctx, pdf_document *pdf, PyObject *numbers) | |
| 13 { | |
| 14 fz_try(ctx) { | |
| 15 int i, j, pno, len, pagecount = pdf_count_pages(ctx, pdf); | |
| 16 PyObject *n1 = NULL; | |
| 17 pdf_obj *target, *annots, *pageref, *o, *action, *dest; | |
| 18 for (i = 0; i < pagecount; i++) { | |
| 19 n1 = PyLong_FromLong((long) i); | |
| 20 if (PySet_Contains(numbers, n1)) { | |
| 21 Py_DECREF(n1); | |
| 22 continue; | |
| 23 } | |
| 24 Py_DECREF(n1); | |
| 25 | |
| 26 pageref = pdf_lookup_page_obj(ctx, pdf, i); | |
| 27 annots = pdf_dict_get(ctx, pageref, PDF_NAME(Annots)); | |
| 28 if (!annots) continue; | |
| 29 len = pdf_array_len(ctx, annots); | |
| 30 for (j = len - 1; j >= 0; j -= 1) { | |
| 31 o = pdf_array_get(ctx, annots, j); | |
| 32 if (!pdf_name_eq(ctx, pdf_dict_get(ctx, o, PDF_NAME(Subtype)), PDF_NAME(Link))) { | |
| 33 continue; | |
| 34 } | |
| 35 action = pdf_dict_get(ctx, o, PDF_NAME(A)); | |
| 36 dest = pdf_dict_get(ctx, o, PDF_NAME(Dest)); | |
| 37 if (action) { | |
| 38 if (!pdf_name_eq(ctx, pdf_dict_get(ctx, action, | |
| 39 PDF_NAME(S)), PDF_NAME(GoTo))) | |
| 40 continue; | |
| 41 dest = pdf_dict_get(ctx, action, PDF_NAME(D)); | |
| 42 } | |
| 43 pno = -1; | |
| 44 if (pdf_is_array(ctx, dest)) { | |
| 45 target = pdf_array_get(ctx, dest, 0); | |
| 46 pno = pdf_lookup_page_number(ctx, pdf, target); | |
| 47 } | |
| 48 else if (pdf_is_string(ctx, dest)) { | |
| 49 fz_location location = fz_resolve_link(ctx, &pdf->super, | |
| 50 pdf_to_text_string(ctx, dest), | |
| 51 NULL, NULL); | |
| 52 pno = location.page; | |
| 53 } | |
| 54 if (pno < 0) { // page number lookup did not work | |
| 55 continue; | |
| 56 } | |
| 57 n1 = PyLong_FromLong((long) pno); | |
| 58 if (PySet_Contains(numbers, n1)) { | |
| 59 pdf_array_delete(ctx, annots, j); | |
| 60 } | |
| 61 Py_DECREF(n1); | |
| 62 } | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 fz_catch(ctx) { | |
| 67 fz_rethrow(ctx); | |
| 68 } | |
| 69 return; | |
| 70 } | |
| 71 %} |
