Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 61 additions & 18 deletions src_classic/helper-select.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,98 @@
# maintained and developed by Artifex Software, Inc. https://artifex.com.
# ------------------------------------------------------------------------
*/


void remove_dest_range(fz_context *ctx, pdf_document *pdf, PyObject *numbers)
{
fz_try(ctx) {
int i, j, pno, len, pagecount = pdf_count_pages(ctx, pdf);
int i, j, pno, len;
int pagecount = pdf_count_pages(ctx, pdf);
PyObject *n1 = NULL;
pdf_obj *target, *annots, *pageref, *o, *action, *dest;

for (i = 0; i < pagecount; i++) {
n1 = PyLong_FromLong((long) i);
if (PySet_Contains(numbers, n1)) {

/* Create page index Python int */
n1 = PyLong_FromLong(i);
if (!n1) {
fz_throw(ctx, FZ_ERROR_GENERIC, "Out of memory in PyLong_FromLong");
}

int contains = PySet_Contains(numbers, n1);
if (contains == -1) {
Py_DECREF(n1);
fz_throw(ctx, FZ_ERROR_GENERIC, "PySet_Contains failed");
}

if (contains) {
Py_DECREF(n1);
continue;
}
Py_DECREF(n1);

pageref = pdf_lookup_page_obj(ctx, pdf, i);
annots = pdf_dict_get(ctx, pageref, PDF_NAME(Annots));
if (!annots) continue;
if (!annots) {
continue;
}

len = pdf_array_len(ctx, annots);
for (j = len - 1; j >= 0; j -= 1) {

/* Iterate backwards to safely delete array entries */
for (j = len - 1; j >= 0; j--) {

o = pdf_array_get(ctx, annots, j);
if (!pdf_name_eq(ctx, pdf_dict_get(ctx, o, PDF_NAME(Subtype)), PDF_NAME(Link))) {

if (!pdf_name_eq(ctx,
pdf_dict_get(ctx, o, PDF_NAME(Subtype)),
PDF_NAME(Link))) {
continue;
}

action = pdf_dict_get(ctx, o, PDF_NAME(A));
dest = pdf_dict_get(ctx, o, PDF_NAME(Dest));
dest = pdf_dict_get(ctx, o, PDF_NAME(Dest));

if (action) {
if (!pdf_name_eq(ctx, pdf_dict_get(ctx, action,
PDF_NAME(S)), PDF_NAME(GoTo)))
if (!pdf_name_eq(ctx,
pdf_dict_get(ctx, action, PDF_NAME(S)),
PDF_NAME(GoTo))) {
continue;
}
dest = pdf_dict_get(ctx, action, PDF_NAME(D));
}

pno = -1;
if (pdf_is_array(ctx, dest)) {
target = pdf_array_get(ctx, dest, 0);
pno = pdf_lookup_page_number(ctx, pdf, target);

} else if (pdf_is_string(ctx, dest)) {
fz_location loc = fz_resolve_link(ctx, &pdf->super,
pdf_to_text_string(ctx, dest),
NULL, NULL);
pno = loc.page;
}
else if (pdf_is_string(ctx, dest)) {
fz_location location = fz_resolve_link(ctx, &pdf->super,
pdf_to_text_string(ctx, dest),
NULL, NULL);
pno = location.page;

if (pno < 0) {
continue; /* could not resolve link target */
}
if (pno < 0) { // page number lookup did not work
continue;

n1 = PyLong_FromLong(pno);
if (!n1) {
fz_throw(ctx, FZ_ERROR_GENERIC, "Out of memory in PyLong_FromLong");
}

contains = PySet_Contains(numbers, n1);
if (contains == -1) {
Py_DECREF(n1);
fz_throw(ctx, FZ_ERROR_GENERIC, "PySet_Contains failed");
}
n1 = PyLong_FromLong((long) pno);
if (PySet_Contains(numbers, n1)) {

if (contains) {
pdf_array_delete(ctx, annots, j);
}

Py_DECREF(n1);
}
}
Expand Down
Loading