summaryrefslogtreecommitdiff
path: root/pdf/pdf_nametree.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-09-14 17:36:57 +0100
committerRobin Watts <Robin.Watts@artifex.com>2011-09-15 14:50:17 +0100
commitb51ef0eea028c73b6379e832eaa34fff3fbbb927 (patch)
tree1ab685ccd356e7fdc832b2e3322c0486b2670cfb /pdf/pdf_nametree.c
parent89ae81f651bfa112b8e07317eb6983beaf7cb212 (diff)
downloadmupdf-b51ef0eea028c73b6379e832eaa34fff3fbbb927.tar.xz
Add context to mupdf.
Huge pervasive change to lots of files, adding a context for exception handling and allocation. In time we'll move more statics into there. Also fix some for(i = 0; i < function(...); i++) calls.
Diffstat (limited to 'pdf/pdf_nametree.c')
-rw-r--r--pdf/pdf_nametree.c95
1 files changed, 51 insertions, 44 deletions
diff --git a/pdf/pdf_nametree.c b/pdf/pdf_nametree.c
index e2b3e160..838caa94 100644
--- a/pdf/pdf_nametree.c
+++ b/pdf/pdf_nametree.c
@@ -2,44 +2,44 @@
#include "mupdf.h"
static fz_obj *
-pdf_lookup_name_imp(fz_obj *node, fz_obj *needle)
+pdf_lookup_name_imp(fz_context *ctx, fz_obj *node, fz_obj *needle)
{
- fz_obj *kids = fz_dict_gets(node, "Kids");
- fz_obj *names = fz_dict_gets(node, "Names");
+ fz_obj *kids = fz_dict_gets(ctx, node, "Kids");
+ fz_obj *names = fz_dict_gets(ctx, node, "Names");
- if (fz_is_array(kids))
+ if (fz_is_array(ctx, kids))
{
int l = 0;
- int r = fz_array_len(kids) - 1;
+ int r = fz_array_len(ctx, kids) - 1;
while (l <= r)
{
int m = (l + r) >> 1;
- fz_obj *kid = fz_array_get(kids, m);
- fz_obj *limits = fz_dict_gets(kid, "Limits");
- fz_obj *first = fz_array_get(limits, 0);
- fz_obj *last = fz_array_get(limits, 1);
+ fz_obj *kid = fz_array_get(ctx, kids, m);
+ fz_obj *limits = fz_dict_gets(ctx, kid, "Limits");
+ fz_obj *first = fz_array_get(ctx, limits, 0);
+ fz_obj *last = fz_array_get(ctx, limits, 1);
if (fz_objcmp(needle, first) < 0)
r = m - 1;
else if (fz_objcmp(needle, last) > 0)
l = m + 1;
else
- return pdf_lookup_name_imp(kid, needle);
+ return pdf_lookup_name_imp(ctx, kid, needle);
}
}
- if (fz_is_array(names))
+ if (fz_is_array(ctx, names))
{
int l = 0;
- int r = (fz_array_len(names) / 2) - 1;
+ int r = (fz_array_len(ctx, names) / 2) - 1;
while (l <= r)
{
int m = (l + r) >> 1;
int c;
- fz_obj *key = fz_array_get(names, m * 2);
- fz_obj *val = fz_array_get(names, m * 2 + 1);
+ fz_obj *key = fz_array_get(ctx, names, m * 2);
+ fz_obj *val = fz_array_get(ctx, names, m * 2 + 1);
c = fz_objcmp(needle, key);
if (c < 0)
@@ -57,34 +57,38 @@ pdf_lookup_name_imp(fz_obj *node, fz_obj *needle)
fz_obj *
pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *needle)
{
- fz_obj *root = fz_dict_gets(xref->trailer, "Root");
- fz_obj *names = fz_dict_gets(root, "Names");
- fz_obj *tree = fz_dict_gets(names, which);
- return pdf_lookup_name_imp(tree, needle);
+ fz_context *ctx = xref->ctx;
+
+ fz_obj *root = fz_dict_gets(ctx, xref->trailer, "Root");
+ fz_obj *names = fz_dict_gets(ctx, root, "Names");
+ fz_obj *tree = fz_dict_gets(ctx, names, which);
+ return pdf_lookup_name_imp(ctx, tree, needle);
}
fz_obj *
pdf_lookup_dest(pdf_xref *xref, fz_obj *needle)
{
- fz_obj *root = fz_dict_gets(xref->trailer, "Root");
- fz_obj *dests = fz_dict_gets(root, "Dests");
- fz_obj *names = fz_dict_gets(root, "Names");
+ fz_context *ctx = xref->ctx;
+
+ fz_obj *root = fz_dict_gets(ctx, xref->trailer, "Root");
+ fz_obj *dests = fz_dict_gets(ctx, root, "Dests");
+ fz_obj *names = fz_dict_gets(ctx, root, "Names");
fz_obj *dest = NULL;
/* PDF 1.1 has destinations in a dictionary */
if (dests)
{
- if (fz_is_name(needle))
- return fz_dict_get(dests, needle);
+ if (fz_is_name(ctx, needle))
+ return fz_dict_get(ctx, dests, needle);
else
- return fz_dict_gets(dests, fz_to_str_buf(needle));
+ return fz_dict_gets(ctx, dests, fz_to_str_buf(ctx, needle));
}
/* PDF 1.2 has destinations in a name tree */
if (names && !dest)
{
- fz_obj *tree = fz_dict_gets(names, "Dests");
- return pdf_lookup_name_imp(tree, needle);
+ fz_obj *tree = fz_dict_gets(ctx, names, "Dests");
+ return pdf_lookup_name_imp(ctx, tree, needle);
}
return NULL;
@@ -93,31 +97,32 @@ pdf_lookup_dest(pdf_xref *xref, fz_obj *needle)
static void
pdf_load_name_tree_imp(fz_obj *dict, pdf_xref *xref, fz_obj *node)
{
- fz_obj *kids = fz_dict_gets(node, "Kids");
- fz_obj *names = fz_dict_gets(node, "Names");
+ fz_context *ctx = xref->ctx;
+ fz_obj *kids = fz_dict_gets(ctx, node, "Kids");
+ fz_obj *names = fz_dict_gets(ctx, node, "Names");
int i;
if (kids)
{
- for (i = 0; i < fz_array_len(kids); i++)
- pdf_load_name_tree_imp(dict, xref, fz_array_get(kids, i));
+ for (i = 0; i < fz_array_len(ctx, kids); i++)
+ pdf_load_name_tree_imp(dict, xref, fz_array_get(ctx, kids, i));
}
if (names)
{
- for (i = 0; i + 1 < fz_array_len(names); i += 2)
+ for (i = 0; i + 1 < fz_array_len(ctx, names); i += 2)
{
- fz_obj *key = fz_array_get(names, i);
- fz_obj *val = fz_array_get(names, i + 1);
- if (fz_is_string(key))
+ fz_obj *key = fz_array_get(ctx, names, i);
+ fz_obj *val = fz_array_get(ctx, names, i + 1);
+ if (fz_is_string(ctx, key))
{
- key = pdf_to_utf8_name(key);
- fz_dict_put(dict, key, val);
- fz_drop_obj(key);
+ key = pdf_to_utf8_name(ctx, key);
+ fz_dict_put(ctx, dict, key, val);
+ fz_drop_obj(ctx, key);
}
- else if (fz_is_name(key))
+ else if (fz_is_name(ctx, key))
{
- fz_dict_put(dict, key, val);
+ fz_dict_put(ctx, dict, key, val);
}
}
}
@@ -126,12 +131,14 @@ pdf_load_name_tree_imp(fz_obj *dict, pdf_xref *xref, fz_obj *node)
fz_obj *
pdf_load_name_tree(pdf_xref *xref, char *which)
{
- fz_obj *root = fz_dict_gets(xref->trailer, "Root");
- fz_obj *names = fz_dict_gets(root, "Names");
- fz_obj *tree = fz_dict_gets(names, which);
- if (fz_is_dict(tree))
+ fz_context *ctx = xref->ctx;
+
+ fz_obj *root = fz_dict_gets(ctx, xref->trailer, "Root");
+ fz_obj *names = fz_dict_gets(ctx, root, "Names");
+ fz_obj *tree = fz_dict_gets(ctx, names, which);
+ if (fz_is_dict(ctx, tree))
{
- fz_obj *dict = fz_new_dict(100);
+ fz_obj *dict = fz_new_dict(ctx, 100);
pdf_load_name_tree_imp(dict, xref, tree);
return dict;
}