static void add_field_hierarchy_to_array(pdf_obj *array, pdf_obj *field) { pdf_obj *kids = pdf_dict_gets(field, "Kids"); pdf_obj *exclude = pdf_dict_gets(field, "Exclude"); if (exclude) return; pdf_array_push(array, field); if (kids) { int i, n = pdf_array_len(kids); for (i = 0; i < n; i++) add_field_hierarchy_to_array(array, pdf_array_get(kids, i)); } }
static void add_field_hierarchy_to_array(fz_context *ctx, pdf_obj *array, pdf_obj *field) { pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); pdf_obj *exclude = pdf_dict_get(ctx, field, PDF_NAME_Exclude); if (exclude) return; pdf_array_push(ctx, array, field); if (kids) { int i, n = pdf_array_len(ctx, kids); for (i = 0; i < n; i++) add_field_hierarchy_to_array(ctx, array, pdf_array_get(ctx, kids, i)); } }
/* When resetting or submitting a form, the fields to act upon are defined by an array of either field references or field names, plus a flag determining whether to act upon the fields in the array, or all fields other than those in the array. specified_fields interprets this information and produces the array of fields to be acted upon. */ static pdf_obj *specified_fields(pdf_document *doc, pdf_obj *fields, int exclude) { fz_context *ctx = doc->ctx; pdf_obj *form = pdf_dict_getp(pdf_trailer(doc), "Root/AcroForm/Fields"); int i, n; pdf_obj *result = pdf_new_array(doc, 0); pdf_obj *nil = NULL; fz_var(nil); fz_try(ctx) { /* The 'fields' array not being present signals that all fields * should be acted upon, so handle it using the exclude case - excluding none */ if (exclude || !fields) { /* mark the fields we don't want to act upon */ nil = pdf_new_null(doc); n = pdf_array_len(fields); for (i = 0; i < n; i++) { pdf_obj *field = pdf_array_get(fields, i); if (pdf_is_string(field)) field = pdf_lookup_field(form, pdf_to_str_buf(field)); if (field) pdf_dict_puts(field, "Exclude", nil); } /* Act upon all unmarked fields */ n = pdf_array_len(form); for (i = 0; i < n; i++) add_field_hierarchy_to_array(result, pdf_array_get(form, i)); /* Unmark the marked fields */ n = pdf_array_len(fields); for (i = 0; i < n; i++) { pdf_obj *field = pdf_array_get(fields, i); if (pdf_is_string(field)) field = pdf_lookup_field(form, pdf_to_str_buf(field)); if (field) pdf_dict_dels(field, "Exclude"); } } else { n = pdf_array_len(fields); for (i = 0; i < n; i++) { pdf_obj *field = pdf_array_get(fields, i); if (pdf_is_string(field)) field = pdf_lookup_field(form, pdf_to_str_buf(field)); if (field) add_field_hierarchy_to_array(result, field); } } } fz_always(ctx) { pdf_drop_obj(nil); } fz_catch(ctx) { pdf_drop_obj(result); fz_rethrow(ctx); } return result; }