diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-05-28 13:23:38 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-05-29 13:03:20 +0100 |
commit | c630e8e213f5b697b3b78989ba866fed9dd0d45f (patch) | |
tree | 7558b7a2f46ee889d98ade65e8733ffe24580693 /pdf | |
parent | 9fff004ccb4f03495f6f2872af861263eba2def1 (diff) | |
download | mupdf-c630e8e213f5b697b3b78989ba866fed9dd0d45f.tar.xz |
Access the trailer via an interface
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/mupdf-internal.h | 2 | ||||
-rw-r--r-- | pdf/pdf_field.c | 2 | ||||
-rw-r--r-- | pdf/pdf_form.c | 4 | ||||
-rw-r--r-- | pdf/pdf_js.c | 2 | ||||
-rw-r--r-- | pdf/pdf_nametree.c | 6 | ||||
-rw-r--r-- | pdf/pdf_outline.c | 2 | ||||
-rw-r--r-- | pdf/pdf_page.c | 2 | ||||
-rw-r--r-- | pdf/pdf_repair.c | 16 | ||||
-rw-r--r-- | pdf/pdf_write.c | 14 | ||||
-rw-r--r-- | pdf/pdf_xref.c | 51 |
10 files changed, 60 insertions, 41 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h index bea1c0d3..5b84bed7 100644 --- a/pdf/mupdf-internal.h +++ b/pdf/mupdf-internal.h @@ -173,6 +173,8 @@ fz_buffer *pdf_load_raw_renumbered_stream(pdf_document *doc, int num, int gen, i fz_buffer *pdf_load_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen, int *truncated); fz_stream *pdf_open_raw_renumbered_stream(pdf_document *doc, int num, int gen, int orig_num, int orig_gen); +pdf_obj *pdf_trailer(pdf_document *doc); +void pdf_set_xref_trailer(pdf_document *doc, pdf_obj *trailer); void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf); void pdf_repair_obj_stms(pdf_document *doc); void pdf_resize_xref(pdf_document *doc, int newcap); diff --git a/pdf/pdf_field.c b/pdf/pdf_field.c index 4d6d9cdb..964c04c1 100644 --- a/pdf/pdf_field.c +++ b/pdf/pdf_field.c @@ -14,7 +14,7 @@ pdf_obj *pdf_get_inheritable(pdf_document *doc, pdf_obj *obj, char *key) } return fobj ? fobj - : pdf_dict_gets(pdf_dict_gets(pdf_dict_gets(doc->trailer, "Root"), "AcroForm"), key); + : pdf_dict_gets(pdf_dict_gets(pdf_dict_gets(pdf_trailer(doc), "Root"), "AcroForm"), key); } int pdf_get_field_flags(pdf_document *doc, pdf_obj *obj) diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 339968a3..d7dd6503 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -1578,7 +1578,7 @@ static void add_field_hierarchy_to_array(pdf_obj *array, pdf_obj *field) static pdf_obj *specified_fields(pdf_document *doc, pdf_obj *fields, int exclude) { fz_context *ctx = doc->ctx; - pdf_obj *form = pdf_dict_getp(doc->trailer, "Root/AcroForm/Fields"); + pdf_obj *form = pdf_dict_getp(pdf_trailer(doc), "Root/AcroForm/Fields"); int i, n; pdf_obj *result = pdf_new_array(ctx, 0); pdf_obj *nil = NULL; @@ -1924,7 +1924,7 @@ static void recalculate(pdf_document *doc) doc->recalculating = 1; fz_try(ctx) { - pdf_obj *co = pdf_dict_getp(doc->trailer, "Root/AcroForm/CO"); + pdf_obj *co = pdf_dict_getp(pdf_trailer(doc), "Root/AcroForm/CO"); if (co && doc->js) { diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c index 23b51df6..266bc1c7 100644 --- a/pdf/pdf_js.c +++ b/pdf/pdf_js.c @@ -778,7 +778,7 @@ pdf_js *pdf_new_js(pdf_document *doc) js->doc = doc; /* Find the form array */ - root = pdf_dict_gets(doc->trailer, "Root"); + root = pdf_dict_gets(pdf_trailer(doc), "Root"); acroform = pdf_dict_gets(root, "AcroForm"); js->form = pdf_dict_gets(acroform, "Fields"); diff --git a/pdf/pdf_nametree.c b/pdf/pdf_nametree.c index 6677e7a2..b175456e 100644 --- a/pdf/pdf_nametree.c +++ b/pdf/pdf_nametree.c @@ -75,7 +75,7 @@ pdf_lookup_name(pdf_document *xref, char *which, pdf_obj *needle) { fz_context *ctx = xref->ctx; - pdf_obj *root = pdf_dict_gets(xref->trailer, "Root"); + pdf_obj *root = pdf_dict_gets(pdf_trailer(xref), "Root"); pdf_obj *names = pdf_dict_gets(root, "Names"); pdf_obj *tree = pdf_dict_gets(names, which); return pdf_lookup_name_imp(ctx, tree, needle); @@ -86,7 +86,7 @@ pdf_lookup_dest(pdf_document *xref, pdf_obj *needle) { fz_context *ctx = xref->ctx; - pdf_obj *root = pdf_dict_gets(xref->trailer, "Root"); + pdf_obj *root = pdf_dict_gets(pdf_trailer(xref), "Root"); pdf_obj *dests = pdf_dict_gets(root, "Dests"); pdf_obj *names = pdf_dict_gets(root, "Names"); pdf_obj *dest = NULL; @@ -154,7 +154,7 @@ pdf_load_name_tree(pdf_document *xref, char *which) { fz_context *ctx = xref->ctx; - pdf_obj *root = pdf_dict_gets(xref->trailer, "Root"); + pdf_obj *root = pdf_dict_gets(pdf_trailer(xref), "Root"); pdf_obj *names = pdf_dict_gets(root, "Names"); pdf_obj *tree = pdf_dict_gets(names, which); if (pdf_is_dict(tree)) diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c index 3a0e803e..fb750b9f 100644 --- a/pdf/pdf_outline.c +++ b/pdf/pdf_outline.c @@ -63,7 +63,7 @@ pdf_load_outline(pdf_document *xref) { pdf_obj *root, *obj, *first; - root = pdf_dict_gets(xref->trailer, "Root"); + root = pdf_dict_gets(pdf_trailer(xref), "Root"); obj = pdf_dict_gets(root, "Outlines"); first = pdf_dict_gets(obj, "First"); if (first) diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 5d6d6bca..99776f42 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -157,7 +157,7 @@ pdf_load_page_tree(pdf_document *xref) if (xref->page_refs) return; - catalog = pdf_dict_gets(xref->trailer, "Root"); + catalog = pdf_dict_gets(pdf_trailer(xref), "Root"); pages = pdf_dict_gets(catalog, "Pages"); count = pdf_dict_gets(pages, "Count"); diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index c74f25af..e26baefa 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -441,21 +441,25 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) /* create a repaired trailer, Root will be added later */ - xref->trailer = pdf_new_dict(ctx, 5); + obj = pdf_new_dict(ctx, 5); + pdf_set_xref_trailer(xref, obj); + pdf_drop_obj(obj); + obj = NULL; obj = pdf_new_int(ctx, maxnum + 1); - pdf_dict_puts(xref->trailer, "Size", obj); + pdf_dict_puts(pdf_trailer(xref), "Size", obj); pdf_drop_obj(obj); + obj = NULL; if (root) { - pdf_dict_puts(xref->trailer, "Root", root); + pdf_dict_puts(pdf_trailer(xref), "Root", root); pdf_drop_obj(root); root = NULL; } if (info) { - pdf_dict_puts(xref->trailer, "Info", info); + pdf_dict_puts(pdf_trailer(xref), "Info", info); pdf_drop_obj(info); info = NULL; } @@ -469,7 +473,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) pdf_drop_obj(encrypt); encrypt = obj; } - pdf_dict_puts(xref->trailer, "Encrypt", encrypt); + pdf_dict_puts(pdf_trailer(xref), "Encrypt", encrypt); pdf_drop_obj(encrypt); encrypt = NULL; } @@ -483,7 +487,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) pdf_drop_obj(id); id = obj; } - pdf_dict_puts(xref->trailer, "ID", id); + pdf_dict_puts(pdf_trailer(xref), "ID", id); pdf_drop_obj(id); id = NULL; } diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c index b7f2bdef..5e21e7f8 100644 --- a/pdf/pdf_write.c +++ b/pdf/pdf_write.c @@ -763,7 +763,7 @@ static void renumberobjs(pdf_document *xref, pdf_write_options *opts) fz_try(ctx) { /* Apply renumber map to indirect references in all objects in xref */ - renumberobj(xref, opts, xref->trailer); + renumberobj(xref, opts, pdf_trailer(xref)); for (num = 0; num < xref->len; num++) { pdf_obj *obj = xref->table[num].obj; @@ -1301,7 +1301,7 @@ pdf_localise_page_resources(pdf_document *xref) if (xref->resources_localised) return; - lpr(ctx, pdf_dict_getp(xref->trailer, "Root/Pages"), 0, 0); + lpr(ctx, pdf_dict_getp(pdf_trailer(xref), "Root/Pages"), 0, 0); xref->resources_localised = 1; } @@ -1326,7 +1326,7 @@ linearize(pdf_document *xref, pdf_write_options *opts) /* Walk the objects for each page, marking which ones are used, where */ memset(opts->use_list, 0, n * sizeof(int)); - mark_trailer(xref, opts, xref->trailer); + mark_trailer(xref, opts, pdf_trailer(xref)); /* Add new objects required for linearization */ add_linearization_objs(xref, opts); @@ -1769,15 +1769,15 @@ static void writexref(pdf_document *xref, pdf_write_options *opts, int from, int if (first) { - obj = pdf_dict_gets(xref->trailer, "Info"); + obj = pdf_dict_gets(pdf_trailer(xref), "Info"); if (obj) pdf_dict_puts(trailer, "Info", obj); - obj = pdf_dict_gets(xref->trailer, "Root"); + obj = pdf_dict_gets(pdf_trailer(xref), "Root"); if (obj) pdf_dict_puts(trailer, "Root", obj); - obj = pdf_dict_gets(xref->trailer, "ID"); + obj = pdf_dict_gets(pdf_trailer(xref), "ID"); if (obj) pdf_dict_puts(trailer, "ID", obj); } @@ -2256,7 +2256,7 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz /* Sweep & mark objects from the trailer */ if (opts.do_garbage >= 1) - sweepobj(xref, &opts, xref->trailer); + sweepobj(xref, &opts, pdf_trailer(xref)); else for (num = 0; num < xref->len; num++) opts.use_list[num] = 1; diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index b3455773..254c0a3f 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -12,6 +12,17 @@ static inline int iswhite(int ch) * magic version tag and startxref */ +pdf_obj *pdf_trailer(pdf_document *doc) +{ + return doc->trailer; +} + +void pdf_set_xref_trailer(pdf_document *doc, pdf_obj *trailer) +{ + pdf_drop_obj(doc->trailer); + doc->trailer = pdf_keep_obj(trailer); +} + static void pdf_load_version(pdf_document *xref) { @@ -102,6 +113,7 @@ pdf_read_old_trailer(pdf_document *xref, pdf_lexbuf *buf) fz_try(xref->ctx) { + pdf_obj *trailer; tok = pdf_lex(xref->file, buf); if (tok != PDF_TOK_TRAILER) fz_throw(xref->ctx, "expected trailer marker"); @@ -110,7 +122,9 @@ pdf_read_old_trailer(pdf_document *xref, pdf_lexbuf *buf) if (tok != PDF_TOK_OPEN_DICT) fz_throw(xref->ctx, "expected trailer dictionary"); - xref->trailer = pdf_parse_dict(xref, xref->file, buf); + trailer = pdf_parse_dict(xref, xref->file, buf); + pdf_set_xref_trailer(xref, trailer); + pdf_drop_obj(trailer); } fz_catch(xref->ctx) { @@ -123,16 +137,19 @@ pdf_read_new_trailer(pdf_document *xref, pdf_lexbuf *buf) { fz_try(xref->ctx) { + pdf_obj *trailer; int num, gen, stm_ofs, ofs; ofs = fz_tell(xref->file); - xref->trailer = pdf_parse_ind_obj(xref, xref->file, buf, &num, &gen, &stm_ofs); + trailer = pdf_parse_ind_obj(xref, xref->file, buf, &num, &gen, &stm_ofs); + pdf_set_xref_trailer(xref, trailer); + pdf_drop_obj(trailer); if (num >= xref->len) pdf_resize_xref(xref, num+1); xref->table[num].ofs = ofs; xref->table[num].gen = gen; xref->table[num].stm_ofs = stm_ofs; pdf_drop_obj(xref->table[num].obj); - xref->table[num].obj = pdf_keep_obj(xref->trailer); + xref->table[num].obj = pdf_keep_obj(pdf_trailer(xref)); xref->table[num].type = 'n'; } fz_catch(xref->ctx) @@ -561,7 +578,7 @@ pdf_load_xref(pdf_document *xref, pdf_lexbuf *buf) pdf_read_trailer(xref, buf); - size = pdf_to_int(pdf_dict_gets(xref->trailer, "Size")); + size = pdf_to_int(pdf_dict_gets(pdf_trailer(xref), "Size")); if (!size) fz_throw(ctx, "trailer missing Size entry"); @@ -600,7 +617,7 @@ pdf_ocg_set_config(pdf_document *xref, int config) pdf_obj *obj, *cobj; char *name; - obj = pdf_dict_gets(pdf_dict_gets(xref->trailer, "Root"), "OCProperties"); + obj = pdf_dict_gets(pdf_dict_gets(pdf_trailer(xref), "Root"), "OCProperties"); if (!obj) { if (config == 0) @@ -706,7 +723,7 @@ pdf_read_ocg(pdf_document *xref) fz_var(desc); - obj = pdf_dict_gets(pdf_dict_gets(xref->trailer, "Root"), "OCProperties"); + obj = pdf_dict_gets(pdf_dict_gets(pdf_trailer(xref), "Root"), "OCProperties"); if (!obj) return; ocg = pdf_dict_gets(obj, "OCGs"); @@ -781,11 +798,7 @@ pdf_init_document(pdf_document *xref) xref->table = NULL; xref->len = 0; } - if (xref->trailer) - { - pdf_drop_obj(xref->trailer); - xref->trailer = NULL; - } + pdf_set_xref_trailer(xref, NULL); fz_warn(xref->ctx, "trying to repair broken xref"); repaired = 1; } @@ -797,8 +810,8 @@ pdf_init_document(pdf_document *xref) if (repaired) pdf_repair_xref(xref, &xref->lexbuf.base); - encrypt = pdf_dict_gets(xref->trailer, "Encrypt"); - id = pdf_dict_gets(xref->trailer, "ID"); + encrypt = pdf_dict_gets(pdf_trailer(xref), "Encrypt"); + id = pdf_dict_gets(pdf_trailer(xref), "ID"); if (pdf_is_dict(encrypt)) xref->crypt = pdf_new_crypt(ctx, encrypt, id); @@ -809,8 +822,8 @@ pdf_init_document(pdf_document *xref) { pdf_repair_obj_stms(xref); - hasroot = (pdf_dict_gets(xref->trailer, "Root") != NULL); - hasinfo = (pdf_dict_gets(xref->trailer, "Info") != NULL); + hasroot = (pdf_dict_gets(pdf_trailer(xref), "Root") != NULL); + hasinfo = (pdf_dict_gets(pdf_trailer(xref), "Info") != NULL); for (i = 1; i < xref->len; i++) { @@ -833,7 +846,7 @@ pdf_init_document(pdf_document *xref) if (pdf_is_name(obj) && !strcmp(pdf_to_name(obj), "Catalog")) { nobj = pdf_new_indirect(ctx, i, 0, xref); - pdf_dict_puts(xref->trailer, "Root", nobj); + pdf_dict_puts(pdf_trailer(xref), "Root", nobj); pdf_drop_obj(nobj); nobj = NULL; } @@ -844,7 +857,7 @@ pdf_init_document(pdf_document *xref) if (pdf_dict_gets(dict, "Creator") || pdf_dict_gets(dict, "Producer")) { nobj = pdf_new_indirect(ctx, i, 0, xref); - pdf_dict_puts(xref->trailer, "Info", nobj); + pdf_dict_puts(pdf_trailer(xref), "Info", nobj); pdf_drop_obj(nobj); nobj = NULL; } @@ -919,7 +932,7 @@ pdf_close_document(pdf_document *xref) pdf_drop_obj(xref->focus_obj); if (xref->file) fz_close(xref->file); - pdf_drop_obj(xref->trailer); + pdf_drop_obj(pdf_trailer(xref)); if (xref->crypt) pdf_free_crypt(ctx, xref->crypt); @@ -1306,7 +1319,7 @@ pdf_meta(pdf_document *doc, int key, void *ptr, int size) } case FZ_META_INFO: { - pdf_obj *info = pdf_dict_gets(doc->trailer, "Info"); + pdf_obj *info = pdf_dict_gets(pdf_trailer(doc), "Info"); if (!info) { if (ptr) |