From 50c9fd363dfd2f0e169541a91b2074444adafa28 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 28 Jun 2018 14:50:04 +0200 Subject: Fix bugs in triggering has_new_ap update. * Trigger correctly on AS state changes. * Handle the case when there is no AP (such as for unchecked checkboxes): - Don't try to create Widget/Btn streams. - Don't flag/unflag when AP synthesis throws. --- source/pdf/pdf-appearance.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index e936bbb0..c14fc8e3 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -1076,7 +1076,9 @@ pdf_write_widget_appearance(fz_context *ctx, pdf_annot *annot, fz_buffer *buf, fz_rethrow(ctx); } else + { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot create appearance stream for %s widgets", pdf_to_name(ctx, ft)); + } } static void @@ -1170,9 +1172,6 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot) pdf_obj *subtype; pdf_obj *ap, *ap_n, *as; - if (annot->ap && !annot->needs_new_ap) - return; - subtype = pdf_dict_get(ctx, annot->obj, PDF_NAME(Subtype)); if (subtype == PDF_NAME(Popup)) return; @@ -1185,16 +1184,13 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot) if (!pdf_is_stream(ctx, ap_n)) ap_n = pdf_dict_get(ctx, ap_n, as); - if (pdf_is_stream(ctx, ap_n)) + if (annot->ap != ap_n) { - fz_try(ctx) - { - pdf_drop_obj(ctx, annot->ap); - annot->ap = NULL; + pdf_drop_obj(ctx, annot->ap); + annot->ap = NULL; + if (pdf_is_stream(ctx, ap_n)) annot->ap = pdf_keep_obj(ctx, ap_n); - } - fz_catch(ctx) - fz_warn(ctx, "cannot load appearance stream"); + annot->has_new_ap = 1; } if (!annot->ap || annot->needs_new_ap) @@ -1206,6 +1202,14 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot) pdf_obj *new_ap_n = NULL; fz_var(res); fz_var(new_ap_n); + + annot->needs_new_ap = 0; + + /* Ignore Btn widgets */ + if (pdf_name_eq(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME(Subtype)), PDF_NAME(Widget))) + if (pdf_name_eq(ctx, pdf_dict_get_inheritable(ctx, annot->obj, PDF_NAME(FT)), PDF_NAME(Btn))) + return; + fz_try(ctx) { pdf_to_rect(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME(Rect)), &rect); @@ -1231,6 +1235,7 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot) pdf_drop_obj(ctx, annot->ap); annot->ap = NULL; annot->ap = pdf_keep_obj(ctx, new_ap_n); + annot->has_new_ap = 1; } fz_always(ctx) { @@ -1239,10 +1244,9 @@ void pdf_update_appearance(fz_context *ctx, pdf_annot *annot) pdf_drop_obj(ctx, new_ap_n); } fz_catch(ctx) + { fz_warn(ctx, "cannot create appearance stream"); - - annot->needs_new_ap = 0; - annot->has_new_ap = 1; + } } } -- cgit v1.2.3