From d5486af650977320a7469df5877c7c84068f1b83 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Tue, 7 Aug 2012 15:14:08 +0100 Subject: Forms: for choices with a single selection avoid an unnecessary array Also delete the 'I' element to avoid the indexes and values disagreeing. --- pdf/pdf_form.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index d3bb4c40..e77a5a02 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -2134,19 +2134,33 @@ void pdf_widget_choice_set_value(pdf_document *doc, fz_widget *tw, int n, char * fz_var(opt); fz_try(ctx) { - optarr = pdf_new_array(ctx, n); + if (n != 1) + { + optarr = pdf_new_array(ctx, n); - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) + { + opt = pdf_new_string(ctx, opts[i], strlen(opts[i])); + pdf_array_push(optarr, opt); + pdf_drop_obj(opt); + opt = NULL; + } + + pdf_dict_puts(annot->obj, "V", optarr); + pdf_drop_obj(optarr); + } + else { - opt = pdf_new_string(ctx, opts[i], strlen(opts[i])); - pdf_array_push(optarr, opt); + opt = pdf_new_string(ctx, opts[0], strlen(opts[0])); + pdf_dict_puts(annot->obj, "V", opt); pdf_drop_obj(opt); - opt = NULL; } - pdf_dict_puts(annot->obj, "V", optarr); - pdf_drop_obj(optarr); + /* FIXME: when n > 1, we should be regenerating the indexes */ + pdf_dict_dels(annot->obj, "I"); + pdf_field_mark_dirty(ctx, annot->obj); + doc->dirty = 1; } fz_catch(ctx) { -- cgit v1.2.3