diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-06-27 18:24:07 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-06-27 20:05:18 +0100 |
commit | 9df3a0615a1fa7745160c099e1ac7cd4dfcbc86e (patch) | |
tree | 3aac206ddce6e4c50229c9e4e79e3429118035aa /source/pdf | |
parent | 260e54a956c54058051ce6ff31b36ad0ae1b60aa (diff) | |
download | mupdf-9df3a0615a1fa7745160c099e1ac7cd4dfcbc86e.tar.xz |
Move to using a flags bit rather than "Dirty" dict entries.
Correct the naming scheme for pdf_obj_xxx functions.
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-cmap-load.c | 6 | ||||
-rw-r--r-- | source/pdf/pdf-colorspace.c | 4 | ||||
-rw-r--r-- | source/pdf/pdf-form.c | 20 | ||||
-rw-r--r-- | source/pdf/pdf-function.c | 4 | ||||
-rw-r--r-- | source/pdf/pdf-interpret.c | 8 | ||||
-rw-r--r-- | source/pdf/pdf-nametree.c | 8 | ||||
-rw-r--r-- | source/pdf/pdf-object.c | 46 | ||||
-rw-r--r-- | source/pdf/pdf-outline.c | 4 | ||||
-rw-r--r-- | source/pdf/pdf-page.c | 20 | ||||
-rw-r--r-- | source/pdf/pdf-write.c | 22 |
10 files changed, 76 insertions, 66 deletions
diff --git a/source/pdf/pdf-cmap-load.c b/source/pdf/pdf-cmap-load.c index 64dd0e12..68c5b379 100644 --- a/source/pdf/pdf-cmap-load.c +++ b/source/pdf/pdf-cmap-load.c @@ -60,9 +60,9 @@ pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *stmobj) else if (pdf_is_indirect(obj)) { phase = 3; - pdf_obj_mark(obj); + pdf_mark_obj(obj); usecmap = pdf_load_embedded_cmap(doc, obj); - pdf_obj_unmark(obj); + pdf_unmark_obj(obj); phase = 4; pdf_set_usecmap(ctx, cmap, usecmap); pdf_drop_cmap(ctx, usecmap); @@ -85,7 +85,7 @@ pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *stmobj) else { if (phase == 3) - pdf_obj_unmark(obj); + pdf_unmark_obj(obj); fz_rethrow_message(ctx, "cannot load embedded usecmap (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } } diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c index 0d312ac9..e515b30a 100644 --- a/source/pdf/pdf-colorspace.c +++ b/source/pdf/pdf-colorspace.c @@ -272,7 +272,7 @@ pdf_load_colorspace_imp(pdf_document *doc, pdf_obj *obj) fz_colorspace *cs; fz_try(ctx) { - pdf_obj_mark(obj); + pdf_mark_obj(obj); if (!strcmp(str, "ICCBased")) cs = load_icc_based(doc, pdf_array_get(obj, 1)); @@ -304,7 +304,7 @@ pdf_load_colorspace_imp(pdf_document *doc, pdf_obj *obj) } fz_always(ctx) { - pdf_obj_unmark(obj); + pdf_unmark_obj(obj); } fz_catch(ctx) { diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c index 21c27ea7..0e30f1a6 100644 --- a/source/pdf/pdf-form.c +++ b/source/pdf/pdf-form.c @@ -180,21 +180,9 @@ static void pdf_field_mark_dirty(pdf_document *doc, pdf_obj *field) for (i = 0; i < n; i++) pdf_field_mark_dirty(doc, pdf_array_get(kids, i)); } - else if (!pdf_dict_gets(field, "Dirty")) + else { - pdf_obj *nullobj = pdf_new_null(doc); - fz_try(ctx) - { - pdf_dict_puts(field, "Dirty", nullobj); - } - fz_always(ctx) - { - pdf_drop_obj(nullobj); - } - fz_catch(ctx) - { - fz_rethrow(ctx); - } + pdf_dirty_obj(field); } } @@ -1762,7 +1750,7 @@ static void update_text_markup_appearance(pdf_document *doc, pdf_annot *annot, f void pdf_update_appearance(pdf_document *doc, pdf_annot *annot) { pdf_obj *obj = annot->obj; - if (!pdf_dict_gets(obj, "AP") || pdf_dict_gets(obj, "Dirty")) + if (!pdf_dict_gets(obj, "AP") || pdf_obj_is_dirty(obj)) { fz_annot_type type = pdf_annot_obj_type(obj); switch (type) @@ -1815,7 +1803,7 @@ void pdf_update_appearance(pdf_document *doc, pdf_annot *annot) break; } - pdf_dict_dels(obj, "Dirty"); + pdf_clean_obj(obj); } } diff --git a/source/pdf/pdf-function.c b/source/pdf/pdf-function.c index 4496a158..aee546ca 100644 --- a/source/pdf/pdf-function.c +++ b/source/pdf/pdf-function.c @@ -1231,7 +1231,7 @@ load_stitching_func(pdf_function *func, pdf_document *doc, pdf_obj *dict) fz_try(ctx) { - pdf_obj_mark(obj); + pdf_mark_obj(obj); k = pdf_array_len(obj); func->u.st.funcs = fz_malloc_array(ctx, k, sizeof(fz_function*)); @@ -1255,7 +1255,7 @@ load_stitching_func(pdf_function *func, pdf_document *doc, pdf_obj *dict) } fz_always(ctx) { - pdf_obj_unmark(obj); + pdf_unmark_obj(obj); } fz_catch(ctx) { diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index aed02317..cec0d1e5 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -277,7 +277,7 @@ pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) combine = 0; } - if (pdf_obj_mark(ocg)) + if (pdf_mark_obj(ocg)) return 0; /* Should never happen */ fz_try(ctx) { @@ -307,7 +307,7 @@ pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) } fz_always(ctx) { - pdf_obj_unmark(ocg); + pdf_unmark_obj(ocg); } fz_catch(ctx) { @@ -1505,7 +1505,7 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, const fz_ma fz_matrix gparent_save_ctm; /* Avoid infinite recursion */ - if (xobj == NULL || pdf_obj_mark(xobj->me)) + if (xobj == NULL || pdf_mark_obj(xobj->me)) return; fz_var(gstate); @@ -1574,7 +1574,7 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, const fz_ma pdf_grestore(csi); } - pdf_obj_unmark(xobj->me); + pdf_unmark_obj(xobj->me); /* wrap up transparency stacks */ if (xobj->transparency) diff --git a/source/pdf/pdf-nametree.c b/source/pdf/pdf-nametree.c index 0f7af15e..bcbe8002 100644 --- a/source/pdf/pdf-nametree.c +++ b/source/pdf/pdf-nametree.c @@ -27,10 +27,10 @@ pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) { pdf_obj *obj; - if (pdf_obj_mark(node)) + if (pdf_mark_obj(node)) break; obj = pdf_lookup_name_imp(ctx, kid, needle); - pdf_obj_unmark(node); + pdf_unmark_obj(node); return obj; } } @@ -119,12 +119,12 @@ pdf_load_name_tree_imp(pdf_obj *dict, pdf_document *doc, pdf_obj *node) UNUSED(ctx); - if (kids && !pdf_obj_mark(node)) + if (kids && !pdf_mark_obj(node)) { int len = pdf_array_len(kids); for (i = 0; i < len; i++) pdf_load_name_tree_imp(dict, doc, pdf_array_get(kids, i)); - pdf_obj_unmark(node); + pdf_unmark_obj(node); } if (names) diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index ddeffac0..037f1e16 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -23,8 +23,9 @@ enum { PDF_FLAGS_MARKED = 1, PDF_FLAGS_SORTED = 2, - PDF_FLAGS_STASH = 4, - PDF_FLAGS_STASH_BOOL = 8 + PDF_FLAGS_MEMO = 4, + PDF_FLAGS_MEMO_BOOL = 8, + PDF_FLAGS_DIRTY = 16 }; struct pdf_obj_s @@ -1170,7 +1171,7 @@ pdf_obj_marked(pdf_obj *obj) } int -pdf_obj_mark(pdf_obj *obj) +pdf_mark_obj(pdf_obj *obj) { int marked; RESOLVE(obj); @@ -1182,7 +1183,7 @@ pdf_obj_mark(pdf_obj *obj) } void -pdf_obj_unmark(pdf_obj *obj) +pdf_unmark_obj(pdf_obj *obj) { RESOLVE(obj); if (!obj) @@ -1191,24 +1192,45 @@ pdf_obj_unmark(pdf_obj *obj) } void -pdf_obj_stash(pdf_obj *obj, int stash) +pdf_set_obj_memo(pdf_obj *obj, int memo) { - obj->flags |= PDF_FLAGS_STASH; - if (stash) - obj->flags |= PDF_FLAGS_STASH_BOOL; + obj->flags |= PDF_FLAGS_MEMO; + if (memo) + obj->flags |= PDF_FLAGS_MEMO_BOOL; else - obj->flags &= ~PDF_FLAGS_STASH_BOOL; + obj->flags &= ~PDF_FLAGS_MEMO_BOOL; } int -pdf_obj_stashed(pdf_obj *obj, int *stash) +pdf_obj_memo(pdf_obj *obj, int *memo) { - if (!(obj->flags & PDF_FLAGS_STASH)) + if (!(obj->flags & PDF_FLAGS_MEMO)) return 0; - *stash = !!(obj->flags & PDF_FLAGS_STASH_BOOL); + *memo = !!(obj->flags & PDF_FLAGS_MEMO_BOOL); return 1; } +int pdf_obj_is_dirty(pdf_obj *obj) +{ + if (!obj) + return 0; + return !!(obj->flags & PDF_FLAGS_DIRTY); +} + +void pdf_dirty_obj(pdf_obj *obj) +{ + if (!obj) + return; + obj->flags |= PDF_FLAGS_DIRTY; +} + +void pdf_clean_obj(pdf_obj *obj) +{ + if (!obj) + return; + obj->flags &= ~PDF_FLAGS_DIRTY; +} + static void pdf_free_array(pdf_obj *obj) { diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c index e83997b8..2d545b63 100644 --- a/source/pdf/pdf-outline.c +++ b/source/pdf/pdf-outline.c @@ -17,7 +17,7 @@ pdf_load_outline_imp(pdf_document *doc, pdf_obj *dict) prev = &first; while (dict && pdf_is_dict(dict)) { - if (pdf_obj_mark(dict)) + if (pdf_mark_obj(dict)) break; node = fz_malloc_struct(ctx, fz_outline); node->title = NULL; @@ -46,7 +46,7 @@ pdf_load_outline_imp(pdf_document *doc, pdf_obj *dict) fz_always(ctx) { for (dict = odict; dict && pdf_obj_marked(dict); dict = pdf_dict_gets(dict, "Next")) - pdf_obj_unmark(dict); + pdf_unmark_obj(dict); } fz_catch(ctx) { diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 82c7aa5c..2e14bf6c 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -33,7 +33,7 @@ pdf_load_page_tree_node(pdf_document *doc, pdf_obj *node, struct info info) { do { - if (!node || pdf_obj_mark(node)) + if (!node || pdf_mark_obj(node)) { /* NULL node, or we've been here before. * Nothing to do. */ @@ -91,7 +91,7 @@ pdf_load_page_tree_node(pdf_document *doc, pdf_obj *node, struct info info) doc->page_refs[doc->page_len] = pdf_keep_obj(node); doc->page_objs[doc->page_len] = pdf_keep_obj(dict); doc->page_len ++; - pdf_obj_unmark(node); + pdf_unmark_obj(node); } } /* Get the next node */ @@ -99,13 +99,13 @@ pdf_load_page_tree_node(pdf_document *doc, pdf_obj *node, struct info info) break; while (++stack[stacklen].pos == stack[stacklen].max) { - pdf_obj_unmark(stack[stacklen].node); + pdf_unmark_obj(stack[stacklen].node); stacklen--; if (stacklen < 0) /* No more to pop! */ break; node = stack[stacklen].node; info = stack[stacklen].info; - pdf_obj_unmark(node); /* Unmark it, cos we're about to mark it again */ + pdf_unmark_obj(node); /* Unmark it, cos we're about to mark it again */ } if (stacklen >= 0) node = pdf_array_get(stack[stacklen].kids, stack[stacklen].pos); @@ -115,7 +115,7 @@ pdf_load_page_tree_node(pdf_document *doc, pdf_obj *node, struct info info) fz_always(ctx) { while (stacklen >= 0) - pdf_obj_unmark(stack[stacklen--].node); + pdf_unmark_obj(stack[stacklen--].node); fz_free(ctx, stack); } fz_catch(ctx) @@ -218,12 +218,12 @@ pdf_resources_use_blending(pdf_document *doc, pdf_obj *rdb) if (!rdb) return 0; - /* Have we been here before and stashed an answer? */ - if (pdf_obj_stashed(rdb, &useBM)) + /* Have we been here before and remembered an answer? */ + if (pdf_obj_memo(rdb, &useBM)) return useBM; /* stop on cyclic resource dependencies */ - if (pdf_obj_mark(rdb)) + if (pdf_mark_obj(rdb)) return 0; fz_try(ctx) @@ -253,14 +253,14 @@ found: } fz_always(ctx) { - pdf_obj_unmark(rdb); + pdf_unmark_obj(rdb); } fz_catch(ctx) { fz_rethrow(ctx); } - pdf_obj_stash(rdb, useBM); + pdf_set_obj_memo(rdb, useBM); return useBM; } diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index 1c87d2c0..79271499 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -842,7 +842,7 @@ mark_all(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int flag, int { fz_context *ctx = doc->ctx; - if (pdf_obj_mark(val)) + if (pdf_mark_obj(val)) return; fz_try(ctx) @@ -880,7 +880,7 @@ mark_all(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int flag, int } fz_always(ctx) { - pdf_obj_unmark(val); + pdf_unmark_obj(val); } fz_catch(ctx) { @@ -893,7 +893,7 @@ mark_pages(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int pagenum { fz_context *ctx = doc->ctx; - if (pdf_obj_mark(val)) + if (pdf_mark_obj(val)) return pagenum; fz_try(ctx) @@ -903,7 +903,7 @@ mark_pages(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int pagenum if (!strcmp("Page", pdf_to_name(pdf_dict_gets(val, "Type")))) { int num = pdf_to_num(val); - pdf_obj_unmark(val); + pdf_unmark_obj(val); mark_all(doc, opts, val, pagenum == 0 ? USE_PAGE1 : (pagenum<<USE_PAGE_SHIFT), pagenum); page_objects_list_set_page_object(ctx, opts, pagenum, num); pagenum++; @@ -948,7 +948,7 @@ mark_pages(pdf_document *doc, pdf_write_options *opts, pdf_obj *val, int pagenum } fz_always(ctx) { - pdf_obj_unmark(val); + pdf_unmark_obj(val); } fz_catch(ctx) { @@ -963,7 +963,7 @@ mark_root(pdf_document *doc, pdf_write_options *opts, pdf_obj *dict) fz_context *ctx = doc->ctx; int i, n = pdf_dict_len(dict); - if (pdf_obj_mark(dict)) + if (pdf_mark_obj(dict)) return; fz_try(ctx) @@ -1002,7 +1002,7 @@ mark_root(pdf_document *doc, pdf_write_options *opts, pdf_obj *dict) } fz_always(ctx) { - pdf_obj_unmark(dict); + pdf_unmark_obj(dict); } fz_catch(ctx) { @@ -1016,7 +1016,7 @@ mark_trailer(pdf_document *doc, pdf_write_options *opts, pdf_obj *dict) fz_context *ctx = doc->ctx; int i, n = pdf_dict_len(dict); - if (pdf_obj_mark(dict)) + if (pdf_mark_obj(dict)) return; fz_try(ctx) @@ -1034,7 +1034,7 @@ mark_trailer(pdf_document *doc, pdf_write_options *opts, pdf_obj *dict) } fz_always(ctx) { - pdf_obj_unmark(dict); + pdf_unmark_obj(dict); } fz_catch(ctx) { @@ -1226,7 +1226,7 @@ lpr(pdf_document *doc, pdf_obj *node, int depth, int page) int i, n; fz_context *ctx = doc->ctx; - if (pdf_obj_mark(node)) + if (pdf_mark_obj(node)) return page; fz_var(o); @@ -1291,7 +1291,7 @@ lpr(pdf_document *doc, pdf_obj *node, int depth, int page) fz_rethrow(ctx); } - pdf_obj_unmark(node); + pdf_unmark_obj(node); return page; } |