From b33b3b41100f2bb0b63dbf270bdd4401451c081a Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 3 Jul 2013 18:45:55 +0100 Subject: Avoid fz_throw/message on every annotation without appearance. Annotations can sometimes not have appearance streams (such as Links). Avoid spewing messages to the console about this. Also avoids overhead of throw/catch each time. --- source/pdf/pdf-annot.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index cbe2d201..bfc31e9a 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -479,12 +479,13 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) { pdf_annot *annot, *head, **itr; pdf_obj *obj, *ap, *as, *n, *rect; - int i, len, is_dict; + int i, len, keep_annot; fz_context *ctx = doc->ctx; fz_var(annot); fz_var(itr); fz_var(head); + fz_var(keep_annot); head = NULL; @@ -538,10 +539,13 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) rect = pdf_dict_gets(obj, "Rect"); ap = pdf_dict_gets(obj, "AP"); as = pdf_dict_gets(obj, "AS"); - is_dict = pdf_is_dict(ap); - if (!is_dict) - fz_throw(ctx, FZ_ERROR_NO_APPEARANCE_STREAM, "Annotation has no appearance stream"); + /* We only collect annotations with an appearance + * stream into this list, so remove any that don't + * (such as links) and continue. */ + keep_annot = pdf_is_dict(ap); + if (!keep_annot) + break; if (hp->num == pdf_to_num(obj) && hp->gen == pdf_to_gen(obj) @@ -578,14 +582,17 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) itr = &annot->next; } fz_catch(ctx) + { + keep_annot = 0; + fz_warn(ctx, "ignoring broken annotation"); + /* FIXME: TryLater */ + } + if (!keep_annot) { /* Move to next item in the linked list, dropping this one */ *itr = annot->next; annot->next = NULL; /* Required because pdf_free_annot follows the "next" chain */ pdf_free_annot(ctx, annot); - if (fz_caught(ctx) != FZ_ERROR_NO_APPEARANCE_STREAM) - fz_warn(ctx, "ignoring broken annotation"); - /* FIXME: TryLater */ } } -- cgit v1.2.3