From 80292f4511278d6ec3c7b3c0cc8d860f1d9bb8c5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 20 Mar 2014 16:55:55 +0100 Subject: Break dependencies on pdf-form.c and pdf-js.c Split functions out of pdf-form.c that shouldn't be there, and make javascript initialization explicit. --- source/pdf/pdf-appearance.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'source/pdf/pdf-appearance.c') diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index 2d1a6b54..db11c32a 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -2207,3 +2207,83 @@ void pdf_set_signature_appearance(pdf_document *doc, pdf_annot *annot, char *nam fz_rethrow(ctx); } } + +void pdf_update_appearance(pdf_document *doc, pdf_annot *annot) +{ + pdf_obj *obj = annot->obj; + if (!pdf_dict_gets(obj, "AP") || pdf_obj_is_dirty(obj)) + { + fz_annot_type type = pdf_annot_obj_type(obj); + switch (type) + { + case FZ_ANNOT_WIDGET: + switch (pdf_field_type(doc, obj)) + { + case PDF_WIDGET_TYPE_TEXT: + { + #if 0 + pdf_obj *formatting = pdf_dict_getp(obj, "AA/F"); + if (formatting && doc->js) + { + /* Apply formatting */ + pdf_js_event e; + fz_context *ctx = doc->ctx; + + e.target = obj; + e.value = pdf_field_value(doc, obj); + fz_try(ctx) + { + pdf_js_setup_event(doc->js, &e); + } + fz_always(ctx) + { + fz_free(ctx, e.value); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } + execute_action(doc, obj, formatting); + /* Update appearance from JS event.value */ + pdf_update_text_appearance(doc, obj, pdf_js_get_event(doc->js)->value); + } + else + #endif + { + /* Update appearance from field value */ + pdf_update_text_appearance(doc, obj, NULL); + } + } + break; + case PDF_WIDGET_TYPE_PUSHBUTTON: + pdf_update_pushbutton_appearance(doc, obj); + break; + case PDF_WIDGET_TYPE_LISTBOX: + case PDF_WIDGET_TYPE_COMBOBOX: + /* Treating listbox and combobox identically for now, + * and the behaviour is most appropriate for a combobox */ + pdf_update_combobox_appearance(doc, obj); + break; + } + break; + case FZ_ANNOT_TEXT: + pdf_update_text_annot_appearance(doc, annot); + break; + case FZ_ANNOT_FREETEXT: + pdf_update_free_text_annot_appearance(doc, annot); + break; + case FZ_ANNOT_STRIKEOUT: + case FZ_ANNOT_UNDERLINE: + case FZ_ANNOT_HIGHLIGHT: + pdf_update_text_markup_appearance(doc, annot, type); + break; + case FZ_ANNOT_INK: + pdf_update_ink_appearance(doc, annot); + break; + default: + break; + } + + pdf_clean_obj(obj); + } +} -- cgit v1.2.3