summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-09-21 00:11:22 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-09-21 00:11:22 +0200
commit69ed4a8f4dbfac7f2f1de925e34807e4fee3b27c (patch)
treeb7f82296a259d360ce90f0826e475321d630a222
parent99ba154018b7c4a2c47b4c7e721ffe6d9164f9f3 (diff)
downloadmupdf-69ed4a8f4dbfac7f2f1de925e34807e4fee3b27c.tar.xz
Don't thread ctx through safe fz_obj functions.
-rw-r--r--apps/pdfapp.c10
-rw-r--r--apps/pdfclean.c166
-rw-r--r--apps/pdfextract.c28
-rw-r--r--apps/pdfinfo.c188
-rw-r--r--apps/pdfshow.c16
-rw-r--r--fitz/base_context.c61
-rw-r--r--fitz/base_object.c620
-rw-r--r--fitz/dev_bbox.c2
-rw-r--r--fitz/dev_null.c3
-rw-r--r--fitz/filt_dctd.c10
-rw-r--r--fitz/filt_faxd.c28
-rw-r--r--fitz/filt_lzwd.c4
-rw-r--r--fitz/filt_predict.c16
-rw-r--r--fitz/fitz.h83
-rw-r--r--fitz/obj_print.c342
-rw-r--r--fitz/res_font.c2
-rw-r--r--pdf/pdf_annot.c61
-rw-r--r--pdf/pdf_cmap_load.c14
-rw-r--r--pdf/pdf_colorspace.c88
-rw-r--r--pdf/pdf_crypt.c153
-rw-r--r--pdf/pdf_font.c177
-rw-r--r--pdf/pdf_function.c109
-rw-r--r--pdf/pdf_image.c42
-rw-r--r--pdf/pdf_interpret.c157
-rw-r--r--pdf/pdf_nametree.c76
-rw-r--r--pdf/pdf_outline.c25
-rw-r--r--pdf/pdf_page.c118
-rw-r--r--pdf/pdf_parse.c132
-rw-r--r--pdf/pdf_pattern.c14
-rw-r--r--pdf/pdf_repair.c87
-rw-r--r--pdf/pdf_shade.c133
-rw-r--r--pdf/pdf_store.c10
-rw-r--r--pdf/pdf_stream.c75
-rw-r--r--pdf/pdf_type3.c56
-rw-r--r--pdf/pdf_xobject.c20
-rw-r--r--pdf/pdf_xref.c109
-rw-r--r--scripts/cmapdump.c2
-rw-r--r--win32/libmupdf.vcproj4
-rw-r--r--xps/xps_tiff.c24
39 files changed, 1646 insertions, 1619 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 0e328a0a..36985010 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -145,10 +145,10 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd)
app->doctitle = strrchr(app->doctitle, '\\') + 1;
if (strrchr(app->doctitle, '/'))
app->doctitle = strrchr(app->doctitle, '/') + 1;
- info = fz_dict_gets(app->ctx, app->xref->trailer, "Info");
+ info = fz_dict_gets(app->xref->trailer, "Info");
if (info)
{
- obj = fz_dict_gets(app->ctx, info, "Title");
+ obj = fz_dict_gets(info, "Title");
if (obj)
app->doctitle = pdf_to_utf8(app->ctx, obj);
}
@@ -432,9 +432,9 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai
static void pdfapp_gotouri(pdfapp_t *app, fz_obj *uri)
{
char *buf;
- int n = fz_to_str_len(app->ctx, uri);
+ int n = fz_to_str_len(uri);
buf = fz_malloc(app->ctx, n + 1);
- memcpy(buf, fz_to_str_buf(app->ctx, uri), n);
+ memcpy(buf, fz_to_str_buf(uri), n);
buf[n] = 0;
winopenuri(app, buf);
fz_free(app->ctx, buf);
@@ -1001,7 +1001,7 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta
if (link->kind == PDF_LINK_URI)
pdfapp_gotouri(app, link->dest);
else if (link->kind == PDF_LINK_GOTO)
- pdfapp_gotopage(app, fz_array_get(app->ctx, link->dest, 0)); /* [ pageobj ... ] */
+ pdfapp_gotopage(app, fz_array_get(link->dest, 0)); /* [ pageobj ... ] */
return;
}
}
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index 2a8c54f2..302970bc 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -61,18 +61,18 @@ static void sweepobj(fz_obj *obj)
if (fz_is_indirect(obj))
sweepref(obj);
- else if (fz_is_dict(ctx, obj))
+ else if (fz_is_dict(obj))
{
- int n = fz_dict_len(ctx, obj);
+ int n = fz_dict_len(obj);
for (i = 0; i < n; i++)
- sweepobj(fz_dict_get_val(ctx, obj, i));
+ sweepobj(fz_dict_get_val(obj, i));
}
- else if (fz_is_array(ctx, obj))
+ else if (fz_is_array(obj))
{
- int n = fz_array_len(ctx, obj);
+ int n = fz_array_len(obj);
for (i = 0; i < n; i++)
- sweepobj(fz_array_get(ctx, obj, i));
+ sweepobj(fz_array_get(obj, i));
}
}
@@ -91,16 +91,16 @@ static void sweepref(fz_obj *obj)
/* Bake in /Length in stream objects */
if (pdf_is_stream(xref, num, gen))
{
- fz_obj *len = fz_dict_gets(ctx, obj, "Length");
+ fz_obj *len = fz_dict_gets(obj, "Length");
if (fz_is_indirect(len))
{
uselist[fz_to_num(len)] = 0;
- len = fz_resolve_indirect(xref->ctx, len);
- fz_dict_puts(ctx, obj, "Length", len);
+ len = fz_resolve_indirect(len);
+ fz_dict_puts(obj, "Length", len);
}
}
- sweepobj(fz_resolve_indirect(xref->ctx, obj));
+ sweepobj(fz_resolve_indirect(obj));
}
/*
@@ -133,8 +133,8 @@ static void removeduplicateobjs(void)
a = xref->table[num].obj;
b = xref->table[other].obj;
- a = fz_resolve_indirect(xref->ctx, a);
- b = fz_resolve_indirect(xref->ctx, b);
+ a = fz_resolve_indirect(a);
+ b = fz_resolve_indirect(b);
if (fz_objcmp(a, b))
continue;
@@ -185,18 +185,18 @@ static void renumberobj(fz_obj *obj)
int i;
fz_context *ctx = xref->ctx;
- if (fz_is_dict(ctx, obj))
+ if (fz_is_dict(obj))
{
- int n = fz_dict_len(ctx, obj);
+ int n = fz_dict_len(obj);
for (i = 0; i < n; i++)
{
- fz_obj *key = fz_dict_get_key(ctx, obj, i);
- fz_obj *val = fz_dict_get_val(ctx, obj, i);
+ fz_obj *key = fz_dict_get_key(obj, i);
+ fz_obj *val = fz_dict_get_val(obj, i);
if (fz_is_indirect(val))
{
val = fz_new_indirect(ctx, renumbermap[fz_to_num(val)], 0, xref);
- fz_dict_put(ctx, obj, key, val);
- fz_drop_obj(ctx, val);
+ fz_dict_put(obj, key, val);
+ fz_drop_obj(val);
}
else
{
@@ -205,17 +205,17 @@ static void renumberobj(fz_obj *obj)
}
}
- else if (fz_is_array(ctx, obj))
+ else if (fz_is_array(obj))
{
- int n = fz_array_len(ctx, obj);
+ int n = fz_array_len(obj);
for (i = 0; i < n; i++)
{
- fz_obj *val = fz_array_get(ctx, obj, i);
+ fz_obj *val = fz_array_get(obj, i);
if (fz_is_indirect(val))
{
val = fz_new_indirect(ctx, renumbermap[fz_to_num(val)], 0, xref);
- fz_array_put(ctx, obj, i, val);
- fz_drop_obj(ctx, val);
+ fz_array_put(obj, i, val);
+ fz_drop_obj(val);
}
else
{
@@ -241,7 +241,7 @@ static void renumberobjs(void)
{
obj = fz_new_indirect(ctx, renumbermap[fz_to_num(obj)], 0, xref);
pdf_update_object(xref, num, 0, obj);
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
else
{
@@ -267,7 +267,7 @@ static void renumberobjs(void)
else
{
if (oldxref[num].obj)
- fz_drop_obj(ctx, oldxref[num].obj);
+ fz_drop_obj(oldxref[num].obj);
}
}
@@ -296,16 +296,16 @@ static void retainpages(int argc, char **argv)
die(fz_error_note(error, "cannot load page tree"));
/* Keep only pages/type entry to avoid references to unretained pages */
- oldroot = fz_dict_gets(ctx, xref->trailer, "Root");
- pages = fz_dict_gets(ctx, oldroot, "Pages");
+ oldroot = fz_dict_gets(xref->trailer, "Root");
+ pages = fz_dict_gets(oldroot, "Pages");
root = fz_new_dict(ctx, 2);
- fz_dict_puts(ctx, root, "Type", fz_dict_gets(ctx, oldroot, "Type"));
- fz_dict_puts(ctx, root, "Pages", fz_dict_gets(ctx, oldroot, "Pages"));
+ fz_dict_puts(root, "Type", fz_dict_gets(oldroot, "Type"));
+ fz_dict_puts(root, "Pages", fz_dict_gets(oldroot, "Pages"));
pdf_update_object(xref, fz_to_num(oldroot), fz_to_gen(oldroot), root);
- fz_drop_obj(ctx, root);
+ fz_drop_obj(root);
/* Create a new kids array with only the pages we want to keep */
parent = fz_new_indirect(ctx, fz_to_num(pages), fz_to_gen(pages), xref);
@@ -349,10 +349,10 @@ static void retainpages(int argc, char **argv)
fz_obj *pageobj = xref->page_objs[page-1];
fz_obj *pageref = xref->page_refs[page-1];
- fz_dict_puts(ctx, pageobj, "Parent", parent);
+ fz_dict_puts(pageobj, "Parent", parent);
/* Store page object in new kids array */
- fz_array_push(ctx, kids, pageref);
+ fz_array_push(kids, pageref);
}
spec = fz_strsep(&pagelist, ",");
@@ -361,14 +361,14 @@ static void retainpages(int argc, char **argv)
fz_optind++;
}
- fz_drop_obj(ctx, parent);
+ fz_drop_obj(parent);
/* Update page count and kids array */
- countobj = fz_new_int(ctx, fz_array_len(ctx, kids));
- fz_dict_puts(ctx, pages, "Count", countobj);
- fz_drop_obj(ctx, countobj);
- fz_dict_puts(ctx, pages, "Kids", kids);
- fz_drop_obj(ctx, kids);
+ countobj = fz_new_int(ctx, fz_array_len(kids));
+ fz_dict_puts(pages, "Count", countobj);
+ fz_drop_obj(countobj);
+ fz_dict_puts(pages, "Kids", kids);
+ fz_drop_obj(kids);
}
/*
@@ -388,7 +388,7 @@ static void preloadobjstms(void)
error = pdf_load_object(&obj, xref, num, 0);
if (error)
die(error);
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
}
}
@@ -448,42 +448,42 @@ static void addhexfilter(fz_obj *dict)
nullobj = fz_new_null(ctx);
newf = newdp = NULL;
- f = fz_dict_gets(ctx, dict, "Filter");
- dp = fz_dict_gets(ctx, dict, "DecodeParms");
+ f = fz_dict_gets(dict, "Filter");
+ dp = fz_dict_gets(dict, "DecodeParms");
- if (fz_is_name(ctx, f))
+ if (fz_is_name(f))
{
newf = fz_new_array(ctx, 2);
- fz_array_push(ctx, newf, ahx);
- fz_array_push(ctx, newf, f);
+ fz_array_push(newf, ahx);
+ fz_array_push(newf, f);
f = newf;
- if (fz_is_dict(ctx, dp))
+ if (fz_is_dict(dp))
{
newdp = fz_new_array(ctx, 2);
- fz_array_push(ctx, newdp, nullobj);
- fz_array_push(ctx, newdp, dp);
+ fz_array_push(newdp, nullobj);
+ fz_array_push(newdp, dp);
dp = newdp;
}
}
- else if (fz_is_array(ctx, f))
+ else if (fz_is_array(f))
{
- fz_array_insert(ctx, f, ahx);
- if (fz_is_array(ctx, dp))
- fz_array_insert(ctx, dp, nullobj);
+ fz_array_insert(f, ahx);
+ if (fz_is_array(dp))
+ fz_array_insert(dp, nullobj);
}
else
f = ahx;
- fz_dict_puts(ctx, dict, "Filter", f);
+ fz_dict_puts(dict, "Filter", f);
if (dp)
- fz_dict_puts(ctx, dict, "DecodeParms", dp);
+ fz_dict_puts(dict, "DecodeParms", dp);
- fz_drop_obj(ctx, ahx);
- fz_drop_obj(ctx, nullobj);
+ fz_drop_obj(ahx);
+ fz_drop_obj(nullobj);
if (newf)
- fz_drop_obj(ctx, newf);
+ fz_drop_obj(newf);
if (newdp)
- fz_drop_obj(ctx, newdp);
+ fz_drop_obj(newdp);
}
static void copystream(fz_obj *obj, int num, int gen)
@@ -505,12 +505,12 @@ static void copystream(fz_obj *obj, int num, int gen)
addhexfilter(obj);
newlen = fz_new_int(ctx, buf->len);
- fz_dict_puts(ctx, obj, "Length", newlen);
- fz_drop_obj(ctx, newlen);
+ fz_dict_puts(obj, "Length", newlen);
+ fz_drop_obj(newlen);
}
fprintf(out, "%d %d obj\n", num, gen);
- fz_fprint_obj(ctx, out, obj, !doexpand);
+ fz_fprint_obj(out, obj, !doexpand);
fprintf(out, "stream\n");
fwrite(buf->data, 1, buf->len, out);
fprintf(out, "endstream\nendobj\n\n");
@@ -528,8 +528,8 @@ static void expandstream(fz_obj *obj, int num, int gen)
if (error)
die(error);
- fz_dict_dels(ctx, obj, "Filter");
- fz_dict_dels(ctx, obj, "DecodeParms");
+ fz_dict_dels(obj, "Filter");
+ fz_dict_dels(obj, "DecodeParms");
if (doascii && isbinarystream(buf))
{
@@ -541,11 +541,11 @@ static void expandstream(fz_obj *obj, int num, int gen)
}
newlen = fz_new_int(ctx, buf->len);
- fz_dict_puts(ctx, obj, "Length", newlen);
- fz_drop_obj(ctx, newlen);
+ fz_dict_puts(obj, "Length", newlen);
+ fz_drop_obj(newlen);
fprintf(out, "%d %d obj\n", num, gen);
- fz_fprint_obj(ctx, out, obj, !doexpand);
+ fz_fprint_obj(out, obj, !doexpand);
fprintf(out, "stream\n");
fwrite(buf->data, 1, buf->len, out);
fprintf(out, "endstream\nendobj\n\n");
@@ -564,19 +564,19 @@ static void writeobject(int num, int gen)
die(error);
/* skip ObjStm and XRef objects */
- if (fz_is_dict(ctx, obj))
+ if (fz_is_dict(obj))
{
- type = fz_dict_gets(ctx, obj, "Type");
- if (fz_is_name(ctx, type) && !strcmp(fz_to_name(ctx, type), "ObjStm"))
+ type = fz_dict_gets(obj, "Type");
+ if (fz_is_name(type) && !strcmp(fz_to_name(type), "ObjStm"))
{
uselist[num] = 0;
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
return;
}
- if (fz_is_name(ctx, type) && !strcmp(fz_to_name(ctx, type), "XRef"))
+ if (fz_is_name(type) && !strcmp(fz_to_name(type), "XRef"))
{
uselist[num] = 0;
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
return;
}
}
@@ -584,7 +584,7 @@ static void writeobject(int num, int gen)
if (!pdf_is_stream(xref, num, gen))
{
fprintf(out, "%d %d obj\n", num, gen);
- fz_fprint_obj(ctx, out, obj, !doexpand);
+ fz_fprint_obj(out, obj, !doexpand);
fprintf(out, "endobj\n\n");
}
else
@@ -595,7 +595,7 @@ static void writeobject(int num, int gen)
copystream(obj, num, gen);
}
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
static void writexref(void)
@@ -620,26 +620,26 @@ static void writexref(void)
trailer = fz_new_dict(ctx, 5);
obj = fz_new_int(ctx, xref->len);
- fz_dict_puts(ctx, trailer, "Size", obj);
- fz_drop_obj(ctx, obj);
+ fz_dict_puts(trailer, "Size", obj);
+ fz_drop_obj(obj);
- obj = fz_dict_gets(ctx, xref->trailer, "Info");
+ obj = fz_dict_gets(xref->trailer, "Info");
if (obj)
- fz_dict_puts(ctx, trailer, "Info", obj);
+ fz_dict_puts(trailer, "Info", obj);
- obj = fz_dict_gets(ctx, xref->trailer, "Root");
+ obj = fz_dict_gets(xref->trailer, "Root");
if (obj)
- fz_dict_puts(ctx, trailer, "Root", obj);
+ fz_dict_puts(trailer, "Root", obj);
- obj = fz_dict_gets(ctx, xref->trailer, "ID");
+ obj = fz_dict_gets(xref->trailer, "ID");
if (obj)
- fz_dict_puts(ctx, trailer, "ID", obj);
+ fz_dict_puts(trailer, "ID", obj);
fprintf(out, "trailer\n");
- fz_fprint_obj(ctx, out, trailer, !doexpand);
+ fz_fprint_obj(out, trailer, !doexpand);
fprintf(out, "\n");
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
fprintf(out, "startxref\n%d\n%%%%EOF\n", startxref);
}
diff --git a/apps/pdfextract.c b/apps/pdfextract.c
index 96ea7e87..490a8c1e 100644
--- a/apps/pdfextract.c
+++ b/apps/pdfextract.c
@@ -27,14 +27,14 @@ static void usage(void)
static int isimage(fz_obj *obj)
{
- fz_obj *type = fz_dict_gets(ctx, obj, "Subtype");
- return fz_is_name(ctx, type) && !strcmp(fz_to_name(ctx, type), "Image");
+ fz_obj *type = fz_dict_gets(obj, "Subtype");
+ return fz_is_name(type) && !strcmp(fz_to_name(type), "Image");
}
static int isfontdesc(fz_obj *obj)
{
- fz_obj *type = fz_dict_gets(ctx, obj, "Type");
- return fz_is_name(ctx, type) && !strcmp(fz_to_name(ctx, type), "FontDescriptor");
+ fz_obj *type = fz_dict_gets(obj, "Type");
+ return fz_is_name(type) && !strcmp(fz_to_name(type), "FontDescriptor");
}
static void saveimage(int num)
@@ -75,7 +75,7 @@ static void saveimage(int num)
}
fz_drop_pixmap(ctx, img);
- fz_drop_obj(ctx, ref);
+ fz_drop_obj(ref);
}
static void savefont(fz_obj *dict, int num)
@@ -91,34 +91,34 @@ static void savefont(fz_obj *dict, int num)
char *fontname = "font";
int n;
- obj = fz_dict_gets(ctx, dict, "FontName");
+ obj = fz_dict_gets(dict, "FontName");
if (obj)
- fontname = fz_to_name(ctx, obj);
+ fontname = fz_to_name(obj);
- obj = fz_dict_gets(ctx, dict, "FontFile");
+ obj = fz_dict_gets(dict, "FontFile");
if (obj)
{
stream = obj;
ext = "pfa";
}
- obj = fz_dict_gets(ctx, dict, "FontFile2");
+ obj = fz_dict_gets(dict, "FontFile2");
if (obj)
{
stream = obj;
ext = "ttf";
}
- obj = fz_dict_gets(ctx, dict, "FontFile3");
+ obj = fz_dict_gets(dict, "FontFile3");
if (obj)
{
stream = obj;
- obj = fz_dict_gets(ctx, obj, "Subtype");
- if (obj && !fz_is_name(ctx, obj))
+ obj = fz_dict_gets(obj, "Subtype");
+ if (obj && !fz_is_name(obj))
die(fz_error_make("Invalid font descriptor subtype"));
- subtype = fz_to_name(ctx, obj);
+ subtype = fz_to_name(obj);
if (!strcmp(subtype, "Type1C"))
ext = "cff";
else if (!strcmp(subtype, "CIDFontType0C"))
@@ -173,7 +173,7 @@ static void showobject(int num)
else if (isfontdesc(obj))
savefont(obj, num);
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
int main(int argc, char **argv)
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index 2006b0be..cf81105c 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -185,18 +185,18 @@ showglobalinfo(void)
printf("\nPDF-%d.%d\n", xref->version / 10, xref->version % 10);
- obj = fz_dict_gets(ctx, xref->trailer, "Info");
+ obj = fz_dict_gets(xref->trailer, "Info");
if (obj)
{
printf("Info object (%d %d R):\n", fz_to_num(obj), fz_to_gen(obj));
- fz_debug_obj(ctx, fz_resolve_indirect(xref->ctx, obj));
+ fz_debug_obj(fz_resolve_indirect(obj));
}
- obj = fz_dict_gets(ctx, xref->trailer, "Encrypt");
+ obj = fz_dict_gets(xref->trailer, "Encrypt");
if (obj)
{
printf("\nEncryption object (%d %d R):\n", fz_to_num(obj), fz_to_gen(obj));
- fz_debug_obj(ctx, fz_resolve_indirect(xref->ctx, obj));
+ fz_debug_obj(fz_resolve_indirect(obj));
}
printf("\nPages: %d\n\n", pagecount);
@@ -209,8 +209,8 @@ gatherdimensions(int page, fz_obj *pageref, fz_obj *pageobj)
fz_obj *obj;
int j;
- obj = fz_dict_gets(ctx, pageobj, "MediaBox");
- if (!fz_is_array(ctx, obj))
+ obj = fz_dict_gets(pageobj, "MediaBox");
+ if (!fz_is_array(obj))
return;
bbox = pdf_to_rect(ctx, obj);
@@ -239,7 +239,7 @@ gatherfonts(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
int i, n;
- n = fz_dict_len(ctx, dict);
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
{
fz_obj *fontdict = NULL;
@@ -248,17 +248,17 @@ gatherfonts(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_obj *name = NULL;
int k;
- fontdict = fz_dict_get_val(ctx, dict, i);
- if (!fz_is_dict(ctx, fontdict))
+ fontdict = fz_dict_get_val(dict, i);
+ if (!fz_is_dict(fontdict))
{
fz_warn("not a font dict (%d %d R)", fz_to_num(fontdict), fz_to_gen(fontdict));
continue;
}
- subtype = fz_dict_gets(ctx, fontdict, "Subtype");
- basefont = fz_dict_gets(ctx, fontdict, "BaseFont");
- if (!basefont || fz_is_null(ctx, basefont))
- name = fz_dict_gets(ctx, fontdict, "Name");
+ subtype = fz_dict_gets(fontdict, "Subtype");
+ basefont = fz_dict_gets(fontdict, "BaseFont");
+ if (!basefont || fz_is_null(basefont))
+ name = fz_dict_gets(fontdict, "Name");
for (k = 0; k < fonts; k++)
if (!fz_objcmp(font[k].u.font.obj, fontdict))
@@ -284,7 +284,7 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
int i, n;
- n = fz_dict_len(ctx, dict);
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
{
fz_obj *imagedict;
@@ -297,37 +297,37 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_obj *altcs;
int k;
- imagedict = fz_dict_get_val(ctx, dict, i);
- if (!fz_is_dict(ctx, imagedict))
+ imagedict = fz_dict_get_val(dict, i);
+ if (!fz_is_dict(imagedict))
{
fz_warn("not an image dict (%d %d R)", fz_to_num(imagedict), fz_to_gen(imagedict));
continue;
}
- type = fz_dict_gets(ctx, imagedict, "Subtype");
- if (strcmp(fz_to_name(ctx, type), "Image"))
+ type = fz_dict_gets(imagedict, "Subtype");
+ if (strcmp(fz_to_name(type), "Image"))
continue;
- filter = fz_dict_gets(ctx, imagedict, "Filter");
+ filter = fz_dict_gets(imagedict, "Filter");
altcs = NULL;
- cs = fz_dict_gets(ctx, imagedict, "ColorSpace");
- if (fz_is_array(ctx, cs))
+ cs = fz_dict_gets(imagedict, "ColorSpace");
+ if (fz_is_array(cs))
{
fz_obj *cses = cs;
- cs = fz_array_get(ctx, cses, 0);
- if (fz_is_name(ctx, cs) && (!strcmp(fz_to_name(ctx, cs), "DeviceN") || !strcmp(fz_to_name(ctx, cs), "Separation")))
+ cs = fz_array_get(cses, 0);
+ if (fz_is_name(cs) && (!strcmp(fz_to_name(cs), "DeviceN") || !strcmp(fz_to_name(cs), "Separation")))
{
- altcs = fz_array_get(ctx, cses, 2);
- if (fz_is_array(ctx, altcs))
- altcs = fz_array_get(ctx, altcs, 0);
+ altcs = fz_array_get(cses, 2);
+ if (fz_is_array(altcs))
+ altcs = fz_array_get(altcs, 0);
}
}
- width = fz_dict_gets(ctx, imagedict, "Width");
- height = fz_dict_gets(ctx, imagedict, "Height");
- bpc = fz_dict_gets(ctx, imagedict, "BitsPerComponent");
+ width = fz_dict_gets(imagedict, "Width");
+ height = fz_dict_gets(imagedict, "Height");
+ bpc = fz_dict_gets(imagedict, "BitsPerComponent");
for (k = 0; k < images; k++)
if (!fz_objcmp(image[k].u.image.obj, imagedict))
@@ -357,7 +357,7 @@ gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
int i, n;
- n = fz_dict_len(ctx, dict);
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
{
fz_obj *xobjdict;
@@ -368,24 +368,24 @@ gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_obj *reference;
int k;
- xobjdict = fz_dict_get_val(ctx, dict, i);
- if (!fz_is_dict(ctx, xobjdict))
+ xobjdict = fz_dict_get_val(dict, i);
+ if (!fz_is_dict(xobjdict))
{
fz_warn("not a xobject dict (%d %d R)", fz_to_num(xobjdict), fz_to_gen(xobjdict));
continue;
}
- type = fz_dict_gets(ctx, xobjdict, "Subtype");
- if (strcmp(fz_to_name(ctx, type), "Form"))
+ type = fz_dict_gets(xobjdict, "Subtype");
+ if (strcmp(fz_to_name(type), "Form"))
continue;
- subtype = fz_dict_gets(ctx, xobjdict, "Subtype2");
- if (!strcmp(fz_to_name(ctx, subtype), "PS"))
+ subtype = fz_dict_gets(xobjdict, "Subtype2");
+ if (!strcmp(fz_to_name(subtype), "PS"))
continue;
- group = fz_dict_gets(ctx, xobjdict, "Group");
- groupsubtype = fz_dict_gets(ctx, group, "S");
- reference = fz_dict_gets(ctx, xobjdict, "Ref");
+ group = fz_dict_gets(xobjdict, "Group");
+ groupsubtype = fz_dict_gets(group, "S");
+ reference = fz_dict_gets(xobjdict, "Ref");
for (k = 0; k < forms; k++)
if (!fz_objcmp(form[k].u.form.obj, xobjdict))
@@ -411,7 +411,7 @@ gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
int i, n;
- n = fz_dict_len(ctx, dict);
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
{
fz_obj *xobjdict;
@@ -419,17 +419,17 @@ gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_obj *subtype;
int k;
- xobjdict = fz_dict_get_val(ctx, dict, i);
- if (!fz_is_dict(ctx, xobjdict))
+ xobjdict = fz_dict_get_val(dict, i);
+ if (!fz_is_dict(xobjdict))
{
fz_warn("not a xobject dict (%d %d R)", fz_to_num(xobjdict), fz_to_gen(xobjdict));
continue;
}
- type = fz_dict_gets(ctx, xobjdict, "Subtype");
- subtype = fz_dict_gets(ctx, xobjdict, "Subtype2");
- if (strcmp(fz_to_name(ctx, type), "PS") &&
- (strcmp(fz_to_name(ctx, type), "Form") || strcmp(fz_to_name(ctx, subtype), "PS")))
+ type = fz_dict_gets(xobjdict, "Subtype");
+ subtype = fz_dict_gets(xobjdict, "Subtype2");
+ if (strcmp(fz_to_name(type), "PS") &&
+ (strcmp(fz_to_name(type), "Form") || strcmp(fz_to_name(subtype), "PS")))
continue;
for (k = 0; k < psobjs; k++)
@@ -454,22 +454,22 @@ gathershadings(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
int i, n;
- n = fz_dict_len(ctx, dict);
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
{
fz_obj *shade;
fz_obj *type;
int k;
- shade = fz_dict_get_val(ctx, dict, i);
- if (!fz_is_dict(ctx, shade))
+ shade = fz_dict_get_val(dict, i);
+ if (!fz_is_dict(shade))
{
fz_warn("not a shading dict (%d %d R)", fz_to_num(shade), fz_to_gen(shade));
continue;
}
- type = fz_dict_gets(ctx, shade, "ShadingType");
- if (!fz_is_int(ctx, type) || fz_to_int(ctx, type) < 1 || fz_to_int(ctx, type) > 7)
+ type = fz_dict_gets(shade, "ShadingType");
+ if (!fz_is_int(type) || fz_to_int(type) < 1 || fz_to_int(type) > 7)
{
fz_warn("not a shading type (%d %d R)", fz_to_num(shade), fz_to_gen(shade));
type = NULL;
@@ -498,7 +498,7 @@ gatherpatterns(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
int i, n;
- n = fz_dict_len(ctx, dict);
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
{
fz_obj *patterndict;
@@ -508,31 +508,31 @@ gatherpatterns(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_obj *shading = NULL;
int k;
- patterndict = fz_dict_get_val(ctx, dict, i);
- if (!fz_is_dict(ctx, patterndict))
+ patterndict = fz_dict_get_val(dict, i);
+ if (!fz_is_dict(patterndict))
{
fz_warn("not a pattern dict (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict));
continue;
}
- type = fz_dict_gets(ctx, patterndict, "PatternType");
- if (!fz_is_int(ctx, type) || fz_to_int(ctx, type) < 1 || fz_to_int(ctx, type) > 2)
+ type = fz_dict_gets(patterndict, "PatternType");
+ if (!fz_is_int(type) || fz_to_int(type) < 1 || fz_to_int(type) > 2)
{
fz_warn("not a pattern type (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict));
type = NULL;
}
- if (fz_to_int(ctx, type) == 1)
+ if (fz_to_int(type) == 1)
{
- paint = fz_dict_gets(ctx, patterndict, "PaintType");
- if (!fz_is_int(ctx, paint) || fz_to_int(ctx, paint) < 1 || fz_to_int(ctx, paint) > 2)
+ paint = fz_dict_gets(patterndict, "PaintType");
+ if (!fz_is_int(paint) || fz_to_int(paint) < 1 || fz_to_int(paint) > 2)
{
fz_warn("not a pattern paint type (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict));
paint = NULL;
}
- tiling = fz_dict_gets(ctx, patterndict, "TilingType");
- if (!fz_is_int(ctx, tiling) || fz_to_int(ctx, tiling) < 1 || fz_to_int(ctx, tiling) > 3)
+ tiling = fz_dict_gets(patterndict, "TilingType");
+ if (!fz_is_int(tiling) || fz_to_int(tiling) < 1 || fz_to_int(tiling) > 3)
{
fz_warn("not a pattern tiling type (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict));
tiling = NULL;
@@ -540,7 +540,7 @@ gatherpatterns(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
}
else
{
- shading = fz_dict_gets(ctx, patterndict, "Shading");
+ shading = fz_dict_gets(patterndict, "Shading");
}
for (k = 0; k < patterns; k++)
@@ -582,24 +582,24 @@ gatherresourceinfo(int page, fz_obj *rsrc)
if (!pageobj)
die(fz_error_make("cannot retrieve info from page %d", page));
- font = fz_dict_gets(ctx, rsrc, "Font");
+ font = fz_dict_gets(rsrc, "Font");
if (font)
{
int n;
gatherfonts(page, pageref, pageobj, font);
- n = fz_dict_len(ctx, font);
+ n = fz_dict_len(font);
for (i = 0; i < n; i++)
{
- fz_obj *obj = fz_dict_get_val(ctx, font, i);
+ fz_obj *obj = fz_dict_get_val(font, i);
- subrsrc = fz_dict_gets(ctx, obj, "Resources");
+ subrsrc = fz_dict_gets(obj, "Resources");
if (subrsrc && fz_objcmp(rsrc, subrsrc))
gatherresourceinfo(page, subrsrc);
}
}
- xobj = fz_dict_gets(ctx, rsrc, "XObject");
+ xobj = fz_dict_gets(rsrc, "XObject");
if (xobj)
{
int n;
@@ -607,30 +607,30 @@ gatherresourceinfo(int page, fz_obj *rsrc)
gatherimages(page, pageref, pageobj, xobj);
gatherforms(page, pageref, pageobj, xobj);
gatherpsobjs(page, pageref, pageobj, xobj);
- n = fz_dict_len(ctx, xobj);
+ n = fz_dict_len(xobj);
for (i = 0; i < n; i++)
{
- fz_obj *obj = fz_dict_get_val(ctx, xobj, i);
- subrsrc = fz_dict_gets(ctx, obj, "Resources");
+ fz_obj *obj = fz_dict_get_val(xobj, i);
+ subrsrc = fz_dict_gets(obj, "Resources");
if (subrsrc && fz_objcmp(rsrc, subrsrc))
gatherresourceinfo(page, subrsrc);
}
}
- shade = fz_dict_gets(ctx, rsrc, "Shading");
+ shade = fz_dict_gets(rsrc, "Shading");
if (shade)
gathershadings(page, pageref, pageobj, shade);
- pattern = fz_dict_gets(ctx, rsrc, "Pattern");
+ pattern = fz_dict_gets(rsrc, "Pattern");
if (pattern)
{
int n;
gatherpatterns(page, pageref, pageobj, pattern);
- n = fz_dict_len(ctx, pattern);
+ n = fz_dict_len(pattern);
for (i = 0; i < n; i++)
{
- fz_obj *obj = fz_dict_get_val(ctx, pattern, i);
- subrsrc = fz_dict_gets(ctx, obj, "Resources");
+ fz_obj *obj = fz_dict_get_val(pattern, i);
+ subrsrc = fz_dict_gets(obj, "Resources");
if (subrsrc && fz_objcmp(rsrc, subrsrc))
gatherresourceinfo(page, subrsrc);
}
@@ -652,7 +652,7 @@ gatherpageinfo(int page)
gatherdimensions(page, pageref, pageobj);
- rsrc = fz_dict_gets(ctx, pageobj, "Resources");
+ rsrc = fz_dict_gets(pageobj, "Resources");
gatherresourceinfo(page, rsrc);
}
@@ -688,8 +688,8 @@ printinfo(char *filename, int show, int page)
printf(PAGE_FMT "%s '%s' (%d %d R)\n",
font[i].page,
fz_to_num(font[i].pageref), fz_to_gen(font[i].pageref),
- fz_to_name(ctx, font[i].u.font.subtype),
- fz_to_name(ctx, font[i].u.font.name),
+ fz_to_name(font[i].u.font.subtype),
+ fz_to_name(font[i].u.font.name),
fz_to_num(font[i].u.font.obj), fz_to_gen(font[i].u.font.obj));
}
printf("\n");
@@ -707,27 +707,27 @@ printinfo(char *filename, int show, int page)
image[i].page,
fz_to_num(image[i].pageref), fz_to_gen(image[i].pageref));
- if (fz_is_array(ctx, image[i].u.image.filter))
+ if (fz_is_array(image[i].u.image.filter))
{
- int n = fz_array_len(ctx, image[i].u.image.filter);
+ int n = fz_array_len(image[i].u.image.filter);
for (j = 0; j < n; j++)
{
- fz_obj *obj = fz_array_get(ctx, image[i].u.image.filter, j);
- char *filter = fz_strdup(ctx, fz_to_name(ctx, obj));
+ fz_obj *obj = fz_array_get(image[i].u.image.filter, j);
+ char *filter = fz_strdup(ctx, fz_to_name(obj));
if (strstr(filter, "Decode"))
*(strstr(filter, "Decode")) = '\0';
printf("%s%s",
filter,
- j == fz_array_len(ctx, image[i].u.image.filter) - 1 ? "" : " ");
+ j == fz_array_len(image[i].u.image.filter) - 1 ? "" : " ");
fz_free(ctx, filter);
}
}
else if (image[i].u.image.filter)
{
fz_obj *obj = image[i].u.image.filter;
- char *filter = fz_strdup(ctx, fz_to_name(ctx, obj));
+ char *filter = fz_strdup(ctx, fz_to_name(obj));
if (strstr(filter, "Decode"))
*(strstr(filter, "Decode")) = '\0';
@@ -740,7 +740,7 @@ printinfo(char *filename, int show, int page)
if (image[i].u.image.cs)
{
- cs = fz_strdup(ctx, fz_to_name(ctx, image[i].u.image.cs));
+ cs = fz_strdup(ctx, fz_to_name(image[i].u.image.cs));
if (!strncmp(cs, "Device", 6))
{
@@ -759,7 +759,7 @@ printinfo(char *filename, int show, int page)
}
if (image[i].u.image.altcs)
{
- altcs = fz_strdup(ctx, fz_to_name(ctx, image[i].u.image.altcs));
+ altcs = fz_strdup(ctx, fz_to_name(image[i].u.image.altcs));
if (!strncmp(altcs, "Device", 6))
{
@@ -778,9 +778,9 @@ printinfo(char *filename, int show, int page)
}
printf(" ] %dx%d %dbpc %s%s%s (%d %d R)\n",
- fz_to_int(ctx, image[i].u.image.width),
- fz_to_int(ctx, image[i].u.image.height),
- image[i].u.image.bpc ? fz_to_int(ctx, image[i].u.image.bpc) : 1,
+ fz_to_int(image[i].u.image.width),
+ fz_to_int(image[i].u.image.height),
+ image[i].u.image.bpc ? fz_to_int(image[i].u.image.bpc) : 1,
image[i].u.image.cs ? cs : "ImageMask",
image[i].u.image.altcs ? " " : "",
image[i].u.image.altcs ? altcs : "",
@@ -812,7 +812,7 @@ printinfo(char *filename, int show, int page)
printf(PAGE_FMT "%s (%d %d R)\n",
shading[i].page,
fz_to_num(shading[i].pageref), fz_to_gen(shading[i].pageref),
- shadingtype[fz_to_int(ctx, shading[i].u.shading.type)],
+ shadingtype[fz_to_int(shading[i].u.shading.type)],
fz_to_num(shading[i].u.shading.obj), fz_to_gen(shading[i].u.shading.obj));
}
printf("\n");
@@ -823,7 +823,7 @@ printinfo(char *filename, int show, int page)
printf("Patterns (%d):\n", patterns);
for (i = 0; i < patterns; i++)
{
- if (fz_to_int(ctx, pattern[i].u.pattern.type) == 1)
+ if (fz_to_int(pattern[i].u.pattern.type) == 1)
{
char *painttype[] =
{
@@ -842,8 +842,8 @@ printinfo(char *filename, int show, int page)
printf(PAGE_FMT "Tiling %s %s (%d %d R)\n",
pattern[i].page,
fz_to_num(pattern[i].pageref), fz_to_gen(pattern[i].pageref),
- painttype[fz_to_int(ctx, pattern[i].u.pattern.paint)],
- tilingtype[fz_to_int(ctx, pattern[i].u.pattern.tiling)],
+ painttype[fz_to_int(pattern[i].u.pattern.paint)],
+ tilingtype[fz_to_int(pattern[i].u.pattern.tiling)],
fz_to_num(pattern[i].u.pattern.obj), fz_to_gen(pattern[i].u.pattern.obj));
}
else
@@ -867,7 +867,7 @@ printinfo(char *filename, int show, int page)
form[i].page,
fz_to_num(form[i].pageref), fz_to_gen(form[i].pageref),
form[i].u.form.groupsubtype ? " " : "",
- form[i].u.form.groupsubtype ? fz_to_name(ctx, form[i].u.form.groupsubtype) : "",
+ form[i].u.form.groupsubtype ? fz_to_name(form[i].u.form.groupsubtype) : "",
form[i].u.form.groupsubtype ? " Group" : "",
form[i].u.form.reference ? " Reference" : "",
fz_to_num(form[i].u.form.obj), fz_to_gen(form[i].u.form.obj));
diff --git a/apps/pdfshow.c b/apps/pdfshow.c
index 653ffff6..0fd49010 100644
--- a/apps/pdfshow.c
+++ b/apps/pdfshow.c
@@ -33,7 +33,7 @@ static void showtrailer(void)
if (!xref)
die(fz_error_make("no file specified"));
printf("trailer\n");
- fz_debug_obj(ctx, xref->trailer);
+ fz_debug_obj(xref->trailer);
printf("\n");
}
@@ -147,7 +147,7 @@ static void showobject(int num, int gen)
else
{
printf("%d %d obj\n", num, gen);
- fz_debug_obj(ctx, obj);
+ fz_debug_obj(obj);
printf("stream\n");
showstream(num, gen);
printf("endstream\n");
@@ -157,11 +157,11 @@ static void showobject(int num, int gen)
else
{
printf("%d %d obj\n", num, gen);
- fz_debug_obj(ctx, obj);
+ fz_debug_obj(obj);
printf("endobj\n\n");
}
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
static void showgrep(char *filename)
@@ -178,17 +178,17 @@ static void showgrep(char *filename)
if (error)
die(error);
- fz_sort_dict(ctx, obj);
+ fz_sort_dict(obj);
printf("%s:%d: ", filename, i);
- fz_fprint_obj(ctx, stdout, obj, 1);
+ fz_fprint_obj(stdout, obj, 1);
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
}
printf("%s:trailer: ", filename);
- fz_fprint_obj(ctx, stdout, xref->trailer, 1);
+ fz_fprint_obj(stdout, xref->trailer, 1);
}
int main(int argc, char **argv)
diff --git a/fitz/base_context.c b/fitz/base_context.c
new file mode 100644
index 00000000..db702e8e
--- /dev/null
+++ b/fitz/base_context.c
@@ -0,0 +1,61 @@
+#include "fitz.h"
+
+static fz_obj *
+fz_resolve_indirect_null(fz_obj *ref)
+{
+ return ref;
+}
+
+fz_obj *(*fz_resolve_indirect)(fz_obj*) = fz_resolve_indirect_null;
+
+void
+fz_free_context(fz_context *ctx)
+{
+ assert(ctx != NULL);
+
+ /* Other finalisation calls go here (in reverse order) */
+
+ if (ctx->error)
+ {
+ assert(ctx->error->top == -1);
+ ctx->alloc->free(ctx->alloc->opaque, ctx->error);
+ }
+
+ /* Free the context itself */
+ ctx->alloc->free(ctx->alloc->opaque, ctx);
+
+ /* We do NOT free the allocator! */
+}
+
+fz_context *
+fz_new_context(fz_alloc_context *alloc)
+{
+ fz_context *ctx;
+
+ assert(alloc != NULL);
+ ctx = alloc->malloc(alloc->opaque, sizeof(fz_context));
+ if (ctx == NULL)
+ return NULL;
+ ctx->alloc = alloc;
+
+ ctx->error = alloc->malloc(alloc->opaque, sizeof(fz_error_context));
+ if (!ctx->error)
+ goto cleanup;
+ ctx->error->top = -1;
+ ctx->error->message[0] = 0;
+
+ /* New initialisation calls for context entries go here */
+
+ return ctx;
+
+cleanup:
+ fprintf(stderr, "cannot create context\n");
+ fz_free_context(ctx);
+ return NULL;
+}
+
+fz_context *
+fz_clone_context(fz_context *ctx)
+{
+ return fz_new_context(ctx->alloc);
+}
diff --git a/fitz/base_object.c b/fitz/base_object.c
index 5d10d860..c515b70d 100644
--- a/fitz/base_object.c
+++ b/fitz/base_object.c
@@ -1,9 +1,5 @@
#include "fitz.h"
-#if defined(_WIN32) || defined(_WIN64)
-#define MISSING_QSORT_R
-#endif
-
typedef enum fz_objkind_e
{
FZ_NULL,
@@ -27,6 +23,7 @@ struct fz_obj_s
{
int refs;
fz_objkind kind;
+ fz_context *ctx;
union
{
int b;
@@ -60,6 +57,7 @@ fz_obj *
fz_new_null(fz_context *ctx)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_NULL;
return obj;
@@ -69,6 +67,7 @@ fz_obj *
fz_new_bool(fz_context *ctx, int b)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_BOOL;
obj->u.b = b;
@@ -79,6 +78,7 @@ fz_obj *
fz_new_int(fz_context *ctx, int i)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_INT;
obj->u.i = i;
@@ -89,6 +89,7 @@ fz_obj *
fz_new_real(fz_context *ctx, float f)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_REAL;
obj->u.f = f;
@@ -99,6 +100,7 @@ fz_obj *
fz_new_string(fz_context *ctx, char *str, int len)
{
fz_obj *obj = fz_malloc(ctx, offsetof(fz_obj, u.s.buf) + len + 1);
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_STRING;
obj->u.s.len = len;
@@ -111,6 +113,7 @@ fz_obj *
fz_new_name(fz_context *ctx, char *str)
{
fz_obj *obj = fz_malloc(ctx, offsetof(fz_obj, u.n) + strlen(str) + 1);
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_NAME;
strcpy(obj->u.n, str);
@@ -121,6 +124,7 @@ fz_obj *
fz_new_indirect(fz_context *ctx, int num, int gen, void *xref)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_INDIRECT;
obj->u.r.num = num;
@@ -142,111 +146,111 @@ int fz_is_indirect(fz_obj *obj)
return obj ? obj->kind == FZ_INDIRECT : 0;
}
-int fz_is_null(fz_context *ctx, fz_obj *obj)
+int fz_is_null(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_NULL : 0;
}
-int fz_is_bool(fz_context *ctx, fz_obj *obj)
+int fz_is_bool(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_BOOL : 0;
}
-int fz_is_int(fz_context *ctx, fz_obj *obj)
+int fz_is_int(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_INT : 0;
}
-int fz_is_real(fz_context *ctx, fz_obj *obj)
+int fz_is_real(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_REAL : 0;
}
-int fz_is_string(fz_context *ctx, fz_obj *obj)
+int fz_is_string(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_STRING : 0;
}
-int fz_is_name(fz_context *ctx, fz_obj *obj)
+int fz_is_name(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_NAME : 0;
}
-int fz_is_array(fz_context *ctx, fz_obj *obj)
+int fz_is_array(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_ARRAY : 0;
}
-int fz_is_dict(fz_context *ctx, fz_obj *obj)
+int fz_is_dict(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
return obj ? obj->kind == FZ_DICT : 0;
}
-int fz_to_bool(fz_context *ctx, fz_obj *obj)
+int fz_to_bool(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_bool(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_bool(obj))
return obj->u.b;
return 0;
}
-int fz_to_int(fz_context *ctx, fz_obj *obj)
+int fz_to_int(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_int(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_int(obj))
return obj->u.i;
- if (fz_is_real(ctx, obj))
+ if (fz_is_real(obj))
return obj->u.f;
return 0;
}
-float fz_to_real(fz_context *ctx, fz_obj *obj)
+float fz_to_real(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_real(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_real(obj))
return obj->u.f;
- if (fz_is_int(ctx, obj))
+ if (fz_is_int(obj))
return obj->u.i;
return 0;
}
-char *fz_to_name(fz_context *ctx, fz_obj *obj)
+char *fz_to_name(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_name(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_name(obj))
return obj->u.n;
return "";
}
-char *fz_to_str_buf(fz_context *ctx, fz_obj *obj)
+char *fz_to_str_buf(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_string(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_string(obj))
return obj->u.s.buf;
return "";
}
-int fz_to_str_len(fz_context *ctx, fz_obj *obj)
+int fz_to_str_len(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_string(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_string(obj))
return obj->u.s.len;
return 0;
}
/* for use by pdf_crypt_obj_imp to decrypt AES string in place */
-void fz_set_str_len(fz_context *ctx, fz_obj *obj, int newlen)
+void fz_set_str_len(fz_obj *obj, int newlen)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (fz_is_string(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (fz_is_string(obj))
if (newlen < obj->u.s.len)
obj->u.s.len = newlen;
}
@@ -378,6 +382,7 @@ fz_new_array(fz_context *ctx, int initialcap)
int i;
obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_ARRAY;
@@ -398,32 +403,32 @@ fz_copy_array(fz_context *ctx, fz_obj *obj)
int i;
int n;
- if (fz_is_indirect(obj) || !fz_is_array(ctx, obj))
+ if (fz_is_indirect(obj) || !fz_is_array(obj))
fz_warn("assert: not an array (%s)", fz_objkindstr(obj));
- new = fz_new_array(ctx, fz_array_len(ctx, obj));
- n = fz_array_len(ctx, obj);
+ new = fz_new_array(ctx, fz_array_len(obj));
+ n = fz_array_len(obj);
for (i = 0; i < n; i++)
- fz_array_push(ctx, new, fz_array_get(ctx, obj, i));
+ fz_array_push(new, fz_array_get(obj, i));
return new;
}
int
-fz_array_len(fz_context *ctx, fz_obj *obj)
+fz_array_len(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (!fz_is_array(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (!fz_is_array(obj))
return 0;
return obj->u.a.len;
}
fz_obj *
-fz_array_get(fz_context *ctx, fz_obj *obj, int i)
+fz_array_get(fz_obj *obj, int i)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_array(ctx, obj))
+ if (!fz_is_array(obj))
return NULL;
if (i < 0 || i >= obj->u.a.len)
@@ -433,11 +438,11 @@ fz_array_get(fz_context *ctx, fz_obj *obj, int i)
}
void
-fz_array_put(fz_context *ctx, fz_obj *obj, int i, fz_obj *item)
+fz_array_put(fz_obj *obj, int i, fz_obj *item)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_array(ctx, obj))
+ if (!fz_is_array(obj))
fz_warn("assert: not an array (%s)", fz_objkindstr(obj));
else if (i < 0)
fz_warn("assert: index %d < 0", i);
@@ -446,17 +451,17 @@ fz_array_put(fz_context *ctx, fz_obj *obj, int i, fz_obj *item)
else
{
if (obj->u.a.items[i])
- fz_drop_obj(ctx, obj->u.a.items[i]);
+ fz_drop_obj(obj->u.a.items[i]);
obj->u.a.items[i] = fz_keep_obj(item);
}
}
void
-fz_array_push(fz_context *ctx, fz_obj *obj, fz_obj *item)
+fz_array_push(fz_obj *obj, fz_obj *item)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_array(ctx, obj))
+ if (!fz_is_array(obj))
fz_warn("assert: not an array (%s)", fz_objkindstr(obj));
else
{
@@ -464,7 +469,7 @@ fz_array_push(fz_context *ctx, fz_obj *obj, fz_obj *item)
{
int i;
obj->u.a.cap = (obj->u.a.cap * 3) / 2;
- obj->u.a.items = fz_realloc(ctx, obj->u.a.items, obj->u.a.cap * sizeof(fz_obj*));
+ obj->u.a.items = fz_realloc(obj->ctx, obj->u.a.items, obj->u.a.cap * sizeof(fz_obj*));
for (i = obj->u.a.len ; i < obj->u.a.cap; i++)
obj->u.a.items[i] = NULL;
}
@@ -474,11 +479,11 @@ fz_array_push(fz_context *ctx, fz_obj *obj, fz_obj *item)
}
void
-fz_array_insert(fz_context *ctx, fz_obj *obj, fz_obj *item)
+fz_array_insert(fz_obj *obj, fz_obj *item)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_array(ctx, obj))
+ if (!fz_is_array(obj))
fz_warn("assert: not an array (%s)", fz_objkindstr(obj));
else
{
@@ -486,7 +491,7 @@ fz_array_insert(fz_context *ctx, fz_obj *obj, fz_obj *item)
{
int i;
obj->u.a.cap = (obj->u.a.cap * 3) / 2;
- obj->u.a.items = fz_realloc(ctx, obj->u.a.items, obj->u.a.cap * sizeof(fz_obj*));
+ obj->u.a.items = fz_realloc(obj->ctx, obj->u.a.items, obj->u.a.cap * sizeof(fz_obj*));
for (i = obj->u.a.len ; i < obj->u.a.cap; i++)
obj->u.a.items[i] = NULL;
}
@@ -498,21 +503,12 @@ fz_array_insert(fz_context *ctx, fz_obj *obj, fz_obj *item)
/* dicts may only have names as keys! */
-static int keyvalcmp(void *ctxp, const void *ap, const void *bp)
+static int keyvalcmp(const void *ap, const void *bp)
{
- fz_context *ctx = (fz_context *)ctxp;
const struct keyval *a = ap;
const struct keyval *b = bp;
- return strcmp(fz_to_name(ctx, a->k), fz_to_name(ctx, b->k));
-}
-
-#ifdef MISSING_QSORT_R
-static void *qsort_r_hack;
-static int keyvalcmp_hack(const void *ap, const void *bp)
-{
- return keyvalcmp(qsort_r_hack, ap, bp);
+ return strcmp(fz_to_name(a->k), fz_to_name(b->k));
}
-#endif
fz_obj *
fz_new_dict(fz_context *ctx, int initialcap)
@@ -521,6 +517,7 @@ fz_new_dict(fz_context *ctx, int initialcap)
int i;
obj = fz_malloc(ctx, sizeof(fz_obj));
+ obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_DICT;
@@ -544,32 +541,32 @@ fz_copy_dict(fz_context *ctx, fz_obj *obj)
fz_obj *new;
int i, n;
- if (fz_is_indirect(obj) || !fz_is_dict(ctx, obj))
+ if (fz_is_indirect(obj) || !fz_is_dict(obj))
fz_error_make("assert: not a dict (%s)", fz_objkindstr(obj));
- n = fz_dict_len(ctx, obj);
+ n = fz_dict_len(obj);
new = fz_new_dict(ctx, n);
for (i = 0; i < n; i++)
- fz_dict_put(ctx, new, fz_dict_get_key(ctx, obj, i), fz_dict_get_val(ctx, obj, i));
+ fz_dict_put(new, fz_dict_get_key(obj, i), fz_dict_get_val(obj, i));
return new;
}
int
-fz_dict_len(fz_context *ctx, fz_obj *obj)
+fz_dict_len(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (!fz_is_dict(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (!fz_is_dict(obj))
return 0;
return obj->u.d.len;
}
fz_obj *
-fz_dict_get_key(fz_context *ctx, fz_obj *obj, int i)
+fz_dict_get_key(fz_obj *obj, int i)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_dict(ctx, obj))
+ if (!fz_is_dict(obj))
return NULL;
if (i < 0 || i >= obj->u.d.len)
@@ -579,11 +576,11 @@ fz_dict_get_key(fz_context *ctx, fz_obj *obj, int i)
}
fz_obj *
-fz_dict_get_val(fz_context *ctx, fz_obj *obj, int i)
+fz_dict_get_val(fz_obj *obj, int i)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_dict(ctx, obj))
+ if (!fz_is_dict(obj))
return NULL;
if (i < 0 || i >= obj->u.d.len)
@@ -593,7 +590,7 @@ fz_dict_get_val(fz_context *ctx, fz_obj *obj, int i)
}
static int
-fz_dict_finds(fz_context *ctx, fz_obj *obj, char *key)
+fz_dict_finds(fz_obj *obj, char *key)
{
if (obj->u.d.sorted)
{
@@ -602,7 +599,7 @@ fz_dict_finds(fz_context *ctx, fz_obj *obj, char *key)
while (l <= r)
{
int m = (l + r) >> 1;
- int c = -strcmp(fz_to_name(ctx, obj->u.d.items[m].k), key);
+ int c = -strcmp(fz_to_name(obj->u.d.items[m].k), key);
if (c < 0)
r = m - 1;
else if (c > 0)
@@ -616,7 +613,7 @@ fz_dict_finds(fz_context *ctx, fz_obj *obj, char *key)
{
int i;
for (i = 0; i < obj->u.d.len; i++)
- if (strcmp(fz_to_name(ctx, obj->u.d.items[i].k), key) == 0)
+ if (strcmp(fz_to_name(obj->u.d.items[i].k), key) == 0)
return i;
}
@@ -624,16 +621,16 @@ fz_dict_finds(fz_context *ctx, fz_obj *obj, char *key)
}
fz_obj *
-fz_dict_gets(fz_context *ctx, fz_obj *obj, char *key)
+fz_dict_gets(fz_obj *obj, char *key)
{
int i;
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_dict(ctx, obj))
+ if (!fz_is_dict(obj))
return NULL;
- i = fz_dict_finds(ctx, obj, key);
+ i = fz_dict_finds(obj, key);
if (i >= 0)
return obj->u.d.items[i].v;
@@ -641,39 +638,39 @@ fz_dict_gets(fz_context *ctx, fz_obj *obj, char *key)
}
fz_obj *
-fz_dict_get(fz_context *ctx, fz_obj *obj, fz_obj *key)
+fz_dict_get(fz_obj *obj, fz_obj *key)
{
- if (fz_is_name(ctx, key))
- return fz_dict_gets(ctx, obj, fz_to_name(ctx, key));
+ if (fz_is_name(key))
+ return fz_dict_gets(obj, fz_to_name(key));
return NULL;
}
fz_obj *
-fz_dict_getsa(fz_context *ctx, fz_obj *obj, char *key, char *abbrev)
+fz_dict_getsa(fz_obj *obj, char *key, char *abbrev)
{
fz_obj *v;
- v = fz_dict_gets(ctx, obj, key);
+ v = fz_dict_gets(obj, key);
if (v)
return v;
- return fz_dict_gets(ctx, obj, abbrev);
+ return fz_dict_gets(obj, abbrev);
}
void
-fz_dict_put(fz_context *ctx, fz_obj *obj, fz_obj *key, fz_obj *val)
+fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val)
{
char *s;
int i;
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_dict(ctx, obj))
+ if (!fz_is_dict(obj))
{
fz_warn("assert: not a dict (%s)", fz_objkindstr(obj));
return;
}
- if (fz_is_name(ctx, key))
- s = fz_to_name(ctx, key);
+ if (fz_is_name(key))
+ s = fz_to_name(key);
else
{
fz_warn("assert: key is not a name (%s)", fz_objkindstr(obj));
@@ -686,10 +683,10 @@ fz_dict_put(fz_context *ctx, fz_obj *obj, fz_obj *key, fz_obj *val)
return;
}
- i = fz_dict_finds(ctx, obj, s);
+ i = fz_dict_finds(obj, s);
if (i >= 0)
{
- fz_drop_obj(ctx, obj->u.d.items[i].v);
+ fz_drop_obj(obj->u.d.items[i].v);
obj->u.d.items[i].v = fz_keep_obj(val);
return;
}
@@ -697,7 +694,7 @@ fz_dict_put(fz_context *ctx, fz_obj *obj, fz_obj *key, fz_obj *val)
if (obj->u.d.len + 1 > obj->u.d.cap)
{
obj->u.d.cap = (obj->u.d.cap * 3) / 2;
- obj->u.d.items = fz_realloc(ctx, obj->u.d.items, obj->u.d.cap * sizeof(struct keyval));
+ obj->u.d.items = fz_realloc(obj->ctx, obj->u.d.items, obj->u.d.cap * sizeof(struct keyval));
for (i = obj->u.d.len; i < obj->u.d.cap; i++)
{
obj->u.d.items[i].k = NULL;
@@ -707,7 +704,7 @@ fz_dict_put(fz_context *ctx, fz_obj *obj, fz_obj *key, fz_obj *val)
/* borked! */
if (obj->u.d.len)
- if (strcmp(fz_to_name(ctx, obj->u.d.items[obj->u.d.len - 1].k), s) > 0)
+ if (strcmp(fz_to_name(obj->u.d.items[obj->u.d.len - 1].k), s) > 0)
obj->u.d.sorted = 0;
obj->u.d.items[obj->u.d.len].k = fz_keep_obj(key);
@@ -716,27 +713,27 @@ fz_dict_put(fz_context *ctx, fz_obj *obj, fz_obj *key, fz_obj *val)
}
void
-fz_dict_puts(fz_context *ctx, fz_obj *obj, char *key, fz_obj *val)
+fz_dict_puts(fz_obj *obj, char *key, fz_obj *val)
{
- fz_obj *keyobj = fz_new_name(ctx, key);
- fz_dict_put(ctx, obj, keyobj, val);
- fz_drop_obj(ctx, keyobj);
+ fz_obj *keyobj = fz_new_name(obj->ctx, key);
+ fz_dict_put(obj, keyobj, val);
+ fz_drop_obj(keyobj);
}
void
-fz_dict_dels(fz_context *ctx, fz_obj *obj, char *key)
+fz_dict_dels(fz_obj *obj, char *key)
{
- obj = fz_resolve_indirect(ctx, obj);
+ obj = fz_resolve_indirect(obj);
- if (!fz_is_dict(ctx, obj))
+ if (!fz_is_dict(obj))
fz_warn("assert: not a dict (%s)", fz_objkindstr(obj));
else
{
- int i = fz_dict_finds(ctx, obj, key);
+ int i = fz_dict_finds(obj, key);
if (i >= 0)
{
- fz_drop_obj(ctx, obj->u.d.items[i].k);
- fz_drop_obj(ctx, obj->u.d.items[i].v);
+ fz_drop_obj(obj->u.d.items[i].k);
+ fz_drop_obj(obj->u.d.items[i].v);
obj->u.d.sorted = 0;
obj->u.d.items[i] = obj->u.d.items[obj->u.d.len-1];
obj->u.d.len --;
@@ -745,72 +742,403 @@ fz_dict_dels(fz_context *ctx, fz_obj *obj, char *key)
}
void
-fz_dict_del(fz_context *ctx, fz_obj *obj, fz_obj *key)
+fz_dict_del(fz_obj *obj, fz_obj *key)
{
- if (fz_is_name(ctx, key))
- fz_dict_dels(ctx, obj, fz_to_name(ctx, key));
+ if (fz_is_name(key))
+ fz_dict_dels(obj, fz_to_name(key));
else
fz_warn("assert: key is not a name (%s)", fz_objkindstr(obj));
}
void
-fz_sort_dict(fz_context *ctx, fz_obj *obj)
+fz_sort_dict(fz_obj *obj)
{
- obj = fz_resolve_indirect(ctx, obj);
- if (!fz_is_dict(ctx, obj))
+ obj = fz_resolve_indirect(obj);
+ if (!fz_is_dict(obj))
return;
if (!obj->u.d.sorted)
{
-#ifdef MISSING_QSORT_R
- qsort_r_hack = ctx;
- qsort(obj->u.d.items, obj->u.d.len, sizeof(struct keyval), keyvalcmp_hack);
-#else
- qsort_r(obj->u.d.items, obj->u.d.len, sizeof(struct keyval), ctx, keyvalcmp);
-#endif
- obj->u.d.sorted = 1;
+ qsort(obj->u.d.items, obj->u.d.len, sizeof(struct keyval), keyvalcmp);
+ obj->u.d.sorted = 1;
}
}
static void
-fz_free_array(fz_context *ctx, fz_obj *obj)
+fz_free_array(fz_obj *obj)
{
int i;
for (i = 0; i < obj->u.a.len; i++)
if (obj->u.a.items[i])
- fz_drop_obj(ctx, obj->u.a.items[i]);
+ fz_drop_obj(obj->u.a.items[i]);
- fz_free(ctx, obj->u.a.items);
- fz_free(ctx, obj);
+ fz_free(obj->ctx, obj->u.a.items);
+ fz_free(obj->ctx, obj);
}
static void
-fz_free_dict(fz_context *ctx, fz_obj *obj)
+fz_free_dict(fz_obj *obj)
{
int i;
for (i = 0; i < obj->u.d.len; i++) {
if (obj->u.d.items[i].k)
- fz_drop_obj(ctx, obj->u.d.items[i].k);
+ fz_drop_obj(obj->u.d.items[i].k);
if (obj->u.d.items[i].v)
- fz_drop_obj(ctx, obj->u.d.items[i].v);
+ fz_drop_obj(obj->u.d.items[i].v);
}
- fz_free(ctx, obj->u.d.items);
- fz_free(ctx, obj);
+ fz_free(obj->ctx, obj->u.d.items);
+ fz_free(obj->ctx, obj);
}
void
-fz_drop_obj(fz_context *ctx, fz_obj *obj)
+fz_drop_obj(fz_obj *obj)
{
assert(obj != NULL);
if (--obj->refs == 0)
{
if (obj->kind == FZ_ARRAY)
- fz_free_array(ctx, obj);
+ fz_free_array(obj);
else if (obj->kind == FZ_DICT)
- fz_free_dict(ctx, obj);
+ fz_free_dict(obj);
+ else
+ fz_free(obj->ctx, obj);
+ }
+}
+
+/* Pretty printing objects */
+
+struct fmt
+{
+ char *buf;
+ int cap;
+ int len;
+ int indent;
+ int tight;
+ int col;
+ int sep;
+ int last;
+};
+
+static void fmt_obj(struct fmt *fmt, fz_obj *obj);
+
+static inline int iswhite(int ch)
+{
+ return
+ ch == '\000' ||
+ ch == '\011' ||
+ ch == '\012' ||
+ ch == '\014' ||
+ ch == '\015' ||
+ ch == '\040';
+}
+
+static inline int isdelim(int ch)
+{
+ return ch == '(' || ch == ')' ||
+ ch == '<' || ch == '>' ||
+ ch == '[' || ch == ']' ||
+ ch == '{' || ch == '}' ||
+ ch == '/' ||
+ ch == '%';
+}
+
+static inline void fmt_putc(struct fmt *fmt, int c)
+{
+ if (fmt->sep && !isdelim(fmt->last) && !isdelim(c)) {
+ fmt->sep = 0;
+ fmt_putc(fmt, ' ');
+ }
+ fmt->sep = 0;
+
+ if (fmt->buf && fmt->len < fmt->cap)
+ fmt->buf[fmt->len] = c;
+
+ if (c == '\n')
+ fmt->col = 0;
+ else
+ fmt->col ++;
+
+ fmt->len ++;
+
+ fmt->last = c;
+}
+
+static inline void fmt_indent(struct fmt *fmt)
+{
+ int i = fmt->indent;
+ while (i--) {
+ fmt_putc(fmt, ' ');
+ fmt_putc(fmt, ' ');
+ }
+}
+
+static inline void fmt_puts(struct fmt *fmt, char *s)
+{
+ while (*s)
+ fmt_putc(fmt, *s++);
+}
+
+static inline void fmt_sep(struct fmt *fmt)
+{
+ fmt->sep = 1;
+}
+
+static void fmt_str(struct fmt *fmt, fz_obj *obj)
+{
+ char *s = fz_to_str_buf(obj);
+ int n = fz_to_str_len(obj);
+ int i, c;
+
+ fmt_putc(fmt, '(');
+ for (i = 0; i < n; i++)
+ {
+ c = (unsigned char)s[i];
+ if (c == '\n')
+ fmt_puts(fmt, "\\n");
+ else if (c == '\r')
+ fmt_puts(fmt, "\\r");
+ else if (c == '\t')
+ fmt_puts(fmt, "\\t");
+ else if (c == '\b')
+ fmt_puts(fmt, "\\b");
+ else if (c == '\f')
+ fmt_puts(fmt, "\\f");
+ else if (c == '(')
+ fmt_puts(fmt, "\\(");
+ else if (c == ')')
+ fmt_puts(fmt, "\\)");
+ else if (c < 32 || c >= 127) {
+ char buf[16];
+ fmt_putc(fmt, '\\');
+ sprintf(buf, "%03o", c);
+ fmt_puts(fmt, buf);
+ }
+ else
+ fmt_putc(fmt, c);
+ }
+ fmt_putc(fmt, ')');
+}
+
+static void fmt_hex(struct fmt *fmt, fz_obj *obj)
+{
+ char *s = fz_to_str_buf(obj);
+ int n = fz_to_str_len(obj);
+ int i, b, c;
+
+ fmt_putc(fmt, '<');
+ for (i = 0; i < n; i++) {
+ b = (unsigned char) s[i];
+ c = (b >> 4) & 0x0f;
+ fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
+ c = (b) & 0x0f;
+ fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
+ }
+ fmt_putc(fmt, '>');
+}
+
+static void fmt_name(struct fmt *fmt, fz_obj *obj)
+{
+ unsigned char *s = (unsigned char *) fz_to_name(obj);
+ int i, c;
+
+ fmt_putc(fmt, '/');
+
+ for (i = 0; s[i]; i++)
+ {
+ if (isdelim(s[i]) || iswhite(s[i]) ||
+ s[i] == '#' || s[i] < 32 || s[i] >= 127)
+ {
+ fmt_putc(fmt, '#');
+ c = (s[i] >> 4) & 0xf;
+ fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
+ c = s[i] & 0xf;
+ fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
+ }
+ else
+ {
+ fmt_putc(fmt, s[i]);
+ }
+ }
+}
+
+static void fmt_array(struct fmt *fmt, fz_obj *obj)
+{
+ int i, n;
+
+ n = fz_array_len(obj);
+ if (fmt->tight) {
+ fmt_putc(fmt, '[');
+ for (i = 0; i < n; i++) {
+ fmt_obj(fmt, fz_array_get(obj, i));
+ fmt_sep(fmt);
+ }
+ fmt_putc(fmt, ']');
+ }
+ else {
+ fmt_puts(fmt, "[ ");
+ for (i = 0; i < n; i++) {
+ if (fmt->col > 60) {
+ fmt_putc(fmt, '\n');
+ fmt_indent(fmt);
+ }
+ fmt_obj(fmt, fz_array_get(obj, i));
+ fmt_putc(fmt, ' ');
+ }
+ fmt_putc(fmt, ']');
+ fmt_sep(fmt);
+ }
+}
+
+static void fmt_dict(struct fmt *fmt, fz_obj *obj)
+{
+ int i, n;
+ fz_obj *key, *val;
+
+ n = fz_dict_len(obj);
+ if (fmt->tight) {
+ fmt_puts(fmt, "<<");
+ for (i = 0; i < n; i++) {
+ fmt_obj(fmt, fz_dict_get_key(obj, i));
+ fmt_sep(fmt);
+ fmt_obj(fmt, fz_dict_get_val(obj, i));
+ fmt_sep(fmt);
+ }
+ fmt_puts(fmt, ">>");
+ }
+ else {
+ fmt_puts(fmt, "<<\n");
+ fmt->indent ++;
+ for (i = 0; i < n; i++) {
+ key = fz_dict_get_key(obj, i);
+ val = fz_dict_get_val(obj, i);
+ fmt_indent(fmt);
+ fmt_obj(fmt, key);
+ fmt_putc(fmt, ' ');
+ if (!fz_is_indirect(val) && fz_is_array(val))
+ fmt->indent ++;
+ fmt_obj(fmt, val);
+ fmt_putc(fmt, '\n');
+ if (!fz_is_indirect(val) && fz_is_array(val))
+ fmt->indent --;
+ }
+ fmt->indent --;
+ fmt_indent(fmt);
+ fmt_puts(fmt, ">>");
+ }
+}
+
+static void fmt_obj(struct fmt *fmt, fz_obj *obj)
+{
+ char buf[256];
+
+ if (!obj)
+ fmt_puts(fmt, "<NULL>");
+ else if (fz_is_indirect(obj))
+ {
+ sprintf(buf, "%d %d R", fz_to_num(obj), fz_to_gen(obj));
+ fmt_puts(fmt, buf);
+ }
+ else if (fz_is_null(obj))
+ fmt_puts(fmt, "null");
+ else if (fz_is_bool(obj))
+ fmt_puts(fmt, fz_to_bool(obj) ? "true" : "false");
+ else if (fz_is_int(obj))
+ {
+ sprintf(buf, "%d", fz_to_int(obj));
+ fmt_puts(fmt, buf);
+ }
+ else if (fz_is_real(obj))
+ {
+ sprintf(buf, "%g", fz_to_real(obj));
+ if (strchr(buf, 'e')) /* bad news! */
+ sprintf(buf, fabsf(fz_to_real(obj)) > 1 ? "%1.1f" : "%1.8f", fz_to_real(obj));
+ fmt_puts(fmt, buf);
+ }
+ else if (fz_is_string(obj))
+ {
+ char *str = fz_to_str_buf(obj);
+ int len = fz_to_str_len(obj);
+ int added = 0;
+ int i, c;
+ for (i = 0; i < len; i++) {
+ c = (unsigned char)str[i];
+ if (strchr("()\\\n\r\t\b\f", c))
+ added ++;
+ else if (c < 32 || c >= 127)
+ added += 3;
+ }
+ if (added < len)
+ fmt_str(fmt, obj);
else
- fz_free(ctx, obj);
+ fmt_hex(fmt, obj);
}
+ else if (fz_is_name(obj))
+ fmt_name(fmt, obj);
+ else if (fz_is_array(obj))
+ fmt_array(fmt, obj);
+ else if (fz_is_dict(obj))
+ fmt_dict(fmt, obj);
+ else
+ fmt_puts(fmt, "<unknown object>");
+}
+
+static int
+fz_sprint_obj(char *s, int n, fz_obj *obj, int tight)
+{
+ struct fmt fmt;
+
+ fmt.indent = 0;
+ fmt.col = 0;
+ fmt.sep = 0;
+ fmt.last = 0;
+
+ fmt.tight = tight;
+ fmt.buf = s;
+ fmt.cap = n;
+ fmt.len = 0;
+ fmt_obj(&fmt, obj);
+
+ if (fmt.buf && fmt.len < fmt.cap)
+ fmt.buf[fmt.len] = '\0';
+
+ return fmt.len;
+}
+
+int
+fz_fprint_obj(FILE *fp, fz_obj *obj, int tight)
+{
+ char buf[1024];
+ char *ptr;
+ int n;
+
+ n = fz_sprint_obj(NULL, 0, obj, tight);
+ if ((n + 1) < sizeof buf)
+ {
+ fz_sprint_obj(buf, sizeof buf, obj, tight);
+ fputs(buf, fp);
+ fputc('\n', fp);
+ }
+ else
+ {
+ ptr = fz_malloc(obj->ctx, n + 1);
+ fz_sprint_obj(ptr, n + 1, obj, tight);
+ fputs(ptr, fp);
+ fputc('\n', fp);
+ fz_free(obj->ctx, ptr);
+ }
+ return n;
+}
+
+void
+fz_debug_obj(fz_obj *obj)
+{
+ fz_fprint_obj(stdout, obj, 0);
+}
+
+void
+fz_debug_ref(fz_obj *ref)
+{
+ fz_debug_obj(fz_resolve_indirect(ref));
}
diff --git a/fitz/dev_bbox.c b/fitz/dev_bbox.c
index e83cbcc5..766adefa 100644
--- a/fitz/dev_bbox.c
+++ b/fitz/dev_bbox.c
@@ -58,7 +58,7 @@ static void
fz_bbox_fill_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm,
fz_colorspace *colorspace, float *color, float alpha)
{
- fz_bbox_fill_image(dev->user, image, ctm, alpha);
+ fz_bbox_fill_image(dev, image, ctm, alpha);
}
fz_device *
diff --git a/fitz/dev_null.c b/fitz/dev_null.c
index 394f8374..dc6105f4 100644
--- a/fitz/dev_null.c
+++ b/fitz/dev_null.c
@@ -3,7 +3,8 @@
fz_device *
fz_new_device(fz_context *ctx, void *user)
{
- fz_device *dev = fz_calloc(ctx, 1, sizeof(fz_device));
+ fz_device *dev = fz_malloc(ctx, sizeof(fz_device));
+ memset(dev, 0, sizeof *dev);
dev->hints = 0;
dev->flags = 0;
dev->user = user;
diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c
index 94a06afb..7efbac91 100644
--- a/fitz/filt_dctd.c
+++ b/fitz/filt_dctd.c
@@ -208,16 +208,16 @@ fz_open_dctd(fz_stream *chain, fz_obj *params)
fz_dctd *state;
fz_obj *obj;
- assert(chain);
- state = fz_calloc(chain->ctx, 1, sizeof(fz_dctd));
- state->ctx = chain->ctx;
+ state = fz_malloc(chain->ctx, sizeof(fz_dctd));
+ memset(state, 0, sizeof(fz_dctd));
+ state->ctx = chain->ctx;
state->chain = chain;
state->color_transform = -1; /* unset */
state->init = 0;
- obj = fz_dict_gets(chain->ctx, params, "ColorTransform");
+ obj = fz_dict_gets(params, "ColorTransform");
if (obj)
- state->color_transform = fz_to_int(chain->ctx, obj);
+ state->color_transform = fz_to_int(obj);
return fz_new_stream(chain->ctx, state, read_dctd, close_dctd);
}
diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c
index 27e8ed60..bd64939d 100644
--- a/fitz/filt_faxd.c
+++ b/fitz/filt_faxd.c
@@ -690,26 +690,26 @@ fz_open_faxd(fz_stream *chain, fz_obj *params)
fax->end_of_block = 1;
fax->black_is_1 = 0;
- obj = fz_dict_gets(ctx, params, "K");
- if (obj) fax->k = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(params, "K");
+ if (obj) fax->k = fz_to_int(obj);
- obj = fz_dict_gets(ctx, params, "EndOfLine");
- if (obj) fax->end_of_line = fz_to_bool(ctx, obj);
+ obj = fz_dict_gets(params, "EndOfLine");
+ if (obj) fax->end_of_line = fz_to_bool(obj);
- obj = fz_dict_gets(ctx, params, "EncodedByteAlign");
- if (obj) fax->encoded_byte_align = fz_to_bool(ctx, obj);
+ obj = fz_dict_gets(params, "EncodedByteAlign");
+ if (obj) fax->encoded_byte_align = fz_to_bool(obj);
- obj = fz_dict_gets(ctx, params, "Columns");
- if (obj) fax->columns = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(params, "Columns");
+ if (obj) fax->columns = fz_to_int(obj);
- obj = fz_dict_gets(ctx, params, "Rows");
- if (obj) fax->rows = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(params, "Rows");
+ if (obj) fax->rows = fz_to_int(obj);
- obj = fz_dict_gets(ctx, params, "EndOfBlock");
- if (obj) fax->end_of_block = fz_to_bool(ctx, obj);
+ obj = fz_dict_gets(params, "EndOfBlock");
+ if (obj) fax->end_of_block = fz_to_bool(obj);
- obj = fz_dict_gets(ctx, params, "BlackIs1");
- if (obj) fax->black_is_1 = fz_to_bool(ctx, obj);
+ obj = fz_dict_gets(params, "BlackIs1");
+ if (obj) fax->black_is_1 = fz_to_bool(obj);
fax->stride = ((fax->columns - 1) >> 3) + 1;
fax->ridx = 0;
diff --git a/fitz/filt_lzwd.c b/fitz/filt_lzwd.c
index b6534dfe..17d41d94 100644
--- a/fitz/filt_lzwd.c
+++ b/fitz/filt_lzwd.c
@@ -176,9 +176,9 @@ fz_open_lzwd(fz_stream *chain, fz_obj *params)
lzw->eod = 0;
lzw->early_change = 1;
- obj = fz_dict_gets(chain->ctx, params, "EarlyChange");
+ obj = fz_dict_gets(params, "EarlyChange");
if (obj)
- lzw->early_change = !!fz_to_int(chain->ctx, obj);
+ lzw->early_change = !!fz_to_int(obj);
for (i = 0; i < 256; i++)
{
diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c
index fc22ed97..266cc033 100644
--- a/fitz/filt_predict.c
+++ b/fitz/filt_predict.c
@@ -204,9 +204,9 @@ fz_open_predict(fz_stream *chain, fz_obj *params)
state->colors = 1;
state->bpc = 8;
- obj = fz_dict_gets(ctx, params, "Predictor");
+ obj = fz_dict_gets(params, "Predictor");
if (obj)
- state->predictor = fz_to_int(ctx, obj);
+ state->predictor = fz_to_int(obj);
if (state->predictor != 1 && state->predictor != 2 &&
state->predictor != 10 && state->predictor != 11 &&
@@ -217,17 +217,17 @@ fz_open_predict(fz_stream *chain, fz_obj *params)
state->predictor = 1;
}
- obj = fz_dict_gets(ctx, params, "Columns");
+ obj = fz_dict_gets(params, "Columns");
if (obj)
- state->columns = fz_to_int(ctx, obj);
+ state->columns = fz_to_int(obj);
- obj = fz_dict_gets(ctx, params, "Colors");
+ obj = fz_dict_gets(params, "Colors");
if (obj)
- state->colors = fz_to_int(ctx, obj);
+ state->colors = fz_to_int(obj);
- obj = fz_dict_gets(ctx, params, "BitsPerComponent");
+ obj = fz_dict_gets(params, "BitsPerComponent");
if (obj)
- state->bpc = fz_to_int(ctx, obj);
+ state->bpc = fz_to_int(obj);
state->stride = (state->bpc * state->colors * state->columns + 7) / 8;
state->bpp = (state->bpc * state->colors + 7) / 8;
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 841e0f61..0f0d3b5c 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -189,7 +189,6 @@ struct fz_context_s
{
fz_alloc_context *alloc;
fz_error_context *error;
- struct fz_obj_s *(*resolve_indirect)(struct fz_obj_s *);
};
fz_context *fz_new_context(fz_alloc_context *alloc);
@@ -427,7 +426,7 @@ void aes_crypt_cbc( fz_aes *ctx, int mode, int length,
typedef struct fz_obj_s fz_obj;
-#define fz_resolve_indirect(ctx, obj) (ctx)->resolve_indirect((obj))
+extern fz_obj *(*fz_resolve_indirect)(fz_obj *obj);
fz_obj *fz_new_null(fz_context *ctx);
fz_obj *fz_new_bool(fz_context *ctx, int b);
@@ -443,54 +442,54 @@ fz_obj *fz_copy_array(fz_context *ctx, fz_obj *array);
fz_obj *fz_copy_dict(fz_context *ctx, fz_obj *dict);
fz_obj *fz_keep_obj(fz_obj *obj);
-void fz_drop_obj(fz_context *ctx, fz_obj *obj);
+void fz_drop_obj(fz_obj *obj);
/* type queries */
-int fz_is_null(fz_context *ctx, fz_obj *obj);
-int fz_is_bool(fz_context *ctx, fz_obj *obj);
-int fz_is_int(fz_context *ctx, fz_obj *obj);
-int fz_is_real(fz_context *ctx, fz_obj *obj);
-int fz_is_name(fz_context *ctx, fz_obj *obj);
-int fz_is_string(fz_context *ctx, fz_obj *obj);
-int fz_is_array(fz_context *ctx, fz_obj *obj);
-int fz_is_dict(fz_context *ctx, fz_obj *obj);
+int fz_is_null(fz_obj *obj);
+int fz_is_bool(fz_obj *obj);
+int fz_is_int(fz_obj *obj);
+int fz_is_real(fz_obj *obj);
+int fz_is_name(fz_obj *obj);
+int fz_is_string(fz_obj *obj);
+int fz_is_array(fz_obj *obj);
+int fz_is_dict(fz_obj *obj);
int fz_is_indirect(fz_obj *obj);
int fz_objcmp(fz_obj *a, fz_obj *b);
-/* safe, silent failure, no error reporting */
-int fz_to_bool(fz_context *ctx, fz_obj *obj);
-int fz_to_int(fz_context *ctx, fz_obj *obj);
-float fz_to_real(fz_context *ctx, fz_obj *obj);
-char *fz_to_name(fz_context *ctx, fz_obj *obj);
-char *fz_to_str_buf(fz_context *ctx, fz_obj *obj);
-int fz_to_str_len(fz_context *ctx, fz_obj *obj);
+/* safe, silent failure, no error reporting on type mismatches */
+int fz_to_bool(fz_obj *obj);
+int fz_to_int(fz_obj *obj);
+float fz_to_real(fz_obj *obj);
+char *fz_to_name(fz_obj *obj);
+char *fz_to_str_buf(fz_obj *obj);
+int fz_to_str_len(fz_obj *obj);
int fz_to_num(fz_obj *obj);
int fz_to_gen(fz_obj *obj);
-int fz_array_len(fz_context *ctx, fz_obj *array);
-fz_obj *fz_array_get(fz_context *ctx, fz_obj *array, int i);
-void fz_array_put(fz_context *ctx, fz_obj *array, int i, fz_obj *obj);
-void fz_array_push(fz_context *ctx, fz_obj *array, fz_obj *obj);
-void fz_array_insert(fz_context *ctx, fz_obj *array, fz_obj *obj);
-
-int fz_dict_len(fz_context *ctx, fz_obj *dict);
-fz_obj *fz_dict_get_key(fz_context *ctx, fz_obj *dict, int idx);
-fz_obj *fz_dict_get_val(fz_context *ctx, fz_obj *dict, int idx);
-fz_obj *fz_dict_get(fz_context *ctx, fz_obj *dict, fz_obj *key);
-fz_obj *fz_dict_gets(fz_context *ctx, fz_obj *dict, char *key);
-fz_obj *fz_dict_getsa(fz_context *ctx, fz_obj *dict, char *key, char *abbrev);
-void fz_dict_put(fz_context *ctx, fz_obj *dict, fz_obj *key, fz_obj *val);
-void fz_dict_puts(fz_context *ctx, fz_obj *dict, char *key, fz_obj *val);
-void fz_dict_del(fz_context *ctx, fz_obj *dict, fz_obj *key);
-void fz_dict_dels(fz_context *ctx, fz_obj *dict, char *key);
-void fz_sort_dict(fz_context *ctx, fz_obj *dict);
-
-int fz_fprint_obj(fz_context *ctx, FILE *fp, fz_obj *obj, int tight);
-void fz_debug_obj(fz_context *ctx, fz_obj *obj);
-void fz_debug_ref(fz_context *ctx, fz_obj *obj);
-
-void fz_set_str_len(fz_context *ctx, fz_obj *obj, int newlen); /* private */
+int fz_array_len(fz_obj *array);
+fz_obj *fz_array_get(fz_obj *array, int i);
+void fz_array_put(fz_obj *array, int i, fz_obj *obj);
+void fz_array_push(fz_obj *array, fz_obj *obj);
+void fz_array_insert(fz_obj *array, fz_obj *obj);
+
+int fz_dict_len(fz_obj *dict);
+fz_obj *fz_dict_get_key(fz_obj *dict, int idx);
+fz_obj *fz_dict_get_val(fz_obj *dict, int idx);
+fz_obj *fz_dict_get(fz_obj *dict, fz_obj *key);
+fz_obj *fz_dict_gets(fz_obj *dict, char *key);
+fz_obj *fz_dict_getsa(fz_obj *dict, char *key, char *abbrev);
+void fz_dict_put(fz_obj *dict, fz_obj *key, fz_obj *val);
+void fz_dict_puts(fz_obj *dict, char *key, fz_obj *val);
+void fz_dict_del(fz_obj *dict, fz_obj *key);
+void fz_dict_dels(fz_obj *dict, char *key);
+void fz_sort_dict(fz_obj *dict);
+
+int fz_fprint_obj(FILE *fp, fz_obj *obj, int tight);
+void fz_debug_obj(fz_obj *obj);
+void fz_debug_ref(fz_obj *obj);
+
+void fz_set_str_len(fz_obj *obj, int newlen); /* private */
void *fz_get_indirect_xref(fz_obj *obj); /* private */
/*
@@ -522,6 +521,7 @@ typedef struct fz_stream_s fz_stream;
struct fz_stream_s
{
+ fz_context *ctx;
int refs;
int error;
int eof;
@@ -530,7 +530,6 @@ struct fz_stream_s
int bits;
unsigned char *bp, *rp, *wp, *ep;
void *state;
- fz_context *ctx;
int (*read)(fz_stream *stm, unsigned char *buf, int len);
void (*close)(fz_stream *stm);
void (*seek)(fz_stream *stm, int offset, int whence);
diff --git a/fitz/obj_print.c b/fitz/obj_print.c
deleted file mode 100644
index a6313e02..00000000
--- a/fitz/obj_print.c
+++ /dev/null
@@ -1,342 +0,0 @@
-#include "fitz.h"
-
-struct fmt
-{
- char *buf;
- int cap;
- int len;
- int indent;
- int tight;
- int col;
- int sep;
- int last;
- fz_context *ctx;
-};
-
-static void fmt_obj(struct fmt *fmt, fz_obj *obj);
-
-static inline int iswhite(int ch)
-{
- return
- ch == '\000' ||
- ch == '\011' ||
- ch == '\012' ||
- ch == '\014' ||
- ch == '\015' ||
- ch == '\040';
-}
-
-static inline int isdelim(int ch)
-{
- return ch == '(' || ch == ')' ||
- ch == '<' || ch == '>' ||
- ch == '[' || ch == ']' ||
- ch == '{' || ch == '}' ||
- ch == '/' ||
- ch == '%';
-}
-
-static inline void fmt_putc(struct fmt *fmt, int c)
-{
- if (fmt->sep && !isdelim(fmt->last) && !isdelim(c)) {
- fmt->sep = 0;
- fmt_putc(fmt, ' ');
- }
- fmt->sep = 0;
-
- if (fmt->buf && fmt->len < fmt->cap)
- fmt->buf[fmt->len] = c;
-
- if (c == '\n')
- fmt->col = 0;
- else
- fmt->col ++;
-
- fmt->len ++;
-
- fmt->last = c;
-}
-
-static inline void fmt_indent(struct fmt *fmt)
-{
- int i = fmt->indent;
- while (i--) {
- fmt_putc(fmt, ' ');
- fmt_putc(fmt, ' ');
- }
-}
-
-static inline void fmt_puts(struct fmt *fmt, char *s)
-{
- while (*s)
- fmt_putc(fmt, *s++);
-}
-
-static inline void fmt_sep(struct fmt *fmt)
-{
- fmt->sep = 1;
-}
-
-static void fmt_str(struct fmt *fmt, fz_obj *obj)
-{
- char *s = fz_to_str_buf(fmt->ctx, obj);
- int n = fz_to_str_len(fmt->ctx, obj);
- int i, c;
-
- fmt_putc(fmt, '(');
- for (i = 0; i < n; i++)
- {
- c = (unsigned char)s[i];
- if (c == '\n')
- fmt_puts(fmt, "\\n");
- else if (c == '\r')
- fmt_puts(fmt, "\\r");
- else if (c == '\t')
- fmt_puts(fmt, "\\t");
- else if (c == '\b')
- fmt_puts(fmt, "\\b");
- else if (c == '\f')
- fmt_puts(fmt, "\\f");
- else if (c == '(')
- fmt_puts(fmt, "\\(");
- else if (c == ')')
- fmt_puts(fmt, "\\)");
- else if (c < 32 || c >= 127) {
- char buf[16];
- fmt_putc(fmt, '\\');
- sprintf(buf, "%03o", c);
- fmt_puts(fmt, buf);
- }
- else
- fmt_putc(fmt, c);
- }
- fmt_putc(fmt, ')');
-}
-
-static void fmt_hex(struct fmt *fmt, fz_obj *obj)
-{
- char *s = fz_to_str_buf(fmt->ctx, obj);
- int n = fz_to_str_len(fmt->ctx, obj);
- int i, b, c;
-
- fmt_putc(fmt, '<');
- for (i = 0; i < n; i++) {
- b = (unsigned char) s[i];
- c = (b >> 4) & 0x0f;
- fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
- c = (b) & 0x0f;
- fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
- }
- fmt_putc(fmt, '>');
-}
-
-static void fmt_name(struct fmt *fmt, fz_obj *obj)
-{
- unsigned char *s = (unsigned char *) fz_to_name(fmt->ctx, obj);
- int i, c;
-
- fmt_putc(fmt, '/');
-
- for (i = 0; s[i]; i++)
- {
- if (isdelim(s[i]) || iswhite(s[i]) ||
- s[i] == '#' || s[i] < 32 || s[i] >= 127)
- {
- fmt_putc(fmt, '#');
- c = (s[i] >> 4) & 0xf;
- fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
- c = s[i] & 0xf;
- fmt_putc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
- }
- else
- {
- fmt_putc(fmt, s[i]);
- }
- }
-}
-
-static void fmt_array(struct fmt *fmt, fz_obj *obj)
-{
- int i, n;
- fz_context *ctx = fmt->ctx;
-
- n = fz_array_len(ctx, obj);
- if (fmt->tight) {
- fmt_putc(fmt, '[');
- for (i = 0; i < n; i++) {
- fmt_obj(fmt, fz_array_get(ctx, obj, i));
- fmt_sep(fmt);
- }
- fmt_putc(fmt, ']');
- }
- else {
- fmt_puts(fmt, "[ ");
- for (i = 0; i < n; i++) {
- if (fmt->col > 60) {
- fmt_putc(fmt, '\n');
- fmt_indent(fmt);
- }
- fmt_obj(fmt, fz_array_get(ctx, obj, i));
- fmt_putc(fmt, ' ');
- }
- fmt_putc(fmt, ']');
- fmt_sep(fmt);
- }
-}
-
-static void fmt_dict(struct fmt *fmt, fz_obj *obj)
-{
- int i, n;
- fz_obj *key, *val;
- fz_context *ctx = fmt->ctx;
-
- n = fz_dict_len(ctx, obj);
- if (fmt->tight) {
- fmt_puts(fmt, "<<");
- for (i = 0; i < n; i++) {
- fmt_obj(fmt, fz_dict_get_key(ctx, obj, i));
- fmt_sep(fmt);
- fmt_obj(fmt, fz_dict_get_val(ctx, obj, i));
- fmt_sep(fmt);
- }
- fmt_puts(fmt, ">>");
- }
- else {
- fmt_puts(fmt, "<<\n");
- fmt->indent ++;
- for (i = 0; i < n; i++) {
- key = fz_dict_get_key(ctx, obj, i);
- val = fz_dict_get_val(ctx, obj, i);
- fmt_indent(fmt);
- fmt_obj(fmt, key);
- fmt_putc(fmt, ' ');
- if (!fz_is_indirect(val) && fz_is_array(ctx, val))
- fmt->indent ++;
- fmt_obj(fmt, val);
- fmt_putc(fmt, '\n');
- if (!fz_is_indirect(val) && fz_is_array(ctx, val))
- fmt->indent --;
- }
- fmt->indent --;
- fmt_indent(fmt);
- fmt_puts(fmt, ">>");
- }
-}
-
-static void fmt_obj(struct fmt *fmt, fz_obj *obj)
-{
- char buf[256];
- fz_context *ctx = fmt->ctx;
-
- if (!obj)
- fmt_puts(fmt, "<NULL>");
- else if (fz_is_indirect(obj))
- {
- sprintf(buf, "%d %d R", fz_to_num(obj), fz_to_gen(obj));
- fmt_puts(fmt, buf);
- }
- else if (fz_is_null(ctx, obj))
- fmt_puts(fmt, "null");
- else if (fz_is_bool(ctx, obj))
- fmt_puts(fmt, fz_to_bool(ctx, obj) ? "true" : "false");
- else if (fz_is_int(ctx, obj))
- {
- sprintf(buf, "%d", fz_to_int(ctx, obj));
- fmt_puts(fmt, buf);
- }
- else if (fz_is_real(ctx, obj))
- {
- sprintf(buf, "%g", fz_to_real(ctx, obj));
- if (strchr(buf, 'e')) /* bad news! */
- sprintf(buf, fabsf(fz_to_real(ctx, obj)) > 1 ? "%1.1f" : "%1.8f", fz_to_real(ctx, obj));
- fmt_puts(fmt, buf);
- }
- else if (fz_is_string(ctx, obj))
- {
- char *str = fz_to_str_buf(ctx, obj);
- int len = fz_to_str_len(ctx, obj);
- int added = 0;
- int i, c;
- for (i = 0; i < len; i++) {
- c = (unsigned char)str[i];
- if (strchr("()\\\n\r\t\b\f", c))
- added ++;
- else if (c < 32 || c >= 127)
- added += 3;
- }
- if (added < len)
- fmt_str(fmt, obj);
- else
- fmt_hex(fmt, obj);
- }
- else if (fz_is_name(ctx, obj))
- fmt_name(fmt, obj);
- else if (fz_is_array(ctx, obj))
- fmt_array(fmt, obj);
- else if (fz_is_dict(ctx, obj))
- fmt_dict(fmt, obj);
- else
- fmt_puts(fmt, "<unknown object>");
-}
-
-static int
-fz_sprint_obj(fz_context *ctx, char *s, int n, fz_obj *obj, int tight)
-{
- struct fmt fmt;
-
- fmt.indent = 0;
- fmt.col = 0;
- fmt.sep = 0;
- fmt.last = 0;
-
- fmt.tight = tight;
- fmt.buf = s;
- fmt.cap = n;
- fmt.len = 0;
- fmt.ctx = ctx;
- fmt_obj(&fmt, obj);
-
- if (fmt.buf && fmt.len < fmt.cap)
- fmt.buf[fmt.len] = '\0';
-
- return fmt.len;
-}
-
-int
-fz_fprint_obj(fz_context *ctx, FILE *fp, fz_obj *obj, int tight)
-{
- char buf[1024];
- char *ptr;
- int n;
-
- n = fz_sprint_obj(ctx, NULL, 0, obj, tight);
- if ((n + 1) < sizeof buf)
- {
- fz_sprint_obj(ctx, buf, sizeof buf, obj, tight);
- fputs(buf, fp);
- fputc('\n', fp);
- }
- else
- {
- ptr = fz_malloc(ctx, n + 1);
- fz_sprint_obj(ctx, ptr, n + 1, obj, tight);
- fputs(ptr, fp);
- fputc('\n', fp);
- fz_free(ctx, ptr);
- }
- return n;
-}
-
-void
-fz_debug_obj(fz_context *ctx, fz_obj *obj)
-{
- fz_fprint_obj(ctx, stdout, obj, 0);
-}
-
-void
-fz_debug_ref(fz_context *ctx, fz_obj *ref)
-{
- fz_obj *obj;
- obj = fz_resolve_indirect(ctx, ref);
- fz_debug_obj(ctx, obj);
-}
diff --git a/fitz/res_font.c b/fitz/res_font.c
index f3018fcb..b32f6a61 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -65,7 +65,7 @@ fz_drop_font(fz_context *ctx, fz_font *font)
if (font->t3procs)
{
if (font->t3resources)
- fz_drop_obj(ctx, font->t3resources);
+ fz_drop_obj(font->t3resources);
for (i = 0; i < 256; i++)
if (font->t3procs[i])
fz_drop_buffer(ctx, font->t3procs[i]);
diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c
index cc057d6f..aa640610 100644
--- a/pdf/pdf_annot.c
+++ b/pdf/pdf_annot.c
@@ -10,7 +10,7 @@ pdf_free_link(fz_context *ctx, pdf_link *link)
{
next = link->next;
if (link->dest)
- fz_drop_obj(ctx, link->dest);
+ fz_drop_obj(link->dest);
fz_free(ctx, link);
link = next;
}
@@ -20,20 +20,20 @@ pdf_free_link(fz_context *ctx, pdf_link *link)
static fz_obj *
resolve_dest(pdf_xref *xref, fz_obj *dest)
{
- if (fz_is_name(xref->ctx, dest) || fz_is_string(xref->ctx, dest))
+ if (fz_is_name(dest) || fz_is_string(dest))
{
dest = pdf_lookup_dest(xref, dest);
return resolve_dest(xref, dest);
}
- else if (fz_is_array(xref->ctx, dest))
+ else if (fz_is_array(dest))
{
return dest;
}
- else if (fz_is_dict(xref->ctx, dest))
+ else if (fz_is_dict(dest))
{
- dest = fz_dict_gets(xref->ctx, dest, "D");
+ dest = fz_dict_gets(dest, "D");
return resolve_dest(xref, dest);
}
@@ -55,49 +55,49 @@ pdf_load_link(pdf_xref *xref, fz_obj *dict)
dest = NULL;
- obj = fz_dict_gets(ctx, dict, "Rect");
+ obj = fz_dict_gets(dict, "Rect");
if (obj)
bbox = pdf_to_rect(ctx, obj);
else
bbox = fz_empty_rect;
- obj = fz_dict_gets(ctx, dict, "Dest");
+ obj = fz_dict_gets(dict, "Dest");
if (obj)
{
kind = PDF_LINK_GOTO;
dest = resolve_dest(xref, obj);
}
- action = fz_dict_gets(ctx, dict, "A");
+ action = fz_dict_gets(dict, "A");
/* fall back to additional action button's down/up action */
if (!action)
- action = fz_dict_getsa(ctx, fz_dict_gets(ctx, dict, "AA"), "U", "D");
+ action = fz_dict_getsa(fz_dict_gets(dict, "AA"), "U", "D");
if (action)
{
- obj = fz_dict_gets(ctx, action, "S");
- if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "GoTo"))
+ obj = fz_dict_gets(action, "S");
+ if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "GoTo"))
{
kind = PDF_LINK_GOTO;
- dest = resolve_dest(xref, fz_dict_gets(ctx, action, "D"));
+ dest = resolve_dest(xref, fz_dict_gets(action, "D"));
}
- else if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "URI"))
+ else if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "URI"))
{
kind = PDF_LINK_URI;
- dest = fz_dict_gets(ctx, action, "URI");
+ dest = fz_dict_gets(action, "URI");
}
- else if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Launch"))
+ else if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Launch"))
{
kind = PDF_LINK_LAUNCH;
- dest = fz_dict_gets(ctx, action, "F");
+ dest = fz_dict_gets(action, "F");
}
- else if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Named"))
+ else if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Named"))
{
kind = PDF_LINK_NAMED;
- dest = fz_dict_gets(ctx, action, "N");
+ dest = fz_dict_gets(action, "N");
}
- else if (fz_is_name(ctx, obj) && (!strcmp(fz_to_name(ctx, obj), "GoToR")))
+ else if (fz_is_name(obj) && (!strcmp(fz_to_name(obj), "GoToR")))
{
kind = PDF_LINK_ACTION;
dest = action;
@@ -127,15 +127,14 @@ pdf_load_links(pdf_link **linkp, pdf_xref *xref, fz_obj *annots)
pdf_link *link, *head, *tail;
fz_obj *obj;
int i, n;
- fz_context *ctx = xref->ctx;
head = tail = NULL;
link = NULL;
- n = fz_array_len(ctx, annots);
+ n = fz_array_len(annots);
for (i = 0; i < n; i++)
{
- obj = fz_array_get(ctx, annots, i);
+ obj = fz_array_get(annots, i);
link = pdf_load_link(xref, obj);
if (link)
{
@@ -163,7 +162,7 @@ pdf_free_annot(fz_context *ctx, pdf_annot *annot)
if (annot->ap)
pdf_drop_xobject(ctx, annot->ap);
if (annot->obj)
- fz_drop_obj(ctx, annot->obj);
+ fz_drop_obj(annot->obj);
fz_free(ctx, annot);
annot = next;
}
@@ -200,21 +199,21 @@ pdf_load_annots(pdf_annot **annotp, pdf_xref *xref, fz_obj *annots)
head = tail = NULL;
annot = NULL;
- len = fz_array_len(ctx, annots);
+ len = fz_array_len(annots);
for (i = 0; i < len; i++)
{
- obj = fz_array_get(ctx, annots, i);
+ obj = fz_array_get(annots, i);
- rect = fz_dict_gets(ctx, obj, "Rect");
- ap = fz_dict_gets(ctx, obj, "AP");
- as = fz_dict_gets(ctx, obj, "AS");
- if (fz_is_dict(ctx, ap))
+ rect = fz_dict_gets(obj, "Rect");
+ ap = fz_dict_gets(obj, "AP");
+ as = fz_dict_gets(obj, "AS");
+ if (fz_is_dict(ap))
{
- n = fz_dict_gets(ctx, ap, "N"); /* normal state */
+ n = fz_dict_gets(ap, "N"); /* normal state */
/* lookup current state in sub-dictionary */
if (!pdf_is_stream(xref, fz_to_num(n), fz_to_gen(n)))
- n = fz_dict_get(ctx, n, as);
+ n = fz_dict_get(n, as);
if (pdf_is_stream(xref, fz_to_num(n), fz_to_gen(n)))
{
diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c
index b9c2a5f4..4329ad19 100644
--- a/pdf/pdf_cmap_load.c
+++ b/pdf/pdf_cmap_load.c
@@ -37,17 +37,17 @@ pdf_load_embedded_cmap(pdf_cmap **cmapp, pdf_xref *xref, fz_obj *stmobj)
fz_close(file);
- wmode = fz_dict_gets(ctx, stmobj, "WMode");
- if (fz_is_int(ctx, wmode))
- pdf_set_wmode(cmap, fz_to_int(ctx, wmode));
+ wmode = fz_dict_gets(stmobj, "WMode");
+ if (fz_is_int(wmode))
+ pdf_set_wmode(cmap, fz_to_int(wmode));
- obj = fz_dict_gets(ctx, stmobj, "UseCMap");
- if (fz_is_name(ctx, obj))
+ obj = fz_dict_gets(stmobj, "UseCMap");
+ if (fz_is_name(obj))
{
- error = pdf_load_system_cmap(ctx, &usecmap, fz_to_name(ctx, obj));
+ error = pdf_load_system_cmap(ctx, &usecmap, fz_to_name(obj));
if (error)
{
- error = fz_error_note(error, "cannot load system usecmap '%s'", fz_to_name(ctx, obj));
+ error = fz_error_note(error, "cannot load system usecmap '%s'", fz_to_name(obj));
goto cleanup;
}
pdf_set_usecmap(ctx, cmap, usecmap);
diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c
index a83cde09..56a54e5c 100644
--- a/pdf/pdf_colorspace.c
+++ b/pdf/pdf_colorspace.c
@@ -8,7 +8,7 @@ load_icc_based(fz_colorspace **csp, pdf_xref *xref, fz_obj *dict)
{
int n;
- n = fz_to_int(xref->ctx, fz_dict_gets(xref->ctx, dict, "N"));
+ n = fz_to_int(fz_dict_gets(dict, "N"));
switch (n)
{
@@ -96,15 +96,15 @@ load_separation(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
fz_colorspace *cs;
struct separation *sep;
fz_context *ctx = xref->ctx;
- fz_obj *nameobj = fz_array_get(ctx, array, 1);
- fz_obj *baseobj = fz_array_get(ctx, array, 2);
- fz_obj *tintobj = fz_array_get(ctx, array, 3);
+ fz_obj *nameobj = fz_array_get(array, 1);
+ fz_obj *baseobj = fz_array_get(array, 2);
+ fz_obj *tintobj = fz_array_get(array, 3);
fz_colorspace *base;
pdf_function *tint;
int n;
- if (fz_is_array(ctx, nameobj))
- n = fz_array_len(ctx, nameobj);
+ if (fz_is_array(nameobj))
+ n = fz_array_len(nameobj);
else
n = 1;
@@ -215,9 +215,9 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
fz_colorspace *cs;
struct indexed *idx;
fz_context *ctx = xref->ctx;
- fz_obj *baseobj = fz_array_get(ctx, array, 1);
- fz_obj *highobj = fz_array_get(ctx, array, 2);
- fz_obj *lookup = fz_array_get(ctx, array, 3);
+ fz_obj *baseobj = fz_array_get(array, 1);
+ fz_obj *highobj = fz_array_get(array, 2);
+ fz_obj *lookup = fz_array_get(array, 3);
fz_colorspace *base;
int i, n;
@@ -227,7 +227,7 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
idx = fz_malloc(ctx, sizeof(struct indexed));
idx->base = base;
- idx->high = fz_to_int(ctx, highobj);
+ idx->high = fz_to_int(highobj);
idx->high = CLAMP(idx->high, 0, 255);
n = base->n * (idx->high + 1);
idx->lookup = fz_calloc(ctx, 1, n);
@@ -237,9 +237,9 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
cs->free_data = free_indexed;
cs->data = idx;
- if (fz_is_string(ctx, lookup) && fz_to_str_len(ctx, lookup) == n)
+ if (fz_is_string(lookup) && fz_to_str_len(lookup) == n)
{
- unsigned char *buf = (unsigned char *) fz_to_str_buf(ctx, lookup);
+ unsigned char *buf = (unsigned char *) fz_to_str_buf(lookup);
for (i = 0; i < n; i++)
idx->lookup[i] = buf[i];
}
@@ -278,41 +278,39 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
static fz_error
pdf_load_colorspace_imp(fz_colorspace **csp, pdf_xref *xref, fz_obj *obj)
{
- fz_context *ctx = xref->ctx;
-
- if (fz_is_name(ctx, obj))
+ if (fz_is_name(obj))
{
- if (!strcmp(fz_to_name(ctx, obj), "Pattern"))
+ if (!strcmp(fz_to_name(obj), "Pattern"))
*csp = fz_device_gray;
- else if (!strcmp(fz_to_name(ctx, obj), "G"))
+ else if (!strcmp(fz_to_name(obj), "G"))
*csp = fz_device_gray;
- else if (!strcmp(fz_to_name(ctx, obj), "RGB"))
+ else if (!strcmp(fz_to_name(obj), "RGB"))
*csp = fz_device_rgb;
- else if (!strcmp(fz_to_name(ctx, obj), "CMYK"))
+ else if (!strcmp(fz_to_name(obj), "CMYK"))
*csp = fz_device_cmyk;
- else if (!strcmp(fz_to_name(ctx, obj), "DeviceGray"))
+ else if (!strcmp(fz_to_name(obj), "DeviceGray"))
*csp = fz_device_gray;
- else if (!strcmp(fz_to_name(ctx, obj), "DeviceRGB"))
+ else if (!strcmp(fz_to_name(obj), "DeviceRGB"))
*csp = fz_device_rgb;
- else if (!strcmp(fz_to_name(ctx, obj), "DeviceCMYK"))
+ else if (!strcmp(fz_to_name(obj), "DeviceCMYK"))
*csp = fz_device_cmyk;
else
- return fz_error_make("unknown colorspace: %s", fz_to_name(ctx, obj));
+ return fz_error_make("unknown colorspace: %s", fz_to_name(obj));
return fz_okay;
}
- else if (fz_is_array(ctx, obj))
+ else if (fz_is_array(obj))
{
- fz_obj *name = fz_array_get(ctx, obj, 0);
+ fz_obj *name = fz_array_get(obj, 0);
- if (fz_is_name(ctx, name))
+ if (fz_is_name(name))
{
/* load base colorspace instead */
- if (!strcmp(fz_to_name(ctx, name), "Pattern"))
+ if (!strcmp(fz_to_name(name), "Pattern"))
{
fz_error error;
- obj = fz_array_get(ctx, obj, 1);
+ obj = fz_array_get(obj, 1);
if (!obj)
{
*csp = fz_device_gray;
@@ -324,43 +322,43 @@ pdf_load_colorspace_imp(fz_colorspace **csp, pdf_xref *xref, fz_obj *obj)
return fz_error_note(error, "cannot load pattern (%d %d R)", fz_to_num(obj), fz_to_gen(obj));
}
- else if (!strcmp(fz_to_name(ctx, name), "G"))
+ else if (!strcmp(fz_to_name(name), "G"))
*csp = fz_device_gray;
- else if (!strcmp(fz_to_name(ctx, name), "RGB"))
+ else if (!strcmp(fz_to_name(name), "RGB"))
*csp = fz_device_rgb;
- else if (!strcmp(fz_to_name(ctx, name), "CMYK"))
+ else if (!strcmp(fz_to_name(name), "CMYK"))
*csp = fz_device_cmyk;
- else if (!strcmp(fz_to_name(ctx, name), "DeviceGray"))
+ else if (!strcmp(fz_to_name(name), "DeviceGray"))
*csp = fz_device_gray;
- else if (!strcmp(fz_to_name(ctx, name), "DeviceRGB"))
+ else if (!strcmp(fz_to_name(name), "DeviceRGB"))
*csp = fz_device_rgb;
- else if (!strcmp(fz_to_name(ctx, name), "DeviceCMYK"))
+ else if (!strcmp(fz_to_name(name), "DeviceCMYK"))
*csp = fz_device_cmyk;
- else if (!strcmp(fz_to_name(ctx, name), "CalGray"))
+ else if (!strcmp(fz_to_name(name), "CalGray"))
*csp = fz_device_gray;
- else if (!strcmp(fz_to_name(ctx, name), "CalRGB"))
+ else if (!strcmp(fz_to_name(name), "CalRGB"))
*csp = fz_device_rgb;
- else if (!strcmp(fz_to_name(ctx, name), "CalCMYK"))
+ else if (!strcmp(fz_to_name(name), "CalCMYK"))
*csp = fz_device_cmyk;
- else if (!strcmp(fz_to_name(ctx, name), "Lab"))
+ else if (!strcmp(fz_to_name(name), "Lab"))
*csp = fz_device_lab;
- else if (!strcmp(fz_to_name(ctx, name), "ICCBased"))
- return load_icc_based(csp, xref, fz_array_get(ctx, obj, 1));
+ else if (!strcmp(fz_to_name(name), "ICCBased"))
+ return load_icc_based(csp, xref, fz_array_get(obj, 1));
- else if (!strcmp(fz_to_name(ctx, name), "Indexed"))
+ else if (!strcmp(fz_to_name(name), "Indexed"))
return load_indexed(csp, xref, obj);
- else if (!strcmp(fz_to_name(ctx, name), "I"))
+ else if (!strcmp(fz_to_name(name), "I"))
return load_indexed(csp, xref, obj);
- else if (!strcmp(fz_to_name(ctx, name), "Separation"))
+ else if (!strcmp(fz_to_name(name), "Separation"))
return load_separation(csp, xref, obj);
- else if (!strcmp(fz_to_name(ctx, name), "DeviceN"))
+ else if (!strcmp(fz_to_name(name), "DeviceN"))
return load_separation(csp, xref, obj);
else
- return fz_error_make("syntaxerror: unknown colorspace %s", fz_to_name(ctx, name));
+ return fz_error_make("syntaxerror: unknown colorspace %s", fz_to_name(name));
return fz_okay;
}
diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c
index 81f3781a..7d5b7902 100644
--- a/pdf/pdf_crypt.c
+++ b/pdf/pdf_crypt.c
@@ -54,26 +54,27 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
fz_error error;
fz_obj *obj;
- crypt = fz_calloc(ctx, 1, sizeof(pdf_crypt));
+ crypt = fz_malloc(ctx, sizeof(pdf_crypt));
+ memset(crypt, 0, sizeof *crypt);
/* Common to all security handlers (PDF 1.7 table 3.18) */
- obj = fz_dict_gets(ctx, dict, "Filter");
- if (!fz_is_name(ctx, obj))
+ obj = fz_dict_gets(dict, "Filter");
+ if (!fz_is_name(obj))
{
pdf_free_crypt(ctx, crypt);
return fz_error_make("unspecified encryption handler");
}
- if (strcmp(fz_to_name(ctx, obj), "Standard") != 0)
+ if (strcmp(fz_to_name(obj), "Standard") != 0)
{
pdf_free_crypt(ctx, crypt);
- return fz_error_make("unknown encryption handler: '%s'", fz_to_name(ctx, obj));
+ return fz_error_make("unknown encryption handler: '%s'", fz_to_name(obj));
}
crypt->v = 0;
- obj = fz_dict_gets(ctx, dict, "V");
- if (fz_is_int(ctx, obj))
- crypt->v = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "V");
+ if (fz_is_int(obj))
+ crypt->v = fz_to_int(obj);
if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4 && crypt->v != 5)
{
pdf_free_crypt(ctx, crypt);
@@ -83,9 +84,9 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
crypt->length = 40;
if (crypt->v == 2 || crypt->v == 4)
{
- obj = fz_dict_gets(ctx, dict, "Length");
- if (fz_is_int(ctx, obj))
- crypt->length = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "Length");
+ if (fz_is_int(obj))
+ crypt->length = fz_to_int(obj);
/* work-around for pdf generators that assume length is in bytes */
if (crypt->length < 40)
@@ -123,8 +124,8 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
crypt->strf.method = PDF_CRYPT_NONE;
crypt->strf.length = crypt->length;
- obj = fz_dict_gets(ctx, dict, "CF");
- if (fz_is_dict(ctx, obj))
+ obj = fz_dict_gets(dict, "CF");
+ if (fz_is_dict(obj))
{
crypt->cf = fz_keep_obj(obj);
}
@@ -133,10 +134,10 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
crypt->cf = NULL;
}
- obj = fz_dict_gets(ctx, dict, "StmF");
- if (fz_is_name(ctx, obj))
+ obj = fz_dict_gets(dict, "StmF");
+ if (fz_is_name(obj))
{
- error = pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt->cf, fz_to_name(ctx, obj), crypt->length);
+ error = pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt->cf, fz_to_name(obj), crypt->length);
if (error)
{
pdf_free_crypt(ctx, crypt);
@@ -144,10 +145,10 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
}
}
- obj = fz_dict_gets(ctx, dict, "StrF");
- if (fz_is_name(ctx, obj))
+ obj = fz_dict_gets(dict, "StrF");
+ if (fz_is_name(obj))
{
- error = pdf_parse_crypt_filter(ctx, &crypt->strf, crypt->cf, fz_to_name(ctx, obj), crypt->length);
+ error = pdf_parse_crypt_filter(ctx, &crypt->strf, crypt->cf, fz_to_name(obj), crypt->length);
if (error)
{
pdf_free_crypt(ctx, crypt);
@@ -162,36 +163,36 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
/* Standard security handler (PDF 1.7 table 3.19) */
- obj = fz_dict_gets(ctx, dict, "R");
- if (fz_is_int(ctx, obj))
- crypt->r = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "R");
+ if (fz_is_int(obj))
+ crypt->r = fz_to_int(obj);
else
{
pdf_free_crypt(ctx, crypt);
return fz_error_make("encryption dictionary missing revision value");
}
- obj = fz_dict_gets(ctx, dict, "O");
- if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) == 32)
- memcpy(crypt->o, fz_to_str_buf(ctx, obj), 32);
+ obj = fz_dict_gets(dict, "O");
+ if (fz_is_string(obj) && fz_to_str_len(obj) == 32)
+ memcpy(crypt->o, fz_to_str_buf(obj), 32);
/* /O and /U are supposed to be 48 bytes long for revision 5, they're often longer, though */
- else if (crypt->r == 5 && fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) >= 48)
- memcpy(crypt->o, fz_to_str_buf(ctx, obj), 48);
+ else if (crypt->r == 5 && fz_is_string(obj) && fz_to_str_len(obj) >= 48)
+ memcpy(crypt->o, fz_to_str_buf(obj), 48);
else
{
pdf_free_crypt(ctx, crypt);
return fz_error_make("encryption dictionary missing owner password");
}
- obj = fz_dict_gets(ctx, dict, "U");
- if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) == 32)
- memcpy(crypt->u, fz_to_str_buf(ctx, obj), 32);
- else if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) >= 48 && crypt->r == 5)
- memcpy(crypt->u, fz_to_str_buf(ctx, obj), 48);
- else if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) < 32)
+ obj = fz_dict_gets(dict, "U");
+ if (fz_is_string(obj) && fz_to_str_len(obj) == 32)
+ memcpy(crypt->u, fz_to_str_buf(obj), 32);
+ else if (fz_is_string(obj) && fz_to_str_len(obj) >= 48 && crypt->r == 5)
+ memcpy(crypt->u, fz_to_str_buf(obj), 48);
+ else if (fz_is_string(obj) && fz_to_str_len(obj) < 32)
{
- fz_warn("encryption password key too short (%d)", fz_to_str_len(ctx, obj));
- memcpy(crypt->u, fz_to_str_buf(ctx, obj), fz_to_str_len(ctx, obj));
+ fz_warn("encryption password key too short (%d)", fz_to_str_len(obj));
+ memcpy(crypt->u, fz_to_str_buf(obj), fz_to_str_len(obj));
}
else
{
@@ -199,9 +200,9 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
return fz_error_make("encryption dictionary missing user password");
}
- obj = fz_dict_gets(ctx, dict, "P");
- if (fz_is_int(ctx, obj))
- crypt->p = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "P");
+ if (fz_is_int(obj))
+ crypt->p = fz_to_int(obj);
else
{
pdf_free_crypt(ctx, crypt);
@@ -210,34 +211,34 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
if (crypt->r == 5)
{
- obj = fz_dict_gets(ctx, dict, "OE");
- if (!fz_is_string(ctx, obj) || fz_to_str_len(ctx, obj) != 32)
+ obj = fz_dict_gets(dict, "OE");
+ if (!fz_is_string(obj) || fz_to_str_len(obj) != 32)
{
pdf_free_crypt(ctx, crypt);
return fz_error_make("encryption dictionary missing owner encryption key");
}
- memcpy(crypt->oe, fz_to_str_buf(ctx, obj), 32);
+ memcpy(crypt->oe, fz_to_str_buf(obj), 32);
- obj = fz_dict_gets(ctx, dict, "UE");
- if (!fz_is_string(ctx, obj) || fz_to_str_len(ctx, obj) != 32)
+ obj = fz_dict_gets(dict, "UE");
+ if (!fz_is_string(obj) || fz_to_str_len(obj) != 32)
{
pdf_free_crypt(ctx, crypt);
return fz_error_make("encryption dictionary missing user encryption key");
}
- memcpy(crypt->ue, fz_to_str_buf(ctx, obj), 32);
+ memcpy(crypt->ue, fz_to_str_buf(obj), 32);
}
crypt->encrypt_metadata = 1;
- obj = fz_dict_gets(ctx, dict, "EncryptMetadata");
- if (fz_is_bool(ctx, obj))
- crypt->encrypt_metadata = fz_to_bool(ctx, obj);
+ obj = fz_dict_gets(dict, "EncryptMetadata");
+ if (fz_is_bool(obj))
+ crypt->encrypt_metadata = fz_to_bool(obj);
/* Extract file identifier string */
- if (fz_is_array(ctx, id) && fz_array_len(ctx, id) == 2)
+ if (fz_is_array(id) && fz_array_len(id) == 2)
{
- obj = fz_array_get(ctx, id, 0);
- if (fz_is_string(ctx, obj))
+ obj = fz_array_get(id, 0);
+ if (fz_is_string(obj))
crypt->id = fz_keep_obj(obj);
}
else
@@ -250,8 +251,8 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id)
void
pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt)
{
- if (crypt->id) fz_drop_obj(ctx, crypt->id);
- if (crypt->cf) fz_drop_obj(ctx, crypt->cf);
+ if (crypt->id) fz_drop_obj(crypt->id);
+ if (crypt->cf) fz_drop_obj(crypt->cf);
fz_free(ctx, crypt);
}
@@ -280,29 +281,29 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, fz_obj *cf_obj, ch
return fz_okay;
}
- dict = fz_dict_gets(ctx, cf_obj, name);
- if (!fz_is_dict(ctx, dict))
+ dict = fz_dict_gets(cf_obj, name);
+ if (!fz_is_dict(dict))
{
return fz_error_make("cannot parse crypt filter (%d %d R)", fz_to_num(cf_obj), fz_to_gen(cf_obj));
}
- obj = fz_dict_gets(ctx, dict, "CFM");
- if (fz_is_name(ctx, obj))
+ obj = fz_dict_gets(dict, "CFM");
+ if (fz_is_name(obj))
{
- if (!strcmp(fz_to_name(ctx, obj), "None"))
+ if (!strcmp(fz_to_name(obj), "None"))
cf->method = PDF_CRYPT_NONE;
- else if (!strcmp(fz_to_name(ctx, obj), "V2"))
+ else if (!strcmp(fz_to_name(obj), "V2"))
cf->method = PDF_CRYPT_RC4;
- else if (!strcmp(fz_to_name(ctx, obj), "AESV2"))
+ else if (!strcmp(fz_to_name(obj), "AESV2"))
cf->method = PDF_CRYPT_AESV2;
- else if (!strcmp(fz_to_name(ctx, obj), "AESV3"))
+ else if (!strcmp(fz_to_name(obj), "AESV3"))
cf->method = PDF_CRYPT_AESV3;
else
- fz_error_make("unknown encryption method: %s", fz_to_name(ctx, obj));
+ fz_error_make("unknown encryption method: %s", fz_to_name(obj));
}
- obj = fz_dict_gets(ctx, dict, "Length");
- if (fz_is_int(ctx, obj))
- cf->length = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "Length");
+ if (fz_is_int(obj))
+ cf->length = fz_to_int(obj);
/* the length for crypt filters is supposed to be in bytes not bits */
if (cf->length < 40)
@@ -358,7 +359,7 @@ pdf_compute_encryption_key(pdf_crypt *crypt, unsigned char *password, int pwlen,
fz_md5_update(&md5, buf, 4);
/* Step 5 - pass first element of ID array */
- fz_md5_update(&md5, (unsigned char *)fz_to_str_buf(crypt->ctx, crypt->id), fz_to_str_len(crypt->ctx, crypt->id));
+ fz_md5_update(&md5, (unsigned char *)fz_to_str_buf(crypt->id), fz_to_str_len(crypt->id));
/* Step 6 (revision 4 or greater) - if metadata is not encrypted pass 0xFFFFFFFF */
if (crypt->r >= 4)
@@ -467,7 +468,7 @@ pdf_compute_user_password(pdf_crypt *crypt, unsigned char *password, int pwlen,
fz_md5_init(&md5);
fz_md5_update(&md5, padding, 32);
- fz_md5_update(&md5, (unsigned char*)fz_to_str_buf(crypt->ctx, crypt->id), fz_to_str_len(crypt->ctx, crypt->id));
+ fz_md5_update(&md5, (unsigned char*)fz_to_str_buf(crypt->id), fz_to_str_len(crypt->id));
fz_md5_final(&md5, digest);
fz_arc4_init(&arc4, crypt->key, n);
@@ -715,10 +716,10 @@ pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, unsigned char
if (fz_is_indirect(obj))
return;
- if (fz_is_string(ctx, obj))
+ if (fz_is_string(obj))
{
- s = (unsigned char *)fz_to_str_buf(ctx, obj);
- n = fz_to_str_len(ctx, obj);
+ s = (unsigned char *)fz_to_str_buf(obj);
+ n = fz_to_str_len(obj);
if (crypt->strf.method == PDF_CRYPT_RC4)
{
@@ -742,26 +743,26 @@ pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, unsigned char
if (s[n - 17] < 1 || s[n - 17] > 16)
fz_warn("aes padding out of range");
else
- fz_set_str_len(ctx, obj, n - 16 - s[n - 17]);
+ fz_set_str_len(obj, n - 16 - s[n - 17]);
}
}
}
- else if (fz_is_array(ctx, obj))
+ else if (fz_is_array(obj))
{
- n = fz_array_len(ctx, obj);
+ n = fz_array_len(obj);
for (i = 0; i < n; i++)
{
- pdf_crypt_obj_imp(ctx, crypt, fz_array_get(ctx, obj, i), key, keylen);
+ pdf_crypt_obj_imp(ctx, crypt, fz_array_get(obj, i), key, keylen);
}
}
- else if (fz_is_dict(ctx, obj))
+ else if (fz_is_dict(obj))
{
- n = fz_dict_len(ctx, obj);
+ n = fz_dict_len(obj);
for (i = 0; i < n; i++)
{
- pdf_crypt_obj_imp(ctx, crypt, fz_dict_get_val(ctx, obj, i), key, keylen);
+ pdf_crypt_obj_imp(ctx, crypt, fz_dict_get_val(obj, i), key, keylen);
}
}
}
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index 3b8322db..ad5b8d97 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -413,14 +413,14 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict)
int fterr;
fz_context *ctx = xref->ctx;
- basefont = fz_to_name(ctx, fz_dict_gets(ctx, dict, "BaseFont"));
+ basefont = fz_to_name(fz_dict_gets(dict, "BaseFont"));
fontname = clean_font_name(basefont);
/* Load font file */
fontdesc = pdf_new_font_desc(ctx);
- descriptor = fz_dict_gets(ctx, dict, "FontDescriptor");
+ descriptor = fz_dict_gets(dict, "FontDescriptor");
if (descriptor)
error = pdf_load_font_descriptor(fontdesc, xref, descriptor, NULL, basefont);
else
@@ -430,9 +430,9 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict)
/* Some chinese documents mistakenly consider WinAnsiEncoding to be codepage 936 */
if (!*fontdesc->font->name &&
- !fz_dict_gets(ctx, dict, "ToUnicode") &&
- !strcmp(fz_to_name(ctx, fz_dict_gets(ctx, dict, "Encoding")), "WinAnsiEncoding") &&
- fz_to_int(ctx, fz_dict_gets(ctx, descriptor, "Flags")) == 4)
+ !fz_dict_gets(dict, "ToUnicode") &&
+ !strcmp(fz_to_name(fz_dict_gets(dict, "Encoding")), "WinAnsiEncoding") &&
+ fz_to_int(fz_dict_gets(descriptor, "Flags")) == 4)
{
/* note: without the comma, pdf_load_font_descriptor would prefer /FontName over /BaseFont */
char *cp936fonts[] = {
@@ -511,34 +511,34 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict)
etable[i] = 0;
}
- encoding = fz_dict_gets(ctx, dict, "Encoding");
+ encoding = fz_dict_gets(dict, "Encoding");
if (encoding)
{
- if (fz_is_name(ctx, encoding))
- pdf_load_encoding(estrings, fz_to_name(ctx, encoding));
+ if (fz_is_name(encoding))
+ pdf_load_encoding(estrings, fz_to_name(encoding));
- if (fz_is_dict(ctx, encoding))
+ if (fz_is_dict(encoding))
{
fz_obj *base, *diff, *item;
- base = fz_dict_gets(ctx, encoding, "BaseEncoding");
- if (fz_is_name(ctx, base))
- pdf_load_encoding(estrings, fz_to_name(ctx, base));
+ base = fz_dict_gets(encoding, "BaseEncoding");
+ if (fz_is_name(base))
+ pdf_load_encoding(estrings, fz_to_name(base));
else if (!fontdesc->is_embedded && !symbolic)
pdf_load_encoding(estrings, "StandardEncoding");
- diff = fz_dict_gets(ctx, encoding, "Differences");
- if (fz_is_array(ctx, diff))
+ diff = fz_dict_gets(encoding, "Differences");
+ if (fz_is_array(diff))
{
- n = fz_array_len(ctx, diff);
+ n = fz_array_len(diff);
k = 0;
for (i = 0; i < n; i++)
{
- item = fz_array_get(ctx, diff, i);
- if (fz_is_int(ctx, item))
- k = fz_to_int(ctx, item);
- if (fz_is_name(ctx, item))
- estrings[k++] = fz_to_name(ctx, item);
+ item = fz_array_get(diff, i);
+ if (fz_is_int(item))
+ k = fz_to_int(item);
+ if (fz_is_name(item))
+ estrings[k++] = fz_to_name(item);
if (k < 0) k = 0;
if (k > 255) k = 255;
}
@@ -648,7 +648,7 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict)
fontdesc->cid_to_gid_len = 256;
fontdesc->cid_to_gid = etable;
- error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(ctx, dict, "ToUnicode"));
+ error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(dict, "ToUnicode"));
if (error)
fz_error_handle(error, "cannot load to_unicode");
@@ -658,20 +658,20 @@ skip_encoding:
pdf_set_default_hmtx(fontdesc, fontdesc->missing_width);
- widths = fz_dict_gets(ctx, dict, "Widths");
+ widths = fz_dict_gets(dict, "Widths");
if (widths)
{
int first, last;
- first = fz_to_int(ctx, fz_dict_gets(ctx, dict, "FirstChar"));
- last = fz_to_int(ctx, fz_dict_gets(ctx, dict, "LastChar"));
+ first = fz_to_int(fz_dict_gets(dict, "FirstChar"));
+ last = fz_to_int(fz_dict_gets(dict, "LastChar"));
if (first < 0 || last > 255 || first > last)
first = last = 0;
for (i = 0; i < last - first + 1; i++)
{
- int wid = fz_to_int(ctx, fz_array_get(ctx, widths, i));
+ int wid = fz_to_int(fz_array_get(widths, i));
pdf_add_hmtx(ctx, fontdesc, i + first, i + first, wid);
}
}
@@ -720,28 +720,28 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e
/* Get font name and CID collection */
- basefont = fz_to_name(ctx, fz_dict_gets(ctx, dict, "BaseFont"));
+ basefont = fz_to_name(fz_dict_gets(dict, "BaseFont"));
{
fz_obj *cidinfo;
char tmpstr[64];
int tmplen;
- cidinfo = fz_dict_gets(ctx, dict, "CIDSystemInfo");
+ cidinfo = fz_dict_gets(dict, "CIDSystemInfo");
if (!cidinfo)
return fz_error_make("cid font is missing info");
- obj = fz_dict_gets(ctx, cidinfo, "Registry");
- tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(ctx, obj));
- memcpy(tmpstr, fz_to_str_buf(ctx, obj), tmplen);
+ obj = fz_dict_gets(cidinfo, "Registry");
+ tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(obj));
+ memcpy(tmpstr, fz_to_str_buf(obj), tmplen);
tmpstr[tmplen] = '\0';
fz_strlcpy(collection, tmpstr, sizeof collection);
fz_strlcat(collection, "-", sizeof collection);
- obj = fz_dict_gets(ctx, cidinfo, "Ordering");
- tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(ctx, obj));
- memcpy(tmpstr, fz_to_str_buf(ctx, obj), tmplen);
+ obj = fz_dict_gets(cidinfo, "Ordering");
+ tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(obj));
+ memcpy(tmpstr, fz_to_str_buf(obj), tmplen);
tmpstr[tmplen] = '\0';
fz_strlcat(collection, tmpstr, sizeof collection);
}
@@ -750,7 +750,7 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e
fontdesc = pdf_new_font_desc(ctx);
- descriptor = fz_dict_gets(ctx, dict, "FontDescriptor");
+ descriptor = fz_dict_gets(dict, "FontDescriptor");
if (descriptor)
error = pdf_load_font_descriptor(fontdesc, xref, descriptor, collection, basefont);
else
@@ -764,14 +764,14 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e
/* Encoding */
error = fz_okay;
- if (fz_is_name(ctx, encoding))
+ if (fz_is_name(encoding))
{
- if (!strcmp(fz_to_name(ctx, encoding), "Identity-H"))
+ if (!strcmp(fz_to_name(encoding), "Identity-H"))
fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 2);
- else if (!strcmp(fz_to_name(ctx, encoding), "Identity-V"))
+ else if (!strcmp(fz_to_name(encoding), "Identity-V"))
fontdesc->encoding = pdf_new_identity_cmap(ctx, 1, 2);
else
- error = pdf_load_system_cmap(ctx, &fontdesc->encoding, fz_to_name(ctx, encoding));
+ error = pdf_load_system_cmap(ctx, &fontdesc->encoding, fz_to_name(encoding));
}
else if (fz_is_indirect(encoding))
{
@@ -790,7 +790,7 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e
{
fz_obj *cidtogidmap;
- cidtogidmap = fz_dict_gets(ctx, dict, "CIDToGIDMap");
+ cidtogidmap = fz_dict_gets(dict, "CIDToGIDMap");
if (fz_is_indirect(cidtogidmap))
{
fz_buffer *buf;
@@ -847,35 +847,35 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e
/* Horizontal */
dw = 1000;
- obj = fz_dict_gets(ctx, dict, "DW");
+ obj = fz_dict_gets(dict, "DW");
if (obj)
- dw = fz_to_int(ctx, obj);
+ dw = fz_to_int(obj);
pdf_set_default_hmtx(fontdesc, dw);
- widths = fz_dict_gets(ctx, dict, "W");
+ widths = fz_dict_gets(dict, "W");
if (widths)
{
int c0, c1, w, n, m;
- n = fz_array_len(ctx, widths);
+ n = fz_array_len(widths);
for (i = 0; i < n; )
{
- c0 = fz_to_int(ctx, fz_array_get(ctx, widths, i));
- obj = fz_array_get(ctx, widths, i + 1);
- if (fz_is_array(ctx, obj))
+ c0 = fz_to_int(fz_array_get(widths, i));
+ obj = fz_array_get(widths, i + 1);
+ if (fz_is_array(obj))
{
- m = fz_array_len(ctx, obj);
+ m = fz_array_len(obj);
for (k = 0; k < m; k++)
{
- w = fz_to_int(ctx, fz_array_get(ctx, obj, k));
+ w = fz_to_int(fz_array_get(obj, k));
pdf_add_hmtx(ctx, fontdesc, c0 + k, c0 + k, w);
}
i += 2;
}
else
{
- c1 = fz_to_int(ctx, obj);
- w = fz_to_int(ctx, fz_array_get(ctx, widths, i + 2));
+ c1 = fz_to_int(obj);
+ w = fz_to_int(fz_array_get(widths, i + 2));
pdf_add_hmtx(ctx, fontdesc, c0, c1, w);
i += 3;
}
@@ -891,43 +891,43 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e
int dw2y = 880;
int dw2w = -1000;
- obj = fz_dict_gets(ctx, dict, "DW2");
+ obj = fz_dict_gets(dict, "DW2");
if (obj)
{
- dw2y = fz_to_int(ctx, fz_array_get(ctx, obj, 0));
- dw2w = fz_to_int(ctx, fz_array_get(ctx, obj, 1));
+ dw2y = fz_to_int(fz_array_get(obj, 0));
+ dw2w = fz_to_int(fz_array_get(obj, 1));
}
pdf_set_default_vmtx(fontdesc, dw2y, dw2w);
- widths = fz_dict_gets(ctx, dict, "W2");
+ widths = fz_dict_gets(dict, "W2");
if (widths)
{
int c0, c1, w, x, y, n;
- n = fz_array_len(ctx, widths);
+ n = fz_array_len(widths);
for (i = 0; i < n; )
{
- c0 = fz_to_int(ctx, fz_array_get(ctx, widths, i));
- obj = fz_array_get(ctx, widths, i + 1);
- if (fz_is_array(ctx, obj))
+ c0 = fz_to_int(fz_array_get(widths, i));
+ obj = fz_array_get(widths, i + 1);
+ if (fz_is_array(obj))
{
- int m = fz_array_len(ctx, obj);
+ int m = fz_array_len(obj);
for (k = 0; k * 3 < m; k ++)
{
- w = fz_to_int(ctx, fz_array_get(ctx, obj, k * 3 + 0));
- x = fz_to_int(ctx, fz_array_get(ctx, obj, k * 3 + 1));
- y = fz_to_int(ctx, fz_array_get(ctx, obj, k * 3 + 2));
+ w = fz_to_int(fz_array_get(obj, k * 3 + 0));
+ x = fz_to_int(fz_array_get(obj, k * 3 + 1));
+ y = fz_to_int(fz_array_get(obj, k * 3 + 2));
pdf_add_vmtx(ctx, fontdesc, c0 + k, c0 + k, x, y, w);
}
i += 2;
}
else
{
- c1 = fz_to_int(ctx, obj);
- w = fz_to_int(ctx, fz_array_get(ctx, widths, i + 2));
- x = fz_to_int(ctx, fz_array_get(ctx, widths, i + 3));
- y = fz_to_int(ctx, fz_array_get(ctx, widths, i + 4));
+ c1 = fz_to_int(obj);
+ w = fz_to_int(fz_array_get(widths, i + 2));
+ x = fz_to_int(fz_array_get(widths, i + 3));
+ y = fz_to_int(fz_array_get(widths, i + 4));
pdf_add_vmtx(ctx, fontdesc, c0, c1, x, y, w);
i += 5;
}
@@ -954,21 +954,20 @@ pdf_load_type0_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict)
fz_obj *subtype;
fz_obj *encoding;
fz_obj *to_unicode;
- fz_context *ctx = xref->ctx;
- dfonts = fz_dict_gets(ctx, dict, "DescendantFonts");
+ dfonts = fz_dict_gets(dict, "DescendantFonts");
if (!dfonts)
return fz_error_make("cid font is missing descendant fonts");
- dfont = fz_array_get(ctx, dfonts, 0);
+ dfont = fz_array_get(dfonts, 0);
- subtype = fz_dict_gets(ctx, dfont, "Subtype");
- encoding = fz_dict_gets(ctx, dict, "Encoding");
- to_unicode = fz_dict_gets(ctx, dict, "ToUnicode");
+ subtype = fz_dict_gets(dfont, "Subtype");
+ encoding = fz_dict_gets(dict, "Encoding");
+ to_unicode = fz_dict_gets(dict, "ToUnicode");
- if (fz_is_name(ctx, subtype) && !strcmp(fz_to_name(ctx, subtype), "CIDFontType0"))
+ if (fz_is_name(subtype) && !strcmp(fz_to_name(subtype), "CIDFontType0"))
error = load_cid_font(fontdescp, xref, dfont, encoding, to_unicode);
- else if (fz_is_name(ctx, subtype) && !strcmp(fz_to_name(ctx, subtype), "CIDFontType2"))
+ else if (fz_is_name(subtype) && !strcmp(fz_to_name(subtype), "CIDFontType2"))
error = load_cid_font(fontdescp, xref, dfont, encoding, to_unicode);
else
error = fz_error_make("syntaxerror: unknown cid font type");
@@ -993,22 +992,22 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *dict,
fz_context *ctx = xref->ctx;
if (!strchr(basefont, ',') || strchr(basefont, '+'))
- origname = fz_to_name(ctx, fz_dict_gets(ctx, dict, "FontName"));
+ origname = fz_to_name(fz_dict_gets(dict, "FontName"));
else
origname = basefont;
fontname = clean_font_name(origname);
- fontdesc->flags = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Flags"));
- fontdesc->italic_angle = fz_to_real(ctx, fz_dict_gets(ctx, dict, "ItalicAngle"));
- fontdesc->ascent = fz_to_real(ctx, fz_dict_gets(ctx, dict, "Ascent"));
- fontdesc->descent = fz_to_real(ctx, fz_dict_gets(ctx, dict, "Descent"));
- fontdesc->cap_height = fz_to_real(ctx, fz_dict_gets(ctx, dict, "CapHeight"));
- fontdesc->x_height = fz_to_real(ctx, fz_dict_gets(ctx, dict, "XHeight"));
- fontdesc->missing_width = fz_to_real(ctx, fz_dict_gets(ctx, dict, "MissingWidth"));
-
- obj1 = fz_dict_gets(ctx, dict, "FontFile");
- obj2 = fz_dict_gets(ctx, dict, "FontFile2");
- obj3 = fz_dict_gets(ctx, dict, "FontFile3");
+ fontdesc->flags = fz_to_int(fz_dict_gets(dict, "Flags"));
+ fontdesc->italic_angle = fz_to_real(fz_dict_gets(dict, "ItalicAngle"));
+ fontdesc->ascent = fz_to_real(fz_dict_gets(dict, "Ascent"));
+ fontdesc->descent = fz_to_real(fz_dict_gets(dict, "Descent"));
+ fontdesc->cap_height = fz_to_real(fz_dict_gets(dict, "CapHeight"));
+ fontdesc->x_height = fz_to_real(fz_dict_gets(dict, "XHeight"));
+ fontdesc->missing_width = fz_to_real(fz_dict_gets(dict, "MissingWidth"));
+
+ obj1 = fz_dict_gets(dict, "FontFile");
+ obj2 = fz_dict_gets(dict, "FontFile2");
+ obj3 = fz_dict_gets(dict, "FontFile3");
obj = obj1 ? obj1 : obj2 ? obj2 : obj3;
if (fz_is_indirect(obj))
@@ -1097,9 +1096,9 @@ pdf_load_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_obj *di
return fz_okay;
}
- subtype = fz_to_name(ctx, fz_dict_gets(ctx, dict, "Subtype"));
- dfonts = fz_dict_gets(ctx, dict, "DescendantFonts");
- charprocs = fz_dict_gets(ctx, dict, "CharProcs");
+ subtype = fz_to_name(fz_dict_gets(dict, "Subtype"));
+ dfonts = fz_dict_gets(dict, "DescendantFonts");
+ charprocs = fz_dict_gets(dict, "CharProcs");
if (subtype && !strcmp(subtype, "Type0"))
error = pdf_load_type0_font(fontdescp, xref, dict);
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 3905f75e..7ab681c3 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -906,26 +906,26 @@ load_sample_func(pdf_function *func, pdf_xref *xref, fz_obj *dict, int num, int
func->u.sa.samples = NULL;
- obj = fz_dict_gets(ctx, dict, "Size");
- if (!fz_is_array(ctx, obj) || fz_array_len(ctx, obj) != func->m)
+ obj = fz_dict_gets(dict, "Size");
+ if (!fz_is_array(obj) || fz_array_len(obj) != func->m)
return fz_error_make("malformed /Size");
for (i = 0; i < func->m; i++)
- func->u.sa.size[i] = fz_to_int(ctx, fz_array_get(ctx, obj, i));
+ func->u.sa.size[i] = fz_to_int(fz_array_get(obj, i));
- obj = fz_dict_gets(ctx, dict, "BitsPerSample");
- if (!fz_is_int(ctx, obj))
+ obj = fz_dict_gets(dict, "BitsPerSample");
+ if (!fz_is_int(obj))
return fz_error_make("malformed /BitsPerSample");
- func->u.sa.bps = bps = fz_to_int(ctx, obj);
+ func->u.sa.bps = bps = fz_to_int(obj);
- obj = fz_dict_gets(ctx, dict, "Encode");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "Encode");
+ if (fz_is_array(obj))
{
- if (fz_array_len(ctx, obj) != func->m * 2)
+ if (fz_array_len(obj) != func->m * 2)
return fz_error_make("malformed /Encode");
for (i = 0; i < func->m; i++)
{
- func->u.sa.encode[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+0));
- func->u.sa.encode[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+1));
+ func->u.sa.encode[i][0] = fz_to_real(fz_array_get(obj, i*2+0));
+ func->u.sa.encode[i][1] = fz_to_real(fz_array_get(obj, i*2+1));
}
}
else
@@ -937,15 +937,15 @@ load_sample_func(pdf_function *func, pdf_xref *xref, fz_obj *dict, int num, int
}
}
- obj = fz_dict_gets(ctx, dict, "Decode");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "Decode");
+ if (fz_is_array(obj))
{
- if (fz_array_len(ctx, obj) != func->n * 2)
+ if (fz_array_len(obj) != func->n * 2)
return fz_error_make("malformed /Decode");
for (i = 0; i < func->n; i++)
{
- func->u.sa.decode[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+0));
- func->u.sa.decode[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+1));
+ func->u.sa.decode[i][0] = fz_to_real(fz_array_get(obj, i*2+0));
+ func->u.sa.decode[i][1] = fz_to_real(fz_array_get(obj, i*2+1));
}
}
else
@@ -1116,19 +1116,19 @@ load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict)
if (func->m != 1)
return fz_error_make("/Domain must be one dimension (%d)", func->m);
- obj = fz_dict_gets(ctx, dict, "N");
- if (!fz_is_int(ctx, obj) && !fz_is_real(ctx, obj))
+ obj = fz_dict_gets(dict, "N");
+ if (!fz_is_int(obj) && !fz_is_real(obj))
return fz_error_make("malformed /N");
- func->u.e.n = fz_to_real(ctx, obj);
+ func->u.e.n = fz_to_real(obj);
- obj = fz_dict_gets(ctx, dict, "C0");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "C0");
+ if (fz_is_array(obj))
{
- func->n = fz_array_len(ctx, obj);
+ func->n = fz_array_len(obj);
if (func->n >= MAXN)
return fz_error_make("exponential function result array out of range");
for (i = 0; i < func->n; i++)
- func->u.e.c0[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i));
+ func->u.e.c0[i] = fz_to_real(fz_array_get(obj, i));
}
else
{
@@ -1136,13 +1136,13 @@ load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict)
func->u.e.c0[0] = 0;
}
- obj = fz_dict_gets(ctx, dict, "C1");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "C1");
+ if (fz_is_array(obj))
{
- if (fz_array_len(ctx, obj) != func->n)
+ if (fz_array_len(obj) != func->n)
return fz_error_make("/C1 must match /C0 length");
for (i = 0; i < func->n; i++)
- func->u.e.c1[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i));
+ func->u.e.c1[i] = fz_to_real(fz_array_get(obj, i));
}
else
{
@@ -1200,11 +1200,11 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict)
if (func->m != 1)
return fz_error_make("/Domain must be one dimension (%d)", func->m);
- obj = fz_dict_gets(ctx, dict, "Functions");
- if (!fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "Functions");
+ if (!fz_is_array(obj))
return fz_error_make("stitching function has no input functions");
{
- k = fz_array_len(ctx, obj);
+ k = fz_array_len(obj);
func->u.st.funcs = fz_calloc(ctx, k, sizeof(pdf_function*));
func->u.st.bounds = fz_calloc(ctx, k - 1, sizeof(float));
@@ -1213,7 +1213,7 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict)
for (i = 0; i < k; i++)
{
- sub = fz_array_get(ctx, obj, i);
+ sub = fz_array_get(obj, i);
error = pdf_load_function(&funcs[i], xref, sub);
if (error)
return fz_error_note(error, "cannot load sub function %d (%d %d R)", i, fz_to_num(sub), fz_to_gen(sub));
@@ -1228,19 +1228,19 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict)
return fz_error_make("sub function /Domain or /Range mismatch");
}
- obj = fz_dict_gets(ctx, dict, "Bounds");
- if (!fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "Bounds");
+ if (!fz_is_array(obj))
return fz_error_make("stitching function has no bounds");
{
- if (!fz_is_array(ctx, obj) || fz_array_len(ctx, obj) != k - 1)
+ if (!fz_is_array(obj) || fz_array_len(obj) != k - 1)
return fz_error_make("malformed /Bounds (not array or wrong length)");
for (i = 0; i < k-1; i++)
{
- num = fz_array_get(ctx, obj, i);
- if (!fz_is_int(ctx, num) && !fz_is_real(ctx, num))
+ num = fz_array_get(obj, i);
+ if (!fz_is_int(num) && !fz_is_real(num))
return fz_error_make("malformed /Bounds (item not real)");
- func->u.st.bounds[i] = fz_to_real(ctx, num);
+ func->u.st.bounds[i] = fz_to_real(num);
if (i && func->u.st.bounds[i-1] > func->u.st.bounds[i])
return fz_error_make("malformed /Bounds (item not monotonic)");
}
@@ -1250,16 +1250,16 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict)
fz_warn("malformed shading function bounds (domain mismatch), proceeding anyway.");
}
- obj = fz_dict_gets(ctx, dict, "Encode");
- if (!fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "Encode");
+ if (!fz_is_array(obj))
return fz_error_make("stitching function is missing encoding");
{
- if (!fz_is_array(ctx, obj) || fz_array_len(ctx, obj) != k * 2)
+ if (!fz_is_array(obj) || fz_array_len(obj) != k * 2)
return fz_error_make("malformed /Encode");
for (i = 0; i < k; i++)
{
- func->u.st.encode[i*2+0] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+0));
- func->u.st.encode[i*2+1] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+1));
+ func->u.st.encode[i*2+0] = fz_to_real(fz_array_get(obj, i*2+0));
+ func->u.st.encode[i*2+1] = fz_to_real(fz_array_get(obj, i*2+1));
}
}
@@ -1362,31 +1362,32 @@ pdf_load_function(pdf_function **funcp, pdf_xref *xref, fz_obj *dict)
return fz_okay;
}
- func = fz_calloc(ctx, 1, sizeof(pdf_function));
+ func = fz_malloc(ctx, sizeof(pdf_function));
+ memset(func, 0, sizeof *func);
func->refs = 1;
- obj = fz_dict_gets(ctx, dict, "FunctionType");
- func->type = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "FunctionType");
+ func->type = fz_to_int(obj);
/* required for all */
- obj = fz_dict_gets(ctx, dict, "Domain");
- func->m = fz_array_len(ctx, obj) / 2;
+ obj = fz_dict_gets(dict, "Domain");
+ func->m = fz_array_len(obj) / 2;
for (i = 0; i < func->m; i++)
{
- func->domain[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 0));
- func->domain[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 1));
+ func->domain[i][0] = fz_to_real(fz_array_get(obj, i * 2 + 0));
+ func->domain[i][1] = fz_to_real(fz_array_get(obj, i * 2 + 1));
}
/* required for type0 and type4, optional otherwise */
- obj = fz_dict_gets(ctx, dict, "Range");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "Range");
+ if (fz_is_array(obj))
{
func->has_range = 1;
- func->n = fz_array_len(ctx, obj) / 2;
+ func->n = fz_array_len(obj) / 2;
for (i = 0; i < func->n; i++)
{
- func->range[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 0));
- func->range[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 1));
+ func->range[i][0] = fz_to_real(fz_array_get(obj, i * 2 + 0));
+ func->range[i][1] = fz_to_real(fz_array_get(obj, i * 2 + 1));
}
}
else
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 95f26c31..cb63309d 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -71,11 +71,11 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
return fz_okay;
}
- w = fz_to_int(ctx, fz_dict_getsa(ctx, dict, "Width", "W"));
- h = fz_to_int(ctx, fz_dict_getsa(ctx, dict, "Height", "H"));
- bpc = fz_to_int(ctx, fz_dict_getsa(ctx, dict, "BitsPerComponent", "BPC"));
- imagemask = fz_to_bool(ctx, fz_dict_getsa(ctx, dict, "ImageMask", "IM"));
- interpolate = fz_to_bool(ctx, fz_dict_getsa(ctx, dict, "Interpolate", "I"));
+ w = fz_to_int(fz_dict_getsa(dict, "Width", "W"));
+ h = fz_to_int(fz_dict_getsa(dict, "Height", "H"));
+ bpc = fz_to_int(fz_dict_getsa(dict, "BitsPerComponent", "BPC"));
+ imagemask = fz_to_bool(fz_dict_getsa(dict, "ImageMask", "IM"));
+ interpolate = fz_to_bool(fz_dict_getsa(dict, "Interpolate", "I"));
indexed = 0;
usecolorkey = 0;
@@ -98,13 +98,13 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
if (h > (1 << 16))
return fz_error_make("image is too high");
- obj = fz_dict_getsa(ctx, dict, "ColorSpace", "CS");
+ obj = fz_dict_getsa(dict, "ColorSpace", "CS");
if (obj && !imagemask && !forcemask)
{
/* colorspace resource lookup is only done for inline images */
- if (fz_is_name(ctx, obj))
+ if (fz_is_name(obj))
{
- res = fz_dict_get(ctx, fz_dict_gets(ctx, rdb, "ColorSpace"), obj);
+ res = fz_dict_get(fz_dict_gets(rdb, "ColorSpace"), obj);
if (res)
obj = res;
}
@@ -123,11 +123,11 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
n = 1;
}
- obj = fz_dict_getsa(ctx, dict, "Decode", "D");
+ obj = fz_dict_getsa(dict, "Decode", "D");
if (obj)
{
for (i = 0; i < n * 2; i++)
- decode[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i));
+ decode[i] = fz_to_real(fz_array_get(obj, i));
}
else
{
@@ -136,8 +136,8 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
decode[i] = i & 1 ? maxval : 0;
}
- obj = fz_dict_getsa(ctx, dict, "SMask", "Mask");
- if (fz_is_dict(ctx, obj))
+ obj = fz_dict_getsa(dict, "SMask", "Mask");
+ if (fz_is_dict(obj))
{
/* Not allowed for inline images */
if (!cstm)
@@ -151,11 +151,11 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict,
}
}
}
- else if (fz_is_array(ctx, obj))
+ else if (fz_is_array(obj))
{
usecolorkey = 1;
for (i = 0; i < n * 2; i++)
- colorkey[i] = fz_to_int(ctx, fz_array_get(ctx, obj, i));
+ colorkey[i] = fz_to_int(fz_array_get(obj, i));
}
/* Allocate now, to fail early if we run out of memory */
@@ -274,12 +274,12 @@ pdf_is_jpx_image(fz_context *ctx, fz_obj *dict)
fz_obj *filter;
int i, n;
- filter = fz_dict_gets(ctx, dict, "Filter");
- if (!strcmp(fz_to_name(ctx, filter), "JPXDecode"))
+ filter = fz_dict_gets(dict, "Filter");
+ if (!strcmp(fz_to_name(filter), "JPXDecode"))
return 1;
- n = fz_array_len(ctx, filter);
+ n = fz_array_len(filter);
for (i = 0; i < n; i++)
- if (!strcmp(fz_to_name(ctx, fz_array_get(ctx, filter, i)), "JPXDecode"))
+ if (!strcmp(fz_to_name(fz_array_get(filter, i)), "JPXDecode"))
return 1;
return 0;
}
@@ -300,7 +300,7 @@ pdf_load_jpx_image(fz_pixmap **imgp, pdf_xref *xref, fz_obj *dict)
if (error)
return fz_error_note(error, "cannot load jpx image data");
- obj = fz_dict_gets(ctx, dict, "ColorSpace");
+ obj = fz_dict_gets(dict, "ColorSpace");
if (obj)
{
error = pdf_load_colorspace(&colorspace, xref, obj);
@@ -321,8 +321,8 @@ pdf_load_jpx_image(fz_pixmap **imgp, pdf_xref *xref, fz_obj *dict)
fz_drop_colorspace(ctx, colorspace);
fz_drop_buffer(ctx, buf);
- obj = fz_dict_getsa(ctx, dict, "SMask", "Mask");
- if (fz_is_dict(ctx, obj))
+ obj = fz_dict_getsa(dict, "SMask", "Mask");
+ if (fz_is_dict(obj))
{
error = pdf_load_image_imp(&img->mask, xref, NULL, obj, NULL, 1);
if (error)
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index d4d909bd..e3272edf 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -110,14 +110,14 @@ pdf_is_hidden_ocg(fz_context *ctx, fz_obj *xobj, char *target)
fz_strlcpy(target_state, target, sizeof target_state);
fz_strlcat(target_state, "State", sizeof target_state);
- obj = fz_dict_gets(ctx, xobj, "OC");
- obj = fz_dict_gets(ctx, obj, "OCGs");
- if (fz_is_array(ctx, obj))
- obj = fz_array_get(ctx, obj, 0);
- obj = fz_dict_gets(ctx, obj, "Usage");
- obj = fz_dict_gets(ctx, obj, target);
- obj = fz_dict_gets(ctx, obj, target_state);
- return !strcmp(fz_to_name(ctx, obj), "OFF");
+ obj = fz_dict_gets(xobj, "OC");
+ obj = fz_dict_gets(obj, "OCGs");
+ if (fz_is_array(obj))
+ obj = fz_array_get(obj, 0);
+ obj = fz_dict_gets(obj, "Usage");
+ obj = fz_dict_gets(obj, target);
+ obj = fz_dict_gets(obj, target_state);
+ return !strcmp(fz_to_name(obj), "OFF");
}
/*
@@ -587,23 +587,22 @@ pdf_show_text(pdf_csi *csi, fz_obj *text)
{
pdf_gstate *gstate = csi->gstate + csi->gtop;
int i;
- fz_context *ctx = csi->dev->ctx;
- if (fz_is_array(ctx, text))
+ if (fz_is_array(text))
{
- int n = fz_array_len(ctx, text);
+ int n = fz_array_len(text);
for (i = 0; i < n; i++)
{
- fz_obj *item = fz_array_get(ctx, text, i);
- if (fz_is_string(ctx, item))
- pdf_show_string(csi, (unsigned char *)fz_to_str_buf(ctx, item), fz_to_str_len(ctx, item));
+ fz_obj *item = fz_array_get(text, i);
+ if (fz_is_string(item))
+ pdf_show_string(csi, (unsigned char *)fz_to_str_buf(item), fz_to_str_len(item));
else
- pdf_show_space(csi, - fz_to_real(ctx, item) * gstate->size * 0.001f);
+ pdf_show_space(csi, - fz_to_real(item) * gstate->size * 0.001f);
}
}
- else if (fz_is_string(ctx, text))
+ else if (fz_is_string(text))
{
- pdf_show_string(csi, (unsigned char *)fz_to_str_buf(ctx, text), fz_to_str_len(ctx, text));
+ pdf_show_string(csi, (unsigned char *)fz_to_str_buf(text), fz_to_str_len(text));
}
}
@@ -696,7 +695,7 @@ pdf_clear_stack(pdf_csi *csi)
int i;
if (csi->obj)
- fz_drop_obj(csi->dev->ctx, csi->obj);
+ fz_drop_obj(csi->obj);
csi->obj = NULL;
csi->name[0] = 0;
@@ -1129,19 +1128,19 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
pdf_flush_text(csi);
- n = fz_dict_len(ctx, extgstate);
+ n = fz_dict_len(extgstate);
for (i = 0; i < n; i++)
{
- fz_obj *key = fz_dict_get_key(ctx, extgstate, i);
- fz_obj *val = fz_dict_get_val(ctx, extgstate, i);
- char *s = fz_to_name(ctx, key);
+ fz_obj *key = fz_dict_get_key(extgstate, i);
+ fz_obj *val = fz_dict_get_val(extgstate, i);
+ char *s = fz_to_name(key);
if (!strcmp(s, "Font"))
{
- if (fz_is_array(ctx, val) && fz_array_len(ctx, val) == 2)
+ if (fz_is_array(val) && fz_array_len(val) == 2)
{
fz_error error;
- fz_obj *font = fz_array_get(ctx, val, 0);
+ fz_obj *font = fz_array_get(val, 0);
if (gstate->font)
{
@@ -1154,7 +1153,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
return fz_error_note(error, "cannot load font (%d %d R)", fz_to_num(font), fz_to_gen(font));
if (!gstate->font)
return fz_error_make("cannot find font in store");
- gstate->size = fz_to_real(ctx, fz_array_get(ctx, val, 1));
+ gstate->size = fz_to_real(fz_array_get(val, 1));
}
else
return fz_error_make("malformed /Font dictionary");
@@ -1162,47 +1161,47 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
else if (!strcmp(s, "LC"))
{
- gstate->stroke_state.start_cap = fz_to_int(ctx, val);
- gstate->stroke_state.dash_cap = fz_to_int(ctx, val);
- gstate->stroke_state.end_cap = fz_to_int(ctx, val);
+ gstate->stroke_state.start_cap = fz_to_int(val);
+ gstate->stroke_state.dash_cap = fz_to_int(val);
+ gstate->stroke_state.end_cap = fz_to_int(val);
}
else if (!strcmp(s, "LW"))
- gstate->stroke_state.linewidth = fz_to_real(ctx, val);
+ gstate->stroke_state.linewidth = fz_to_real(val);
else if (!strcmp(s, "LJ"))
- gstate->stroke_state.linejoin = fz_to_int(ctx, val);
+ gstate->stroke_state.linejoin = fz_to_int(val);
else if (!strcmp(s, "ML"))
- gstate->stroke_state.miterlimit = fz_to_real(ctx, val);
+ gstate->stroke_state.miterlimit = fz_to_real(val);
else if (!strcmp(s, "D"))
{
- if (fz_is_array(ctx, val) && fz_array_len(ctx, val) == 2)
+ if (fz_is_array(val) && fz_array_len(val) == 2)
{
- fz_obj *dashes = fz_array_get(ctx, val, 0);
- gstate->stroke_state.dash_len = MAX(fz_array_len(ctx, dashes), 32);
+ fz_obj *dashes = fz_array_get(val, 0);
+ gstate->stroke_state.dash_len = MAX(fz_array_len(dashes), 32);
for (k = 0; k < gstate->stroke_state.dash_len; k++)
- gstate->stroke_state.dash_list[k] = fz_to_real(ctx, fz_array_get(ctx, dashes, k));
- gstate->stroke_state.dash_phase = fz_to_real(ctx, fz_array_get(ctx, val, 1));
+ gstate->stroke_state.dash_list[k] = fz_to_real(fz_array_get(dashes, k));
+ gstate->stroke_state.dash_phase = fz_to_real(fz_array_get(val, 1));
}
else
return fz_error_make("malformed /D");
}
else if (!strcmp(s, "CA"))
- gstate->stroke.alpha = fz_to_real(ctx, val);
+ gstate->stroke.alpha = fz_to_real(val);
else if (!strcmp(s, "ca"))
- gstate->fill.alpha = fz_to_real(ctx, val);
+ gstate->fill.alpha = fz_to_real(val);
else if (!strcmp(s, "BM"))
{
- if (fz_is_array(ctx, val))
- val = fz_array_get(ctx, val, 0);
- gstate->blendmode = fz_find_blendmode(fz_to_name(ctx, val));
+ if (fz_is_array(val))
+ val = fz_array_get(val, 0);
+ gstate->blendmode = fz_find_blendmode(fz_to_name(val));
}
else if (!strcmp(s, "SMask"))
{
- if (fz_is_dict(ctx, val))
+ if (fz_is_dict(val))
{
fz_error error;
pdf_xobject *xobj;
@@ -1214,7 +1213,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
gstate->softmask = NULL;
}
- group = fz_dict_gets(ctx, val, "G");
+ group = fz_dict_gets(val, "G");
if (!group)
return fz_error_make("cannot load softmask xobject (%d %d R)", fz_to_num(val), fz_to_gen(val));
error = pdf_load_xobject(&xobj, csi->xref, group);
@@ -1230,20 +1229,20 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
for (k = 0; k < colorspace->n; k++)
gstate->softmask_bc[k] = 0;
- bc = fz_dict_gets(ctx, val, "BC");
- if (fz_is_array(ctx, bc))
+ bc = fz_dict_gets(val, "BC");
+ if (fz_is_array(bc))
{
for (k = 0; k < colorspace->n; k++)
- gstate->softmask_bc[k] = fz_to_real(ctx, fz_array_get(ctx, bc, k));
+ gstate->softmask_bc[k] = fz_to_real(fz_array_get(bc, k));
}
- luminosity = fz_dict_gets(ctx, val, "S");
- if (fz_is_name(ctx, luminosity) && !strcmp(fz_to_name(ctx, luminosity), "Luminosity"))
+ luminosity = fz_dict_gets(val, "S");
+ if (fz_is_name(luminosity) && !strcmp(fz_to_name(luminosity), "Luminosity"))
gstate->luminosity = 1;
else
gstate->luminosity = 0;
}
- else if (fz_is_name(ctx, val) && !strcmp(fz_to_name(ctx, val), "None"))
+ else if (fz_is_name(val) && !strcmp(fz_to_name(val), "None"))
{
if (gstate->softmask)
{
@@ -1255,7 +1254,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate)
else if (!strcmp(s, "TR"))
{
- if (fz_is_name(ctx, val) && strcmp(fz_to_name(ctx, val), "Identity"))
+ if (fz_is_name(val) && strcmp(fz_to_name(val), "Identity"))
fz_warn("ignoring transfer function");
}
}
@@ -1292,7 +1291,7 @@ static fz_error pdf_run_BI(pdf_csi *csi, fz_obj *rdb, fz_stream *file)
fz_read_byte(file);
error = pdf_load_inline_image(&img, csi->xref, rdb, obj, file);
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
if (error)
return fz_error_note(error, "cannot load inline image");
@@ -1358,10 +1357,10 @@ static fz_error pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what)
colorspace = fz_keep_colorspace(fz_device_cmyk);
else
{
- dict = fz_dict_gets(ctx, rdb, "ColorSpace");
+ dict = fz_dict_gets(rdb, "ColorSpace");
if (!dict)
return fz_error_make("cannot find ColorSpace dictionary");
- obj = fz_dict_gets(ctx, dict, csi->name);
+ obj = fz_dict_gets(dict, csi->name);
if (!obj)
return fz_error_make("cannot find colorspace resource '%s'", csi->name);
error = pdf_load_colorspace(&colorspace, csi->xref, obj);
@@ -1404,25 +1403,25 @@ static fz_error pdf_run_Do(pdf_csi *csi, fz_obj *rdb)
fz_error error;
fz_context *ctx = csi->dev->ctx;
- dict = fz_dict_gets(ctx, rdb, "XObject");
+ dict = fz_dict_gets(rdb, "XObject");
if (!dict)
return fz_error_make("cannot find XObject dictionary when looking for: '%s'", csi->name);
- obj = fz_dict_gets(ctx, dict, csi->name);
+ obj = fz_dict_gets(dict, csi->name);
if (!obj)
return fz_error_make("cannot find xobject resource: '%s'", csi->name);
- subtype = fz_dict_gets(ctx, obj, "Subtype");
- if (!fz_is_name(ctx, subtype))
+ subtype = fz_dict_gets(obj, "Subtype");
+ if (!fz_is_name(subtype))
return fz_error_make("no XObject subtype specified");
if (pdf_is_hidden_ocg(ctx, obj, csi->target))
return fz_okay;
- if (!strcmp(fz_to_name(ctx, subtype), "Form") && fz_dict_gets(ctx, obj, "Subtype2"))
- subtype = fz_dict_gets(ctx, obj, "Subtype2");
+ if (!strcmp(fz_to_name(subtype), "Form") && fz_dict_gets(obj, "Subtype2"))
+ subtype = fz_dict_gets(obj, "Subtype2");
- if (!strcmp(fz_to_name(ctx, subtype), "Form"))
+ if (!strcmp(fz_to_name(subtype), "Form"))
{
pdf_xobject *xobj;
@@ -1441,7 +1440,7 @@ static fz_error pdf_run_Do(pdf_csi *csi, fz_obj *rdb)
pdf_drop_xobject(ctx, xobj);
}
- else if (!strcmp(fz_to_name(ctx, subtype), "Image"))
+ else if (!strcmp(fz_to_name(subtype), "Image"))
{
if ((csi->dev->hints & FZ_IGNORE_IMAGE) == 0)
{
@@ -1454,14 +1453,14 @@ static fz_error pdf_run_Do(pdf_csi *csi, fz_obj *rdb)
}
}
- else if (!strcmp(fz_to_name(ctx, subtype), "PS"))
+ else if (!strcmp(fz_to_name(subtype), "PS"))
{
fz_warn("ignoring XObject with subtype PS");
}
else
{
- return fz_error_make("unknown XObject subtype: '%s'", fz_to_name(ctx, subtype));
+ return fz_error_make("unknown XObject subtype: '%s'", fz_to_name(subtype));
}
return fz_okay;
@@ -1557,17 +1556,17 @@ static fz_error pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material
break;
case PDF_MAT_PATTERN:
- dict = fz_dict_gets(ctx, rdb, "Pattern");
+ dict = fz_dict_gets(rdb, "Pattern");
if (!dict)
return fz_error_make("cannot find Pattern dictionary");
- obj = fz_dict_gets(ctx, dict, csi->name);
+ obj = fz_dict_gets(dict, csi->name);
if (!obj)
return fz_error_make("cannot find pattern resource '%s'", csi->name);
- patterntype = fz_dict_gets(ctx, obj, "PatternType");
+ patterntype = fz_dict_gets(obj, "PatternType");
- if (fz_to_int(ctx, patterntype) == 1)
+ if (fz_to_int(patterntype) == 1)
{
pdf_pattern *pat;
error = pdf_load_pattern(&pat, csi->xref, obj);
@@ -1576,7 +1575,7 @@ static fz_error pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material
pdf_set_pattern(csi, what, pat, csi->top > 0 ? csi->stack : NULL);
pdf_drop_pattern(ctx, pat);
}
- else if (fz_to_int(ctx, patterntype) == 2)
+ else if (fz_to_int(patterntype) == 2)
{
fz_shade *shd;
error = pdf_load_shading(&shd, csi->xref, obj);
@@ -1587,7 +1586,7 @@ static fz_error pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material
}
else
{
- return fz_error_make("unknown pattern type: %d", fz_to_int(ctx, patterntype));
+ return fz_error_make("unknown pattern type: %d", fz_to_int(patterntype));
}
break;
@@ -1655,11 +1654,11 @@ static fz_error pdf_run_Tf(pdf_csi *csi, fz_obj *rdb)
pdf_drop_font(ctx, gstate->font);
gstate->font = NULL;
- dict = fz_dict_gets(ctx, rdb, "Font");
+ dict = fz_dict_gets(rdb, "Font");
if (!dict)
return fz_error_make("cannot find Font dictionary");
- obj = fz_dict_gets(ctx, dict, csi->name);
+ obj = fz_dict_gets(dict, csi->name);
if (!obj)
return fz_error_make("cannot find font resource: '%s'", csi->name);
@@ -1787,12 +1786,11 @@ static void pdf_run_d(pdf_csi *csi)
pdf_gstate *gstate = csi->gstate + csi->gtop;
fz_obj *array;
int i;
- fz_context *ctx = csi->dev->ctx;
array = csi->obj;
- gstate->stroke_state.dash_len = MIN(fz_array_len(ctx, array), nelem(gstate->stroke_state.dash_list));
+ gstate->stroke_state.dash_len = MIN(fz_array_len(array), nelem(gstate->stroke_state.dash_list));
for (i = 0; i < gstate->stroke_state.dash_len; i++)
- gstate->stroke_state.dash_list[i] = fz_to_real(ctx, fz_array_get(ctx, array, i));
+ gstate->stroke_state.dash_list[i] = fz_to_real(fz_array_get(array, i));
gstate->stroke_state.dash_phase = csi->stack[0];
}
@@ -1827,13 +1825,12 @@ static fz_error pdf_run_gs(pdf_csi *csi, fz_obj *rdb)
fz_error error;
fz_obj *dict;
fz_obj *obj;
- fz_context *ctx = csi->dev->ctx;
- dict = fz_dict_gets(ctx, rdb, "ExtGState");
+ dict = fz_dict_gets(rdb, "ExtGState");
if (!dict)
return fz_error_make("cannot find ExtGState dictionary");
- obj = fz_dict_gets(ctx, dict, csi->name);
+ obj = fz_dict_gets(dict, csi->name);
if (!obj)
return fz_error_make("cannot find extgstate resource '%s'", csi->name);
@@ -1930,11 +1927,11 @@ static fz_error pdf_run_sh(pdf_csi *csi, fz_obj *rdb)
fz_error error;
fz_context *ctx = csi->dev->ctx;
- dict = fz_dict_gets(ctx, rdb, "Shading");
+ dict = fz_dict_gets(rdb, "Shading");
if (!dict)
return fz_error_make("cannot find shading dictionary");
- obj = fz_dict_gets(ctx, dict, csi->name);
+ obj = fz_dict_gets(dict, csi->name);
if (!obj)
return fz_error_make("cannot find shading resource: '%s'", csi->name);
@@ -2288,7 +2285,7 @@ pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matri
for (annot = page->annots; annot; annot = annot->next)
{
- flags = fz_to_int(ctx, fz_dict_gets(ctx, annot->obj, "F"));
+ flags = fz_to_int(fz_dict_gets(annot->obj, "F"));
/* TODO: NoZoom and NoRotate */
if (flags & (1 << 0)) /* Invisible */
diff --git a/pdf/pdf_nametree.c b/pdf/pdf_nametree.c
index 838caa94..d84f2e8b 100644
--- a/pdf/pdf_nametree.c
+++ b/pdf/pdf_nametree.c
@@ -4,21 +4,21 @@
static fz_obj *
pdf_lookup_name_imp(fz_context *ctx, fz_obj *node, fz_obj *needle)
{
- fz_obj *kids = fz_dict_gets(ctx, node, "Kids");
- fz_obj *names = fz_dict_gets(ctx, node, "Names");
+ fz_obj *kids = fz_dict_gets(node, "Kids");
+ fz_obj *names = fz_dict_gets(node, "Names");
- if (fz_is_array(ctx, kids))
+ if (fz_is_array(kids))
{
int l = 0;
- int r = fz_array_len(ctx, kids) - 1;
+ int r = fz_array_len(kids) - 1;
while (l <= r)
{
int m = (l + r) >> 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);
+ 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);
if (fz_objcmp(needle, first) < 0)
r = m - 1;
@@ -29,17 +29,17 @@ pdf_lookup_name_imp(fz_context *ctx, fz_obj *node, fz_obj *needle)
}
}
- if (fz_is_array(ctx, names))
+ if (fz_is_array(names))
{
int l = 0;
- int r = (fz_array_len(ctx, names) / 2) - 1;
+ int r = (fz_array_len(names) / 2) - 1;
while (l <= r)
{
int m = (l + r) >> 1;
int c;
- fz_obj *key = fz_array_get(ctx, names, m * 2);
- fz_obj *val = fz_array_get(ctx, names, m * 2 + 1);
+ fz_obj *key = fz_array_get(names, m * 2);
+ fz_obj *val = fz_array_get(names, m * 2 + 1);
c = fz_objcmp(needle, key);
if (c < 0)
@@ -59,9 +59,9 @@ pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *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);
+ 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(ctx, tree, needle);
}
@@ -70,24 +70,24 @@ pdf_lookup_dest(pdf_xref *xref, fz_obj *needle)
{
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 *root = fz_dict_gets(xref->trailer, "Root");
+ fz_obj *dests = fz_dict_gets(root, "Dests");
+ fz_obj *names = fz_dict_gets(root, "Names");
fz_obj *dest = NULL;
/* PDF 1.1 has destinations in a dictionary */
if (dests)
{
- if (fz_is_name(ctx, needle))
- return fz_dict_get(ctx, dests, needle);
+ if (fz_is_name(needle))
+ return fz_dict_get(dests, needle);
else
- return fz_dict_gets(ctx, dests, fz_to_str_buf(ctx, needle));
+ return fz_dict_gets(dests, fz_to_str_buf(needle));
}
/* PDF 1.2 has destinations in a name tree */
if (names && !dest)
{
- fz_obj *tree = fz_dict_gets(ctx, names, "Dests");
+ fz_obj *tree = fz_dict_gets(names, "Dests");
return pdf_lookup_name_imp(ctx, tree, needle);
}
@@ -98,31 +98,31 @@ static void
pdf_load_name_tree_imp(fz_obj *dict, pdf_xref *xref, fz_obj *node)
{
fz_context *ctx = xref->ctx;
- fz_obj *kids = fz_dict_gets(ctx, node, "Kids");
- fz_obj *names = fz_dict_gets(ctx, node, "Names");
+ fz_obj *kids = fz_dict_gets(node, "Kids");
+ fz_obj *names = fz_dict_gets(node, "Names");
int i;
if (kids)
{
- for (i = 0; i < fz_array_len(ctx, kids); i++)
- pdf_load_name_tree_imp(dict, xref, fz_array_get(ctx, kids, i));
+ for (i = 0; i < fz_array_len(kids); i++)
+ pdf_load_name_tree_imp(dict, xref, fz_array_get(kids, i));
}
if (names)
{
- for (i = 0; i + 1 < fz_array_len(ctx, names); i += 2)
+ for (i = 0; i + 1 < fz_array_len(names); i += 2)
{
- 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))
+ fz_obj *key = fz_array_get(names, i);
+ fz_obj *val = fz_array_get(names, i + 1);
+ if (fz_is_string(key))
{
key = pdf_to_utf8_name(ctx, key);
- fz_dict_put(ctx, dict, key, val);
- fz_drop_obj(ctx, key);
+ fz_dict_put(dict, key, val);
+ fz_drop_obj(key);
}
- else if (fz_is_name(ctx, key))
+ else if (fz_is_name(key))
{
- fz_dict_put(ctx, dict, key, val);
+ fz_dict_put(dict, key, val);
}
}
}
@@ -133,10 +133,10 @@ pdf_load_name_tree(pdf_xref *xref, char *which)
{
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 *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_obj *dict = fz_new_dict(ctx, 100);
pdf_load_name_tree_imp(dict, xref, tree);
diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c
index 0e6ab233..677a701f 100644
--- a/pdf/pdf_outline.c
+++ b/pdf/pdf_outline.c
@@ -4,11 +4,11 @@
static pdf_outline *
pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict)
{
+ fz_context *ctx = xref->ctx;
pdf_outline *node;
fz_obj *obj;
- fz_context *ctx = xref->ctx;
- if (fz_is_null(ctx, dict))
+ if (fz_is_null(dict))
return NULL;
node = fz_malloc(ctx, sizeof(pdf_outline));
@@ -18,22 +18,22 @@ pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict)
node->next = NULL;
node->count = 0;
- obj = fz_dict_gets(ctx, dict, "Title");
+ obj = fz_dict_gets(dict, "Title");
if (obj)
node->title = pdf_to_utf8(ctx, obj);
- obj = fz_dict_gets(ctx, dict, "Count");
+ obj = fz_dict_gets(dict, "Count");
if (obj)
- node->count = fz_to_int(ctx, obj);
+ node->count = fz_to_int(obj);
- if (fz_dict_gets(ctx, dict, "Dest") || fz_dict_gets(ctx, dict, "A"))
+ if (fz_dict_gets(dict, "Dest") || fz_dict_gets(dict, "A"))
node->link = pdf_load_link(xref, dict);
- obj = fz_dict_gets(ctx, dict, "First");
+ obj = fz_dict_gets(dict, "First");
if (obj)
node->child = pdf_load_outline_imp(xref, obj);
- obj = fz_dict_gets(ctx, dict, "Next");
+ obj = fz_dict_gets(dict, "Next");
if (obj)
node->next = pdf_load_outline_imp(xref, obj);
@@ -44,11 +44,10 @@ pdf_outline *
pdf_load_outline(pdf_xref *xref)
{
fz_obj *root, *obj, *first;
- fz_context *ctx = xref->ctx;
- root = fz_dict_gets(ctx, xref->trailer, "Root");
- obj = fz_dict_gets(ctx, root, "Outlines");
- first = fz_dict_gets(ctx, obj, "First");
+ root = fz_dict_gets(xref->trailer, "Root");
+ obj = fz_dict_gets(root, "Outlines");
+ first = fz_dict_gets(obj, "First");
if (first)
return pdf_load_outline_imp(xref, first);
@@ -83,7 +82,7 @@ pdf_debug_outline(fz_context *ctx, pdf_outline *outline, int level)
printf("<NULL> ");
if (outline->link)
- fz_debug_obj(ctx, outline->link->dest);
+ fz_debug_obj(outline->link->dest);
else
printf("<NULL>\n");
diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c
index 724a4d13..88825531 100644
--- a/pdf/pdf_page.c
+++ b/pdf/pdf_page.c
@@ -34,52 +34,52 @@ pdf_load_page_tree_node(pdf_xref *xref, fz_obj *node, struct info info)
fz_context *ctx = xref->ctx;
/* prevent infinite recursion */
- if (fz_dict_gets(ctx, node, ".seen"))
+ if (fz_dict_gets(node, ".seen"))
return;
- kids = fz_dict_gets(ctx, node, "Kids");
- count = fz_dict_gets(ctx, node, "Count");
+ kids = fz_dict_gets(node, "Kids");
+ count = fz_dict_gets(node, "Count");
- if (fz_is_array(ctx, kids) && fz_is_int(ctx, count))
+ if (fz_is_array(kids) && fz_is_int(count))
{
- obj = fz_dict_gets(ctx, node, "Resources");
+ obj = fz_dict_gets(node, "Resources");
if (obj)
info.resources = obj;
- obj = fz_dict_gets(ctx, node, "MediaBox");
+ obj = fz_dict_gets(node, "MediaBox");
if (obj)
info.mediabox = obj;
- obj = fz_dict_gets(ctx, node, "CropBox");
+ obj = fz_dict_gets(node, "CropBox");
if (obj)
info.cropbox = obj;
- obj = fz_dict_gets(ctx, node, "Rotate");
+ obj = fz_dict_gets(node, "Rotate");
if (obj)
info.rotate = obj;
tmp = fz_new_null(ctx);
- fz_dict_puts(ctx, node, ".seen", tmp);
- fz_drop_obj(ctx, tmp);
+ fz_dict_puts(node, ".seen", tmp);
+ fz_drop_obj(tmp);
- n = fz_array_len(ctx, kids);
+ n = fz_array_len(kids);
for (i = 0; i < n; i++)
{
- obj = fz_array_get(ctx, kids, i);
+ obj = fz_array_get(kids, i);
pdf_load_page_tree_node(xref, obj, info);
}
- fz_dict_dels(ctx, node, ".seen");
+ fz_dict_dels(node, ".seen");
}
else
{
- dict = fz_resolve_indirect(ctx, node);
+ dict = fz_resolve_indirect(node);
- if (info.resources && !fz_dict_gets(ctx, dict, "Resources"))
- fz_dict_puts(ctx, dict, "Resources", info.resources);
- if (info.mediabox && !fz_dict_gets(ctx, dict, "MediaBox"))
- fz_dict_puts(ctx, dict, "MediaBox", info.mediabox);
- if (info.cropbox && !fz_dict_gets(ctx, dict, "CropBox"))
- fz_dict_puts(ctx, dict, "CropBox", info.cropbox);
- if (info.rotate && !fz_dict_gets(ctx, dict, "Rotate"))
- fz_dict_puts(ctx, dict, "Rotate", info.rotate);
+ if (info.resources && !fz_dict_gets(dict, "Resources"))
+ fz_dict_puts(dict, "Resources", info.resources);
+ if (info.mediabox && !fz_dict_gets(dict, "MediaBox"))
+ fz_dict_puts(dict, "MediaBox", info.mediabox);
+ if (info.cropbox && !fz_dict_gets(dict, "CropBox"))
+ fz_dict_puts(dict, "CropBox", info.cropbox);
+ if (info.rotate && !fz_dict_gets(dict, "Rotate"))
+ fz_dict_puts(dict, "Rotate", info.rotate);
if (xref->page_len == xref->page_cap)
{
@@ -100,16 +100,16 @@ pdf_load_page_tree(pdf_xref *xref)
{
struct info info;
fz_context *ctx = xref->ctx;
- fz_obj *catalog = fz_dict_gets(ctx, xref->trailer, "Root");
- fz_obj *pages = fz_dict_gets(ctx, catalog, "Pages");
- fz_obj *count = fz_dict_gets(ctx, pages, "Count");
+ fz_obj *catalog = fz_dict_gets(xref->trailer, "Root");
+ fz_obj *pages = fz_dict_gets(catalog, "Pages");
+ fz_obj *count = fz_dict_gets(pages, "Count");
- if (!fz_is_dict(ctx, pages))
+ if (!fz_is_dict(pages))
return fz_error_make("missing page tree");
- if (!fz_is_int(ctx, count))
+ if (!fz_is_int(count))
return fz_error_make("missing page count");
- xref->page_cap = fz_to_int(ctx, count);
+ xref->page_cap = fz_to_int(count);
xref->page_len = 0;
xref->page_refs = fz_calloc(ctx, xref->page_cap, sizeof(fz_obj*));
xref->page_objs = fz_calloc(ctx, xref->page_cap, sizeof(fz_obj*));
@@ -131,8 +131,8 @@ static int pdf_resources_use_blending(fz_context *ctx, fz_obj *rdb);
static int
pdf_extgstate_uses_blending(fz_context *ctx, fz_obj *dict)
{
- fz_obj *obj = fz_dict_gets(ctx, dict, "BM");
- if (fz_is_name(ctx, obj) && strcmp(fz_to_name(ctx, obj), "Normal"))
+ fz_obj *obj = fz_dict_gets(dict, "BM");
+ if (fz_is_name(obj) && strcmp(fz_to_name(obj), "Normal"))
return 1;
return 0;
}
@@ -141,17 +141,17 @@ static int
pdf_pattern_uses_blending(fz_context *ctx, fz_obj *dict)
{
fz_obj *obj;
- obj = fz_dict_gets(ctx, dict, "Resources");
+ obj = fz_dict_gets(dict, "Resources");
if (pdf_resources_use_blending(ctx, obj))
return 1;
- obj = fz_dict_gets(ctx, dict, "ExtGState");
+ obj = fz_dict_gets(dict, "ExtGState");
return pdf_extgstate_uses_blending(ctx, obj);
}
static int
pdf_xobject_uses_blending(fz_context *ctx, fz_obj *dict)
{
- fz_obj *obj = fz_dict_gets(ctx, dict, "Resources");
+ fz_obj *obj = fz_dict_gets(dict, "Resources");
return pdf_resources_use_blending(ctx, obj);
}
@@ -166,37 +166,37 @@ pdf_resources_use_blending(fz_context *ctx, fz_obj *rdb)
return 0;
/* stop on cyclic resource dependencies */
- if (fz_dict_gets(ctx, rdb, ".useBM"))
- return fz_to_bool(ctx, fz_dict_gets(ctx, rdb, ".useBM"));
+ if (fz_dict_gets(rdb, ".useBM"))
+ return fz_to_bool(fz_dict_gets(rdb, ".useBM"));
tmp = fz_new_bool(ctx, 0);
- fz_dict_puts(ctx, rdb, ".useBM", tmp);
- fz_drop_obj(ctx, tmp);
+ fz_dict_puts(rdb, ".useBM", tmp);
+ fz_drop_obj(tmp);
- dict = fz_dict_gets(ctx, rdb, "ExtGState");
- n = fz_dict_len(ctx, dict);
+ dict = fz_dict_gets(rdb, "ExtGState");
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
- if (pdf_extgstate_uses_blending(ctx, fz_dict_get_val(ctx, dict, i)))
+ if (pdf_extgstate_uses_blending(ctx, fz_dict_get_val(dict, i)))
goto found;
- dict = fz_dict_gets(ctx, rdb, "Pattern");
- n = fz_dict_len(ctx, dict);
+ dict = fz_dict_gets(rdb, "Pattern");
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
- if (pdf_pattern_uses_blending(ctx, fz_dict_get_val(ctx, dict, i)))
+ if (pdf_pattern_uses_blending(ctx, fz_dict_get_val(dict, i)))
goto found;
- dict = fz_dict_gets(ctx, rdb, "XObject");
- n = fz_dict_len(ctx, dict);
+ dict = fz_dict_gets(rdb, "XObject");
+ n = fz_dict_len(dict);
for (i = 0; i < n; i++)
- if (pdf_xobject_uses_blending(ctx, fz_dict_get_val(ctx, dict, i)))
+ if (pdf_xobject_uses_blending(ctx, fz_dict_get_val(dict, i)))
goto found;
return 0;
found:
tmp = fz_new_bool(ctx, 1);
- fz_dict_puts(ctx, rdb, ".useBM", tmp);
- fz_drop_obj(ctx, tmp);
+ fz_dict_puts(rdb, ".useBM", tmp);
+ fz_drop_obj(tmp);
return 1;
}
@@ -213,10 +213,10 @@ pdf_load_page_contents_array(fz_buffer **bigbufp, pdf_xref *xref, fz_obj *list)
big = fz_new_buffer(ctx, 32 * 1024);
- n = fz_array_len(ctx, list);
+ n = fz_array_len(list);
for (i = 0; i < n; i++)
{
- fz_obj *stm = fz_array_get(ctx, list, i);
+ fz_obj *stm = fz_array_get(list, i);
error = pdf_load_stream(&one, xref, fz_to_num(stm), fz_to_gen(stm));
if (error)
{
@@ -249,7 +249,7 @@ pdf_load_page_contents(fz_buffer **bufp, pdf_xref *xref, fz_obj *obj)
fz_error error;
fz_context *ctx = xref->ctx;
- if (fz_is_array(ctx, obj))
+ if (fz_is_array(obj))
{
error = pdf_load_page_contents_array(bufp, xref, obj);
if (error)
@@ -298,7 +298,7 @@ pdf_load_page(pdf_page **pagep, pdf_xref *xref, int number)
page->links = NULL;
page->annots = NULL;
- obj = fz_dict_gets(ctx, pageobj, "MediaBox");
+ obj = fz_dict_gets(pageobj, "MediaBox");
bbox = fz_round_rect(pdf_to_rect(ctx, obj));
if (fz_is_empty_rect(pdf_to_rect(ctx, obj)))
{
@@ -309,8 +309,8 @@ pdf_load_page(pdf_page **pagep, pdf_xref *xref, int number)
bbox.y1 = 792;
}
- obj = fz_dict_gets(ctx, pageobj, "CropBox");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(pageobj, "CropBox");
+ if (fz_is_array(obj))
{
fz_bbox cropbox = fz_round_rect(pdf_to_rect(ctx, obj));
bbox = fz_intersect_bbox(bbox, cropbox);
@@ -327,20 +327,20 @@ pdf_load_page(pdf_page **pagep, pdf_xref *xref, int number)
page->mediabox = fz_unit_rect;
}
- page->rotate = fz_to_int(ctx, fz_dict_gets(ctx, pageobj, "Rotate"));
+ page->rotate = fz_to_int(fz_dict_gets(pageobj, "Rotate"));
- obj = fz_dict_gets(ctx, pageobj, "Annots");
+ obj = fz_dict_gets(pageobj, "Annots");
if (obj)
{
pdf_load_links(&page->links, xref, obj);
pdf_load_annots(&page->annots, xref, obj);
}
- page->resources = fz_dict_gets(ctx, pageobj, "Resources");
+ page->resources = fz_dict_gets(pageobj, "Resources");
if (page->resources)
fz_keep_obj(page->resources);
- obj = fz_dict_gets(ctx, pageobj, "Contents");
+ obj = fz_dict_gets(pageobj, "Contents");
error = pdf_load_page_contents(&page->contents, xref, obj);
if (error)
{
@@ -363,7 +363,7 @@ void
pdf_free_page(fz_context *ctx, pdf_page *page)
{
if (page->resources)
- fz_drop_obj(ctx, page->resources);
+ fz_drop_obj(page->resources);
if (page->contents)
fz_drop_buffer(ctx, page->contents);
if (page->links)
diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c
index e01734d7..04c67eca 100644
--- a/pdf/pdf_parse.c
+++ b/pdf/pdf_parse.c
@@ -5,10 +5,10 @@ fz_rect
pdf_to_rect(fz_context *ctx, fz_obj *array)
{
fz_rect r;
- float a = fz_to_real(ctx, fz_array_get(ctx, array, 0));
- float b = fz_to_real(ctx, fz_array_get(ctx, array, 1));
- float c = fz_to_real(ctx, fz_array_get(ctx, array, 2));
- float d = fz_to_real(ctx, fz_array_get(ctx, array, 3));
+ float a = fz_to_real(fz_array_get(array, 0));
+ float b = fz_to_real(fz_array_get(array, 1));
+ float c = fz_to_real(fz_array_get(array, 2));
+ float d = fz_to_real(fz_array_get(array, 3));
r.x0 = MIN(a, c);
r.y0 = MIN(b, d);
r.x1 = MAX(a, c);
@@ -20,12 +20,12 @@ fz_matrix
pdf_to_matrix(fz_context *ctx, fz_obj *array)
{
fz_matrix m;
- m.a = fz_to_real(ctx, fz_array_get(ctx, array, 0));
- m.b = fz_to_real(ctx, fz_array_get(ctx, array, 1));
- m.c = fz_to_real(ctx, fz_array_get(ctx, array, 2));
- m.d = fz_to_real(ctx, fz_array_get(ctx, array, 3));
- m.e = fz_to_real(ctx, fz_array_get(ctx, array, 4));
- m.f = fz_to_real(ctx, fz_array_get(ctx, array, 5));
+ m.a = fz_to_real(fz_array_get(array, 0));
+ m.b = fz_to_real(fz_array_get(array, 1));
+ m.c = fz_to_real(fz_array_get(array, 2));
+ m.d = fz_to_real(fz_array_get(array, 3));
+ m.e = fz_to_real(fz_array_get(array, 4));
+ m.f = fz_to_real(fz_array_get(array, 5));
return m;
}
@@ -33,9 +33,9 @@ pdf_to_matrix(fz_context *ctx, fz_obj *array)
char *
pdf_to_utf8(fz_context *ctx, fz_obj *src)
{
- unsigned char *srcptr = (unsigned char *) fz_to_str_buf(ctx, src);
+ unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src);
char *dstptr, *dst;
- int srclen = fz_to_str_len(ctx, src);
+ int srclen = fz_to_str_len(src);
int dstlen = 0;
int ucs;
int i;
@@ -94,9 +94,9 @@ pdf_to_utf8(fz_context *ctx, fz_obj *src)
unsigned short *
pdf_to_ucs2(fz_context *ctx, fz_obj *src)
{
- unsigned char *srcptr = (unsigned char *) fz_to_str_buf(ctx, src);
+ unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src);
unsigned short *dstptr, *dst;
- int srclen = fz_to_str_len(ctx, src);
+ int srclen = fz_to_str_len(src);
int i;
if (srclen >= 2 && srcptr[0] == 254 && srcptr[1] == 255)
@@ -188,7 +188,7 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap
error = pdf_lex(&tok, file, buf, cap, &len);
if (error)
{
- fz_drop_obj(ctx, ary);
+ fz_drop_obj(ary);
return fz_error_note(error, "cannot parse array");
}
@@ -197,14 +197,14 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap
if (n > 0)
{
obj = fz_new_int(ctx, a);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
}
if (n > 1)
{
obj = fz_new_int(ctx, b);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
}
n = 0;
}
@@ -212,8 +212,8 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap
if (tok == PDF_TOK_INT && n == 2)
{
obj = fz_new_int(ctx, a);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
a = b;
n --;
}
@@ -235,12 +235,12 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap
case PDF_TOK_R:
if (n != 2)
{
- fz_drop_obj(ctx, ary);
+ fz_drop_obj(ary);
return fz_error_make("cannot parse indirect reference in array");
}
obj = fz_new_indirect(ctx, a, b, xref);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
n = 0;
break;
@@ -248,57 +248,57 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap
error = pdf_parse_array(&obj, xref, file, buf, cap);
if (error)
{
- fz_drop_obj(ctx, ary);
+ fz_drop_obj(ary);
return fz_error_note(error, "cannot parse array");
}
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_OPEN_DICT:
error = pdf_parse_dict(&obj, xref, file, buf, cap);
if (error)
{
- fz_drop_obj(ctx, ary);
+ fz_drop_obj(ary);
return fz_error_note(error, "cannot parse array");
}
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_NAME:
obj = fz_new_name(ctx, buf);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_REAL:
obj = fz_new_real(ctx, fz_atof(buf));
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_STRING:
obj = fz_new_string(ctx, buf, len);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_TRUE:
obj = fz_new_bool(ctx, 1);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_FALSE:
obj = fz_new_bool(ctx, 0);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
case PDF_TOK_NULL:
obj = fz_new_null(ctx);
- fz_array_push(ctx, ary, obj);
- fz_drop_obj(ctx, obj);
+ fz_array_push(ary, obj);
+ fz_drop_obj(obj);
break;
default:
- fz_drop_obj(ctx, ary);
+ fz_drop_obj(ary);
return fz_error_make("cannot parse token in array");
}
}
@@ -323,7 +323,7 @@ pdf_parse_dict(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap)
error = pdf_lex(&tok, file, buf, cap, &len);
if (error)
{
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
return fz_error_note(error, "cannot parse dict");
}
@@ -343,7 +343,7 @@ skip:
if (tok != PDF_TOK_NAME)
{
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
return fz_error_make("invalid key in dict");
}
@@ -352,8 +352,8 @@ skip:
error = pdf_lex(&tok, file, buf, cap, &len);
if (error)
{
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_note(error, "cannot parse dict");
}
@@ -363,8 +363,8 @@ skip:
error = pdf_parse_array(&val, xref, file, buf, cap);
if (error)
{
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_note(error, "cannot parse dict");
}
break;
@@ -373,8 +373,8 @@ skip:
error = pdf_parse_dict(&val, xref, file, buf, cap);
if (error)
{
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_note(error, "cannot parse dict");
}
break;
@@ -392,17 +392,17 @@ skip:
error = pdf_lex(&tok, file, buf, cap, &len);
if (error)
{
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_note(error, "cannot parse dict");
}
if (tok == PDF_TOK_CLOSE_DICT || tok == PDF_TOK_NAME ||
(tok == PDF_TOK_KEYWORD && !strcmp(buf, "ID")))
{
val = fz_new_int(ctx, a);
- fz_dict_put(ctx, dict, key, val);
- fz_drop_obj(ctx, val);
- fz_drop_obj(ctx, key);
+ fz_dict_put(dict, key, val);
+ fz_drop_obj(val);
+ fz_drop_obj(key);
goto skip;
}
if (tok == PDF_TOK_INT)
@@ -411,8 +411,8 @@ skip:
error = pdf_lex(&tok, file, buf, cap, &len);
if (error)
{
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_note(error, "cannot parse dict");
}
if (tok == PDF_TOK_R)
@@ -421,19 +421,19 @@ skip:
break;
}
}
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_make("invalid indirect reference in dict");
default:
- fz_drop_obj(ctx, key);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(key);
+ fz_drop_obj(dict);
return fz_error_make("unknown token in dict");
}
- fz_dict_put(ctx, dict, key, val);
- fz_drop_obj(ctx, val);
- fz_drop_obj(ctx, key);
+ fz_dict_put(dict, key, val);
+ fz_drop_obj(val);
+ fz_drop_obj(key);
}
}
@@ -567,7 +567,7 @@ pdf_parse_ind_obj(fz_obj **op, pdf_xref *xref,
error = pdf_lex(&tok, file, buf, cap, &len);
if (error)
{
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
return fz_error_note(error, "cannot parse indirect object (%d %d R)", num, gen);
}
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c
index d058b2b5..c50f93ae 100644
--- a/pdf/pdf_pattern.c
+++ b/pdf/pdf_pattern.c
@@ -23,20 +23,20 @@ pdf_load_pattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict)
/* Store pattern now, to avoid possible recursion if objects refer back to this one */
pdf_store_item(ctx, xref->store, (pdf_store_keep_fn *)pdf_keep_pattern, (pdf_store_drop_fn *)pdf_drop_pattern, dict, pat);
- pat->ismask = fz_to_int(ctx, fz_dict_gets(ctx, dict, "PaintType")) == 2;
- pat->xstep = fz_to_real(ctx, fz_dict_gets(ctx, dict, "XStep"));
- pat->ystep = fz_to_real(ctx, fz_dict_gets(ctx, dict, "YStep"));
+ pat->ismask = fz_to_int(fz_dict_gets(dict, "PaintType")) == 2;
+ pat->xstep = fz_to_real(fz_dict_gets(dict, "XStep"));
+ pat->ystep = fz_to_real(fz_dict_gets(dict, "YStep"));
- obj = fz_dict_gets(ctx, dict, "BBox");
+ obj = fz_dict_gets(dict, "BBox");
pat->bbox = pdf_to_rect(ctx, obj);
- obj = fz_dict_gets(ctx, dict, "Matrix");
+ obj = fz_dict_gets(dict, "Matrix");
if (obj)
pat->matrix = pdf_to_matrix(ctx, obj);
else
pat->matrix = fz_identity;
- pat->resources = fz_dict_gets(ctx, dict, "Resources");
+ pat->resources = fz_dict_gets(dict, "Resources");
if (pat->resources)
fz_keep_obj(pat->resources);
@@ -65,7 +65,7 @@ pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat)
if (pat && --pat->refs == 0)
{
if (pat->resources)
- fz_drop_obj(ctx, pat->resources);
+ fz_drop_obj(pat->resources);
if (pat->contents)
fz_drop_buffer(ctx, pat->contents);
fz_free(ctx, pat);
diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c
index e31822af..83b0d814 100644
--- a/pdf/pdf_repair.c
+++ b/pdf/pdf_repair.c
@@ -20,7 +20,6 @@ pdf_repair_obj(fz_stream *file, char *buf, int cap, int *stmofsp, int *stmlenp,
int stm_len;
int len;
int n;
- fz_context *ctx = file->ctx;
*stmofsp = 0;
*stmlenp = -1;
@@ -39,31 +38,31 @@ pdf_repair_obj(fz_stream *file, char *buf, int cap, int *stmofsp, int *stmlenp,
if (error)
return fz_error_note(error, "cannot parse object");
- obj = fz_dict_gets(ctx, dict, "Type");
- if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "XRef"))
+ obj = fz_dict_gets(dict, "Type");
+ if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "XRef"))
{
- obj = fz_dict_gets(ctx, dict, "Encrypt");
+ obj = fz_dict_gets(dict, "Encrypt");
if (obj)
{
if (*encrypt)
- fz_drop_obj(ctx, *encrypt);
+ fz_drop_obj(*encrypt);
*encrypt = fz_keep_obj(obj);
}
- obj = fz_dict_gets(ctx, dict, "ID");
+ obj = fz_dict_gets(dict, "ID");
if (obj)
{
if (*id)
- fz_drop_obj(ctx, *id);
+ fz_drop_obj(*id);
*id = fz_keep_obj(obj);
}
}
- obj = fz_dict_gets(ctx, dict, "Length");
- if (fz_is_int(ctx, obj))
- stm_len = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "Length");
+ if (fz_is_int(obj))
+ stm_len = fz_to_int(obj);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
}
while ( tok != PDF_TOK_STREAM &&
@@ -135,15 +134,14 @@ pdf_repair_obj_stm(pdf_xref *xref, int num, int gen)
int tok;
int i, n, count;
char buf[256];
- fz_context *ctx = xref->ctx;
error = pdf_load_object(&obj, xref, num, gen);
if (error)
return fz_error_note(error, "cannot load object stream object (%d %d R)", num, gen);
- count = fz_to_int(ctx, fz_dict_gets(ctx, obj, "N"));
+ count = fz_to_int(fz_dict_gets(obj, "N"));
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
error = pdf_open_stream(&stm, xref, num, gen);
if (error)
@@ -297,39 +295,39 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize)
goto cleanup;
}
- obj = fz_dict_gets(ctx, dict, "Encrypt");
+ obj = fz_dict_gets(dict, "Encrypt");
if (obj)
{
if (encrypt)
- fz_drop_obj(ctx, encrypt);
+ fz_drop_obj(encrypt);
encrypt = fz_keep_obj(obj);
}
- obj = fz_dict_gets(ctx, dict, "ID");
+ obj = fz_dict_gets(dict, "ID");
if (obj)
{
if (id)
- fz_drop_obj(ctx, id);
+ fz_drop_obj(id);
id = fz_keep_obj(obj);
}
- obj = fz_dict_gets(ctx, dict, "Root");
+ obj = fz_dict_gets(dict, "Root");
if (obj)
{
if (root)
- fz_drop_obj(ctx, root);
+ fz_drop_obj(root);
root = fz_keep_obj(obj);
}
- obj = fz_dict_gets(ctx, dict, "Info");
+ obj = fz_dict_gets(dict, "Info");
if (obj)
{
if (info)
- fz_drop_obj(ctx, info);
+ fz_drop_obj(info);
info = fz_keep_obj(obj);
}
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
}
else if (tok == PDF_TOK_ERROR)
@@ -362,10 +360,10 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize)
}
length = fz_new_int(ctx, list[i].stm_len);
- fz_dict_puts(ctx, dict, "Length", length);
- fz_drop_obj(ctx, length);
+ fz_dict_puts(dict, "Length", length);
+ fz_drop_obj(length);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
}
}
@@ -393,18 +391,18 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize)
xref->trailer = fz_new_dict(ctx, 5);
obj = fz_new_int(ctx, maxnum + 1);
- fz_dict_puts(ctx, xref->trailer, "Size", obj);
- fz_drop_obj(ctx, obj);
+ fz_dict_puts(xref->trailer, "Size", obj);
+ fz_drop_obj(obj);
if (root)
{
- fz_dict_puts(ctx, xref->trailer, "Root", root);
- fz_drop_obj(ctx, root);
+ fz_dict_puts(xref->trailer, "Root", root);
+ fz_drop_obj(root);
}
if (info)
{
- fz_dict_puts(ctx, xref->trailer, "Info", info);
- fz_drop_obj(ctx, info);
+ fz_dict_puts(xref->trailer, "Info", info);
+ fz_drop_obj(info);
}
if (encrypt)
@@ -413,11 +411,11 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize)
{
/* create new reference with non-NULL xref pointer */
obj = fz_new_indirect(ctx, fz_to_num(encrypt), fz_to_gen(encrypt), xref);
- fz_drop_obj(ctx, encrypt);
+ fz_drop_obj(encrypt);
encrypt = obj;
}
- fz_dict_puts(ctx, xref->trailer, "Encrypt", encrypt);
- fz_drop_obj(ctx, encrypt);
+ fz_dict_puts(xref->trailer, "Encrypt", encrypt);
+ fz_drop_obj(encrypt);
}
if (id)
@@ -426,21 +424,21 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize)
{
/* create new reference with non-NULL xref pointer */
obj = fz_new_indirect(ctx, fz_to_num(id), fz_to_gen(id), xref);
- fz_drop_obj(ctx, id);
+ fz_drop_obj(id);
id = obj;
}
- fz_dict_puts(ctx, xref->trailer, "ID", id);
- fz_drop_obj(ctx, id);
+ fz_dict_puts(xref->trailer, "ID", id);
+ fz_drop_obj(id);
}
fz_free(ctx, list);
return fz_okay;
cleanup:
- if (encrypt) fz_drop_obj(ctx, encrypt);
- if (id) fz_drop_obj(ctx, id);
- if (root) fz_drop_obj(ctx, root);
- if (info) fz_drop_obj(ctx, info);
+ if (encrypt) fz_drop_obj(encrypt);
+ if (id) fz_drop_obj(id);
+ if (root) fz_drop_obj(root);
+ if (info) fz_drop_obj(info);
fz_free(ctx, list);
return error; /* already rethrown */
}
@@ -450,16 +448,15 @@ pdf_repair_obj_stms(pdf_xref *xref)
{
fz_obj *dict;
int i;
- fz_context *ctx = xref->ctx;
for (i = 0; i < xref->len; i++)
{
if (xref->table[i].stm_ofs)
{
pdf_load_object(&dict, xref, i, 0);
- if (!strcmp(fz_to_name(ctx, fz_dict_gets(ctx, dict, "Type")), "ObjStm"))
+ if (!strcmp(fz_to_name(fz_dict_gets(dict, "Type")), "ObjStm"))
pdf_repair_obj_stm(xref, i, 0);
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
}
}
diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c
index 53d5700d..a6819521 100644
--- a/pdf/pdf_shade.c
+++ b/pdf/pdf_shade.c
@@ -377,18 +377,18 @@ pdf_load_function_based_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, p
x0 = y0 = 0;
x1 = y1 = 1;
- obj = fz_dict_gets(ctx, dict, "Domain");
- if (fz_array_len(ctx, obj) == 4)
+ obj = fz_dict_gets(dict, "Domain");
+ if (fz_array_len(obj) == 4)
{
- x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0));
- x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1));
- y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 2));
- y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3));
+ x0 = fz_to_real(fz_array_get(obj, 0));
+ x1 = fz_to_real(fz_array_get(obj, 1));
+ y0 = fz_to_real(fz_array_get(obj, 2));
+ y1 = fz_to_real(fz_array_get(obj, 3));
}
matrix = fz_identity;
- obj = fz_dict_gets(ctx, dict, "Matrix");
- if (fz_array_len(ctx, obj) == 6)
+ obj = fz_dict_gets(dict, "Matrix");
+ if (fz_array_len(obj) == 6)
matrix = pdf_to_matrix(ctx, obj);
for (yy = 0; yy < FUNSEGS; yy++)
@@ -437,27 +437,27 @@ pdf_load_axial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs,
struct vertex p1, p2;
fz_context *ctx = xref->ctx;
- obj = fz_dict_gets(ctx, dict, "Coords");
- x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0));
- y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 1));
- x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 2));
- y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3));
+ obj = fz_dict_gets(dict, "Coords");
+ x0 = fz_to_real(fz_array_get(obj, 0));
+ y0 = fz_to_real(fz_array_get(obj, 1));
+ x1 = fz_to_real(fz_array_get(obj, 2));
+ y1 = fz_to_real(fz_array_get(obj, 3));
d0 = 0;
d1 = 1;
- obj = fz_dict_gets(ctx, dict, "Domain");
- if (fz_array_len(ctx, obj) == 2)
+ obj = fz_dict_gets(dict, "Domain");
+ if (fz_array_len(obj) == 2)
{
- d0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0));
- d1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1));
+ d0 = fz_to_real(fz_array_get(obj, 0));
+ d1 = fz_to_real(fz_array_get(obj, 1));
}
e0 = e1 = 0;
- obj = fz_dict_gets(ctx, dict, "Extend");
- if (fz_array_len(ctx, obj) == 2)
+ obj = fz_dict_gets(dict, "Extend");
+ if (fz_array_len(obj) == 2)
{
- e0 = fz_to_bool(ctx, fz_array_get(ctx, obj, 0));
- e1 = fz_to_bool(ctx, fz_array_get(ctx, obj, 1));
+ e0 = fz_to_bool(fz_array_get(obj, 0));
+ e1 = fz_to_bool(fz_array_get(obj, 1));
}
pdf_sample_shade_function(shade, funcs, func, d0, d1);
@@ -488,29 +488,29 @@ pdf_load_radial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs
struct vertex p1, p2;
fz_context *ctx = xref->ctx;
- obj = fz_dict_gets(ctx, dict, "Coords");
- x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0));
- y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 1));
- r0 = fz_to_real(ctx, fz_array_get(ctx, obj, 2));
- x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3));
- y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 4));
- r1 = fz_to_real(ctx, fz_array_get(ctx, obj, 5));
+ obj = fz_dict_gets(dict, "Coords");
+ x0 = fz_to_real(fz_array_get(obj, 0));
+ y0 = fz_to_real(fz_array_get(obj, 1));
+ r0 = fz_to_real(fz_array_get(obj, 2));
+ x1 = fz_to_real(fz_array_get(obj, 3));
+ y1 = fz_to_real(fz_array_get(obj, 4));
+ r1 = fz_to_real(fz_array_get(obj, 5));
d0 = 0;
d1 = 1;
- obj = fz_dict_gets(ctx, dict, "Domain");
- if (fz_array_len(ctx, obj) == 2)
+ obj = fz_dict_gets(dict, "Domain");
+ if (fz_array_len(obj) == 2)
{
- d0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0));
- d1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1));
+ d0 = fz_to_real(fz_array_get(obj, 0));
+ d1 = fz_to_real(fz_array_get(obj, 1));
}
e0 = e1 = 0;
- obj = fz_dict_gets(ctx, dict, "Extend");
- if (fz_array_len(ctx, obj) == 2)
+ obj = fz_dict_gets(dict, "Extend");
+ if (fz_array_len(obj) == 2)
{
- e0 = fz_to_bool(ctx, fz_array_get(ctx, obj, 0));
- e1 = fz_to_bool(ctx, fz_array_get(ctx, obj, 1));
+ e0 = fz_to_bool(fz_array_get(obj, 0));
+ e1 = fz_to_bool(fz_array_get(obj, 1));
}
pdf_sample_shade_function(shade, funcs, func, d0, d1);
@@ -557,7 +557,6 @@ pdf_load_mesh_params(pdf_xref *xref, fz_obj *dict, struct mesh_params *p)
{
fz_obj *obj;
int i, n;
- fz_context *ctx = xref->ctx;
p->x0 = p->y0 = 0;
p->x1 = p->y1 = 1;
@@ -567,23 +566,23 @@ pdf_load_mesh_params(pdf_xref *xref, fz_obj *dict, struct mesh_params *p)
p->c1[i] = 1;
}
- p->vprow = fz_to_int(ctx, fz_dict_gets(ctx, dict, "VerticesPerRow"));
- p->bpflag = fz_to_int(ctx, fz_dict_gets(ctx, dict, "BitsPerFlag"));
- p->bpcoord = fz_to_int(ctx, fz_dict_gets(ctx, dict, "BitsPerCoordinate"));
- p->bpcomp = fz_to_int(ctx, fz_dict_gets(ctx, dict, "BitsPerComponent"));
+ p->vprow = fz_to_int(fz_dict_gets(dict, "VerticesPerRow"));
+ p->bpflag = fz_to_int(fz_dict_gets(dict, "BitsPerFlag"));
+ p->bpcoord = fz_to_int(fz_dict_gets(dict, "BitsPerCoordinate"));
+ p->bpcomp = fz_to_int(fz_dict_gets(dict, "BitsPerComponent"));
- obj = fz_dict_gets(ctx, dict, "Decode");
- if (fz_array_len(ctx, obj) >= 6)
+ obj = fz_dict_gets(dict, "Decode");
+ if (fz_array_len(obj) >= 6)
{
- n = (fz_array_len(ctx, obj) - 4) / 2;
- p->x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0));
- p->x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1));
- p->y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 2));
- p->y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3));
+ n = (fz_array_len(obj) - 4) / 2;
+ p->x0 = fz_to_real(fz_array_get(obj, 0));
+ p->x1 = fz_to_real(fz_array_get(obj, 1));
+ p->y0 = fz_to_real(fz_array_get(obj, 2));
+ p->y1 = fz_to_real(fz_array_get(obj, 3));
for (i = 0; i < n; i++)
{
- p->c0[i] = fz_to_real(ctx, fz_array_get(ctx, obj, 4 + i * 2));
- p->c1[i] = fz_to_real(ctx, fz_array_get(ctx, obj, 5 + i * 2));
+ p->c0[i] = fz_to_real(fz_array_get(obj, 4 + i * 2));
+ p->c1[i] = fz_to_real(fz_array_get(obj, 5 + i * 2));
}
}
@@ -989,10 +988,10 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix
funcs = 0;
- obj = fz_dict_gets(ctx, dict, "ShadingType");
- type = fz_to_int(ctx, obj);
+ obj = fz_dict_gets(dict, "ShadingType");
+ type = fz_to_int(obj);
- obj = fz_dict_gets(ctx, dict, "ColorSpace");
+ obj = fz_dict_gets(dict, "ColorSpace");
if (!obj)
{
fz_drop_shade(ctx, shade);
@@ -1005,22 +1004,22 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix
return fz_error_note(error, "cannot load colorspace (%d %d R)", fz_to_num(obj), fz_to_gen(obj));
}
- obj = fz_dict_gets(ctx, dict, "Background");
+ obj = fz_dict_gets(dict, "Background");
if (obj)
{
shade->use_background = 1;
for (i = 0; i < shade->colorspace->n; i++)
- shade->background[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i));
+ shade->background[i] = fz_to_real(fz_array_get(obj, i));
}
- obj = fz_dict_gets(ctx, dict, "BBox");
- if (fz_is_array(ctx, obj))
+ obj = fz_dict_gets(dict, "BBox");
+ if (fz_is_array(obj))
{
shade->bbox = pdf_to_rect(ctx, obj);
}
- obj = fz_dict_gets(ctx, dict, "Function");
- if (fz_is_dict(ctx, obj))
+ obj = fz_dict_gets(dict, "Function");
+ if (fz_is_dict(obj))
{
funcs = 1;
@@ -1031,9 +1030,9 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix
goto cleanup;
}
}
- else if (fz_is_array(ctx, obj))
+ else if (fz_is_array(obj))
{
- funcs = fz_array_len(ctx, obj);
+ funcs = fz_array_len(obj);
if (funcs != 1 && funcs != shade->colorspace->n)
{
error = fz_error_make("incorrect number of shading functions");
@@ -1042,7 +1041,7 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix
for (i = 0; i < funcs; i++)
{
- error = pdf_load_function(&func[i], xref, fz_array_get(ctx, obj, i));
+ error = pdf_load_function(&func[i], xref, fz_array_get(obj, i));
if (error)
{
error = fz_error_note(error, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj));
@@ -1110,24 +1109,24 @@ pdf_load_shading(fz_shade **shadep, pdf_xref *xref, fz_obj *dict)
}
/* Type 2 pattern dictionary */
- if (fz_dict_gets(ctx, dict, "PatternType"))
+ if (fz_dict_gets(dict, "PatternType"))
{
- obj = fz_dict_gets(ctx, dict, "Matrix");
+ obj = fz_dict_gets(dict, "Matrix");
if (obj)
mat = pdf_to_matrix(ctx, obj);
else
mat = fz_identity;
- obj = fz_dict_gets(ctx, dict, "ExtGState");
+ obj = fz_dict_gets(dict, "ExtGState");
if (obj)
{
- if (fz_dict_gets(ctx, obj, "CA") || fz_dict_gets(ctx, obj, "ca"))
+ if (fz_dict_gets(obj, "CA") || fz_dict_gets(obj, "ca"))
{
fz_warn("shading with alpha not supported");
}
}
- obj = fz_dict_gets(ctx, dict, "Shading");
+ obj = fz_dict_gets(dict, "Shading");
if (!obj)
return fz_error_make("syntaxerror: missing shading dictionary");
diff --git a/pdf/pdf_store.c b/pdf/pdf_store.c
index 346afc5d..c8b8ba1c 100644
--- a/pdf/pdf_store.c
+++ b/pdf/pdf_store.c
@@ -120,7 +120,7 @@ pdf_remove_item(fz_context *ctx, pdf_store *store, pdf_store_drop_fn *drop_func,
{
fz_hash_remove(store->hash, &refkey);
item->drop_func(ctx, item->val);
- fz_drop_obj(ctx, item->key);
+ fz_drop_obj(item->key);
fz_free(ctx, item);
}
}
@@ -137,7 +137,7 @@ pdf_remove_item(fz_context *ctx, pdf_store *store, pdf_store_drop_fn *drop_func,
else
prev->next = next;
item->drop_func(ctx, item->val);
- fz_drop_obj(ctx, item->key);
+ fz_drop_obj(item->key);
fz_free(ctx, item);
}
else
@@ -162,7 +162,7 @@ pdf_age_store(fz_context *ctx, pdf_store *store, int maxage)
{
fz_hash_remove(store->hash, refkey);
item->drop_func(ctx, item->val);
- fz_drop_obj(ctx, item->key);
+ fz_drop_obj(item->key);
fz_free(ctx, item);
i--; /* items with same hash may move into place */
}
@@ -179,7 +179,7 @@ pdf_age_store(fz_context *ctx, pdf_store *store, int maxage)
else
prev->next = next;
item->drop_func(ctx, item->val);
- fz_drop_obj(ctx, item->key);
+ fz_drop_obj(item->key);
fz_free(ctx, item);
}
else
@@ -218,7 +218,7 @@ pdf_debug_store(fz_context *ctx, pdf_store *store)
{
next = item->next;
printf("store[*] ");
- fz_debug_obj(ctx, item->key);
+ fz_debug_obj(item->key);
printf(" = %p\n", item->val);
}
}
diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c
index 4fb9adce..ccf96da9 100644
--- a/pdf/pdf_stream.c
+++ b/pdf/pdf_stream.c
@@ -32,18 +32,18 @@ pdf_stream_has_crypt(fz_context *ctx, fz_obj *stm)
fz_obj *obj;
int i;
- filters = fz_dict_getsa(ctx, stm, "Filter", "F");
+ filters = fz_dict_getsa(stm, "Filter", "F");
if (filters)
{
- if (!strcmp(fz_to_name(ctx, filters), "Crypt"))
+ if (!strcmp(fz_to_name(filters), "Crypt"))
return 1;
- if (fz_is_array(ctx, filters))
+ if (fz_is_array(filters))
{
- int n = fz_array_len(ctx, filters);
+ int n = fz_array_len(filters);
for (i = 0; i < n; i++)
{
- obj = fz_array_get(ctx, filters, i);
- if (!strcmp(fz_to_name(ctx, obj), "Crypt"))
+ obj = fz_array_get(filters, i);
+ if (!strcmp(fz_to_name(obj), "Crypt"))
return 1;
}
}
@@ -61,7 +61,7 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num,
char *s;
fz_context *ctx = chain->ctx;
- s = fz_to_name(ctx, f);
+ s = fz_to_name(f);
if (!strcmp(s, "ASCIIHexDecode") || !strcmp(s, "AHx"))
return fz_open_ahxd(chain);
@@ -80,23 +80,23 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num,
else if (!strcmp(s, "FlateDecode") || !strcmp(s, "Fl"))
{
- fz_obj *obj = fz_dict_gets(ctx, p, "Predictor");
- if (fz_to_int(ctx, obj) > 1)
+ fz_obj *obj = fz_dict_gets(p, "Predictor");
+ if (fz_to_int(obj) > 1)
return fz_open_predict(fz_open_flated(chain), p);
return fz_open_flated(chain);
}
else if (!strcmp(s, "LZWDecode") || !strcmp(s, "LZW"))
{
- fz_obj *obj = fz_dict_gets(ctx, p, "Predictor");
- if (fz_to_int(ctx, obj) > 1)
+ fz_obj *obj = fz_dict_gets(p, "Predictor");
+ if (fz_to_int(obj) > 1)
return fz_open_predict(fz_open_lzwd(chain, p), p);
return fz_open_lzwd(chain, p);
}
else if (!strcmp(s, "JBIG2Decode"))
{
- fz_obj *obj = fz_dict_gets(ctx, p, "JBIG2Globals");
+ fz_obj *obj = fz_dict_gets(p, "JBIG2Globals");
if (obj)
{
fz_buffer *globals;
@@ -123,9 +123,9 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num,
return chain;
}
- name = fz_dict_gets(ctx, p, "Name");
- if (fz_is_name(ctx, name))
- return pdf_open_crypt_with_filter(chain, xref->crypt, fz_to_name(ctx, name), num, gen);
+ name = fz_dict_gets(p, "Name");
+ if (fz_is_name(name))
+ return pdf_open_crypt_with_filter(chain, xref->crypt, fz_to_name(name), num, gen);
return chain;
}
@@ -145,13 +145,12 @@ build_filter_chain(fz_stream *chain, pdf_xref *xref, fz_obj *fs, fz_obj *ps, int
fz_obj *f;
fz_obj *p;
int i, n;
- fz_context *ctx = chain->ctx;
- n = fz_array_len(ctx, fs);
+ n = fz_array_len(fs);
for (i = 0; i < n; i++)
{
- f = fz_array_get(ctx, fs, i);
- p = fz_array_get(ctx, ps, i);
+ f = fz_array_get(fs, i);
+ p = fz_array_get(ps, i);
chain = build_filter(chain, xref, f, p, num, gen);
}
@@ -173,7 +172,7 @@ pdf_open_raw_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, i
/* don't close chain when we close this filter */
fz_keep_stream(chain);
- len = fz_to_int(ctx, fz_dict_gets(ctx, stmobj, "Length"));
+ len = fz_to_int(fz_dict_gets(stmobj, "Length"));
chain = fz_open_null(chain, len);
hascrypt = pdf_stream_has_crypt(ctx, stmobj);
@@ -192,16 +191,15 @@ pdf_open_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int g
{
fz_obj *filters;
fz_obj *params;
- fz_context *ctx = chain->ctx;
- filters = fz_dict_getsa(ctx, stmobj, "Filter", "F");
- params = fz_dict_getsa(ctx, stmobj, "DecodeParms", "DP");
+ filters = fz_dict_getsa(stmobj, "Filter", "F");
+ params = fz_dict_getsa(stmobj, "DecodeParms", "DP");
chain = pdf_open_raw_filter(chain, xref, stmobj, num, gen);
- if (fz_is_name(ctx, filters))
+ if (fz_is_name(filters))
return build_filter(chain, xref, filters, params, num, gen);
- if (fz_array_len(ctx, filters) > 0)
+ if (fz_array_len(filters) > 0)
return build_filter_chain(chain, xref, filters, params, num, gen);
return chain;
@@ -216,17 +214,16 @@ pdf_open_inline_stream(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int len
{
fz_obj *filters;
fz_obj *params;
- fz_context *ctx = chain->ctx;
- filters = fz_dict_getsa(ctx, stmobj, "Filter", "F");
- params = fz_dict_getsa(ctx, stmobj, "DecodeParms", "DP");
+ filters = fz_dict_getsa(stmobj, "Filter", "F");
+ params = fz_dict_getsa(stmobj, "DecodeParms", "DP");
/* don't close chain when we close this filter */
fz_keep_stream(chain);
- if (fz_is_name(ctx, filters))
+ if (fz_is_name(filters))
return build_filter(chain, xref, filters, params, 0, 0);
- if (fz_array_len(ctx, filters) > 0)
+ if (fz_array_len(filters) > 0)
return build_filter_chain(chain, xref, filters, params, 0, 0);
return fz_open_null(chain, length);
@@ -313,15 +310,14 @@ pdf_load_raw_stream(fz_buffer **bufp, pdf_xref *xref, int num, int gen)
fz_stream *stm;
fz_obj *dict;
int len;
- fz_context *ctx = xref->ctx;
error = pdf_load_object(&dict, xref, num, gen);
if (error)
return fz_error_note(error, "cannot load stream dictionary (%d %d R)", num, gen);
- len = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Length"));
+ len = fz_to_int(fz_dict_gets(dict, "Length"));
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
error = pdf_open_raw_stream(&stm, xref, num, gen);
if (error)
@@ -364,7 +360,6 @@ pdf_load_stream(fz_buffer **bufp, pdf_xref *xref, int num, int gen)
fz_stream *stm;
fz_obj *dict, *obj;
int i, len, n;
- fz_context *ctx = xref->ctx;
error = pdf_open_stream(&stm, xref, num, gen);
if (error)
@@ -374,14 +369,14 @@ pdf_load_stream(fz_buffer **bufp, pdf_xref *xref, int num, int gen)
if (error)
return fz_error_note(error, "cannot load stream dictionary (%d %d R)", num, gen);
- len = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Length"));
- obj = fz_dict_gets(ctx, dict, "Filter");
- len = pdf_guess_filter_length(len, fz_to_name(ctx, obj));
- n = fz_array_len(ctx, obj);
+ len = fz_to_int(fz_dict_gets(dict, "Length"));
+ obj = fz_dict_gets(dict, "Filter");
+ len = pdf_guess_filter_length(len, fz_to_name(obj));
+ n = fz_array_len(obj);
for (i = 0; i < n; i++)
- len = pdf_guess_filter_length(len, fz_to_name(ctx, fz_array_get(ctx, obj, i)));
+ len = pdf_guess_filter_length(len, fz_to_name(fz_array_get(obj, i)));
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
error = fz_read_all(bufp, stm, len);
if (error)
diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c
index 7f055f9f..b6306b47 100644
--- a/pdf/pdf_type3.c
+++ b/pdf/pdf_type3.c
@@ -24,18 +24,18 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
fz_matrix matrix;
fz_context *ctx = xref->ctx;
- obj = fz_dict_gets(ctx, dict, "Name");
- if (fz_is_name(ctx, obj))
- fz_strlcpy(buf, fz_to_name(ctx, obj), sizeof buf);
+ obj = fz_dict_gets(dict, "Name");
+ if (fz_is_name(obj))
+ fz_strlcpy(buf, fz_to_name(obj), sizeof buf);
else
sprintf(buf, "Unnamed-T3");
fontdesc = pdf_new_font_desc(ctx);
- obj = fz_dict_gets(ctx, dict, "FontMatrix");
+ obj = fz_dict_gets(dict, "FontMatrix");
matrix = pdf_to_matrix(ctx, obj);
- obj = fz_dict_gets(ctx, dict, "FontBBox");
+ obj = fz_dict_gets(dict, "FontBBox");
bbox = pdf_to_rect(ctx, obj);
fontdesc->font = fz_new_type3_font(ctx, buf, matrix);
@@ -47,36 +47,36 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
for (i = 0; i < 256; i++)
estrings[i] = NULL;
- encoding = fz_dict_gets(ctx, dict, "Encoding");
+ encoding = fz_dict_gets(dict, "Encoding");
if (!encoding)
{
error = fz_error_make("syntaxerror: Type3 font missing Encoding");
goto cleanup;
}
- if (fz_is_name(ctx, encoding))
- pdf_load_encoding(estrings, fz_to_name(ctx, encoding));
+ if (fz_is_name(encoding))
+ pdf_load_encoding(estrings, fz_to_name(encoding));
- if (fz_is_dict(ctx, encoding))
+ if (fz_is_dict(encoding))
{
fz_obj *base, *diff, *item;
- base = fz_dict_gets(ctx, encoding, "BaseEncoding");
- if (fz_is_name(ctx, base))
- pdf_load_encoding(estrings, fz_to_name(ctx, base));
+ base = fz_dict_gets(encoding, "BaseEncoding");
+ if (fz_is_name(base))
+ pdf_load_encoding(estrings, fz_to_name(base));
- diff = fz_dict_gets(ctx, encoding, "Differences");
- if (fz_is_array(ctx, diff))
+ diff = fz_dict_gets(encoding, "Differences");
+ if (fz_is_array(diff))
{
- n = fz_array_len(ctx, diff);
+ n = fz_array_len(diff);
k = 0;
for (i = 0; i < n; i++)
{
- item = fz_array_get(ctx, diff, i);
- if (fz_is_int(ctx, item))
- k = fz_to_int(ctx, item);
- if (fz_is_name(ctx, item))
- estrings[k++] = fz_to_name(ctx, item);
+ item = fz_array_get(diff, i);
+ if (fz_is_int(item))
+ k = fz_to_int(item);
+ if (fz_is_name(item))
+ estrings[k++] = fz_to_name(item);
if (k < 0) k = 0;
if (k > 255) k = 255;
}
@@ -85,7 +85,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 1);
- error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(ctx, dict, "ToUnicode"));
+ error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(dict, "ToUnicode"));
if (error)
goto cleanup;
@@ -93,10 +93,10 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
pdf_set_default_hmtx(fontdesc, 0);
- first = fz_to_int(ctx, fz_dict_gets(ctx, dict, "FirstChar"));
- last = fz_to_int(ctx, fz_dict_gets(ctx, dict, "LastChar"));
+ first = fz_to_int(fz_dict_gets(dict, "FirstChar"));
+ last = fz_to_int(fz_dict_gets(dict, "LastChar"));
- widths = fz_dict_gets(ctx, dict, "Widths");
+ widths = fz_dict_gets(dict, "Widths");
if (!widths)
{
error = fz_error_make("syntaxerror: Type3 font missing Widths");
@@ -105,7 +105,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
for (i = first; i <= last; i++)
{
- float w = fz_to_real(ctx, fz_array_get(ctx, widths, i - first));
+ float w = fz_to_real(fz_array_get(widths, i - first));
w = fontdesc->font->t3matrix.a * w * 1000;
fontdesc->font->t3widths[i] = w * 0.001f;
pdf_add_hmtx(ctx, fontdesc, i, i, w);
@@ -115,7 +115,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
/* Resources -- inherit page resources if the font doesn't have its own */
- fontdesc->font->t3resources = fz_dict_gets(ctx, dict, "Resources");
+ fontdesc->font->t3resources = fz_dict_gets(dict, "Resources");
if (!fontdesc->font->t3resources)
fontdesc->font->t3resources = rdb;
if (fontdesc->font->t3resources)
@@ -128,7 +128,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
/* CharProcs */
- charprocs = fz_dict_gets(ctx, dict, "CharProcs");
+ charprocs = fz_dict_gets(dict, "CharProcs");
if (!charprocs)
{
error = fz_error_make("syntaxerror: Type3 font missing CharProcs");
@@ -139,7 +139,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o
{
if (estrings[i])
{
- obj = fz_dict_gets(ctx, charprocs, estrings[i]);
+ obj = fz_dict_gets(charprocs, estrings[i]);
if (pdf_is_stream(xref, fz_to_num(obj), fz_to_gen(obj)))
{
error = pdf_load_stream(&fontdesc->font->t3procs[i], xref, fz_to_num(obj), fz_to_gen(obj));
diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c
index 1c1bd276..25503374 100644
--- a/pdf/pdf_xobject.c
+++ b/pdf/pdf_xobject.c
@@ -24,10 +24,10 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict)
/* Store item immediately, to avoid possible recursion if objects refer back to this one */
pdf_store_item(ctx, xref->store, (pdf_store_keep_fn *)pdf_keep_xobject, (pdf_store_drop_fn *)pdf_drop_xobject, dict, form);
- obj = fz_dict_gets(ctx, dict, "BBox");
+ obj = fz_dict_gets(dict, "BBox");
form->bbox = pdf_to_rect(ctx, obj);
- obj = fz_dict_gets(ctx, dict, "Matrix");
+ obj = fz_dict_gets(dict, "Matrix");
if (obj)
form->matrix = pdf_to_matrix(ctx, obj);
else
@@ -37,19 +37,19 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict)
form->knockout = 0;
form->transparency = 0;
- obj = fz_dict_gets(ctx, dict, "Group");
+ obj = fz_dict_gets(dict, "Group");
if (obj)
{
fz_obj *attrs = obj;
- form->isolated = fz_to_bool(ctx, fz_dict_gets(ctx, attrs, "I"));
- form->knockout = fz_to_bool(ctx, fz_dict_gets(ctx, attrs, "K"));
+ form->isolated = fz_to_bool(fz_dict_gets(attrs, "I"));
+ form->knockout = fz_to_bool(fz_dict_gets(attrs, "K"));
- obj = fz_dict_gets(ctx, attrs, "S");
- if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Transparency"))
+ obj = fz_dict_gets(attrs, "S");
+ if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Transparency"))
form->transparency = 1;
- obj = fz_dict_gets(ctx, attrs, "CS");
+ obj = fz_dict_gets(attrs, "CS");
if (obj)
{
error = pdf_load_colorspace(&form->colorspace, xref, obj);
@@ -58,7 +58,7 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict)
}
}
- form->resources = fz_dict_gets(ctx, dict, "Resources");
+ form->resources = fz_dict_gets(dict, "Resources");
if (form->resources)
fz_keep_obj(form->resources);
@@ -89,7 +89,7 @@ pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj)
if (xobj->colorspace)
fz_drop_colorspace(ctx, xobj->colorspace);
if (xobj->resources)
- fz_drop_obj(ctx, xobj->resources);
+ fz_drop_obj(xobj->resources);
if (xobj->contents)
fz_drop_buffer(ctx, xobj->contents);
fz_free(ctx, xobj);
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index 1dd591ab..d259e6d0 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -311,19 +311,18 @@ pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
int num, gen, stm_ofs;
int size, w0, w1, w2;
int t;
- fz_context *ctx = xref->ctx;
error = pdf_parse_ind_obj(&trailer, xref, xref->file, buf, cap, &num, &gen, &stm_ofs);
if (error)
return fz_error_note(error, "cannot parse compressed xref stream object");
- obj = fz_dict_gets(ctx, trailer, "Size");
+ obj = fz_dict_gets(trailer, "Size");
if (!obj)
{
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_make("xref stream missing Size entry (%d %d R)", num, gen);
}
- size = fz_to_int(ctx, obj);
+ size = fz_to_int(obj);
if (size > xref->len)
{
@@ -332,25 +331,25 @@ pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
if (num < 0 || num >= xref->len)
{
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_make("object id (%d %d R) out of range (0..%d)", num, gen, xref->len - 1);
}
- obj = fz_dict_gets(ctx, trailer, "W");
+ obj = fz_dict_gets(trailer, "W");
if (!obj) {
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_make("xref stream missing W entry (%d %d R)", num, gen);
}
- w0 = fz_to_int(ctx, fz_array_get(ctx, obj, 0));
- w1 = fz_to_int(ctx, fz_array_get(ctx, obj, 1));
- w2 = fz_to_int(ctx, fz_array_get(ctx, obj, 2));
+ w0 = fz_to_int(fz_array_get(obj, 0));
+ w1 = fz_to_int(fz_array_get(obj, 1));
+ w2 = fz_to_int(fz_array_get(obj, 2));
- index = fz_dict_gets(ctx, trailer, "Index");
+ index = fz_dict_gets(trailer, "Index");
error = pdf_open_stream_at(&stm, xref, num, gen, trailer, stm_ofs);
if (error)
{
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_note(error, "cannot open compressed xref stream (%d %d R)", num, gen);
}
@@ -360,22 +359,22 @@ pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
if (error)
{
fz_close(stm);
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_note(error, "cannot read xref stream (%d %d R)", num, gen);
}
}
else
{
- int n = fz_array_len(ctx, index);
+ int n = fz_array_len(index);
for (t = 0; t < n; t += 2)
{
- int i0 = fz_to_int(ctx, fz_array_get(ctx, index, t + 0));
- int i1 = fz_to_int(ctx, fz_array_get(ctx, index, t + 1));
+ int i0 = fz_to_int(fz_array_get(index, t + 0));
+ int i1 = fz_to_int(fz_array_get(index, t + 1));
error = pdf_read_new_xref_section(xref, stm, i0, i1, w0, w1, w2);
if (error)
{
fz_close(stm);
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_note(error, "cannot read xref stream section (%d %d R)", num, gen);
}
}
@@ -427,36 +426,35 @@ pdf_read_xref_sections(pdf_xref *xref, int ofs, char *buf, int cap)
fz_obj *trailer;
fz_obj *prev;
fz_obj *xrefstm;
- fz_context *ctx = xref->ctx;
error = pdf_read_xref(&trailer, xref, ofs, buf, cap);
if (error)
return fz_error_note(error, "cannot read xref section");
/* FIXME: do we overwrite free entries properly? */
- xrefstm = fz_dict_gets(ctx, trailer, "XRefStm");
+ xrefstm = fz_dict_gets(trailer, "XRefStm");
if (xrefstm)
{
- error = pdf_read_xref_sections(xref, fz_to_int(ctx, xrefstm), buf, cap);
+ error = pdf_read_xref_sections(xref, fz_to_int(xrefstm), buf, cap);
if (error)
{
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_note(error, "cannot read /XRefStm xref section");
}
}
- prev = fz_dict_gets(ctx, trailer, "Prev");
+ prev = fz_dict_gets(trailer, "Prev");
if (prev)
{
- error = pdf_read_xref_sections(xref, fz_to_int(ctx, prev), buf, cap);
+ error = pdf_read_xref_sections(xref, fz_to_int(prev), buf, cap);
if (error)
{
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_error_note(error, "cannot read /Prev xref section");
}
}
- fz_drop_obj(ctx, trailer);
+ fz_drop_obj(trailer);
return fz_okay;
}
@@ -483,11 +481,11 @@ pdf_load_xref(pdf_xref *xref, char *buf, int bufsize)
if (error)
return fz_error_note(error, "cannot read trailer");
- size = fz_dict_gets(xref->ctx, xref->trailer, "Size");
+ size = fz_dict_gets(xref->trailer, "Size");
if (!size)
return fz_error_make("trailer missing Size entry");
- pdf_resize_xref(xref, fz_to_int(xref->ctx, size));
+ pdf_resize_xref(xref, fz_to_int(size));
error = pdf_read_xref_sections(xref, xref->startxref, buf, bufsize);
if (error)
@@ -527,9 +525,10 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password)
fz_context *ctx = file->ctx;
/* install pdf specific callback */
- ctx->resolve_indirect = pdf_resolve_indirect;
+ fz_resolve_indirect = pdf_resolve_indirect;
- xref = fz_calloc(ctx, 1, sizeof(pdf_xref));
+ xref = fz_malloc(ctx, sizeof(pdf_xref));
+ memset(xref, 0, sizeof *xref);
xref->file = fz_keep_stream(file);
xref->ctx = ctx;
@@ -546,7 +545,7 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password)
}
if (xref->trailer)
{
- fz_drop_obj(ctx, xref->trailer);
+ fz_drop_obj(xref->trailer);
xref->trailer = NULL;
}
error = pdf_repair_xref(xref, xref->scratch, sizeof xref->scratch);
@@ -558,9 +557,9 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password)
repaired = 1;
}
- encrypt = fz_dict_gets(ctx, xref->trailer, "Encrypt");
- id = fz_dict_gets(ctx, xref->trailer, "ID");
- if (fz_is_dict(ctx, encrypt))
+ encrypt = fz_dict_gets(xref->trailer, "Encrypt");
+ id = fz_dict_gets(xref->trailer, "ID");
+ if (fz_is_dict(encrypt))
{
error = pdf_new_crypt(ctx, &xref->crypt, encrypt, id);
if (error)
@@ -595,8 +594,8 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password)
return fz_error_note(error, "cannot repair document");
}
- hasroot = fz_dict_gets(ctx, xref->trailer, "Root") != NULL;
- hasinfo = fz_dict_gets(ctx, xref->trailer, "Info") != NULL;
+ hasroot = fz_dict_gets(xref->trailer, "Root") != NULL;
+ hasinfo = fz_dict_gets(xref->trailer, "Info") != NULL;
for (i = 1; i < xref->len; i++)
{
@@ -612,26 +611,26 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password)
if (!hasroot)
{
- obj = fz_dict_gets(ctx, dict, "Type");
- if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Catalog"))
+ obj = fz_dict_gets(dict, "Type");
+ if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Catalog"))
{
obj = fz_new_indirect(ctx, i, 0, xref);
- fz_dict_puts(ctx, xref->trailer, "Root", obj);
- fz_drop_obj(ctx, obj);
+ fz_dict_puts(xref->trailer, "Root", obj);
+ fz_drop_obj(obj);
}
}
if (!hasinfo)
{
- if (fz_dict_gets(ctx, dict, "Creator") || fz_dict_gets(ctx, dict, "Producer"))
+ if (fz_dict_gets(dict, "Creator") || fz_dict_gets(dict, "Producer"))
{
obj = fz_new_indirect(ctx, i, 0, xref);
- fz_dict_puts(ctx, xref->trailer, "Info", obj);
- fz_drop_obj(ctx, obj);
+ fz_dict_puts(xref->trailer, "Info", obj);
+ fz_drop_obj(obj);
}
}
- fz_drop_obj(ctx, dict);
+ fz_drop_obj(dict);
}
}
@@ -654,7 +653,7 @@ pdf_free_xref(pdf_xref *xref)
{
if (xref->table[i].obj)
{
- fz_drop_obj(ctx, xref->table[i].obj);
+ fz_drop_obj(xref->table[i].obj);
xref->table[i].obj = NULL;
}
}
@@ -664,21 +663,21 @@ pdf_free_xref(pdf_xref *xref)
if (xref->page_objs)
{
for (i = 0; i < xref->page_len; i++)
- fz_drop_obj(ctx, xref->page_objs[i]);
+ fz_drop_obj(xref->page_objs[i]);
fz_free(ctx, xref->page_objs);
}
if (xref->page_refs)
{
for (i = 0; i < xref->page_len; i++)
- fz_drop_obj(ctx, xref->page_refs[i]);
+ fz_drop_obj(xref->page_refs[i]);
fz_free(ctx, xref->page_refs);
}
if (xref->file)
fz_close(xref->file);
if (xref->trailer)
- fz_drop_obj(ctx, xref->trailer);
+ fz_drop_obj(xref->trailer);
if (xref->crypt)
pdf_free_crypt(ctx, xref->crypt);
@@ -724,8 +723,8 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap)
if (error)
return fz_error_note(error, "cannot load object stream object (%d %d R)", num, gen);
- count = fz_to_int(ctx, fz_dict_gets(ctx, objstm, "N"));
- first = fz_to_int(ctx, fz_dict_gets(ctx, objstm, "First"));
+ count = fz_to_int(fz_dict_gets(objstm, "N"));
+ first = fz_to_int(fz_dict_gets(objstm, "First"));
numbuf = fz_calloc(ctx, count, sizeof(int));
ofsbuf = fz_calloc(ctx, count, sizeof(int));
@@ -771,7 +770,7 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap)
if (numbuf[i] < 1 || numbuf[i] >= xref->len)
{
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
error = fz_error_make("object id (%d 0 R) out of range (0..%d)", numbuf[i], xref->len - 1);
goto cleanupstm;
}
@@ -779,19 +778,19 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap)
if (xref->table[numbuf[i]].type == 'o' && xref->table[numbuf[i]].ofs == num)
{
if (xref->table[numbuf[i]].obj)
- fz_drop_obj(ctx, xref->table[numbuf[i]].obj);
+ fz_drop_obj(xref->table[numbuf[i]].obj);
xref->table[numbuf[i]].obj = obj;
}
else
{
- fz_drop_obj(ctx, obj);
+ fz_drop_obj(obj);
}
}
fz_close(stm);
fz_free(xref->ctx, ofsbuf);
fz_free(xref->ctx, numbuf);
- fz_drop_obj(ctx, objstm);
+ fz_drop_obj(objstm);
return fz_okay;
cleanupstm:
@@ -799,7 +798,7 @@ cleanupstm:
cleanupbuf:
fz_free(xref->ctx, ofsbuf);
fz_free(xref->ctx, numbuf);
- fz_drop_obj(ctx, objstm);
+ fz_drop_obj(objstm);
return error; /* already rethrown */
}
@@ -916,7 +915,7 @@ pdf_update_object(pdf_xref *xref, int num, int gen, fz_obj *newobj)
x = &xref->table[num];
if (x->obj)
- fz_drop_obj(xref->ctx, x->obj);
+ fz_drop_obj(x->obj);
x->obj = fz_keep_obj(newobj);
x->type = 'n';
diff --git a/scripts/cmapdump.c b/scripts/cmapdump.c
index 23798ec6..ab2eac1d 100644
--- a/scripts/cmapdump.c
+++ b/scripts/cmapdump.c
@@ -9,13 +9,13 @@
#include "fitz.h"
#include "mupdf.h"
+#include "../fitz/base_context.c"
#include "../fitz/base_error.c"
#include "../fitz/base_memory.c"
#include "../fitz/base_string.c"
#include "../fitz/stm_buffer.c"
#include "../fitz/stm_open.c"
#include "../fitz/stm_read.c"
-#include "../fitz/context.c"
#include "../pdf/pdf_lex.c"
#include "../pdf/pdf_cmap.c"
diff --git a/win32/libmupdf.vcproj b/win32/libmupdf.vcproj
index 4ca6be25..1730c7ec 100644
--- a/win32/libmupdf.vcproj
+++ b/win32/libmupdf.vcproj
@@ -455,10 +455,6 @@
>
</File>
<File
- RelativePath="..\fitz\obj_print.c"
- >
- </File>
- <File
RelativePath="..\fitz\res_bitmap.c"
>
</File>
diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c
index 6e890f28..faef1ca7 100644
--- a/xps/xps_tiff.c
+++ b/xps/xps_tiff.c
@@ -192,22 +192,22 @@ xps_decode_tiff_fax(struct tiff *tiff, int comp, fz_stream *chain, byte *wp, int
encoded_byte_align = fz_new_bool(ctx, comp == 2);
params = fz_new_dict(ctx, 5);
- fz_dict_puts(ctx, params, "Columns", columns);
- fz_dict_puts(ctx, params, "Rows", rows);
- fz_dict_puts(ctx, params, "BlackIs1", black_is_1);
- fz_dict_puts(ctx, params, "K", k);
- fz_dict_puts(ctx, params, "EncodedByteAlign", encoded_byte_align);
-
- fz_drop_obj(ctx, columns);
- fz_drop_obj(ctx, rows);
- fz_drop_obj(ctx, black_is_1);
- fz_drop_obj(ctx, k);
- fz_drop_obj(ctx, encoded_byte_align);
+ fz_dict_puts(params, "Columns", columns);
+ fz_dict_puts(params, "Rows", rows);
+ fz_dict_puts(params, "BlackIs1", black_is_1);
+ fz_dict_puts(params, "K", k);
+ fz_dict_puts(params, "EncodedByteAlign", encoded_byte_align);
+
+ fz_drop_obj(columns);
+ fz_drop_obj(rows);
+ fz_drop_obj(black_is_1);
+ fz_drop_obj(k);
+ fz_drop_obj(encoded_byte_align);
stm = fz_open_faxd(chain, params);
n = fz_read(stm, wp, wlen);
fz_close(stm);
- fz_drop_obj(ctx, params);
+ fz_drop_obj(params);
if (n < 0)
return fz_error_note(n, "cannot read fax strip");