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); }
static void pdf_field_mark_dirty(pdf_document *doc, pdf_obj *field) { pdf_obj *kids = pdf_dict_gets(field, "Kids"); if (kids) { int i, n = pdf_array_len(kids); for (i = 0; i < n; i++) pdf_field_mark_dirty(doc, pdf_array_get(kids, i)); } else { pdf_dirty_obj(field); } }
static void pdf_field_mark_dirty(fz_context *ctx, pdf_document *doc, pdf_obj *field) { pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); if (kids) { int i, n = pdf_array_len(ctx, kids); for (i = 0; i < n; i++) pdf_field_mark_dirty(ctx, doc, pdf_array_get(ctx, kids, i)); } else { pdf_dirty_obj(ctx, field); } }
static void reset_field(pdf_document *doc, pdf_obj *field) { fz_context *ctx = doc->ctx; /* Set V to DV whereever DV is present, and delete V where DV is not. * FIXME: we assume for now that V has not been set unequal * to DV higher in the hierarchy than "field". * * At the bottom of the hierarchy we may find widget annotations * that aren't also fields, but DV and V will not be present in their * dictionaries, and attempts to remove V will be harmless. */ pdf_obj *dv = pdf_dict_gets(field, "DV"); pdf_obj *kids = pdf_dict_gets(field, "Kids"); if (dv) pdf_dict_puts(field, "V", dv); else pdf_dict_dels(field, "V"); if (kids == NULL) { /* The leaves of the tree are widget annotations * In some cases we need to update the appearance state; * in others we need to mark the field as dirty so that * the appearance stream will be regenerated. */ switch (pdf_field_type(doc, field)) { case PDF_WIDGET_TYPE_RADIOBUTTON: case PDF_WIDGET_TYPE_CHECKBOX: { pdf_obj *leafv = pdf_get_inheritable(doc, field, "V"); if (leafv) pdf_keep_obj(leafv); else leafv = pdf_new_name(doc, "Off"); fz_try(ctx) { pdf_dict_puts(field, "AS", leafv); } fz_always(ctx) { pdf_drop_obj(leafv); } fz_catch(ctx) { fz_rethrow(ctx); } } break; case PDF_WIDGET_TYPE_PUSHBUTTON: break; default: pdf_field_mark_dirty(doc, field); break; } } doc->dirty = 1; }