summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-form.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-03-20 17:02:35 +0000
committerRobin Watts <robin.watts@artifex.com>2015-03-24 19:49:58 +0000
commitf533104d6e66b3fc6d3b63b98ec7fe4fb175b366 (patch)
tree9b26b57a66dcb5124c568a9826311d41292a6056 /source/pdf/pdf-form.c
parente0f638b398b2362f5843ea0c1907f678cfa8e278 (diff)
downloadmupdf-f533104d6e66b3fc6d3b63b98ec7fe4fb175b366.tar.xz
Rework handling of PDF names for speed and memory.
Currently, every PDF name is allocated in a pdf_obj structure, and comparisons are done using strcmp. Given that we can predict most of the PDF names we'll use in a given file, this seems wasteful. The pdf_obj type is opaque outside the pdf-object.c file, so we can abuse it slightly without anyone outside knowing. We collect a sorted list of names used in PDF (resources/pdf/names.txt), and we add a utility (namedump) that preprocesses this into 2 header files. The first (include/mupdf/pdf/pdf-names-table.h, included as part of include/mupdf/pdf/object.h), defines a set of "PDF_NAME_xxxx" entries. These are pdf_obj *'s that callers can use to mean "A PDF object that means literal name 'xxxx'" The second (source/pdf/pdf-name-impl.h) is a C array of names. We therefore update the code so that rather than passing "xxxx" to functions (such as pdf_dict_gets(...)) we now pass PDF_NAME_xxxx (to pdf_dict_get(...)). This is a fairly natural (if widespread) change. The pdf_dict_getp (and sibling) functions that take a path (e.g. "foo/bar/baz") are therefore supplemented with equivalents that take a list (pdf_dict_getl(... , PDF_NAME_foo, PDF_NAME_bar, PDF_NAME_baz, NULL)). The actual implementation of this relies on the fact that small pointer values are never valid values. For a given pdf_obj *p, if NULL < (intptr_t)p < PDF_NAME__LIMIT then p is a literal entry in the name table. This enables us to do fast pointer compares and to skip expensive strcmps. Also, bring "null", "true" and "false" into the same style as PDF names. Rather than using full pdf_obj structures for null/true/false, use special pointer values just above the PDF_NAME_ table. This saves memory and makes comparisons easier.
Diffstat (limited to 'source/pdf/pdf-form.c')
-rw-r--r--source/pdf/pdf-form.c211
1 files changed, 91 insertions, 120 deletions
diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c
index 4caadd25..f18396c4 100644
--- a/source/pdf/pdf-form.c
+++ b/source/pdf/pdf-form.c
@@ -27,15 +27,15 @@ static int pdf_field_dirties_document(fz_context *ctx, pdf_document *doc, pdf_ob
* share the same name */
static pdf_obj *find_head_of_field_group(fz_context *ctx, pdf_obj *obj)
{
- if (obj == NULL || pdf_dict_gets(ctx, obj, "T"))
+ if (obj == NULL || pdf_dict_get(ctx, obj, PDF_NAME_T))
return obj;
else
- return find_head_of_field_group(ctx, pdf_dict_gets(ctx, obj, "Parent"));
+ return find_head_of_field_group(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Parent));
}
static void pdf_field_mark_dirty(fz_context *ctx, pdf_document *doc, pdf_obj *field)
{
- pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids");
+ pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids);
if (kids)
{
int i, n = pdf_array_len(ctx, kids);
@@ -67,7 +67,7 @@ static void update_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *obj,
fz_try(ctx)
{
sobj = pdf_new_string(ctx, doc, text, strlen(text));
- pdf_dict_puts(ctx, obj, "V", sobj);
+ pdf_dict_put(ctx, obj, PDF_NAME_V, sobj);
}
fz_always(ctx)
{
@@ -92,7 +92,7 @@ static pdf_obj *find_field(fz_context *ctx, pdf_obj *dict, char *name, int len)
char *part;
field = pdf_array_get(ctx, dict, i);
- part = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, field, "T"));
+ part = pdf_to_str_buf(ctx, pdf_dict_get(ctx, field, PDF_NAME_T));
if (strlen(part) == (size_t)len && !memcmp(part, name, len))
return field;
}
@@ -119,7 +119,7 @@ pdf_obj *pdf_lookup_field(fz_context *ctx, pdf_obj *form, char *name)
len = dot ? dot - namep : strlen(namep);
dict = find_field(ctx, form, namep, len);
if (dot)
- form = pdf_dict_gets(ctx, dict, "Kids");
+ form = pdf_dict_get(ctx, dict, PDF_NAME_Kids);
}
return dict;
@@ -134,13 +134,13 @@ static void reset_field(fz_context *ctx, pdf_document *doc, pdf_obj *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(ctx, field, "DV");
- pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids");
+ pdf_obj *dv = pdf_dict_get(ctx, field, PDF_NAME_DV);
+ pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids);
if (dv)
- pdf_dict_puts(ctx, field, "V", dv);
+ pdf_dict_put(ctx, field, PDF_NAME_V, dv);
else
- pdf_dict_dels(ctx, field, "V");
+ pdf_dict_del(ctx, field, PDF_NAME_V);
if (kids == NULL)
{
@@ -153,16 +153,16 @@ static void reset_field(fz_context *ctx, pdf_document *doc, pdf_obj *field)
case PDF_WIDGET_TYPE_RADIOBUTTON:
case PDF_WIDGET_TYPE_CHECKBOX:
{
- pdf_obj *leafv = pdf_get_inheritable(ctx, doc, field, "V");
+ pdf_obj *leafv = pdf_get_inheritable(ctx, doc, field, PDF_NAME_V);
if (leafv)
pdf_keep_obj(ctx, leafv);
else
- leafv = pdf_new_name(ctx, doc, "Off");
+ leafv = PDF_NAME_Off;
fz_try(ctx)
{
- pdf_dict_puts(ctx, field, "AS", leafv);
+ pdf_dict_put(ctx, field, PDF_NAME_AS, leafv);
}
fz_always(ctx)
{
@@ -190,7 +190,7 @@ static void reset_field(fz_context *ctx, pdf_document *doc, pdf_obj *field)
void pdf_field_reset(fz_context *ctx, pdf_document *doc, pdf_obj *field)
{
- pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids");
+ pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids);
reset_field(ctx, doc, field);
@@ -205,8 +205,8 @@ void pdf_field_reset(fz_context *ctx, pdf_document *doc, pdf_obj *field)
static void add_field_hierarchy_to_array(fz_context *ctx, pdf_obj *array, pdf_obj *field)
{
- pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids");
- pdf_obj *exclude = pdf_dict_gets(ctx, field, "Exclude");
+ 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;
@@ -231,7 +231,7 @@ static void add_field_hierarchy_to_array(fz_context *ctx, pdf_obj *array, pdf_ob
*/
static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fields, int exclude)
{
- pdf_obj *form = pdf_dict_getp(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/Fields");
+ pdf_obj *form = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_Fields, NULL);
int i, n;
pdf_obj *result = pdf_new_array(ctx, doc, 0);
pdf_obj *nil = NULL;
@@ -256,7 +256,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi
field = pdf_lookup_field(ctx, form, pdf_to_str_buf(ctx, field));
if (field)
- pdf_dict_puts(ctx, field, "Exclude", nil);
+ pdf_dict_put(ctx, field, PDF_NAME_Exclude, nil);
}
/* Act upon all unmarked fields */
@@ -276,7 +276,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi
field = pdf_lookup_field(ctx, form, pdf_to_str_buf(ctx, field));
if (field)
- pdf_dict_dels(ctx, field, "Exclude");
+ pdf_dict_del(ctx, field, PDF_NAME_Exclude);
}
}
else
@@ -333,11 +333,11 @@ static void execute_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf
{
if (a)
{
- char *type = pdf_to_name(ctx, pdf_dict_gets(ctx, a, "S"));
+ pdf_obj *type = pdf_dict_get(ctx, a, PDF_NAME_S);
- if (!strcmp(type, "JavaScript"))
+ if (pdf_name_eq(ctx, type, PDF_NAME_JavaScript))
{
- pdf_obj *js = pdf_dict_gets(ctx, a, "JS");
+ pdf_obj *js = pdf_dict_get(ctx, a, PDF_NAME_JS);
if (js)
{
char *code = pdf_to_utf8(ctx, doc, js);
@@ -355,15 +355,15 @@ static void execute_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf
}
}
}
- else if (!strcmp(type, "ResetForm"))
+ else if (pdf_name_eq(ctx, type, PDF_NAME_ResetForm))
{
- reset_form(ctx, doc, pdf_dict_gets(ctx, a, "Fields"), pdf_to_int(ctx, pdf_dict_gets(ctx, a, "Flags")) & 1);
+ reset_form(ctx, doc, pdf_dict_get(ctx, a, PDF_NAME_Fields), pdf_to_int(ctx, pdf_dict_get(ctx, a, PDF_NAME_Flags)) & 1);
}
- else if (!strcmp(type, "Named"))
+ else if (pdf_name_eq(ctx, type, PDF_NAME_Named))
{
- char *name = pdf_to_name(ctx, pdf_dict_gets(ctx, a, "N"));
+ pdf_obj *name = pdf_dict_get(ctx, a, PDF_NAME_N);
- if (!strcmp(name, "Print"))
+ if (pdf_name_eq(ctx, name, PDF_NAME_Print))
pdf_event_issue_print(ctx, doc);
}
}
@@ -371,7 +371,7 @@ static void execute_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf
static void execute_action_chain(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
{
- pdf_obj *a = pdf_dict_gets(ctx, obj, "A");
+ pdf_obj *a = pdf_dict_get(ctx, obj, PDF_NAME_A);
pdf_js_event e;
e.target = obj;
@@ -381,7 +381,7 @@ static void execute_action_chain(fz_context *ctx, pdf_document *doc, pdf_obj *ob
while (a)
{
execute_action(ctx, doc, obj, a);
- a = pdf_dict_gets(ctx, a, "Next");
+ a = pdf_dict_get(ctx, a, PDF_NAME_Next);
}
}
@@ -402,56 +402,29 @@ static void execute_additional_action(fz_context *ctx, pdf_document *doc, pdf_ob
static void check_off(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
{
- pdf_obj *off = NULL;
-
- fz_var(off);
- fz_try(ctx);
- {
- off = pdf_new_name(ctx, doc, "Off");
- pdf_dict_puts(ctx, obj, "AS", off);
- }
- fz_always(ctx)
- {
- pdf_drop_obj(ctx, off);
- }
- fz_catch(ctx)
- {
- fz_rethrow(ctx);
- }
+ pdf_dict_put(ctx, obj, PDF_NAME_AS, PDF_NAME_Off);
}
-static void set_check(fz_context *ctx, pdf_document *doc, pdf_obj *chk, char *name)
+static void set_check(fz_context *ctx, pdf_document *doc, pdf_obj *chk, pdf_obj *name)
{
pdf_obj *n = pdf_dict_getp(ctx, chk, "AP/N");
- pdf_obj *val = NULL;
+ pdf_obj *val;
- fz_var(val);
- fz_try(ctx)
- {
- /* If name is a possible value of this check
- * box then use it, otherwise use "Off" */
- if (pdf_dict_gets(ctx, n, name))
- val = pdf_new_name(ctx, doc, name);
- else
- val = pdf_new_name(ctx, doc, "Off");
+ /* If name is a possible value of this check
+ * box then use it, otherwise use "Off" */
+ if (pdf_dict_get(ctx, n, name))
+ val = name;
+ else
+ val = PDF_NAME_Off;
- pdf_dict_puts(ctx, chk, "AS", val);
- }
- fz_always(ctx)
- {
- pdf_drop_obj(ctx, val);
- }
- fz_catch(ctx)
- {
- fz_rethrow(ctx);
- }
+ pdf_dict_put_drop(ctx, chk, PDF_NAME_AS, val);
}
/* Set the values of all fields in a group defined by a node
* in the hierarchy */
-static void set_check_grp(fz_context *ctx, pdf_document *doc, pdf_obj *grp, char *val)
+static void set_check_grp(fz_context *ctx, pdf_document *doc, pdf_obj *grp, pdf_obj *val)
{
- pdf_obj *kids = pdf_dict_gets(ctx, grp, "Kids");
+ pdf_obj *kids = pdf_dict_get(ctx, grp, PDF_NAME_Kids);
if (kids == NULL)
{
@@ -512,16 +485,16 @@ static void recalculate(fz_context *ctx, pdf_document *doc)
static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
{
- pdf_obj *as = pdf_dict_gets(ctx, obj, "AS");
+ pdf_obj *as = pdf_dict_get(ctx, obj, PDF_NAME_AS);
int ff = pdf_get_field_flags(ctx, doc, obj);
int radio = ((ff & (Ff_Pushbutton|Ff_Radio)) == Ff_Radio);
char *val = NULL;
- pdf_obj *grp = radio ? pdf_dict_gets(ctx, obj, "Parent") : find_head_of_field_group(ctx, obj);
+ pdf_obj *grp = radio ? pdf_dict_get(ctx, obj, PDF_NAME_Parent) : find_head_of_field_group(ctx, obj);
if (!grp)
grp = obj;
- if (as && strcmp(pdf_to_name(ctx, as), "Off"))
+ if (as && !pdf_name_eq(ctx, as, PDF_NAME_Off))
{
/* "as" neither missing nor set to Off. Set it to Off, unless
* this is a non-toggle-off radio button. */
@@ -543,7 +516,7 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
for (i = 0; i < len; i++)
{
key = pdf_dict_get_key(ctx, n, i);
- if (pdf_is_name(ctx, key) && strcmp(pdf_to_name(ctx, key), "Off"))
+ if (pdf_is_name(ctx, key) && !pdf_name_eq(ctx, key, PDF_NAME_Off))
break;
}
@@ -551,19 +524,17 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
if (!key)
return;
- val = pdf_to_name(ctx, key);
-
if (radio)
{
/* For radio buttons, first turn off all buttons in the group and
* then set the one that was clicked */
- pdf_obj *kids = pdf_dict_gets(ctx, grp, "Kids");
+ pdf_obj *kids = pdf_dict_get(ctx, grp, PDF_NAME_Kids);
len = pdf_array_len(ctx, kids);
for (i = 0; i < len; i++)
check_off(ctx, doc, pdf_array_get(ctx, kids, i));
- pdf_dict_puts(ctx, obj, "AS", key);
+ pdf_dict_put(ctx, obj, PDF_NAME_AS, key);
}
else
{
@@ -572,9 +543,9 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
* all to the same value. This may cause the group to act like
* radio buttons, if each have distinct "On" values */
if (grp)
- set_check_grp(ctx, doc, grp, val);
+ set_check_grp(ctx, doc, grp, key);
else
- set_check(ctx, doc, obj, val);
+ set_check(ctx, doc, obj, key);
}
}
@@ -586,7 +557,7 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
fz_try(ctx)
{
v = pdf_new_string(ctx, doc, val, strlen(val));
- pdf_dict_puts(ctx, grp, "V", v);
+ pdf_dict_put(ctx, grp, PDF_NAME_V, v);
}
fz_always(ctx)
{
@@ -625,7 +596,7 @@ int pdf_pass_event(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_ui_ev
if (annot)
{
- int f = pdf_to_int(ctx, pdf_dict_gets(ctx, annot->obj, "F"));
+ int f = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F));
if (f & (F_Hidden|F_NoView))
annot = NULL;
@@ -805,13 +776,13 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page
fz_try(ctx)
{
pdf_set_field_type(ctx, doc, annot->obj, type);
- pdf_dict_puts_drop(ctx, annot->obj, "T", pdf_new_string(ctx, doc, fieldname, strlen(fieldname)));
+ pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_T, pdf_new_string(ctx, doc, fieldname, strlen(fieldname)));
annot->widget_type = type;
if (type == PDF_WIDGET_TYPE_SIGNATURE)
{
int sigflags = (old_sigflags | (SigFlag_SignaturesExist|SigFlag_AppendOnly));
- pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/SigFlags", pdf_new_int(ctx, doc, sigflags));
+ pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, doc, sigflags), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_SigFlags, NULL);
}
/*
@@ -822,7 +793,7 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page
if (!form)
{
form = pdf_new_array(ctx, doc, 1);
- pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/Fields", form);
+ pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), form, PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_Fields, NULL);
}
pdf_array_push(ctx, form, annot->obj); /* Cleanup relies on this statement being last */
@@ -834,7 +805,7 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page
/* An empty Fields array may have been created, but that is harmless */
if (type == PDF_WIDGET_TYPE_SIGNATURE)
- pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/SigFlags", pdf_new_int(ctx, doc, old_sigflags));
+ pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, doc, old_sigflags), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_SigFlags, NULL);
fz_rethrow(ctx);
}
@@ -876,7 +847,7 @@ static int set_text_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *fie
static void update_checkbox_selector(fz_context *ctx, pdf_document *doc, pdf_obj *field, char *val)
{
- pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids");
+ pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids);
if (kids)
{
@@ -896,9 +867,9 @@ static void update_checkbox_selector(fz_context *ctx, pdf_document *doc, pdf_obj
if (pdf_dict_gets(ctx, n, val))
oval = pdf_new_name(ctx, doc, val);
else
- oval = pdf_new_name(ctx, doc, "Off");
+ oval = PDF_NAME_Off;
- pdf_dict_puts(ctx, field, "AS", oval);
+ pdf_dict_put(ctx, field, PDF_NAME_AS, oval);
}
fz_always(ctx)
{
@@ -947,7 +918,7 @@ int pdf_field_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, char
char *pdf_field_border_style(fz_context *ctx, pdf_document *doc, pdf_obj *field)
{
- char *bs = pdf_to_name(ctx, pdf_dict_getp(ctx, field, "BS/S"));
+ char *bs = pdf_to_name(ctx, pdf_dict_getl(ctx, field, PDF_NAME_BS, PDF_NAME_S, NULL));
switch (*bs)
{
@@ -966,21 +937,21 @@ void pdf_field_set_border_style(fz_context *ctx, pdf_document *doc, pdf_obj *fie
pdf_obj *val = NULL;
if (!strcmp(text, "Solid"))
- val = pdf_new_name(ctx, doc, "S");
+ val = PDF_NAME_S;
else if (!strcmp(text, "Dashed"))
- val = pdf_new_name(ctx, doc, "D");
+ val = PDF_NAME_D;
else if (!strcmp(text, "Beveled"))
- val = pdf_new_name(ctx, doc, "B");
+ val = PDF_NAME_B;
else if (!strcmp(text, "Inset"))
- val = pdf_new_name(ctx, doc, "I");
+ val = PDF_NAME_I;
else if (!strcmp(text, "Underline"))
- val = pdf_new_name(ctx, doc, "U");
+ val = PDF_NAME_U;
else
return;
fz_try(ctx);
{
- pdf_dict_putp(ctx, field, "BS/S", val);
+ pdf_dict_putl(ctx, field, val, PDF_NAME_BS, PDF_NAME_S, NULL);
pdf_field_mark_dirty(ctx, doc, field);
}
fz_always(ctx)
@@ -1001,7 +972,7 @@ void pdf_field_set_button_caption(fz_context *ctx, pdf_document *doc, pdf_obj *f
{
if (pdf_field_type(ctx, doc, field) == PDF_WIDGET_TYPE_PUSHBUTTON)
{
- pdf_dict_putp(ctx, field, "MK/CA", val);
+ pdf_dict_putl(ctx, field, val, PDF_NAME_MK, PDF_NAME_CA, NULL);
pdf_field_mark_dirty(ctx, doc, field);
}
}
@@ -1023,10 +994,10 @@ int pdf_field_display(fz_context *ctx, pdf_document *doc, pdf_obj *field)
/* Base response on first of children. Not ideal,
* but not clear how to handle children with
* differing values */
- while ((kids = pdf_dict_gets(ctx, field, "Kids")) != NULL)
+ while ((kids = pdf_dict_get(ctx, field, PDF_NAME_Kids)) != NULL)
field = pdf_array_get(ctx, kids, 0);
- f = pdf_to_int(ctx, pdf_dict_gets(ctx, field, "F"));
+ f = pdf_to_int(ctx, pdf_dict_get(ctx, field, PDF_NAME_F));
if (f & F_Hidden)
{
@@ -1055,8 +1026,8 @@ int pdf_field_display(fz_context *ctx, pdf_document *doc, pdf_obj *field)
static char *get_field_name(fz_context *ctx, pdf_document *doc, pdf_obj *field, int spare)
{
char *res = NULL;
- pdf_obj *parent = pdf_dict_gets(ctx, field, "Parent");
- char *lname = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, field, "T"));
+ pdf_obj *parent = pdf_dict_get(ctx, field, PDF_NAME_Parent);
+ char *lname = pdf_to_str_buf(ctx, pdf_dict_get(ctx, field, PDF_NAME_T));
int llen = strlen(lname);
/*
@@ -1094,12 +1065,12 @@ char *pdf_field_name(fz_context *ctx, pdf_document *doc, pdf_obj *field)
void pdf_field_set_display(fz_context *ctx, pdf_document *doc, pdf_obj *field, int d)
{
- pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids");
+ pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids);
if (!kids)
{
int mask = (F_Hidden|F_Print|F_NoView);
- int f = pdf_to_int(ctx, pdf_dict_gets(ctx, field, "F")) & ~mask;
+ int f = pdf_to_int(ctx, pdf_dict_get(ctx, field, PDF_NAME_F)) & ~mask;
pdf_obj *fo = NULL;
switch (d)
@@ -1121,7 +1092,7 @@ void pdf_field_set_display(fz_context *ctx, pdf_document *doc, pdf_obj *field, i
fz_try(ctx)
{
fo = pdf_new_int(ctx, doc, f);
- pdf_dict_puts(ctx, field, "F", fo);
+ pdf_dict_put(ctx, field, PDF_NAME_F, fo);
}
fz_always(ctx)
{
@@ -1146,7 +1117,7 @@ void pdf_field_set_fill_color(fz_context *ctx, pdf_document *doc, pdf_obj *field
/* col == NULL mean transparent, but we can simply pass it on as with
* non-NULL values because pdf_dict_putp interprets a NULL value as
* delete */
- pdf_dict_putp(ctx, field, "MK/BG", col);
+ pdf_dict_putl(ctx, field, col, PDF_NAME_MK, PDF_NAME_BG, NULL);
pdf_field_mark_dirty(ctx, doc, field);
}
@@ -1154,7 +1125,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field
{
pdf_da_info di;
fz_buffer *fzbuf = NULL;
- char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, "DA"));
+ char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME_DA));
unsigned char *buf;
int len;
pdf_obj *daobj = NULL;
@@ -1179,7 +1150,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field
pdf_fzbuf_print_da(ctx, fzbuf, &di);
len = fz_buffer_storage(ctx, fzbuf, &buf);
daobj = pdf_new_string(ctx, doc, (char *)buf, len);
- pdf_dict_puts(ctx, field, "DA", daobj);
+ pdf_dict_put(ctx, field, PDF_NAME_DA, daobj);
pdf_field_mark_dirty(ctx, doc, field);
}
fz_always(ctx)
@@ -1227,7 +1198,7 @@ int pdf_text_widget_max_len(fz_context *ctx, pdf_document *doc, pdf_widget *tw)
{
pdf_annot *annot = (pdf_annot *)tw;
- return pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, annot->obj, "MaxLen"));
+ return pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, annot->obj, PDF_NAME_MaxLen));
}
int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget *tw)
@@ -1239,7 +1210,7 @@ int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget
fz_var(code);
fz_try(ctx)
{
- code = pdf_get_string_or_stream(ctx, doc, pdf_dict_getp(ctx, annot->obj, "AA/F/JS"));
+ code = pdf_get_string_or_stream(ctx, doc, pdf_dict_getl(ctx, annot->obj, PDF_NAME_AA, PDF_NAME_F, PDF_NAME_JS, NULL));
if (code)
{
if (strstr(code, "AFNumber_Format"))
@@ -1266,7 +1237,7 @@ int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget
static int run_keystroke(fz_context *ctx, pdf_document *doc, pdf_obj *field, char **text)
{
- pdf_obj *k = pdf_dict_getp(ctx, field, "AA/K");
+ pdf_obj *k = pdf_dict_getl(ctx, field, PDF_NAME_AA, PDF_NAME_K, NULL);
if (k && doc->js)
{
@@ -1314,7 +1285,7 @@ int pdf_choice_widget_options(fz_context *ctx, pdf_document *doc, pdf_widget *tw
if (!annot)
return 0;
- optarr = pdf_dict_gets(ctx, annot->obj, "Opt");
+ optarr = pdf_dict_get(ctx, annot->obj, PDF_NAME_Opt);
n = pdf_array_len(ctx, optarr);
if (opts)
@@ -1353,7 +1324,7 @@ int pdf_choice_widget_value(fz_context *ctx, pdf_document *doc, pdf_widget *tw,
if (!annot)
return 0;
- optarr = pdf_dict_gets(ctx, annot->obj, "V");
+ optarr = pdf_dict_get(ctx, annot->obj, PDF_NAME_V);
if (pdf_is_string(ctx, optarr))
{
@@ -1408,18 +1379,18 @@ void pdf_choice_widget_set_value(fz_context *ctx, pdf_document *doc, pdf_widget
opt = NULL;
}
- pdf_dict_puts(ctx, annot->obj, "V", optarr);
+ pdf_dict_put(ctx, annot->obj, PDF_NAME_V, optarr);
pdf_drop_obj(ctx, optarr);
}
else
{
opt = pdf_new_string(ctx, doc, opts[0], strlen(opts[0]));
- pdf_dict_puts(ctx, annot->obj, "V", opt);
+ pdf_dict_put(ctx, annot->obj, PDF_NAME_V, opt);
pdf_drop_obj(ctx, opt);
}
/* FIXME: when n > 1, we should be regenerating the indexes */
- pdf_dict_dels(ctx, annot->obj, "I");
+ pdf_dict_del(ctx, annot->obj, PDF_NAME_I);
pdf_field_mark_dirty(ctx, doc, annot->obj);
if (pdf_field_dirties_document(ctx, doc, annot->obj))
@@ -1436,7 +1407,7 @@ void pdf_choice_widget_set_value(fz_context *ctx, pdf_document *doc, pdf_widget
int pdf_signature_widget_byte_range(fz_context *ctx, pdf_document *doc, pdf_widget *widget, int (*byte_range)[2])
{
pdf_annot *annot = (pdf_annot *)widget;
- pdf_obj *br = pdf_dict_getp(ctx, annot->obj, "V/ByteRange");
+ pdf_obj *br = pdf_dict_getl(ctx, annot->obj, PDF_NAME_V, PDF_NAME_ByteRange, NULL);
int i, n = pdf_array_len(ctx, br)/2;
if (byte_range)
@@ -1454,7 +1425,7 @@ int pdf_signature_widget_byte_range(fz_context *ctx, pdf_document *doc, pdf_widg
int pdf_signature_widget_contents(fz_context *ctx, pdf_document *doc, pdf_widget *widget, char **contents)
{
pdf_annot *annot = (pdf_annot *)widget;
- pdf_obj *c = pdf_dict_getp(ctx, annot->obj, "V/Contents");
+ pdf_obj *c = pdf_dict_getl(ctx, annot->obj, PDF_NAME_V, PDF_NAME_Contents, NULL);
if (contents)
*contents = pdf_to_str_buf(ctx, c);
return pdf_to_str_len(ctx, c);
@@ -1474,7 +1445,7 @@ void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field,
vnum = pdf_create_object(ctx, doc);
indv = pdf_new_indirect(ctx, doc, vnum, 0);
- pdf_dict_puts_drop(ctx, field, "V", indv);
+ pdf_dict_put_drop(ctx, field, PDF_NAME_V, indv);
fz_var(v);
fz_try(ctx)
@@ -1492,13 +1463,13 @@ void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field,
}
byte_range = pdf_new_array(ctx, doc, 4);
- pdf_dict_puts_drop(ctx, v, "ByteRange", byte_range);
+ pdf_dict_put_drop(ctx, v, PDF_NAME_ByteRange, byte_range);
contents = pdf_new_string(ctx, doc, buf, sizeof(buf));
- pdf_dict_puts_drop(ctx, v, "Contents", contents);
+ pdf_dict_put_drop(ctx, v, PDF_NAME_Contents, contents);
- pdf_dict_puts_drop(ctx, v, "Filter", pdf_new_name(ctx, doc, "Adobe.PPKLite"));
- pdf_dict_puts_drop(ctx, v, "SubFilter", pdf_new_name(ctx, doc, "adbe.pkcs7.detached"));
+ pdf_dict_put_drop(ctx, v, PDF_NAME_Filter, PDF_NAME_Adobe_PPKLite);
+ pdf_dict_put_drop(ctx, v, PDF_NAME_SubFilter, PDF_NAME_adbe_pkcs7_detached);
/* Record details within the document structure so that contents
* and byte_range can be updated with their correct values at