From ad0fa16fd4e3102ae01b0c84de1f1d52242f99a4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 11 Apr 2014 15:58:51 +0200 Subject: Add all form field flags. Check flags before marking fields dirty. NoExport (and ReadOnly) fields shouldn't mark the document for saving. --- include/mupdf/pdf/field.h | 25 ++++++++++++++++++++----- platform/x11/x11_main.c | 6 +++++- source/pdf/pdf-form.c | 17 ++++++++++++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/include/mupdf/pdf/field.h b/include/mupdf/pdf/field.h index 966a261a..f0aa70ff 100644 --- a/include/mupdf/pdf/field.h +++ b/include/mupdf/pdf/field.h @@ -4,18 +4,33 @@ /* Field flags */ enum { + /* Common to all field types */ + Ff_ReadOnly = 1 << (1-1), + Ff_Required = 1 << (2-1), + Ff_NoExport = 1 << (3-1), + + /* Text fields */ Ff_Multiline = 1 << (13-1), Ff_Password = 1 << (14-1), + + Ff_FileSelect = 1 << (21-1), + Ff_DoNotSpellCheck = 1 << (23-1), + Ff_DoNotScroll = 1 << (24-1), + Ff_Comb = 1 << (25-1), + Ff_RichText = 1 << (26-1), + + /* Button fields */ Ff_NoToggleToOff = 1 << (15-1), Ff_Radio = 1 << (16-1), Ff_Pushbutton = 1 << (17-1), + Ff_RadioInUnison = 1 << (26-1), + + /* Choice fields */ Ff_Combo = 1 << (18-1), - Ff_FileSelect = 1 << (21-1), + Ff_Edit = 1 << (19-1), + Ff_Sort = 1 << (20-1), Ff_MultiSelect = 1 << (22-1), - Ff_DoNotSpellCheck = 1 << (23-1), - Ff_DoNotScroll = 1 << (24-1), - Ff_Comb = 1 << (25-1), - Ff_RadioInUnison = 1 << (26-1) + Ff_CommitOnSelCHange = 1 << (27-1), }; char *pdf_get_string_or_stream(pdf_document *doc, pdf_obj *obj); diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index 5b0266c5..58d0e2af 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -295,11 +295,15 @@ static void winopen(void) void winclose(pdfapp_t *app) { - closing = 1; + if (pdfapp_preclose(app)) + { + closing = 1; + } } int winsavequery(pdfapp_t *app) { + fprintf(stderr, "mupdf: discarded changes to document\n"); /* FIXME: temporary dummy implementation */ return DISCARD; } diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c index ab5a808c..c5e2ef78 100644 --- a/source/pdf/pdf-form.c +++ b/source/pdf/pdf-form.c @@ -15,6 +15,14 @@ enum SigFlag_AppendOnly = 2 }; +static int pdf_field_dirties_document(pdf_document *doc, pdf_obj *field) +{ + int ff = pdf_get_field_flags(doc, field); + if (ff & Ff_NoExport) return 0; + if (ff & Ff_ReadOnly) return 0; + return 1; +} + /* Find the point in a field hierarchy where all descendents * share the same name */ static pdf_obj *find_head_of_field_group(pdf_obj *obj) @@ -178,7 +186,8 @@ static void reset_field(pdf_document *doc, pdf_obj *field) } } - doc->dirty = 1; + if (pdf_field_dirties_document(doc, field)) + doc->dirty = 1; } void pdf_field_reset(pdf_document *doc, pdf_obj *field) @@ -870,7 +879,8 @@ static int set_text_field_value(pdf_document *doc, pdf_obj *field, char *text) text = pdf_js_get_event(doc->js)->value; } - doc->dirty = 1; + if (pdf_field_dirties_document(doc, field)) + doc->dirty = 1; update_field_value(doc, field, text); return 1; @@ -1434,7 +1444,8 @@ void pdf_choice_widget_set_value(pdf_document *doc, pdf_widget *tw, int n, char pdf_dict_dels(annot->obj, "I"); pdf_field_mark_dirty(doc, annot->obj); - doc->dirty = 1; + if (pdf_field_dirties_document(doc, annot->obj)) + doc->dirty = 1; } fz_catch(ctx) { -- cgit v1.2.3