From 56895fa7c1ecc5e3f1e47e5a3e4234755d573262 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Fri, 22 Jun 2012 10:10:12 +0100 Subject: Forms support: correctly locate the field dictionary when setting value Some fields have separate widget annotations. Some have the widget rolled in. This commit correctly identifies the field when setting the field value, thus fixing bug 693145 --- pdf/pdf_form.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 3120cf10..0971edd1 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -716,7 +716,7 @@ static fz_buffer *create_text_appearance(pdf_document *doc, fz_rect *bbox, fz_ma fz_context *ctx = doc->ctx; int fontsize; int variable; - float height, width; + float height, width, full_width; fz_buffer *fzbuf = NULL; fz_buffer *fztmp = NULL; fz_rect rect; @@ -733,6 +733,7 @@ static fz_buffer *create_text_appearance(pdf_document *doc, fz_rect *bbox, fz_ma height = rect.y1 - rect.y0; width = rect.x1 - rect.x0; + full_width = bbox->x1 - bbox->x0; fz_var(fzbuf); fz_var(fztmp); @@ -813,7 +814,7 @@ static fz_buffer *create_text_appearance(pdf_document *doc, fz_rect *bbox, fz_ma else if (info->comb) { int i, n = min((int)strlen(text), info->max_len); - float comb_width = width/info->max_len; + float comb_width = full_width/info->max_len; float char_width = pdf_text_stride(ctx, info->font_rec.font, fontsize, (unsigned char *)"M", 1, FLT_MAX, NULL); float init_skip = (comb_width - char_width)/2.0; @@ -1052,11 +1053,12 @@ static int get_matrix(pdf_document *doc, pdf_xobject *form, int q, fz_matrix *mt static void update_text_field_value(fz_context *ctx, pdf_obj *obj, char *text) { - pdf_obj *parent = pdf_dict_gets(obj, "Parent"); pdf_obj *sobj = NULL; - if (parent) - obj = parent; + /* obj is an annotation. If it isn't also a field then the parent is + * the associated field */ + if (!pdf_dict_gets(obj, "FT")) + obj = pdf_dict_gets(obj, "Parent"); fz_var(sobj); fz_try(ctx) -- cgit v1.2.3