diff options
author | Paul Gardiner <paul@glidos.net> | 2012-06-21 12:54:03 +0100 |
---|---|---|
committer | Paul Gardiner <paul@glidos.net> | 2012-06-21 12:54:03 +0100 |
commit | af86d8111354d8955e3fa109df1625e28181956f (patch) | |
tree | a0507cddbf520dbb91ec4e8f561baba24b712c09 /pdf/pdf_form.c | |
parent | 9142994158d91dc8628a73c2989bebc516842f7d (diff) | |
download | mupdf-af86d8111354d8955e3fa109df1625e28181956f.tar.xz |
Forms: handle exclusivity of radio buttons. Fixes bug 693125
Diffstat (limited to 'pdf/pdf_form.c')
-rw-r--r-- | pdf/pdf_form.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 675cefda..7669c071 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -1432,24 +1432,54 @@ static void execute_action(pdf_document *doc, pdf_obj *obj) } } -static void toggle_check_box(pdf_document *doc, pdf_obj *obj) +static void check_off(fz_context *ctx, pdf_obj *obj) { - pdf_obj *as; - - as = pdf_dict_gets(obj, "AS"); + pdf_obj *off = NULL; - if (strcmp(pdf_to_name(as), "Off")) + fz_var(off); + fz_try(ctx); { - /* "as" neither missing nor set to Off. Set it to Off. */ - pdf_obj *off = fz_new_name(doc->ctx, "Off"); + off = fz_new_name(ctx, "Off"); pdf_dict_puts(obj, "AS", off); + } + fz_always(ctx) + { pdf_drop_obj(off); } + fz_catch(ctx) + { + fz_rethrow(ctx); + } +} + +static void toggle_check_box(pdf_document *doc, pdf_obj *obj) +{ + fz_context *ctx = doc->ctx; + pdf_obj *as = pdf_dict_gets(obj, "AS"); + int ff = get_field_flags(doc, obj); + + if (as && strcmp(pdf_to_name(as), "Off")) + { + /* "as" neither missing nor set to Off. Set it to Off, unless + * this is a non-toggle-off radio button. */ + if ((ff & (Ff_Pushbutton|Ff_NoToggleToOff|Ff_Radio)) != (Ff_NoToggleToOff|Ff_Radio)) + check_off(ctx, obj); + } else { pdf_obj *ap, *n, *key; int len, i; + /* For radio buttons, first turn off all buttons in the group */ + if ((ff & (Ff_Pushbutton|Ff_Radio)) == Ff_Radio) + { + pdf_obj *kids = pdf_dict_getp(obj, "Parent/Kids"); + int i, n = pdf_array_len(kids); + + for (i = 0; i < n; i++) + check_off(ctx, pdf_array_get(kids, i)); + } + ap = pdf_dict_gets(obj, "AP"); n = pdf_dict_gets(ap, "N"); |