From f84a189d5f94250e46d2cbd1a75aba00130e2dd6 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 21 Jan 2015 16:42:45 +0100 Subject: Add ctx parameter and remove embedded contexts for API regularity. Purge several embedded contexts: Remove embedded context in fz_output. Remove embedded context in fz_stream. Remove embedded context in fz_device. Remove fz_rebind_stream (since it is no longer necessary). Remove embedded context in svg_device. Remove embedded context in XML parser. Add ctx argument to fz_document functions. Remove embedded context in fz_document. Remove embedded context in pdf_document. Remove embedded context in pdf_obj. Make fz_page independent of fz_document in the interface. We shouldn't need to pass the document to all functions handling a page. If a page is tied to the source document, it's redundant; otherwise it's just pointless. Fix reference counting oddity in fz_new_image_from_pixmap. --- source/pdf/pdf-nametree.c | 115 ++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 60 deletions(-) (limited to 'source/pdf/pdf-nametree.c') diff --git a/source/pdf/pdf-nametree.c b/source/pdf/pdf-nametree.c index bcbe8002..eecbb320 100644 --- a/source/pdf/pdf-nametree.c +++ b/source/pdf/pdf-nametree.c @@ -3,52 +3,52 @@ static pdf_obj * pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) { - pdf_obj *kids = pdf_dict_gets(node, "Kids"); - pdf_obj *names = pdf_dict_gets(node, "Names"); + pdf_obj *kids = pdf_dict_gets(ctx, node, "Kids"); + pdf_obj *names = pdf_dict_gets(ctx, node, "Names"); - if (pdf_is_array(kids)) + if (pdf_is_array(ctx, kids)) { int l = 0; - int r = pdf_array_len(kids) - 1; + int r = pdf_array_len(ctx, kids) - 1; while (l <= r) { int m = (l + r) >> 1; - pdf_obj *kid = pdf_array_get(kids, m); - pdf_obj *limits = pdf_dict_gets(kid, "Limits"); - pdf_obj *first = pdf_array_get(limits, 0); - pdf_obj *last = pdf_array_get(limits, 1); + pdf_obj *kid = pdf_array_get(ctx, kids, m); + pdf_obj *limits = pdf_dict_gets(ctx, kid, "Limits"); + pdf_obj *first = pdf_array_get(ctx, limits, 0); + pdf_obj *last = pdf_array_get(ctx, limits, 1); - if (pdf_objcmp(needle, first) < 0) + if (pdf_objcmp(ctx, needle, first) < 0) r = m - 1; - else if (pdf_objcmp(needle, last) > 0) + else if (pdf_objcmp(ctx, needle, last) > 0) l = m + 1; else { pdf_obj *obj; - if (pdf_mark_obj(node)) + if (pdf_mark_obj(ctx, node)) break; obj = pdf_lookup_name_imp(ctx, kid, needle); - pdf_unmark_obj(node); + pdf_unmark_obj(ctx, node); return obj; } } } - if (pdf_is_array(names)) + if (pdf_is_array(ctx, names)) { int l = 0; - int r = (pdf_array_len(names) / 2) - 1; + int r = (pdf_array_len(ctx, names) / 2) - 1; while (l <= r) { int m = (l + r) >> 1; int c; - pdf_obj *key = pdf_array_get(names, m * 2); - pdf_obj *val = pdf_array_get(names, m * 2 + 1); + pdf_obj *key = pdf_array_get(ctx, names, m * 2); + pdf_obj *val = pdf_array_get(ctx, names, m * 2 + 1); - c = pdf_objcmp(needle, key); + c = pdf_objcmp(ctx, needle, key); if (c < 0) r = m - 1; else if (c > 0) @@ -60,49 +60,45 @@ pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) /* Spec says names should be sorted (hence the binary search, * above), but Acrobat copes with non-sorted. Drop back to a * simple search if the binary search fails. */ - r = pdf_array_len(names)/2; + r = pdf_array_len(ctx, names)/2; for (l = 0; l < r; l++) - if (!pdf_objcmp(needle, pdf_array_get(names, l * 2))) - return pdf_array_get(names, l * 2 + 1); + if (!pdf_objcmp(ctx, needle, pdf_array_get(ctx, names, l * 2))) + return pdf_array_get(ctx, names, l * 2 + 1); } return NULL; } pdf_obj * -pdf_lookup_name(pdf_document *doc, char *which, pdf_obj *needle) +pdf_lookup_name(fz_context *ctx, pdf_document *doc, char *which, pdf_obj *needle) { - fz_context *ctx = doc->ctx; - - pdf_obj *root = pdf_dict_gets(pdf_trailer(doc), "Root"); - pdf_obj *names = pdf_dict_gets(root, "Names"); - pdf_obj *tree = pdf_dict_gets(names, which); + pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); + pdf_obj *names = pdf_dict_gets(ctx, root, "Names"); + pdf_obj *tree = pdf_dict_gets(ctx, names, which); return pdf_lookup_name_imp(ctx, tree, needle); } pdf_obj * -pdf_lookup_dest(pdf_document *doc, pdf_obj *needle) +pdf_lookup_dest(fz_context *ctx, pdf_document *doc, pdf_obj *needle) { - fz_context *ctx = doc->ctx; - - pdf_obj *root = pdf_dict_gets(pdf_trailer(doc), "Root"); - pdf_obj *dests = pdf_dict_gets(root, "Dests"); - pdf_obj *names = pdf_dict_gets(root, "Names"); + pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); + pdf_obj *dests = pdf_dict_gets(ctx, root, "Dests"); + pdf_obj *names = pdf_dict_gets(ctx, root, "Names"); pdf_obj *dest = NULL; /* PDF 1.1 has destinations in a dictionary */ if (dests) { - if (pdf_is_name(needle)) - return pdf_dict_get(dests, needle); + if (pdf_is_name(ctx, needle)) + return pdf_dict_get(ctx, dests, needle); else - return pdf_dict_gets(dests, pdf_to_str_buf(needle)); + return pdf_dict_gets(ctx, dests, pdf_to_str_buf(ctx, needle)); } /* PDF 1.2 has destinations in a name tree */ if (names && !dest) { - pdf_obj *tree = pdf_dict_gets(names, "Dests"); + pdf_obj *tree = pdf_dict_gets(ctx, names, "Dests"); return pdf_lookup_name_imp(ctx, tree, needle); } @@ -110,54 +106,53 @@ pdf_lookup_dest(pdf_document *doc, pdf_obj *needle) } static void -pdf_load_name_tree_imp(pdf_obj *dict, pdf_document *doc, pdf_obj *node) +pdf_load_name_tree_imp(fz_context *ctx, pdf_obj *dict, pdf_document *doc, pdf_obj *node) { - fz_context *ctx = doc->ctx; - pdf_obj *kids = pdf_dict_gets(node, "Kids"); - pdf_obj *names = pdf_dict_gets(node, "Names"); + pdf_obj *kids = pdf_dict_gets(ctx, node, "Kids"); + pdf_obj *names = pdf_dict_gets(ctx, node, "Names"); int i; UNUSED(ctx); - if (kids && !pdf_mark_obj(node)) + if (kids && !pdf_mark_obj(ctx, node)) { - int len = pdf_array_len(kids); + int len = pdf_array_len(ctx, kids); for (i = 0; i < len; i++) - pdf_load_name_tree_imp(dict, doc, pdf_array_get(kids, i)); - pdf_unmark_obj(node); + pdf_load_name_tree_imp(ctx, dict, doc, pdf_array_get(ctx, kids, i)); + pdf_unmark_obj(ctx, node); } if (names) { - int len = pdf_array_len(names); + int len = pdf_array_len(ctx, names); for (i = 0; i + 1 < len; i += 2) { - pdf_obj *key = pdf_array_get(names, i); - pdf_obj *val = pdf_array_get(names, i + 1); - if (pdf_is_string(key)) + pdf_obj *key = pdf_array_get(ctx, names, i); + pdf_obj *val = pdf_array_get(ctx, names, i + 1); + if (pdf_is_string(ctx, key)) { - key = pdf_to_utf8_name(doc, key); - pdf_dict_put(dict, key, val); - pdf_drop_obj(key); + key = pdf_to_utf8_name(ctx, doc, key); + pdf_dict_put(ctx, dict, key, val); + pdf_drop_obj(ctx, key); } - else if (pdf_is_name(key)) + else if (pdf_is_name(ctx, key)) { - pdf_dict_put(dict, key, val); + pdf_dict_put(ctx, dict, key, val); } } } } pdf_obj * -pdf_load_name_tree(pdf_document *doc, char *which) +pdf_load_name_tree(fz_context *ctx, pdf_document *doc, char *which) { - pdf_obj *root = pdf_dict_gets(pdf_trailer(doc), "Root"); - pdf_obj *names = pdf_dict_gets(root, "Names"); - pdf_obj *tree = pdf_dict_gets(names, which); - if (pdf_is_dict(tree)) + pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); + pdf_obj *names = pdf_dict_gets(ctx, root, "Names"); + pdf_obj *tree = pdf_dict_gets(ctx, names, which); + if (pdf_is_dict(ctx, tree)) { - pdf_obj *dict = pdf_new_dict(doc, 100); - pdf_load_name_tree_imp(dict, doc, tree); + pdf_obj *dict = pdf_new_dict(ctx, doc, 100); + pdf_load_name_tree_imp(ctx, dict, doc, tree); return dict; } return NULL; -- cgit v1.2.3