diff options
Diffstat (limited to 'pdf/pdf_annot.c')
-rw-r--r-- | pdf/pdf_annot.c | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index 2fc9d7bb..2a569e5c 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -2,13 +2,19 @@ #include "mupdf.h" void -pdf_free_link(pdf_link *link) +pdf_free_link(fz_context *ctx, pdf_link *link) { - if (link->next) - pdf_free_link(link->next); - if (link->dest) - fz_drop_obj(link->dest); - fz_free(link); + pdf_link *next; + + do + { + next = link->next; + if (link->dest) + fz_drop_obj(link->dest); + fz_free(ctx, link); + link = next; + } + while(link != NULL); } static fz_obj * @@ -45,12 +51,13 @@ pdf_load_link(pdf_xref *xref, fz_obj *dict) fz_obj *obj; fz_rect bbox; pdf_link_kind kind; + fz_context *ctx = xref->ctx; dest = NULL; obj = fz_dict_gets(dict, "Rect"); if (obj) - bbox = pdf_to_rect(obj); + bbox = pdf_to_rect(ctx, obj); else bbox = fz_empty_rect; @@ -103,7 +110,7 @@ pdf_load_link(pdf_xref *xref, fz_obj *dict) if (dest) { - pdf_link *link = fz_malloc(sizeof(pdf_link)); + pdf_link *link = fz_malloc(ctx, sizeof(pdf_link)); link->kind = kind; link->rect = bbox; link->dest = fz_keep_obj(dest); @@ -119,12 +126,13 @@ pdf_load_links(pdf_link **linkp, pdf_xref *xref, fz_obj *annots) { pdf_link *link, *head, *tail; fz_obj *obj; - int i; + int i, n; head = tail = NULL; link = NULL; - for (i = 0; i < fz_array_len(annots); i++) + n = fz_array_len(annots); + for (i = 0; i < n; i++) { obj = fz_array_get(annots, i); link = pdf_load_link(xref, obj); @@ -144,15 +152,21 @@ pdf_load_links(pdf_link **linkp, pdf_xref *xref, fz_obj *annots) } void -pdf_free_annot(pdf_annot *annot) +pdf_free_annot(fz_context *ctx, pdf_annot *annot) { - if (annot->next) - pdf_free_annot(annot->next); - if (annot->ap) - pdf_drop_xobject(annot->ap); - if (annot->obj) - fz_drop_obj(annot->obj); - fz_free(annot); + pdf_annot *next; + + do + { + next = annot->next; + if (annot->ap) + pdf_drop_xobject(ctx, annot->ap); + if (annot->obj) + fz_drop_obj(annot->obj); + fz_free(ctx, annot); + annot = next; + } + while (annot != NULL); } static void @@ -178,13 +192,14 @@ pdf_load_annots(pdf_annot **annotp, pdf_xref *xref, fz_obj *annots) pdf_annot *annot, *head, *tail; fz_obj *obj, *ap, *as, *n, *rect; pdf_xobject *form; - fz_error error; - int i; + int i, len; + fz_context *ctx = xref->ctx; head = tail = NULL; annot = NULL; - for (i = 0; i < fz_array_len(annots); i++) + len = fz_array_len(annots); + for (i = 0; i < len; i++) { obj = fz_array_get(annots, i); @@ -201,16 +216,19 @@ pdf_load_annots(pdf_annot **annotp, pdf_xref *xref, fz_obj *annots) if (pdf_is_stream(xref, fz_to_num(n), fz_to_gen(n))) { - error = pdf_load_xobject(&form, xref, n); - if (error) + fz_try(ctx) + { + form = pdf_load_xobject(xref, n); + } + fz_catch(ctx) { - fz_catch(error, "ignoring broken annotation"); + fz_warn(ctx, "ignoring broken annotation"); continue; } - annot = fz_malloc(sizeof(pdf_annot)); + annot = fz_malloc(ctx, sizeof(pdf_annot)); annot->obj = fz_keep_obj(obj); - annot->rect = pdf_to_rect(rect); + annot->rect = pdf_to_rect(ctx, rect); annot->ap = form; annot->next = NULL; |