/* 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) { if (obj == NULL || pdf_dict_gets(obj, "T")) return obj; else return find_head_of_field_group(pdf_dict_gets(obj, "Parent")); }
static void update_field_value(pdf_document *doc, pdf_obj *obj, char *text) { fz_context *ctx = doc->ctx; pdf_obj *sobj = NULL; pdf_obj *grp; if (!text) text = ""; /* All fields of the same name should be updated, so * set the value at the head of the group */ grp = find_head_of_field_group(obj); if (grp) obj = grp; fz_var(sobj); fz_try(ctx) { sobj = pdf_new_string(doc, text, strlen(text)); pdf_dict_puts(obj, "V", sobj); } fz_always(ctx) { pdf_drop_obj(sobj); } fz_catch(ctx) { fz_rethrow(ctx); } pdf_field_mark_dirty(doc, obj); }
/* Find the point in a field hierarchy where all descendents * share the same name */ static pdf_obj *find_head_of_field_group(fz_context *ctx, pdf_obj *obj) { if (obj == NULL || pdf_dict_get(ctx, obj, PDF_NAME_T)) return obj; else return find_head_of_field_group(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Parent)); }