summaryrefslogtreecommitdiff
path: root/pdf/pdf_form.c
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2012-08-07 15:14:08 +0100
committerPaul Gardiner <paulg.artifex@glidos.net>2012-08-07 15:14:08 +0100
commitd5486af650977320a7469df5877c7c84068f1b83 (patch)
treec9cc644630b79cc3e8cabaaf82033ec1b38cbdd7 /pdf/pdf_form.c
parentbdb93fc6ac5acc30f22a2f7b43cbfb9c1d2a902f (diff)
downloadmupdf-d5486af650977320a7469df5877c7c84068f1b83.tar.xz
Forms: for choices with a single selection avoid an unnecessary array
Also delete the 'I' element to avoid the indexes and values disagreeing.
Diffstat (limited to 'pdf/pdf_form.c')
-rw-r--r--pdf/pdf_form.c28
1 files 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)
{