From bbfe635555dce16858403706e2031dd3bfa1a9f1 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Sun, 26 Feb 2012 11:15:16 -0800 Subject: Move fz_obj to be pdf_obj. Currently, we are in the slightly strange position of having the PDF specific object types as part of fitz. Here we pull them out into the pdf layer instead. This has been made possible by the recent changes to make the store no longer be tied to having fz_obj's as keys. Most of this work is a simple huge rename; to help customers who may have code that use such functions we have provided a sed script to do the renaming; scripts/rename2.sed. Various other small tweaks are required; the store used to have some debugging code that still required knowledge of fz_obj types - we extract that into a nicer 'type' based function pointer. Also, the type 3 font handling used to have an fz_obj pointer for type 3 resources, and therefore needed to know how to free this; this has become a void * with a function to free it. --- apps/mupdfclean.c | 314 ++++++------- apps/mupdfextract.c | 46 +- apps/mupdfinfo.c | 412 ++++++++-------- apps/mupdfshow.c | 24 +- fitz/base_context.c | 8 - fitz/base_object.c | 1265 ------------------------------------------------- fitz/fitz.h | 88 +--- fitz/res_font.c | 2 +- fitz/res_store.c | 12 +- pdf/base_object.c | 1266 ++++++++++++++++++++++++++++++++++++++++++++++++++ pdf/mupdf.h | 179 +++++-- pdf/pdf_annot.c | 184 ++++---- pdf/pdf_cmap_load.c | 30 +- pdf/pdf_colorspace.c | 116 ++--- pdf/pdf_crypt.c | 182 ++++---- pdf/pdf_font.c | 250 +++++----- pdf/pdf_function.c | 138 +++--- pdf/pdf_image.c | 87 ++-- pdf/pdf_interpret.c | 314 ++++++------- pdf/pdf_nametree.c | 114 ++--- pdf/pdf_outline.c | 36 +- pdf/pdf_page.c | 194 ++++---- pdf/pdf_parse.c | 196 ++++---- pdf/pdf_pattern.c | 24 +- pdf/pdf_repair.c | 134 +++--- pdf/pdf_shade.c | 184 ++++---- pdf/pdf_store.c | 35 +- pdf/pdf_stream.c | 162 +++---- pdf/pdf_type3.c | 88 ++-- pdf/pdf_unicode.c | 6 +- pdf/pdf_xobject.c | 36 +- pdf/pdf_xref.c | 217 +++++---- scripts/rename2.sed | 75 +++ 33 files changed, 3256 insertions(+), 3162 deletions(-) delete mode 100644 fitz/base_object.c create mode 100644 pdf/base_object.c create mode 100644 scripts/rename2.sed diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c index 3130e3f0..f47ea2b5 100644 --- a/apps/mupdfclean.c +++ b/apps/mupdfclean.c @@ -53,34 +53,34 @@ static void usage(void) * Garbage collect objects not reachable from the trailer. */ -static void sweepref(fz_obj *ref); +static void sweepref(pdf_obj *ref); -static void sweepobj(fz_obj *obj) +static void sweepobj(pdf_obj *obj) { int i; - if (fz_is_indirect(obj)) + if (pdf_is_indirect(obj)) sweepref(obj); - else if (fz_is_dict(obj)) + else if (pdf_is_dict(obj)) { - int n = fz_dict_len(obj); + int n = pdf_dict_len(obj); for (i = 0; i < n; i++) - sweepobj(fz_dict_get_val(obj, i)); + sweepobj(pdf_dict_get_val(obj, i)); } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { - int n = fz_array_len(obj); + int n = pdf_array_len(obj); for (i = 0; i < n; i++) - sweepobj(fz_array_get(obj, i)); + sweepobj(pdf_array_get(obj, i)); } } -static void sweepref(fz_obj *obj) +static void sweepref(pdf_obj *obj) { - int num = fz_to_num(obj); - int gen = fz_to_gen(obj); + int num = pdf_to_num(obj); + int gen = pdf_to_gen(obj); if (num < 0 || num >= xref->len) return; @@ -94,12 +94,12 @@ static void sweepref(fz_obj *obj) { if (pdf_is_stream(xref, num, gen)) { - fz_obj *len = fz_dict_gets(obj, "Length"); - if (fz_is_indirect(len)) + pdf_obj *len = pdf_dict_gets(obj, "Length"); + if (pdf_is_indirect(len)) { - uselist[fz_to_num(len)] = 0; - len = fz_resolve_indirect(len); - fz_dict_puts(obj, "Length", len); + uselist[pdf_to_num(len)] = 0; + len = pdf_resolve_indirect(len); + pdf_dict_puts(obj, "Length", len); } } } @@ -108,7 +108,7 @@ static void sweepref(fz_obj *obj) /* Leave broken */ } - sweepobj(fz_resolve_indirect(obj)); + sweepobj(pdf_resolve_indirect(obj)); } /* @@ -124,7 +124,7 @@ static void removeduplicateobjs(void) /* Only compare an object to objects preceding it */ for (other = 1; other < num; other++) { - fz_obj *a, *b; + pdf_obj *a, *b; if (num == other || !uselist[num] || !uselist[other]) continue; @@ -148,10 +148,10 @@ static void removeduplicateobjs(void) a = xref->table[num].obj; b = xref->table[other].obj; - a = fz_resolve_indirect(a); - b = fz_resolve_indirect(b); + a = pdf_resolve_indirect(a); + b = pdf_resolve_indirect(b); - if (fz_objcmp(a, b)) + if (pdf_objcmp(a, b)) continue; /* Keep the lowest numbered object */ @@ -195,23 +195,23 @@ static void compactxref(void) * removing duplicate objects and compacting the xref. */ -static void renumberobj(fz_obj *obj) +static void renumberobj(pdf_obj *obj) { int i; fz_context *ctx = xref->ctx; - if (fz_is_dict(obj)) + if (pdf_is_dict(obj)) { - int n = fz_dict_len(obj); + int n = pdf_dict_len(obj); for (i = 0; i < n; i++) { - fz_obj *key = fz_dict_get_key(obj, i); - fz_obj *val = fz_dict_get_val(obj, i); - if (fz_is_indirect(val)) + pdf_obj *key = pdf_dict_get_key(obj, i); + pdf_obj *val = pdf_dict_get_val(obj, i); + if (pdf_is_indirect(val)) { - val = fz_new_indirect(ctx, renumbermap[fz_to_num(val)], 0, xref); + val = pdf_new_indirect(ctx, renumbermap[pdf_to_num(val)], 0, xref); fz_dict_put(obj, key, val); - fz_drop_obj(val); + pdf_drop_obj(val); } else { @@ -220,17 +220,17 @@ static void renumberobj(fz_obj *obj) } } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { - int n = fz_array_len(obj); + int n = pdf_array_len(obj); for (i = 0; i < n; i++) { - fz_obj *val = fz_array_get(obj, i); - if (fz_is_indirect(val)) + pdf_obj *val = pdf_array_get(obj, i); + if (pdf_is_indirect(val)) { - val = fz_new_indirect(ctx, renumbermap[fz_to_num(val)], 0, xref); - fz_array_put(obj, i, val); - fz_drop_obj(val); + val = pdf_new_indirect(ctx, renumbermap[pdf_to_num(val)], 0, xref); + pdf_array_put(obj, i, val); + pdf_drop_obj(val); } else { @@ -250,13 +250,13 @@ static void renumberobjs(void) renumberobj(xref->trailer); for (num = 0; num < xref->len; num++) { - fz_obj *obj = xref->table[num].obj; + pdf_obj *obj = xref->table[num].obj; - if (fz_is_indirect(obj)) + if (pdf_is_indirect(obj)) { - obj = fz_new_indirect(ctx, renumbermap[fz_to_num(obj)], 0, xref); + obj = pdf_new_indirect(ctx, renumbermap[pdf_to_num(obj)], 0, xref); pdf_update_object(xref, num, 0, obj); - fz_drop_obj(obj); + pdf_drop_obj(obj); } else { @@ -282,7 +282,7 @@ static void renumberobjs(void) else { if (oldxref[num].obj) - fz_drop_obj(oldxref[num].obj); + pdf_drop_obj(oldxref[num].obj); } } @@ -302,25 +302,25 @@ static void renumberobjs(void) static void retainpages(int argc, char **argv) { - fz_obj *oldroot, *root, *pages, *kids, *countobj, *parent, *olddests; + pdf_obj *oldroot, *root, *pages, *kids, *countobj, *parent, *olddests; /* Keep only pages/type and (reduced) dest entries to avoid * references to unretained pages */ - oldroot = fz_dict_gets(xref->trailer, "Root"); - pages = fz_dict_gets(oldroot, "Pages"); + oldroot = pdf_dict_gets(xref->trailer, "Root"); + pages = pdf_dict_gets(oldroot, "Pages"); olddests = pdf_load_name_tree(xref, "Dests"); - root = fz_new_dict(ctx, 2); - fz_dict_puts(root, "Type", fz_dict_gets(oldroot, "Type")); - fz_dict_puts(root, "Pages", fz_dict_gets(oldroot, "Pages")); + root = pdf_new_dict(ctx, 2); + pdf_dict_puts(root, "Type", pdf_dict_gets(oldroot, "Type")); + pdf_dict_puts(root, "Pages", pdf_dict_gets(oldroot, "Pages")); - pdf_update_object(xref, fz_to_num(oldroot), fz_to_gen(oldroot), root); + pdf_update_object(xref, pdf_to_num(oldroot), pdf_to_gen(oldroot), root); - fz_drop_obj(root); + pdf_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); - kids = fz_new_array(ctx, 1); + parent = pdf_new_indirect(ctx, pdf_to_num(pages), pdf_to_gen(pages), xref); + kids = pdf_new_array(ctx, 1); /* Retain pages specified */ while (argc - fz_optind) @@ -357,13 +357,13 @@ static void retainpages(int argc, char **argv) for (page = spage; page <= epage; page++) { - fz_obj *pageobj = xref->page_objs[page-1]; - fz_obj *pageref = xref->page_refs[page-1]; + pdf_obj *pageobj = xref->page_objs[page-1]; + pdf_obj *pageref = xref->page_refs[page-1]; - fz_dict_puts(pageobj, "Parent", parent); + pdf_dict_puts(pageobj, "Parent", parent); /* Store page object in new kids array */ - fz_array_push(kids, pageref); + pdf_array_push(kids, pageref); } spec = fz_strsep(&pagelist, ","); @@ -372,48 +372,48 @@ static void retainpages(int argc, char **argv) fz_optind++; } - fz_drop_obj(parent); + pdf_drop_obj(parent); /* Update page count and kids array */ - 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); + countobj = pdf_new_int(ctx, pdf_array_len(kids)); + pdf_dict_puts(pages, "Count", countobj); + pdf_drop_obj(countobj); + pdf_dict_puts(pages, "Kids", kids); + pdf_drop_obj(kids); /* Also preserve the (partial) Dests name tree */ if (olddests) { int i; - fz_obj *names = fz_new_dict(ctx, 1); - fz_obj *dests = fz_new_dict(ctx, 1); - fz_obj *names_list = fz_new_array(ctx, 32); + pdf_obj *names = pdf_new_dict(ctx, 1); + pdf_obj *dests = pdf_new_dict(ctx, 1); + pdf_obj *names_list = pdf_new_array(ctx, 32); - for (i = 0; i < fz_dict_len(olddests); i++) + for (i = 0; i < pdf_dict_len(olddests); i++) { - fz_obj *key = fz_dict_get_key(olddests, i); - fz_obj *val = fz_dict_get_val(olddests, i); - fz_obj *key_str = fz_new_string(ctx, fz_to_name(key), strlen(fz_to_name(key))); - fz_obj *dest = fz_dict_gets(val, "D"); + pdf_obj *key = pdf_dict_get_key(olddests, i); + pdf_obj *val = pdf_dict_get_val(olddests, i); + pdf_obj *key_str = pdf_new_string(ctx, pdf_to_name(key), strlen(pdf_to_name(key))); + pdf_obj *dest = pdf_dict_gets(val, "D"); - dest = fz_array_get(dest ? dest : val, 0); - if (fz_array_contains(fz_dict_gets(pages, "Kids"), dest)) + dest = pdf_array_get(dest ? dest : val, 0); + if (pdf_array_contains(pdf_dict_gets(pages, "Kids"), dest)) { - fz_array_push(names_list, key_str); - fz_array_push(names_list, val); + pdf_array_push(names_list, key_str); + pdf_array_push(names_list, val); } - fz_drop_obj(key_str); + pdf_drop_obj(key_str); } - root = fz_dict_gets(xref->trailer, "Root"); - fz_dict_puts(dests, "Names", names_list); - fz_dict_puts(names, "Dests", dests); - fz_dict_puts(root, "Names", names); + root = pdf_dict_gets(xref->trailer, "Root"); + pdf_dict_puts(dests, "Names", names_list); + pdf_dict_puts(names, "Dests", dests); + pdf_dict_puts(root, "Names", names); - fz_drop_obj(names); - fz_drop_obj(dests); - fz_drop_obj(names_list); - fz_drop_obj(olddests); + pdf_drop_obj(names); + pdf_drop_obj(dests); + pdf_drop_obj(names_list); + pdf_drop_obj(olddests); } } @@ -423,7 +423,7 @@ static void retainpages(int argc, char **argv) static void preloadobjstms(void) { - fz_obj *obj; + pdf_obj *obj; int num; for (num = 0; num < xref->len; num++) @@ -431,7 +431,7 @@ static void preloadobjstms(void) if (xref->table[num].type == 'o') { obj = pdf_load_object(xref, num, 0); - fz_drop_obj(obj); + pdf_drop_obj(obj); } } } @@ -482,57 +482,57 @@ static fz_buffer *hexbuf(unsigned char *p, int n) return buf; } -static void addhexfilter(fz_obj *dict) +static void addhexfilter(pdf_obj *dict) { - fz_obj *f, *dp, *newf, *newdp; - fz_obj *ahx, *nullobj; + pdf_obj *f, *dp, *newf, *newdp; + pdf_obj *ahx, *nullobj; ahx = fz_new_name(ctx, "ASCIIHexDecode"); - nullobj = fz_new_null(ctx); + nullobj = pdf_new_null(ctx); newf = newdp = NULL; - f = fz_dict_gets(dict, "Filter"); - dp = fz_dict_gets(dict, "DecodeParms"); + f = pdf_dict_gets(dict, "Filter"); + dp = pdf_dict_gets(dict, "DecodeParms"); - if (fz_is_name(f)) + if (pdf_is_name(f)) { - newf = fz_new_array(ctx, 2); - fz_array_push(newf, ahx); - fz_array_push(newf, f); + newf = pdf_new_array(ctx, 2); + pdf_array_push(newf, ahx); + pdf_array_push(newf, f); f = newf; - if (fz_is_dict(dp)) + if (pdf_is_dict(dp)) { - newdp = fz_new_array(ctx, 2); - fz_array_push(newdp, nullobj); - fz_array_push(newdp, dp); + newdp = pdf_new_array(ctx, 2); + pdf_array_push(newdp, nullobj); + pdf_array_push(newdp, dp); dp = newdp; } } - else if (fz_is_array(f)) + else if (pdf_is_array(f)) { - fz_array_insert(f, ahx); - if (fz_is_array(dp)) - fz_array_insert(dp, nullobj); + pdf_array_insert(f, ahx); + if (pdf_is_array(dp)) + pdf_array_insert(dp, nullobj); } else f = ahx; - fz_dict_puts(dict, "Filter", f); + pdf_dict_puts(dict, "Filter", f); if (dp) - fz_dict_puts(dict, "DecodeParms", dp); + pdf_dict_puts(dict, "DecodeParms", dp); - fz_drop_obj(ahx); - fz_drop_obj(nullobj); + pdf_drop_obj(ahx); + pdf_drop_obj(nullobj); if (newf) - fz_drop_obj(newf); + pdf_drop_obj(newf); if (newdp) - fz_drop_obj(newdp); + pdf_drop_obj(newdp); } -static void copystream(fz_obj *obj, int num, int gen) +static void copystream(pdf_obj *obj, int num, int gen) { fz_buffer *buf, *tmp; - fz_obj *newlen; + pdf_obj *newlen; buf = pdf_load_raw_stream(xref, num, gen); @@ -544,13 +544,13 @@ static void copystream(fz_obj *obj, int num, int gen) addhexfilter(obj); - newlen = fz_new_int(ctx, buf->len); - fz_dict_puts(obj, "Length", newlen); - fz_drop_obj(newlen); + newlen = pdf_new_int(ctx, buf->len); + pdf_dict_puts(obj, "Length", newlen); + pdf_drop_obj(newlen); } fprintf(out, "%d %d obj\n", num, gen); - fz_fprint_obj(out, obj, doexpand == 0); + pdf_fprint_obj(out, obj, doexpand == 0); fprintf(out, "stream\n"); fwrite(buf->data, 1, buf->len, out); fprintf(out, "endstream\nendobj\n\n"); @@ -558,15 +558,15 @@ static void copystream(fz_obj *obj, int num, int gen) fz_drop_buffer(ctx, buf); } -static void expandstream(fz_obj *obj, int num, int gen) +static void expandstream(pdf_obj *obj, int num, int gen) { fz_buffer *buf, *tmp; - fz_obj *newlen; + pdf_obj *newlen; buf = pdf_load_stream(xref, num, gen); - fz_dict_dels(obj, "Filter"); - fz_dict_dels(obj, "DecodeParms"); + pdf_dict_dels(obj, "Filter"); + pdf_dict_dels(obj, "DecodeParms"); if (doascii && isbinarystream(buf)) { @@ -577,12 +577,12 @@ static void expandstream(fz_obj *obj, int num, int gen) addhexfilter(obj); } - newlen = fz_new_int(ctx, buf->len); - fz_dict_puts(obj, "Length", newlen); - fz_drop_obj(newlen); + newlen = pdf_new_int(ctx, buf->len); + pdf_dict_puts(obj, "Length", newlen); + pdf_drop_obj(newlen); fprintf(out, "%d %d obj\n", num, gen); - fz_fprint_obj(out, obj, doexpand == 0); + pdf_fprint_obj(out, obj, doexpand == 0); fprintf(out, "stream\n"); fwrite(buf->data, 1, buf->len, out); fprintf(out, "endstream\nendobj\n\n"); @@ -592,25 +592,25 @@ static void expandstream(fz_obj *obj, int num, int gen) static void writeobject(int num, int gen) { - fz_obj *obj; - fz_obj *type; + pdf_obj *obj; + pdf_obj *type; obj = pdf_load_object(xref, num, gen); /* skip ObjStm and XRef objects */ - if (fz_is_dict(obj)) + if (pdf_is_dict(obj)) { - type = fz_dict_gets(obj, "Type"); - if (fz_is_name(type) && !strcmp(fz_to_name(type), "ObjStm")) + type = pdf_dict_gets(obj, "Type"); + if (pdf_is_name(type) && !strcmp(pdf_to_name(type), "ObjStm")) { uselist[num] = 0; - fz_drop_obj(obj); + pdf_drop_obj(obj); return; } - if (fz_is_name(type) && !strcmp(fz_to_name(type), "XRef")) + if (pdf_is_name(type) && !strcmp(pdf_to_name(type), "XRef")) { uselist[num] = 0; - fz_drop_obj(obj); + pdf_drop_obj(obj); return; } } @@ -618,7 +618,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(out, obj, doexpand == 0); + pdf_fprint_obj(out, obj, doexpand == 0); fprintf(out, "endobj\n\n"); } else @@ -626,24 +626,24 @@ static void writeobject(int num, int gen) int dontexpand = 0; if (doexpand != 0 && doexpand != expand_all) { - fz_obj *o; + pdf_obj *o; - if ((o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "XObject")) && - (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Image"))) + if ((o = pdf_dict_gets(obj, "Type"), !strcmp(pdf_to_name(o), "XObject")) && + (o = pdf_dict_gets(obj, "Subtype"), !strcmp(pdf_to_name(o), "Image"))) dontexpand = !(doexpand & expand_images); - if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "Font")) + if (o = pdf_dict_gets(obj, "Type"), !strcmp(pdf_to_name(o), "Font")) dontexpand = !(doexpand & expand_fonts); - if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "FontDescriptor")) + if (o = pdf_dict_gets(obj, "Type"), !strcmp(pdf_to_name(o), "FontDescriptor")) dontexpand = !(doexpand & expand_fonts); - if ((o = fz_dict_gets(obj, "Length1")) != NULL) + if ((o = pdf_dict_gets(obj, "Length1")) != NULL) dontexpand = !(doexpand & expand_fonts); - if ((o = fz_dict_gets(obj, "Length2")) != NULL) + if ((o = pdf_dict_gets(obj, "Length2")) != NULL) dontexpand = !(doexpand & expand_fonts); - if ((o = fz_dict_gets(obj, "Length3")) != NULL) + if ((o = pdf_dict_gets(obj, "Length3")) != NULL) dontexpand = !(doexpand & expand_fonts); - if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Type1C")) + if (o = pdf_dict_gets(obj, "Subtype"), !strcmp(pdf_to_name(o), "Type1C")) dontexpand = !(doexpand & expand_fonts); - if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "CIDFontType0C")) + if (o = pdf_dict_gets(obj, "Subtype"), !strcmp(pdf_to_name(o), "CIDFontType0C")) dontexpand = !(doexpand & expand_fonts); } if (doexpand && !dontexpand && !pdf_is_jpx_image(ctx, obj)) @@ -652,13 +652,13 @@ static void writeobject(int num, int gen) copystream(obj, num, gen); } - fz_drop_obj(obj); + pdf_drop_obj(obj); } static void writexref(void) { - fz_obj *trailer; - fz_obj *obj; + pdf_obj *trailer; + pdf_obj *obj; int startxref; int num; @@ -674,29 +674,29 @@ static void writexref(void) } fprintf(out, "\n"); - trailer = fz_new_dict(ctx, 5); + trailer = pdf_new_dict(ctx, 5); - obj = fz_new_int(ctx, xref->len); - fz_dict_puts(trailer, "Size", obj); - fz_drop_obj(obj); + obj = pdf_new_int(ctx, xref->len); + pdf_dict_puts(trailer, "Size", obj); + pdf_drop_obj(obj); - obj = fz_dict_gets(xref->trailer, "Info"); + obj = pdf_dict_gets(xref->trailer, "Info"); if (obj) - fz_dict_puts(trailer, "Info", obj); + pdf_dict_puts(trailer, "Info", obj); - obj = fz_dict_gets(xref->trailer, "Root"); + obj = pdf_dict_gets(xref->trailer, "Root"); if (obj) - fz_dict_puts(trailer, "Root", obj); + pdf_dict_puts(trailer, "Root", obj); - obj = fz_dict_gets(xref->trailer, "ID"); + obj = pdf_dict_gets(xref->trailer, "ID"); if (obj) - fz_dict_puts(trailer, "ID", obj); + pdf_dict_puts(trailer, "ID", obj); fprintf(out, "trailer\n"); - fz_fprint_obj(out, trailer, doexpand == 0); + pdf_fprint_obj(out, trailer, doexpand == 0); fprintf(out, "\n"); - fz_drop_obj(trailer); + pdf_drop_obj(trailer); fprintf(out, "startxref\n%d\n%%%%EOF\n", startxref); } diff --git a/apps/mupdfextract.c b/apps/mupdfextract.c index 239e9ea7..dd3066f5 100644 --- a/apps/mupdfextract.c +++ b/apps/mupdfextract.c @@ -17,26 +17,26 @@ static void usage(void) exit(1); } -static int isimage(fz_obj *obj) +static int isimage(pdf_obj *obj) { - fz_obj *type = fz_dict_gets(obj, "Subtype"); - return fz_is_name(type) && !strcmp(fz_to_name(type), "Image"); + pdf_obj *type = pdf_dict_gets(obj, "Subtype"); + return pdf_is_name(type) && !strcmp(pdf_to_name(type), "Image"); } -static int isfontdesc(fz_obj *obj) +static int isfontdesc(pdf_obj *obj) { - fz_obj *type = fz_dict_gets(obj, "Type"); - return fz_is_name(type) && !strcmp(fz_to_name(type), "FontDescriptor"); + pdf_obj *type = pdf_dict_gets(obj, "Type"); + return pdf_is_name(type) && !strcmp(pdf_to_name(type), "FontDescriptor"); } static void saveimage(int num) { fz_image *image; fz_pixmap *img; - fz_obj *ref; + pdf_obj *ref; char name[1024]; - ref = fz_new_indirect(ctx, num, 0, doc); + ref = pdf_new_indirect(ctx, num, 0, doc); /* TODO: detect DCTD and save as jpeg */ @@ -67,49 +67,49 @@ static void saveimage(int num) } fz_drop_pixmap(ctx, img); - fz_drop_obj(ref); + pdf_drop_obj(ref); } -static void savefont(fz_obj *dict, int num) +static void savefont(pdf_obj *dict, int num) { char name[1024]; char *subtype; fz_buffer *buf; - fz_obj *stream = NULL; - fz_obj *obj; + pdf_obj *stream = NULL; + pdf_obj *obj; char *ext = ""; FILE *f; char *fontname = "font"; int n; - obj = fz_dict_gets(dict, "FontName"); + obj = pdf_dict_gets(dict, "FontName"); if (obj) - fontname = fz_to_name(obj); + fontname = pdf_to_name(obj); - obj = fz_dict_gets(dict, "FontFile"); + obj = pdf_dict_gets(dict, "FontFile"); if (obj) { stream = obj; ext = "pfa"; } - obj = fz_dict_gets(dict, "FontFile2"); + obj = pdf_dict_gets(dict, "FontFile2"); if (obj) { stream = obj; ext = "ttf"; } - obj = fz_dict_gets(dict, "FontFile3"); + obj = pdf_dict_gets(dict, "FontFile3"); if (obj) { stream = obj; - obj = fz_dict_gets(obj, "Subtype"); - if (obj && !fz_is_name(obj)) + obj = pdf_dict_gets(obj, "Subtype"); + if (obj && !pdf_is_name(obj)) fz_throw(ctx, "Invalid font descriptor subtype"); - subtype = fz_to_name(obj); + subtype = pdf_to_name(obj); if (!strcmp(subtype, "Type1C")) ext = "cff"; else if (!strcmp(subtype, "CIDFontType0C")) @@ -124,7 +124,7 @@ static void savefont(fz_obj *dict, int num) return; } - buf = pdf_load_stream(doc, fz_to_num(stream), fz_to_gen(stream)); + buf = pdf_load_stream(doc, pdf_to_num(stream), pdf_to_gen(stream)); sprintf(name, "%s-%04d.%s", fontname, num, ext); printf("extracting font %s\n", name); @@ -145,7 +145,7 @@ static void savefont(fz_obj *dict, int num) static void showobject(int num) { - fz_obj *obj; + pdf_obj *obj; if (!doc) fz_throw(ctx, "no file specified"); @@ -157,7 +157,7 @@ static void showobject(int num) else if (isfontdesc(obj)) savefont(obj, num); - fz_drop_obj(obj); + pdf_drop_obj(obj); } #ifdef MUPDF_COMBINED_EXE diff --git a/apps/mupdfinfo.c b/apps/mupdfinfo.c index 3c98c772..90316d6f 100644 --- a/apps/mupdfinfo.c +++ b/apps/mupdfinfo.c @@ -28,48 +28,48 @@ enum struct info { int page; - fz_obj *pageref; - fz_obj *pageobj; + pdf_obj *pageref; + pdf_obj *pageobj; union { struct { - fz_obj *obj; + pdf_obj *obj; } info; struct { - fz_obj *obj; + pdf_obj *obj; } crypt; struct { - fz_obj *obj; + pdf_obj *obj; fz_rect *bbox; } dim; struct { - fz_obj *obj; - fz_obj *subtype; - fz_obj *name; + pdf_obj *obj; + pdf_obj *subtype; + pdf_obj *name; } font; struct { - fz_obj *obj; - fz_obj *width; - fz_obj *height; - fz_obj *bpc; - fz_obj *filter; - fz_obj *cs; - fz_obj *altcs; + pdf_obj *obj; + pdf_obj *width; + pdf_obj *height; + pdf_obj *bpc; + pdf_obj *filter; + pdf_obj *cs; + pdf_obj *altcs; } image; struct { - fz_obj *obj; - fz_obj *type; + pdf_obj *obj; + pdf_obj *type; } shading; struct { - fz_obj *obj; - fz_obj *type; - fz_obj *paint; - fz_obj *tiling; - fz_obj *shading; + pdf_obj *obj; + pdf_obj *type; + pdf_obj *paint; + pdf_obj *tiling; + pdf_obj *shading; } pattern; struct { - fz_obj *obj; - fz_obj *groupsubtype; - fz_obj *reference; + pdf_obj *obj; + pdf_obj *groupsubtype; + pdf_obj *reference; } form; } u; }; @@ -168,36 +168,36 @@ infousage(void) static void showglobalinfo(void) { - fz_obj *obj; + pdf_obj *obj; printf("\nPDF-%d.%d\n", xref->version / 10, xref->version % 10); - obj = fz_dict_gets(xref->trailer, "Info"); + obj = pdf_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(fz_resolve_indirect(obj)); + printf("Info object (%d %d R):\n", pdf_to_num(obj), pdf_to_gen(obj)); + pdf_debug_obj(pdf_resolve_indirect(obj)); } - obj = fz_dict_gets(xref->trailer, "Encrypt"); + obj = pdf_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(fz_resolve_indirect(obj)); + printf("\nEncryption object (%d %d R):\n", pdf_to_num(obj), pdf_to_gen(obj)); + pdf_debug_obj(pdf_resolve_indirect(obj)); } printf("\nPages: %d\n\n", pagecount); } static void -gatherdimensions(int page, fz_obj *pageref, fz_obj *pageobj) +gatherdimensions(int page, pdf_obj *pageref, pdf_obj *pageobj) { fz_rect bbox; - fz_obj *obj; + pdf_obj *obj; int j; - obj = fz_dict_gets(pageobj, "MediaBox"); - if (!fz_is_array(obj)) + obj = pdf_dict_gets(pageobj, "MediaBox"); + if (!pdf_is_array(obj)) return; bbox = pdf_to_rect(ctx, obj); @@ -222,33 +222,33 @@ gatherdimensions(int page, fz_obj *pageref, fz_obj *pageobj) } static void -gatherfonts(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) +gatherfonts(int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = fz_dict_len(dict); + n = pdf_dict_len(dict); for (i = 0; i < n; i++) { - fz_obj *fontdict = NULL; - fz_obj *subtype = NULL; - fz_obj *basefont = NULL; - fz_obj *name = NULL; + pdf_obj *fontdict = NULL; + pdf_obj *subtype = NULL; + pdf_obj *basefont = NULL; + pdf_obj *name = NULL; int k; - fontdict = fz_dict_get_val(dict, i); - if (!fz_is_dict(fontdict)) + fontdict = pdf_dict_get_val(dict, i); + if (!pdf_is_dict(fontdict)) { - fz_warn(ctx, "not a font dict (%d %d R)", fz_to_num(fontdict), fz_to_gen(fontdict)); + fz_warn(ctx, "not a font dict (%d %d R)", pdf_to_num(fontdict), pdf_to_gen(fontdict)); continue; } - subtype = fz_dict_gets(fontdict, "Subtype"); - basefont = fz_dict_gets(fontdict, "BaseFont"); - if (!basefont || fz_is_null(basefont)) - name = fz_dict_gets(fontdict, "Name"); + subtype = pdf_dict_gets(fontdict, "Subtype"); + basefont = pdf_dict_gets(fontdict, "BaseFont"); + if (!basefont || pdf_is_null(basefont)) + name = pdf_dict_gets(fontdict, "Name"); for (k = 0; k < fonts; k++) - if (!fz_objcmp(font[k].u.font.obj, fontdict)) + if (!pdf_objcmp(font[k].u.font.obj, fontdict)) break; if (k < fonts) @@ -267,57 +267,57 @@ gatherfonts(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) } static void -gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) +gatherimages(int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = fz_dict_len(dict); + n = pdf_dict_len(dict); for (i = 0; i < n; i++) { - fz_obj *imagedict; - fz_obj *type; - fz_obj *width; - fz_obj *height; - fz_obj *bpc = NULL; - fz_obj *filter = NULL; - fz_obj *cs = NULL; - fz_obj *altcs; + pdf_obj *imagedict; + pdf_obj *type; + pdf_obj *width; + pdf_obj *height; + pdf_obj *bpc = NULL; + pdf_obj *filter = NULL; + pdf_obj *cs = NULL; + pdf_obj *altcs; int k; - imagedict = fz_dict_get_val(dict, i); - if (!fz_is_dict(imagedict)) + imagedict = pdf_dict_get_val(dict, i); + if (!pdf_is_dict(imagedict)) { - fz_warn(ctx, "not an image dict (%d %d R)", fz_to_num(imagedict), fz_to_gen(imagedict)); + fz_warn(ctx, "not an image dict (%d %d R)", pdf_to_num(imagedict), pdf_to_gen(imagedict)); continue; } - type = fz_dict_gets(imagedict, "Subtype"); - if (strcmp(fz_to_name(type), "Image")) + type = pdf_dict_gets(imagedict, "Subtype"); + if (strcmp(pdf_to_name(type), "Image")) continue; - filter = fz_dict_gets(imagedict, "Filter"); + filter = pdf_dict_gets(imagedict, "Filter"); altcs = NULL; - cs = fz_dict_gets(imagedict, "ColorSpace"); - if (fz_is_array(cs)) + cs = pdf_dict_gets(imagedict, "ColorSpace"); + if (pdf_is_array(cs)) { - fz_obj *cses = cs; + pdf_obj *cses = cs; - cs = fz_array_get(cses, 0); - if (fz_is_name(cs) && (!strcmp(fz_to_name(cs), "DeviceN") || !strcmp(fz_to_name(cs), "Separation"))) + cs = pdf_array_get(cses, 0); + if (pdf_is_name(cs) && (!strcmp(pdf_to_name(cs), "DeviceN") || !strcmp(pdf_to_name(cs), "Separation"))) { - altcs = fz_array_get(cses, 2); - if (fz_is_array(altcs)) - altcs = fz_array_get(altcs, 0); + altcs = pdf_array_get(cses, 2); + if (pdf_is_array(altcs)) + altcs = pdf_array_get(altcs, 0); } } - width = fz_dict_gets(imagedict, "Width"); - height = fz_dict_gets(imagedict, "Height"); - bpc = fz_dict_gets(imagedict, "BitsPerComponent"); + width = pdf_dict_gets(imagedict, "Width"); + height = pdf_dict_gets(imagedict, "Height"); + bpc = pdf_dict_gets(imagedict, "BitsPerComponent"); for (k = 0; k < images; k++) - if (!fz_objcmp(image[k].u.image.obj, imagedict)) + if (!pdf_objcmp(image[k].u.image.obj, imagedict)) break; if (k < images) @@ -340,42 +340,42 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) } static void -gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) +gatherforms(int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = fz_dict_len(dict); + n = pdf_dict_len(dict); for (i = 0; i < n; i++) { - fz_obj *xobjdict; - fz_obj *type; - fz_obj *subtype; - fz_obj *group; - fz_obj *groupsubtype; - fz_obj *reference; + pdf_obj *xobjdict; + pdf_obj *type; + pdf_obj *subtype; + pdf_obj *group; + pdf_obj *groupsubtype; + pdf_obj *reference; int k; - xobjdict = fz_dict_get_val(dict, i); - if (!fz_is_dict(xobjdict)) + xobjdict = pdf_dict_get_val(dict, i); + if (!pdf_is_dict(xobjdict)) { - fz_warn(ctx, "not a xobject dict (%d %d R)", fz_to_num(xobjdict), fz_to_gen(xobjdict)); + fz_warn(ctx, "not a xobject dict (%d %d R)", pdf_to_num(xobjdict), pdf_to_gen(xobjdict)); continue; } - type = fz_dict_gets(xobjdict, "Subtype"); - if (strcmp(fz_to_name(type), "Form")) + type = pdf_dict_gets(xobjdict, "Subtype"); + if (strcmp(pdf_to_name(type), "Form")) continue; - subtype = fz_dict_gets(xobjdict, "Subtype2"); - if (!strcmp(fz_to_name(subtype), "PS")) + subtype = pdf_dict_gets(xobjdict, "Subtype2"); + if (!strcmp(pdf_to_name(subtype), "PS")) continue; - group = fz_dict_gets(xobjdict, "Group"); - groupsubtype = fz_dict_gets(group, "S"); - reference = fz_dict_gets(xobjdict, "Ref"); + group = pdf_dict_gets(xobjdict, "Group"); + groupsubtype = pdf_dict_gets(group, "S"); + reference = pdf_dict_gets(xobjdict, "Ref"); for (k = 0; k < forms; k++) - if (!fz_objcmp(form[k].u.form.obj, xobjdict)) + if (!pdf_objcmp(form[k].u.form.obj, xobjdict)) break; if (k < forms) @@ -394,33 +394,33 @@ gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) } static void -gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) +gatherpsobjs(int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = fz_dict_len(dict); + n = pdf_dict_len(dict); for (i = 0; i < n; i++) { - fz_obj *xobjdict; - fz_obj *type; - fz_obj *subtype; + pdf_obj *xobjdict; + pdf_obj *type; + pdf_obj *subtype; int k; - xobjdict = fz_dict_get_val(dict, i); - if (!fz_is_dict(xobjdict)) + xobjdict = pdf_dict_get_val(dict, i); + if (!pdf_is_dict(xobjdict)) { - fz_warn(ctx, "not a xobject dict (%d %d R)", fz_to_num(xobjdict), fz_to_gen(xobjdict)); + fz_warn(ctx, "not a xobject dict (%d %d R)", pdf_to_num(xobjdict), pdf_to_gen(xobjdict)); continue; } - 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"))) + type = pdf_dict_gets(xobjdict, "Subtype"); + subtype = pdf_dict_gets(xobjdict, "Subtype2"); + if (strcmp(pdf_to_name(type), "PS") && + (strcmp(pdf_to_name(type), "Form") || strcmp(pdf_to_name(subtype), "PS"))) continue; for (k = 0; k < psobjs; k++) - if (!fz_objcmp(psobj[k].u.form.obj, xobjdict)) + if (!pdf_objcmp(psobj[k].u.form.obj, xobjdict)) break; if (k < psobjs) @@ -437,33 +437,33 @@ gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) } static void -gathershadings(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) +gathershadings(int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = fz_dict_len(dict); + n = pdf_dict_len(dict); for (i = 0; i < n; i++) { - fz_obj *shade; - fz_obj *type; + pdf_obj *shade; + pdf_obj *type; int k; - shade = fz_dict_get_val(dict, i); - if (!fz_is_dict(shade)) + shade = pdf_dict_get_val(dict, i); + if (!pdf_is_dict(shade)) { - fz_warn(ctx, "not a shading dict (%d %d R)", fz_to_num(shade), fz_to_gen(shade)); + fz_warn(ctx, "not a shading dict (%d %d R)", pdf_to_num(shade), pdf_to_gen(shade)); continue; } - type = fz_dict_gets(shade, "ShadingType"); - if (!fz_is_int(type) || fz_to_int(type) < 1 || fz_to_int(type) > 7) + type = pdf_dict_gets(shade, "ShadingType"); + if (!pdf_is_int(type) || pdf_to_int(type) < 1 || pdf_to_int(type) > 7) { - fz_warn(ctx, "not a shading type (%d %d R)", fz_to_num(shade), fz_to_gen(shade)); + fz_warn(ctx, "not a shading type (%d %d R)", pdf_to_num(shade), pdf_to_gen(shade)); type = NULL; } for (k = 0; k < shadings; k++) - if (!fz_objcmp(shading[k].u.shading.obj, shade)) + if (!pdf_objcmp(shading[k].u.shading.obj, shade)) break; if (k < shadings) @@ -481,57 +481,57 @@ gathershadings(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) } static void -gatherpatterns(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) +gatherpatterns(int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = fz_dict_len(dict); + n = pdf_dict_len(dict); for (i = 0; i < n; i++) { - fz_obj *patterndict; - fz_obj *type; - fz_obj *paint = NULL; - fz_obj *tiling = NULL; - fz_obj *shading = NULL; + pdf_obj *patterndict; + pdf_obj *type; + pdf_obj *paint = NULL; + pdf_obj *tiling = NULL; + pdf_obj *shading = NULL; int k; - patterndict = fz_dict_get_val(dict, i); - if (!fz_is_dict(patterndict)) + patterndict = pdf_dict_get_val(dict, i); + if (!pdf_is_dict(patterndict)) { - fz_warn(ctx, "not a pattern dict (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict)); + fz_warn(ctx, "not a pattern dict (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); continue; } - type = fz_dict_gets(patterndict, "PatternType"); - if (!fz_is_int(type) || fz_to_int(type) < 1 || fz_to_int(type) > 2) + type = pdf_dict_gets(patterndict, "PatternType"); + if (!pdf_is_int(type) || pdf_to_int(type) < 1 || pdf_to_int(type) > 2) { - fz_warn(ctx, "not a pattern type (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict)); + fz_warn(ctx, "not a pattern type (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); type = NULL; } - if (fz_to_int(type) == 1) + if (pdf_to_int(type) == 1) { - paint = fz_dict_gets(patterndict, "PaintType"); - if (!fz_is_int(paint) || fz_to_int(paint) < 1 || fz_to_int(paint) > 2) + paint = pdf_dict_gets(patterndict, "PaintType"); + if (!pdf_is_int(paint) || pdf_to_int(paint) < 1 || pdf_to_int(paint) > 2) { - fz_warn(ctx, "not a pattern paint type (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict)); + fz_warn(ctx, "not a pattern paint type (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); paint = NULL; } - tiling = fz_dict_gets(patterndict, "TilingType"); - if (!fz_is_int(tiling) || fz_to_int(tiling) < 1 || fz_to_int(tiling) > 3) + tiling = pdf_dict_gets(patterndict, "TilingType"); + if (!pdf_is_int(tiling) || pdf_to_int(tiling) < 1 || pdf_to_int(tiling) > 3) { - fz_warn(ctx, "not a pattern tiling type (%d %d R)", fz_to_num(patterndict), fz_to_gen(patterndict)); + fz_warn(ctx, "not a pattern tiling type (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); tiling = NULL; } } else { - shading = fz_dict_gets(patterndict, "Shading"); + shading = pdf_dict_gets(patterndict, "Shading"); } for (k = 0; k < patterns; k++) - if (!fz_objcmp(pattern[k].u.pattern.obj, patterndict)) + if (!pdf_objcmp(pattern[k].u.pattern.obj, patterndict)) break; if (k < patterns) @@ -552,15 +552,15 @@ gatherpatterns(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict) } static void -gatherresourceinfo(int page, fz_obj *rsrc) +gatherresourceinfo(int page, pdf_obj *rsrc) { - fz_obj *pageobj; - fz_obj *pageref; - fz_obj *font; - fz_obj *xobj; - fz_obj *shade; - fz_obj *pattern; - fz_obj *subrsrc; + pdf_obj *pageobj; + pdf_obj *pageref; + pdf_obj *font; + pdf_obj *xobj; + pdf_obj *shade; + pdf_obj *pattern; + pdf_obj *subrsrc; int i; pageobj = xref->page_objs[page-1]; @@ -569,24 +569,24 @@ gatherresourceinfo(int page, fz_obj *rsrc) if (!pageobj) fz_throw(ctx, "cannot retrieve info from page %d", page); - font = fz_dict_gets(rsrc, "Font"); + font = pdf_dict_gets(rsrc, "Font"); if (font) { int n; gatherfonts(page, pageref, pageobj, font); - n = fz_dict_len(font); + n = pdf_dict_len(font); for (i = 0; i < n; i++) { - fz_obj *obj = fz_dict_get_val(font, i); + pdf_obj *obj = pdf_dict_get_val(font, i); - subrsrc = fz_dict_gets(obj, "Resources"); - if (subrsrc && fz_objcmp(rsrc, subrsrc)) + subrsrc = pdf_dict_gets(obj, "Resources"); + if (subrsrc && pdf_objcmp(rsrc, subrsrc)) gatherresourceinfo(page, subrsrc); } } - xobj = fz_dict_gets(rsrc, "XObject"); + xobj = pdf_dict_gets(rsrc, "XObject"); if (xobj) { int n; @@ -594,31 +594,31 @@ 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(xobj); + n = pdf_dict_len(xobj); for (i = 0; i < n; i++) { - fz_obj *obj = fz_dict_get_val(xobj, i); - subrsrc = fz_dict_gets(obj, "Resources"); - if (subrsrc && fz_objcmp(rsrc, subrsrc)) + pdf_obj *obj = pdf_dict_get_val(xobj, i); + subrsrc = pdf_dict_gets(obj, "Resources"); + if (subrsrc && pdf_objcmp(rsrc, subrsrc)) gatherresourceinfo(page, subrsrc); } } - shade = fz_dict_gets(rsrc, "Shading"); + shade = pdf_dict_gets(rsrc, "Shading"); if (shade) gathershadings(page, pageref, pageobj, shade); - pattern = fz_dict_gets(rsrc, "Pattern"); + pattern = pdf_dict_gets(rsrc, "Pattern"); if (pattern) { int n; gatherpatterns(page, pageref, pageobj, pattern); - n = fz_dict_len(pattern); + n = pdf_dict_len(pattern); for (i = 0; i < n; i++) { - fz_obj *obj = fz_dict_get_val(pattern, i); - subrsrc = fz_dict_gets(obj, "Resources"); - if (subrsrc && fz_objcmp(rsrc, subrsrc)) + pdf_obj *obj = pdf_dict_get_val(pattern, i); + subrsrc = pdf_dict_gets(obj, "Resources"); + if (subrsrc && pdf_objcmp(rsrc, subrsrc)) gatherresourceinfo(page, subrsrc); } } @@ -627,9 +627,9 @@ gatherresourceinfo(int page, fz_obj *rsrc) static void gatherpageinfo(int page) { - fz_obj *pageobj; - fz_obj *pageref; - fz_obj *rsrc; + pdf_obj *pageobj; + pdf_obj *pageref; + pdf_obj *rsrc; pageobj = xref->page_objs[page-1]; pageref = xref->page_refs[page-1]; @@ -639,7 +639,7 @@ gatherpageinfo(int page) gatherdimensions(page, pageref, pageobj); - rsrc = fz_dict_gets(pageobj, "Resources"); + rsrc = pdf_dict_gets(pageobj, "Resources"); gatherresourceinfo(page, rsrc); } @@ -658,7 +658,7 @@ printinfo(char *filename, int show, int page) { printf(PAGE_FMT "[ %g %g %g %g ]\n", dim[i].page, - fz_to_num(dim[i].pageref), fz_to_gen(dim[i].pageref), + pdf_to_num(dim[i].pageref), pdf_to_gen(dim[i].pageref), dim[i].u.dim.bbox->x0, dim[i].u.dim.bbox->y0, dim[i].u.dim.bbox->x1, @@ -674,10 +674,10 @@ 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(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)); + pdf_to_num(font[i].pageref), pdf_to_gen(font[i].pageref), + pdf_to_name(font[i].u.font.subtype), + pdf_to_name(font[i].u.font.name), + pdf_to_num(font[i].u.font.obj), pdf_to_gen(font[i].u.font.obj)); } printf("\n"); } @@ -692,29 +692,29 @@ printinfo(char *filename, int show, int page) printf(PAGE_FMT "[ ", image[i].page, - fz_to_num(image[i].pageref), fz_to_gen(image[i].pageref)); + pdf_to_num(image[i].pageref), pdf_to_gen(image[i].pageref)); - if (fz_is_array(image[i].u.image.filter)) + if (pdf_is_array(image[i].u.image.filter)) { - int n = fz_array_len(image[i].u.image.filter); + int n = pdf_array_len(image[i].u.image.filter); for (j = 0; j < n; j++) { - fz_obj *obj = fz_array_get(image[i].u.image.filter, j); - char *filter = fz_strdup(ctx, fz_to_name(obj)); + pdf_obj *obj = pdf_array_get(image[i].u.image.filter, j); + char *filter = fz_strdup(ctx, pdf_to_name(obj)); if (strstr(filter, "Decode")) *(strstr(filter, "Decode")) = '\0'; printf("%s%s", filter, - j == fz_array_len(image[i].u.image.filter) - 1 ? "" : " "); + j == pdf_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(obj)); + pdf_obj *obj = image[i].u.image.filter; + char *filter = fz_strdup(ctx, pdf_to_name(obj)); if (strstr(filter, "Decode")) *(strstr(filter, "Decode")) = '\0'; @@ -727,7 +727,7 @@ printinfo(char *filename, int show, int page) if (image[i].u.image.cs) { - cs = fz_strdup(ctx, fz_to_name(image[i].u.image.cs)); + cs = fz_strdup(ctx, pdf_to_name(image[i].u.image.cs)); if (!strncmp(cs, "Device", 6)) { @@ -746,7 +746,7 @@ printinfo(char *filename, int show, int page) } if (image[i].u.image.altcs) { - altcs = fz_strdup(ctx, fz_to_name(image[i].u.image.altcs)); + altcs = fz_strdup(ctx, pdf_to_name(image[i].u.image.altcs)); if (!strncmp(altcs, "Device", 6)) { @@ -765,13 +765,13 @@ printinfo(char *filename, int show, int page) } printf(" ] %dx%d %dbpc %s%s%s (%d %d R)\n", - 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, + pdf_to_int(image[i].u.image.width), + pdf_to_int(image[i].u.image.height), + image[i].u.image.bpc ? pdf_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 : "", - fz_to_num(image[i].u.image.obj), fz_to_gen(image[i].u.image.obj)); + pdf_to_num(image[i].u.image.obj), pdf_to_gen(image[i].u.image.obj)); fz_free(ctx, cs); fz_free(ctx, altcs); @@ -798,9 +798,9 @@ 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(shading[i].u.shading.type)], - fz_to_num(shading[i].u.shading.obj), fz_to_gen(shading[i].u.shading.obj)); + pdf_to_num(shading[i].pageref), pdf_to_gen(shading[i].pageref), + shadingtype[pdf_to_int(shading[i].u.shading.type)], + pdf_to_num(shading[i].u.shading.obj), pdf_to_gen(shading[i].u.shading.obj)); } printf("\n"); } @@ -810,7 +810,7 @@ printinfo(char *filename, int show, int page) printf("Patterns (%d):\n", patterns); for (i = 0; i < patterns; i++) { - if (fz_to_int(pattern[i].u.pattern.type) == 1) + if (pdf_to_int(pattern[i].u.pattern.type) == 1) { char *painttype[] = { @@ -828,18 +828,18 @@ 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(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)); + pdf_to_num(pattern[i].pageref), pdf_to_gen(pattern[i].pageref), + painttype[pdf_to_int(pattern[i].u.pattern.paint)], + tilingtype[pdf_to_int(pattern[i].u.pattern.tiling)], + pdf_to_num(pattern[i].u.pattern.obj), pdf_to_gen(pattern[i].u.pattern.obj)); } else { printf(PAGE_FMT "Shading %d %d R (%d %d R)\n", pattern[i].page, - fz_to_num(pattern[i].pageref), fz_to_gen(pattern[i].pageref), - fz_to_num(pattern[i].u.pattern.shading), fz_to_gen(pattern[i].u.pattern.shading), - fz_to_num(pattern[i].u.pattern.obj), fz_to_gen(pattern[i].u.pattern.obj)); + pdf_to_num(pattern[i].pageref), pdf_to_gen(pattern[i].pageref), + pdf_to_num(pattern[i].u.pattern.shading), pdf_to_gen(pattern[i].u.pattern.shading), + pdf_to_num(pattern[i].u.pattern.obj), pdf_to_gen(pattern[i].u.pattern.obj)); } } printf("\n"); @@ -852,12 +852,12 @@ printinfo(char *filename, int show, int page) { printf(PAGE_FMT "Form%s%s%s%s (%d %d R)\n", form[i].page, - fz_to_num(form[i].pageref), fz_to_gen(form[i].pageref), + pdf_to_num(form[i].pageref), pdf_to_gen(form[i].pageref), form[i].u.form.groupsubtype ? " " : "", - form[i].u.form.groupsubtype ? fz_to_name(form[i].u.form.groupsubtype) : "", + form[i].u.form.groupsubtype ? pdf_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)); + pdf_to_num(form[i].u.form.obj), pdf_to_gen(form[i].u.form.obj)); } printf("\n"); } @@ -869,8 +869,8 @@ printinfo(char *filename, int show, int page) { printf(PAGE_FMT "(%d %d R)\n", psobj[i].page, - fz_to_num(psobj[i].pageref), fz_to_gen(psobj[i].pageref), - fz_to_num(psobj[i].u.form.obj), fz_to_gen(psobj[i].u.form.obj)); + pdf_to_num(psobj[i].pageref), pdf_to_gen(psobj[i].pageref), + pdf_to_num(psobj[i].u.form.obj), pdf_to_gen(psobj[i].u.form.obj)); } printf("\n"); } diff --git a/apps/mupdfshow.c b/apps/mupdfshow.c index 8dcdd17d..92fcac2d 100644 --- a/apps/mupdfshow.c +++ b/apps/mupdfshow.c @@ -25,7 +25,7 @@ static void showtrailer(void) if (!doc) fz_throw(ctx, "no file specified"); printf("trailer\n"); - fz_debug_obj(doc->trailer); + pdf_debug_obj(doc->trailer); printf("\n"); } @@ -39,7 +39,7 @@ static void showxref(void) static void showpagetree(void) { - fz_obj *ref; + pdf_obj *ref; int count; int i; @@ -50,7 +50,7 @@ static void showpagetree(void) for (i = 0; i < count; i++) { ref = doc->page_refs[i]; - printf("page %d = %d %d R\n", i + 1, fz_to_num(ref), fz_to_gen(ref)); + printf("page %d = %d %d R\n", i + 1, pdf_to_num(ref), pdf_to_gen(ref)); } printf("\n"); } @@ -107,7 +107,7 @@ static void showstream(int num, int gen) static void showobject(int num, int gen) { - fz_obj *obj; + pdf_obj *obj; if (!doc) fz_throw(ctx, "no file specified"); @@ -123,7 +123,7 @@ static void showobject(int num, int gen) else { printf("%d %d obj\n", num, gen); - fz_debug_obj(obj); + pdf_debug_obj(obj); printf("stream\n"); showstream(num, gen); printf("endstream\n"); @@ -133,16 +133,16 @@ static void showobject(int num, int gen) else { printf("%d %d obj\n", num, gen); - fz_debug_obj(obj); + pdf_debug_obj(obj); printf("endobj\n\n"); } - fz_drop_obj(obj); + pdf_drop_obj(obj); } static void showgrep(char *filename) { - fz_obj *obj; + pdf_obj *obj; int i; for (i = 0; i < doc->len; i++) @@ -159,17 +159,17 @@ static void showgrep(char *filename) continue; } - fz_sort_dict(obj); + pdf_sort_dict(obj); printf("%s:%d: ", filename, i); - fz_fprint_obj(stdout, obj, 1); + pdf_fprint_obj(stdout, obj, 1); - fz_drop_obj(obj); + pdf_drop_obj(obj); } } printf("%s:trailer: ", filename); - fz_fprint_obj(stdout, doc->trailer, 1); + pdf_fprint_obj(stdout, doc->trailer, 1); } #ifdef MUPDF_COMBINED_EXE diff --git a/fitz/base_context.c b/fitz/base_context.c index fe69ff8e..d1ce63ae 100644 --- a/fitz/base_context.c +++ b/fitz/base_context.c @@ -1,13 +1,5 @@ #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) { diff --git a/fitz/base_object.c b/fitz/base_object.c deleted file mode 100644 index 964c5bb4..00000000 --- a/fitz/base_object.c +++ /dev/null @@ -1,1265 +0,0 @@ -#include "fitz.h" - -typedef enum fz_objkind_e -{ - FZ_NULL, - FZ_BOOL, - FZ_INT, - FZ_REAL, - FZ_STRING, - FZ_NAME, - FZ_ARRAY, - FZ_DICT, - FZ_INDIRECT -} fz_objkind; - -struct keyval -{ - fz_obj *k; - fz_obj *v; -}; - -struct fz_obj_s -{ - int refs; - fz_objkind kind; - fz_context *ctx; - union - { - int b; - int i; - float f; - struct { - unsigned short len; - char buf[1]; - } s; - char n[1]; - struct { - int len; - int cap; - fz_obj **items; - } a; - struct { - char sorted; - char marked; - int len; - int cap; - struct keyval *items; - } d; - struct { - int num; - int gen; - struct pdf_xref_s *xref; - } r; - } u; -}; - -fz_obj * -fz_new_null(fz_context *ctx) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(null)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_NULL; - return obj; -} - -fz_obj * -fz_new_bool(fz_context *ctx, int b) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(bool)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_BOOL; - obj->u.b = b; - return obj; -} - -fz_obj * -fz_new_int(fz_context *ctx, int i) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(int)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_INT; - obj->u.i = i; - return obj; -} - -fz_obj * -fz_new_real(fz_context *ctx, float f) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(real)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_REAL; - obj->u.f = f; - return obj; -} - -fz_obj * -fz_new_string(fz_context *ctx, char *str, int len) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, offsetof(fz_obj, u.s.buf) + len + 1), "fz_obj(string)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_STRING; - obj->u.s.len = len; - memcpy(obj->u.s.buf, str, len); - obj->u.s.buf[len] = '\0'; - return obj; -} - -fz_obj * -fz_new_name(fz_context *ctx, char *str) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, offsetof(fz_obj, u.n) + strlen(str) + 1), "fz_obj(name)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_NAME; - strcpy(obj->u.n, str); - return obj; -} - -fz_obj * -fz_new_indirect(fz_context *ctx, int num, int gen, void *xref) -{ - fz_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(indirect)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_INDIRECT; - obj->u.r.num = num; - obj->u.r.gen = gen; - obj->u.r.xref = xref; - return obj; -} - -fz_obj * -fz_keep_obj(fz_obj *obj) -{ - assert(obj); - obj->refs ++; - return obj; -} - -int fz_is_indirect(fz_obj *obj) -{ - return obj ? obj->kind == FZ_INDIRECT : 0; -} - -#define RESOLVE(obj) \ - do { \ - if (obj && obj->kind == FZ_INDIRECT) \ - {\ - fz_assert_lock_not_held(obj->ctx, FZ_LOCK_FILE); \ - obj = fz_resolve_indirect(obj); \ - } \ - } while (0) - -int fz_is_null(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_NULL : 0; -} - -int fz_is_bool(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_BOOL : 0; -} - -int fz_is_int(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_INT : 0; -} - -int fz_is_real(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_REAL : 0; -} - -int fz_is_string(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_STRING : 0; -} - -int fz_is_name(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_NAME : 0; -} - -int fz_is_array(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_ARRAY : 0; -} - -int fz_is_dict(fz_obj *obj) -{ - RESOLVE(obj); - return obj ? obj->kind == FZ_DICT : 0; -} - -int fz_to_bool(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj) - return 0; - return obj->kind == FZ_BOOL ? obj->u.b : 0; -} - -int fz_to_int(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj) - return 0; - if (obj->kind == FZ_INT) - return obj->u.i; - if (obj->kind == FZ_REAL) - return (int)(obj->u.f + 0.5f); /* No roundf in MSVC */ - return 0; -} - -float fz_to_real(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj) - return 0; - if (obj->kind == FZ_REAL) - return obj->u.f; - if (obj->kind == FZ_INT) - return obj->u.i; - return 0; -} - -char *fz_to_name(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_NAME) - return ""; - return obj->u.n; -} - -char *fz_to_str_buf(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_STRING) - return ""; - return obj->u.s.buf; -} - -int fz_to_str_len(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_STRING) - return 0; - return obj->u.s.len; -} - -/* for use by pdf_crypt_obj_imp to decrypt AES string in place */ -void fz_set_str_len(fz_obj *obj, int newlen) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_STRING) - return; /* This should never happen */ - if (newlen > obj->u.s.len) - return; /* This should never happen */ - obj->u.s.len = newlen; -} - -fz_obj *fz_to_dict(fz_obj *obj) -{ - RESOLVE(obj); - return (obj && obj->kind == FZ_DICT ? obj : NULL); -} - -int fz_to_num(fz_obj *obj) -{ - if (!obj || obj->kind != FZ_INDIRECT) - return 0; - return obj->u.r.num; -} - -int fz_to_gen(fz_obj *obj) -{ - if (!obj || obj->kind != FZ_INDIRECT) - return 0; - return obj->u.r.gen; -} - -void *fz_get_indirect_document(fz_obj *obj) -{ - if (!obj || obj->kind != FZ_INDIRECT) - return NULL; - return obj->u.r.xref; -} - -int -fz_objcmp(fz_obj *a, fz_obj *b) -{ - int i; - - if (a == b) - return 0; - - if (!a || !b) - return 1; - - if (a->kind != b->kind) - return 1; - - switch (a->kind) - { - case FZ_NULL: - return 0; - - case FZ_BOOL: - return a->u.b - b->u.b; - - case FZ_INT: - return a->u.i - b->u.i; - - case FZ_REAL: - if (a->u.f < b->u.f) - return -1; - if (a->u.f > b->u.f) - return 1; - return 0; - - case FZ_STRING: - if (a->u.s.len < b->u.s.len) - { - if (memcmp(a->u.s.buf, b->u.s.buf, a->u.s.len) <= 0) - return -1; - return 1; - } - if (a->u.s.len > b->u.s.len) - { - if (memcmp(a->u.s.buf, b->u.s.buf, b->u.s.len) >= 0) - return 1; - return -1; - } - return memcmp(a->u.s.buf, b->u.s.buf, a->u.s.len); - - case FZ_NAME: - return strcmp(a->u.n, b->u.n); - - case FZ_INDIRECT: - if (a->u.r.num == b->u.r.num) - return a->u.r.gen - b->u.r.gen; - return a->u.r.num - b->u.r.num; - - case FZ_ARRAY: - if (a->u.a.len != b->u.a.len) - return a->u.a.len - b->u.a.len; - for (i = 0; i < a->u.a.len; i++) - if (fz_objcmp(a->u.a.items[i], b->u.a.items[i])) - return 1; - return 0; - - case FZ_DICT: - if (a->u.d.len != b->u.d.len) - return a->u.d.len - b->u.d.len; - for (i = 0; i < a->u.d.len; i++) - { - if (fz_objcmp(a->u.d.items[i].k, b->u.d.items[i].k)) - return 1; - if (fz_objcmp(a->u.d.items[i].v, b->u.d.items[i].v)) - return 1; - } - return 0; - - } - return 1; -} - -static char * -fz_objkindstr(fz_obj *obj) -{ - if (!obj) - return ""; - switch (obj->kind) - { - case FZ_NULL: return "null"; - case FZ_BOOL: return "boolean"; - case FZ_INT: return "integer"; - case FZ_REAL: return "real"; - case FZ_STRING: return "string"; - case FZ_NAME: return "name"; - case FZ_ARRAY: return "array"; - case FZ_DICT: return "dictionary"; - case FZ_INDIRECT: return "reference"; - } - return ""; -} - -fz_obj * -fz_new_array(fz_context *ctx, int initialcap) -{ - fz_obj *obj; - int i; - - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(array)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_ARRAY; - - obj->u.a.len = 0; - obj->u.a.cap = initialcap > 1 ? initialcap : 6; - - fz_try(ctx) - { - obj->u.a.items = Memento_label(fz_malloc_array(ctx, obj->u.a.cap, sizeof(fz_obj*)), "fz_obj(array items)"); - } - fz_catch(ctx) - { - fz_free(ctx, obj); - fz_rethrow(ctx); - } - for (i = 0; i < obj->u.a.cap; i++) - obj->u.a.items[i] = NULL; - - return obj; -} - -static void -fz_array_grow(fz_obj *obj) -{ - int i; - - obj->u.a.cap = (obj->u.a.cap * 3) / 2; - obj->u.a.items = fz_resize_array(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; -} - -fz_obj * -fz_copy_array(fz_context *ctx, fz_obj *obj) -{ - fz_obj *arr; - int i; - int n; - - RESOLVE(obj); - if (!obj || obj->kind != FZ_ARRAY) - fz_warn(ctx, "assert: not an array (%s)", fz_objkindstr(obj)); - - arr = fz_new_array(ctx, fz_array_len(obj)); - n = fz_array_len(obj); - for (i = 0; i < n; i++) - fz_array_push(arr, fz_array_get(obj, i)); - - return arr; -} - -int -fz_array_len(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_ARRAY) - return 0; - return obj->u.a.len; -} - -fz_obj * -fz_array_get(fz_obj *obj, int i) -{ - RESOLVE(obj); - - if (!obj || obj->kind != FZ_ARRAY) - return NULL; - - if (i < 0 || i >= obj->u.a.len) - return NULL; - - return obj->u.a.items[i]; -} - -void -fz_array_put(fz_obj *obj, int i, fz_obj *item) -{ - RESOLVE(obj); - - if (!obj) - return; /* Can't warn :( */ - if (obj->kind != FZ_ARRAY) - fz_warn(obj->ctx, "assert: not an array (%s)", fz_objkindstr(obj)); - else if (i < 0) - fz_warn(obj->ctx, "assert: index %d < 0", i); - else if (i >= obj->u.a.len) - fz_warn(obj->ctx, "assert: index %d > length %d", i, obj->u.a.len); - else - { - if (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_obj *obj, fz_obj *item) -{ - RESOLVE(obj); - - if (!obj) - return; /* Can't warn :( */ - if (obj->kind != FZ_ARRAY) - fz_warn(obj->ctx, "assert: not an array (%s)", fz_objkindstr(obj)); - else - { - if (obj->u.a.len + 1 > obj->u.a.cap) - fz_array_grow(obj); - obj->u.a.items[obj->u.a.len] = fz_keep_obj(item); - obj->u.a.len++; - } -} - -void -fz_array_insert(fz_obj *obj, fz_obj *item) -{ - RESOLVE(obj); - - if (!obj) - return; /* Can't warn :( */ - if (obj->kind != FZ_ARRAY) - fz_warn(obj->ctx, "assert: not an array (%s)", fz_objkindstr(obj)); - else - { - if (obj->u.a.len + 1 > obj->u.a.cap) - fz_array_grow(obj); - memmove(obj->u.a.items + 1, obj->u.a.items, obj->u.a.len * sizeof(fz_obj*)); - obj->u.a.items[0] = fz_keep_obj(item); - obj->u.a.len++; - } -} - -int -fz_array_contains(fz_obj *arr, fz_obj *obj) -{ - int i; - - for (i = 0; i < fz_array_len(arr); i++) - if (!fz_objcmp(fz_array_get(arr, i), obj)) - return 1; - - return 0; -} - -/* dicts may only have names as keys! */ - -static int keyvalcmp(const void *ap, const void *bp) -{ - const struct keyval *a = ap; - const struct keyval *b = bp; - return strcmp(fz_to_name(a->k), fz_to_name(b->k)); -} - -fz_obj * -fz_new_dict(fz_context *ctx, int initialcap) -{ - fz_obj *obj; - int i; - - obj = Memento_label(fz_malloc(ctx, sizeof(fz_obj)), "fz_obj(dict)"); - obj->ctx = ctx; - obj->refs = 1; - obj->kind = FZ_DICT; - - obj->u.d.sorted = 0; - obj->u.d.marked = 0; - obj->u.d.len = 0; - obj->u.d.cap = initialcap > 1 ? initialcap : 10; - - fz_try(ctx) - { - obj->u.d.items = Memento_label(fz_malloc_array(ctx, obj->u.d.cap, sizeof(struct keyval)), "fz_obj(dict items)"); - } - fz_catch(ctx) - { - fz_free(ctx, obj); - fz_rethrow(ctx); - } - for (i = 0; i < obj->u.d.cap; i++) - { - obj->u.d.items[i].k = NULL; - obj->u.d.items[i].v = NULL; - } - - return obj; -} - -static void -fz_dict_grow(fz_obj *obj) -{ - int i; - - obj->u.d.cap = (obj->u.d.cap * 3) / 2; - obj->u.d.items = fz_resize_array(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; - obj->u.d.items[i].v = NULL; - } -} - -fz_obj * -fz_copy_dict(fz_context *ctx, fz_obj *obj) -{ - fz_obj *dict; - int i, n; - - RESOLVE(obj); - if (obj && obj->kind != FZ_DICT) - fz_warn(ctx, "assert: not a dict (%s)", fz_objkindstr(obj)); - - n = fz_dict_len(obj); - dict = fz_new_dict(ctx, n); - for (i = 0; i < n; i++) - fz_dict_put(dict, fz_dict_get_key(obj, i), fz_dict_get_val(obj, i)); - - return dict; -} - -int -fz_dict_len(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return 0; - return obj->u.d.len; -} - -fz_obj * -fz_dict_get_key(fz_obj *obj, int i) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return NULL; - - if (i < 0 || i >= obj->u.d.len) - return NULL; - - return obj->u.d.items[i].k; -} - -fz_obj * -fz_dict_get_val(fz_obj *obj, int i) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return NULL; - - if (i < 0 || i >= obj->u.d.len) - return NULL; - - return obj->u.d.items[i].v; -} - -static int -fz_dict_finds(fz_obj *obj, char *key, int *location) -{ - if (obj->u.d.sorted && obj->u.d.len > 0) - { - int l = 0; - int r = obj->u.d.len - 1; - - if (strcmp(fz_to_name(obj->u.d.items[r].k), key) < 0) - { - if (location) - *location = r + 1; - return -1; - } - - while (l <= r) - { - int m = (l + r) >> 1; - int c = -strcmp(fz_to_name(obj->u.d.items[m].k), key); - if (c < 0) - r = m - 1; - else if (c > 0) - l = m + 1; - else - return m; - - if (location) - *location = l; - } - } - - else - { - int i; - for (i = 0; i < obj->u.d.len; i++) - if (strcmp(fz_to_name(obj->u.d.items[i].k), key) == 0) - return i; - - if (location) - *location = obj->u.d.len; - } - - return -1; -} - -fz_obj * -fz_dict_gets(fz_obj *obj, char *key) -{ - int i; - - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return NULL; - - i = fz_dict_finds(obj, key, NULL); - if (i >= 0) - return obj->u.d.items[i].v; - - return NULL; -} - -fz_obj * -fz_dict_get(fz_obj *obj, fz_obj *key) -{ - if (!key || key->kind != FZ_NAME) - return NULL; - return fz_dict_gets(obj, fz_to_name(key)); -} - -fz_obj * -fz_dict_getsa(fz_obj *obj, char *key, char *abbrev) -{ - fz_obj *v; - v = fz_dict_gets(obj, key); - if (v) - return v; - return fz_dict_gets(obj, abbrev); -} - -void -fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val) -{ - int location; - char *s; - int i; - - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - { - fz_warn(obj->ctx, "assert: not a dict (%s)", fz_objkindstr(obj)); - return; - } - - RESOLVE(key); - if (!key || key->kind != FZ_NAME) - { - fz_warn(obj->ctx, "assert: key is not a name (%s)", fz_objkindstr(obj)); - return; - } - else - s = fz_to_name(key); - - if (!val) - { - fz_warn(obj->ctx, "assert: val does not exist for key (%s)", s); - return; - } - - if (obj->u.d.len > 100 && !obj->u.d.sorted) - fz_sort_dict(obj); - - i = fz_dict_finds(obj, s, &location); - if (i >= 0 && i < obj->u.d.len) - { - fz_drop_obj(obj->u.d.items[i].v); - obj->u.d.items[i].v = fz_keep_obj(val); - } - else - { - if (obj->u.d.len + 1 > obj->u.d.cap) - fz_dict_grow(obj); - - i = location; - if (obj->u.d.sorted && obj->u.d.len > 0) - memmove(&obj->u.d.items[i + 1], - &obj->u.d.items[i], - (obj->u.d.len - i) * sizeof(struct keyval)); - - obj->u.d.items[i].k = fz_keep_obj(key); - obj->u.d.items[i].v = fz_keep_obj(val); - obj->u.d.len ++; - } -} - -void -fz_dict_puts(fz_obj *obj, char *key, fz_obj *val) -{ - fz_obj *keyobj = fz_new_name(obj->ctx, key); - fz_dict_put(obj, keyobj, val); - fz_drop_obj(keyobj); -} - -void -fz_dict_dels(fz_obj *obj, char *key) -{ - RESOLVE(obj); - - if (!obj || obj->kind != FZ_DICT) - fz_warn(obj->ctx, "assert: not a dict (%s)", fz_objkindstr(obj)); - else - { - int i = fz_dict_finds(obj, key, NULL); - if (i >= 0) - { - 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 --; - } - } -} - -void -fz_dict_del(fz_obj *obj, fz_obj *key) -{ - RESOLVE(key); - if (!key || key->kind != FZ_NAME) - fz_warn(obj->ctx, "assert: key is not a name (%s)", fz_objkindstr(obj)); - else - fz_dict_dels(obj, key->u.n); -} - -void -fz_sort_dict(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return; - if (!obj->u.d.sorted) - { - qsort(obj->u.d.items, obj->u.d.len, sizeof(struct keyval), keyvalcmp); - obj->u.d.sorted = 1; - } -} - -int -fz_dict_marked(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return 0; - return obj->u.d.marked; -} - -int -fz_dict_mark(fz_obj *obj) -{ - int marked; - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return 0; - marked = obj->u.d.marked; - obj->u.d.marked = 1; - return marked; -} - -void -fz_dict_unmark(fz_obj *obj) -{ - RESOLVE(obj); - if (!obj || obj->kind != FZ_DICT) - return; - obj->u.d.marked = 0; -} - -static void -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(obj->u.a.items[i]); - - fz_free(obj->ctx, obj->u.a.items); - fz_free(obj->ctx, obj); -} - -static void -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(obj->u.d.items[i].k); - if (obj->u.d.items[i].v) - fz_drop_obj(obj->u.d.items[i].v); - } - - fz_free(obj->ctx, obj->u.d.items); - fz_free(obj->ctx, obj); -} - -void -fz_drop_obj(fz_obj *obj) -{ - if (!obj) - return; - if (--obj->refs) - return; - if (obj->kind == FZ_ARRAY) - fz_free_array(obj); - else if (obj->kind == FZ_DICT) - 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, ""); - 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 - 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, ""); -} - -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/fitz.h b/fitz/fitz.h index cb7cfa4d..e24d3fbb 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -54,7 +54,6 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); #define snprintf _snprintf -#define strtoll _strtoi64 #else /* Unix or close enough */ @@ -908,87 +907,6 @@ void aes_crypt_cbc( fz_aes *ctx, int mode, int length, const unsigned char *input, unsigned char *output ); -/* - * Dynamic objects. - * The same type of objects as found in PDF and PostScript. - * Used by the filters and the mupdf parser. - */ - -typedef struct fz_obj_s fz_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); -fz_obj *fz_new_int(fz_context *ctx, int i); -fz_obj *fz_new_real(fz_context *ctx, float f); -fz_obj *fz_new_name(fz_context *ctx, char *str); -fz_obj *fz_new_string(fz_context *ctx, char *str, int len); -fz_obj *fz_new_indirect(fz_context *ctx, int num, int gen, void *doc); - -fz_obj *fz_new_array(fz_context *ctx, int initialcap); -fz_obj *fz_new_dict(fz_context *ctx, int initialcap); -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_obj *obj); - -/* type queries */ -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); - -/* dict marking and unmarking functions - to avoid infinite recursions */ -int fz_dict_marked(fz_obj *obj); -int fz_dict_mark(fz_obj *obj); -void fz_dict_unmark(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); -fz_obj *fz_to_dict(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_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_array_contains(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_document(fz_obj *obj); /* private */ - /* fz_buffer is a XXX */ @@ -1071,6 +989,7 @@ struct fz_store_type_s void *(*keep_key)(fz_context *,void *); void (*drop_key)(fz_context *,void *); int (*cmp_key)(void *, void *); + void (*debug)(void *); }; void fz_new_store_context(fz_context *ctx, unsigned int max); @@ -1558,12 +1477,13 @@ struct fz_font_s int ft_size; fz_matrix t3matrix; - fz_obj *t3resources; + void *t3resources; fz_buffer **t3procs; /* has 256 entries if used */ float *t3widths; /* has 256 entries if used */ char *t3flags; /* has 256 entries if used */ void *t3doc; /* a pdf_document for the callback */ - void (*t3run)(void *doc, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); + void (*t3run)(void *doc, void *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); + void (*t3freeres)(void *doc, void *resources); fz_rect bbox; /* font bbox is used only for t3 fonts */ diff --git a/fitz/res_font.c b/fitz/res_font.c index 7a194da6..e44be9b6 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -93,7 +93,7 @@ fz_drop_font(fz_context *ctx, fz_font *font) if (font->t3procs) { if (font->t3resources) - fz_drop_obj(font->t3resources); + font->t3freeres(font->t3doc, font->t3resources); for (i = 0; i < 256; i++) if (font->t3procs[i]) fz_drop_buffer(ctx, font->t3procs[i]); diff --git a/fitz/res_store.c b/fitz/res_store.c index 461ea7c8..8f9c1ad8 100644 --- a/fitz/res_store.c +++ b/fitz/res_store.c @@ -459,17 +459,15 @@ fz_debug_store(fz_context *ctx) for (item = store->head; item; item = next) { next = item->next; - next->val->refs++; + if (next) + next->val->refs++; printf("store[*][refs=%d][size=%d] ", item->val->refs, item->size); fz_unlock(ctx, FZ_LOCK_ALLOC); - if (fz_is_indirect(item->key)) - { - printf("(%d %d R) ", fz_to_num(item->key), fz_to_gen(item->key)); - } else - fz_debug_obj(item->key); + item->type->debug(item->key); printf(" = %p\n", item->val); fz_lock(ctx, FZ_LOCK_ALLOC); - next->val->refs--; + if (next) + next->val->refs--; } fz_unlock(ctx, FZ_LOCK_ALLOC); } diff --git a/pdf/base_object.c b/pdf/base_object.c new file mode 100644 index 00000000..94f1acfc --- /dev/null +++ b/pdf/base_object.c @@ -0,0 +1,1266 @@ +#include "fitz.h" +#include "mupdf.h" + +typedef enum pdf_objkind_e +{ + PDF_NULL, + PDF_BOOL, + PDF_INT, + PDF_REAL, + PDF_STRING, + PDF_NAME, + PDF_ARRAY, + PDF_DICT, + PDF_INDIRECT +} pdf_objkind; + +struct keyval +{ + pdf_obj *k; + pdf_obj *v; +}; + +struct pdf_obj_s +{ + int refs; + pdf_objkind kind; + fz_context *ctx; + union + { + int b; + int i; + float f; + struct { + unsigned short len; + char buf[1]; + } s; + char n[1]; + struct { + int len; + int cap; + pdf_obj **items; + } a; + struct { + char sorted; + char marked; + int len; + int cap; + struct keyval *items; + } d; + struct { + int num; + int gen; + struct pdf_xref_s *xref; + } r; + } u; +}; + +pdf_obj * +pdf_new_null(fz_context *ctx) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(null)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_NULL; + return obj; +} + +pdf_obj * +pdf_new_bool(fz_context *ctx, int b) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(bool)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_BOOL; + obj->u.b = b; + return obj; +} + +pdf_obj * +pdf_new_int(fz_context *ctx, int i) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(int)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_INT; + obj->u.i = i; + return obj; +} + +pdf_obj * +pdf_new_real(fz_context *ctx, float f) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(real)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_REAL; + obj->u.f = f; + return obj; +} + +pdf_obj * +pdf_new_string(fz_context *ctx, char *str, int len) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, offsetof(pdf_obj, u.s.buf) + len + 1), "pdf_obj(string)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_STRING; + obj->u.s.len = len; + memcpy(obj->u.s.buf, str, len); + obj->u.s.buf[len] = '\0'; + return obj; +} + +pdf_obj * +fz_new_name(fz_context *ctx, char *str) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, offsetof(pdf_obj, u.n) + strlen(str) + 1), "pdf_obj(name)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_NAME; + strcpy(obj->u.n, str); + return obj; +} + +pdf_obj * +pdf_new_indirect(fz_context *ctx, int num, int gen, void *xref) +{ + pdf_obj *obj; + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(indirect)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_INDIRECT; + obj->u.r.num = num; + obj->u.r.gen = gen; + obj->u.r.xref = xref; + return obj; +} + +pdf_obj * +pdf_keep_obj(pdf_obj *obj) +{ + assert(obj); + obj->refs ++; + return obj; +} + +int pdf_is_indirect(pdf_obj *obj) +{ + return obj ? obj->kind == PDF_INDIRECT : 0; +} + +#define RESOLVE(obj) \ + do { \ + if (obj && obj->kind == PDF_INDIRECT) \ + {\ + fz_assert_lock_not_held(obj->ctx, FZ_LOCK_FILE); \ + obj = pdf_resolve_indirect(obj); \ + } \ + } while (0) + +int pdf_is_null(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_NULL : 0; +} + +int pdf_is_bool(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_BOOL : 0; +} + +int pdf_is_int(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_INT : 0; +} + +int pdf_is_real(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_REAL : 0; +} + +int pdf_is_string(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_STRING : 0; +} + +int pdf_is_name(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_NAME : 0; +} + +int pdf_is_array(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_ARRAY : 0; +} + +int pdf_is_dict(pdf_obj *obj) +{ + RESOLVE(obj); + return obj ? obj->kind == PDF_DICT : 0; +} + +int pdf_to_bool(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj) + return 0; + return obj->kind == PDF_BOOL ? obj->u.b : 0; +} + +int pdf_to_int(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj) + return 0; + if (obj->kind == PDF_INT) + return obj->u.i; + if (obj->kind == PDF_REAL) + return (int)(obj->u.f + 0.5f); /* No roundf in MSVC */ + return 0; +} + +float pdf_to_real(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj) + return 0; + if (obj->kind == PDF_REAL) + return obj->u.f; + if (obj->kind == PDF_INT) + return obj->u.i; + return 0; +} + +char *pdf_to_name(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_NAME) + return ""; + return obj->u.n; +} + +char *pdf_to_str_buf(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_STRING) + return ""; + return obj->u.s.buf; +} + +int pdf_to_str_len(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_STRING) + return 0; + return obj->u.s.len; +} + +/* for use by pdf_crypt_obj_imp to decrypt AES string in place */ +void pdf_set_str_len(pdf_obj *obj, int newlen) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_STRING) + return; /* This should never happen */ + if (newlen > obj->u.s.len) + return; /* This should never happen */ + obj->u.s.len = newlen; +} + +pdf_obj *pdf_to_dict(pdf_obj *obj) +{ + RESOLVE(obj); + return (obj && obj->kind == PDF_DICT ? obj : NULL); +} + +int pdf_to_num(pdf_obj *obj) +{ + if (!obj || obj->kind != PDF_INDIRECT) + return 0; + return obj->u.r.num; +} + +int pdf_to_gen(pdf_obj *obj) +{ + if (!obj || obj->kind != PDF_INDIRECT) + return 0; + return obj->u.r.gen; +} + +void *pdf_get_indirect_document(pdf_obj *obj) +{ + if (!obj || obj->kind != PDF_INDIRECT) + return NULL; + return obj->u.r.xref; +} + +int +pdf_objcmp(pdf_obj *a, pdf_obj *b) +{ + int i; + + if (a == b) + return 0; + + if (!a || !b) + return 1; + + if (a->kind != b->kind) + return 1; + + switch (a->kind) + { + case PDF_NULL: + return 0; + + case PDF_BOOL: + return a->u.b - b->u.b; + + case PDF_INT: + return a->u.i - b->u.i; + + case PDF_REAL: + if (a->u.f < b->u.f) + return -1; + if (a->u.f > b->u.f) + return 1; + return 0; + + case PDF_STRING: + if (a->u.s.len < b->u.s.len) + { + if (memcmp(a->u.s.buf, b->u.s.buf, a->u.s.len) <= 0) + return -1; + return 1; + } + if (a->u.s.len > b->u.s.len) + { + if (memcmp(a->u.s.buf, b->u.s.buf, b->u.s.len) >= 0) + return 1; + return -1; + } + return memcmp(a->u.s.buf, b->u.s.buf, a->u.s.len); + + case PDF_NAME: + return strcmp(a->u.n, b->u.n); + + case PDF_INDIRECT: + if (a->u.r.num == b->u.r.num) + return a->u.r.gen - b->u.r.gen; + return a->u.r.num - b->u.r.num; + + case PDF_ARRAY: + if (a->u.a.len != b->u.a.len) + return a->u.a.len - b->u.a.len; + for (i = 0; i < a->u.a.len; i++) + if (pdf_objcmp(a->u.a.items[i], b->u.a.items[i])) + return 1; + return 0; + + case PDF_DICT: + if (a->u.d.len != b->u.d.len) + return a->u.d.len - b->u.d.len; + for (i = 0; i < a->u.d.len; i++) + { + if (pdf_objcmp(a->u.d.items[i].k, b->u.d.items[i].k)) + return 1; + if (pdf_objcmp(a->u.d.items[i].v, b->u.d.items[i].v)) + return 1; + } + return 0; + + } + return 1; +} + +static char * +pdf_objkindstr(pdf_obj *obj) +{ + if (!obj) + return ""; + switch (obj->kind) + { + case PDF_NULL: return "null"; + case PDF_BOOL: return "boolean"; + case PDF_INT: return "integer"; + case PDF_REAL: return "real"; + case PDF_STRING: return "string"; + case PDF_NAME: return "name"; + case PDF_ARRAY: return "array"; + case PDF_DICT: return "dictionary"; + case PDF_INDIRECT: return "reference"; + } + return ""; +} + +pdf_obj * +pdf_new_array(fz_context *ctx, int initialcap) +{ + pdf_obj *obj; + int i; + + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(array)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_ARRAY; + + obj->u.a.len = 0; + obj->u.a.cap = initialcap > 1 ? initialcap : 6; + + fz_try(ctx) + { + obj->u.a.items = Memento_label(fz_malloc_array(ctx, obj->u.a.cap, sizeof(pdf_obj*)), "pdf_obj(array items)"); + } + fz_catch(ctx) + { + fz_free(ctx, obj); + fz_rethrow(ctx); + } + for (i = 0; i < obj->u.a.cap; i++) + obj->u.a.items[i] = NULL; + + return obj; +} + +static void +pdf_array_grow(pdf_obj *obj) +{ + int i; + + obj->u.a.cap = (obj->u.a.cap * 3) / 2; + obj->u.a.items = fz_resize_array(obj->ctx, obj->u.a.items, obj->u.a.cap, sizeof(pdf_obj*)); + + for (i = obj->u.a.len ; i < obj->u.a.cap; i++) + obj->u.a.items[i] = NULL; +} + +pdf_obj * +pdf_copy_array(fz_context *ctx, pdf_obj *obj) +{ + pdf_obj *arr; + int i; + int n; + + RESOLVE(obj); + if (!obj || obj->kind != PDF_ARRAY) + fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); + + arr = pdf_new_array(ctx, pdf_array_len(obj)); + n = pdf_array_len(obj); + for (i = 0; i < n; i++) + pdf_array_push(arr, pdf_array_get(obj, i)); + + return arr; +} + +int +pdf_array_len(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_ARRAY) + return 0; + return obj->u.a.len; +} + +pdf_obj * +pdf_array_get(pdf_obj *obj, int i) +{ + RESOLVE(obj); + + if (!obj || obj->kind != PDF_ARRAY) + return NULL; + + if (i < 0 || i >= obj->u.a.len) + return NULL; + + return obj->u.a.items[i]; +} + +void +pdf_array_put(pdf_obj *obj, int i, pdf_obj *item) +{ + RESOLVE(obj); + + if (!obj) + return; /* Can't warn :( */ + if (obj->kind != PDF_ARRAY) + fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); + else if (i < 0) + fz_warn(obj->ctx, "assert: index %d < 0", i); + else if (i >= obj->u.a.len) + fz_warn(obj->ctx, "assert: index %d > length %d", i, obj->u.a.len); + else + { + if (obj->u.a.items[i]) + pdf_drop_obj(obj->u.a.items[i]); + obj->u.a.items[i] = pdf_keep_obj(item); + } +} + +void +pdf_array_push(pdf_obj *obj, pdf_obj *item) +{ + RESOLVE(obj); + + if (!obj) + return; /* Can't warn :( */ + if (obj->kind != PDF_ARRAY) + fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); + else + { + if (obj->u.a.len + 1 > obj->u.a.cap) + pdf_array_grow(obj); + obj->u.a.items[obj->u.a.len] = pdf_keep_obj(item); + obj->u.a.len++; + } +} + +void +pdf_array_insert(pdf_obj *obj, pdf_obj *item) +{ + RESOLVE(obj); + + if (!obj) + return; /* Can't warn :( */ + if (obj->kind != PDF_ARRAY) + fz_warn(obj->ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); + else + { + if (obj->u.a.len + 1 > obj->u.a.cap) + pdf_array_grow(obj); + memmove(obj->u.a.items + 1, obj->u.a.items, obj->u.a.len * sizeof(pdf_obj*)); + obj->u.a.items[0] = pdf_keep_obj(item); + obj->u.a.len++; + } +} + +int +pdf_array_contains(pdf_obj *arr, pdf_obj *obj) +{ + int i; + + for (i = 0; i < pdf_array_len(arr); i++) + if (!pdf_objcmp(pdf_array_get(arr, i), obj)) + return 1; + + return 0; +} + +/* dicts may only have names as keys! */ + +static int keyvalcmp(const void *ap, const void *bp) +{ + const struct keyval *a = ap; + const struct keyval *b = bp; + return strcmp(pdf_to_name(a->k), pdf_to_name(b->k)); +} + +pdf_obj * +pdf_new_dict(fz_context *ctx, int initialcap) +{ + pdf_obj *obj; + int i; + + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(dict)"); + obj->ctx = ctx; + obj->refs = 1; + obj->kind = PDF_DICT; + + obj->u.d.sorted = 0; + obj->u.d.marked = 0; + obj->u.d.len = 0; + obj->u.d.cap = initialcap > 1 ? initialcap : 10; + + fz_try(ctx) + { + obj->u.d.items = Memento_label(fz_malloc_array(ctx, obj->u.d.cap, sizeof(struct keyval)), "pdf_obj(dict items)"); + } + fz_catch(ctx) + { + fz_free(ctx, obj); + fz_rethrow(ctx); + } + for (i = 0; i < obj->u.d.cap; i++) + { + obj->u.d.items[i].k = NULL; + obj->u.d.items[i].v = NULL; + } + + return obj; +} + +static void +pdf_dict_grow(pdf_obj *obj) +{ + int i; + + obj->u.d.cap = (obj->u.d.cap * 3) / 2; + obj->u.d.items = fz_resize_array(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; + obj->u.d.items[i].v = NULL; + } +} + +pdf_obj * +pdf_copy_dict(fz_context *ctx, pdf_obj *obj) +{ + pdf_obj *dict; + int i, n; + + RESOLVE(obj); + if (obj && obj->kind != PDF_DICT) + fz_warn(ctx, "assert: not a dict (%s)", pdf_objkindstr(obj)); + + n = pdf_dict_len(obj); + dict = pdf_new_dict(ctx, n); + for (i = 0; i < n; i++) + fz_dict_put(dict, pdf_dict_get_key(obj, i), pdf_dict_get_val(obj, i)); + + return dict; +} + +int +pdf_dict_len(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return 0; + return obj->u.d.len; +} + +pdf_obj * +pdf_dict_get_key(pdf_obj *obj, int i) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return NULL; + + if (i < 0 || i >= obj->u.d.len) + return NULL; + + return obj->u.d.items[i].k; +} + +pdf_obj * +pdf_dict_get_val(pdf_obj *obj, int i) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return NULL; + + if (i < 0 || i >= obj->u.d.len) + return NULL; + + return obj->u.d.items[i].v; +} + +static int +pdf_dict_finds(pdf_obj *obj, char *key, int *location) +{ + if (obj->u.d.sorted && obj->u.d.len > 0) + { + int l = 0; + int r = obj->u.d.len - 1; + + if (strcmp(pdf_to_name(obj->u.d.items[r].k), key) < 0) + { + if (location) + *location = r + 1; + return -1; + } + + while (l <= r) + { + int m = (l + r) >> 1; + int c = -strcmp(pdf_to_name(obj->u.d.items[m].k), key); + if (c < 0) + r = m - 1; + else if (c > 0) + l = m + 1; + else + return m; + + if (location) + *location = l; + } + } + + else + { + int i; + for (i = 0; i < obj->u.d.len; i++) + if (strcmp(pdf_to_name(obj->u.d.items[i].k), key) == 0) + return i; + + if (location) + *location = obj->u.d.len; + } + + return -1; +} + +pdf_obj * +pdf_dict_gets(pdf_obj *obj, char *key) +{ + int i; + + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return NULL; + + i = pdf_dict_finds(obj, key, NULL); + if (i >= 0) + return obj->u.d.items[i].v; + + return NULL; +} + +pdf_obj * +pdf_dict_get(pdf_obj *obj, pdf_obj *key) +{ + if (!key || key->kind != PDF_NAME) + return NULL; + return pdf_dict_gets(obj, pdf_to_name(key)); +} + +pdf_obj * +pdf_dict_getsa(pdf_obj *obj, char *key, char *abbrev) +{ + pdf_obj *v; + v = pdf_dict_gets(obj, key); + if (v) + return v; + return pdf_dict_gets(obj, abbrev); +} + +void +fz_dict_put(pdf_obj *obj, pdf_obj *key, pdf_obj *val) +{ + int location; + char *s; + int i; + + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + { + fz_warn(obj->ctx, "assert: not a dict (%s)", pdf_objkindstr(obj)); + return; + } + + RESOLVE(key); + if (!key || key->kind != PDF_NAME) + { + fz_warn(obj->ctx, "assert: key is not a name (%s)", pdf_objkindstr(obj)); + return; + } + else + s = pdf_to_name(key); + + if (!val) + { + fz_warn(obj->ctx, "assert: val does not exist for key (%s)", s); + return; + } + + if (obj->u.d.len > 100 && !obj->u.d.sorted) + pdf_sort_dict(obj); + + i = pdf_dict_finds(obj, s, &location); + if (i >= 0 && i < obj->u.d.len) + { + pdf_drop_obj(obj->u.d.items[i].v); + obj->u.d.items[i].v = pdf_keep_obj(val); + } + else + { + if (obj->u.d.len + 1 > obj->u.d.cap) + pdf_dict_grow(obj); + + i = location; + if (obj->u.d.sorted && obj->u.d.len > 0) + memmove(&obj->u.d.items[i + 1], + &obj->u.d.items[i], + (obj->u.d.len - i) * sizeof(struct keyval)); + + obj->u.d.items[i].k = pdf_keep_obj(key); + obj->u.d.items[i].v = pdf_keep_obj(val); + obj->u.d.len ++; + } +} + +void +pdf_dict_puts(pdf_obj *obj, char *key, pdf_obj *val) +{ + pdf_obj *keyobj = fz_new_name(obj->ctx, key); + fz_dict_put(obj, keyobj, val); + pdf_drop_obj(keyobj); +} + +void +pdf_dict_dels(pdf_obj *obj, char *key) +{ + RESOLVE(obj); + + if (!obj || obj->kind != PDF_DICT) + fz_warn(obj->ctx, "assert: not a dict (%s)", pdf_objkindstr(obj)); + else + { + int i = pdf_dict_finds(obj, key, NULL); + if (i >= 0) + { + pdf_drop_obj(obj->u.d.items[i].k); + pdf_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 --; + } + } +} + +void +pdf_dict_del(pdf_obj *obj, pdf_obj *key) +{ + RESOLVE(key); + if (!key || key->kind != PDF_NAME) + fz_warn(obj->ctx, "assert: key is not a name (%s)", pdf_objkindstr(obj)); + else + pdf_dict_dels(obj, key->u.n); +} + +void +pdf_sort_dict(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return; + if (!obj->u.d.sorted) + { + qsort(obj->u.d.items, obj->u.d.len, sizeof(struct keyval), keyvalcmp); + obj->u.d.sorted = 1; + } +} + +int +pdf_dict_marked(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return 0; + return obj->u.d.marked; +} + +int +pdf_dict_mark(pdf_obj *obj) +{ + int marked; + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return 0; + marked = obj->u.d.marked; + obj->u.d.marked = 1; + return marked; +} + +void +pdf_dict_unmark(pdf_obj *obj) +{ + RESOLVE(obj); + if (!obj || obj->kind != PDF_DICT) + return; + obj->u.d.marked = 0; +} + +static void +pdf_free_array(pdf_obj *obj) +{ + int i; + + for (i = 0; i < obj->u.a.len; i++) + if (obj->u.a.items[i]) + pdf_drop_obj(obj->u.a.items[i]); + + fz_free(obj->ctx, obj->u.a.items); + fz_free(obj->ctx, obj); +} + +static void +pdf_free_dict(pdf_obj *obj) +{ + int i; + + for (i = 0; i < obj->u.d.len; i++) { + if (obj->u.d.items[i].k) + pdf_drop_obj(obj->u.d.items[i].k); + if (obj->u.d.items[i].v) + pdf_drop_obj(obj->u.d.items[i].v); + } + + fz_free(obj->ctx, obj->u.d.items); + fz_free(obj->ctx, obj); +} + +void +pdf_drop_obj(pdf_obj *obj) +{ + if (!obj) + return; + if (--obj->refs) + return; + if (obj->kind == PDF_ARRAY) + pdf_free_array(obj); + else if (obj->kind == PDF_DICT) + pdf_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, pdf_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, pdf_obj *obj) +{ + char *s = pdf_to_str_buf(obj); + int n = pdf_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, pdf_obj *obj) +{ + char *s = pdf_to_str_buf(obj); + int n = pdf_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, pdf_obj *obj) +{ + unsigned char *s = (unsigned char *) pdf_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, pdf_obj *obj) +{ + int i, n; + + n = pdf_array_len(obj); + if (fmt->tight) { + fmt_putc(fmt, '['); + for (i = 0; i < n; i++) { + fmt_obj(fmt, pdf_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, pdf_array_get(obj, i)); + fmt_putc(fmt, ' '); + } + fmt_putc(fmt, ']'); + fmt_sep(fmt); + } +} + +static void fmt_dict(struct fmt *fmt, pdf_obj *obj) +{ + int i, n; + pdf_obj *key, *val; + + n = pdf_dict_len(obj); + if (fmt->tight) { + fmt_puts(fmt, "<<"); + for (i = 0; i < n; i++) { + fmt_obj(fmt, pdf_dict_get_key(obj, i)); + fmt_sep(fmt); + fmt_obj(fmt, pdf_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 = pdf_dict_get_key(obj, i); + val = pdf_dict_get_val(obj, i); + fmt_indent(fmt); + fmt_obj(fmt, key); + fmt_putc(fmt, ' '); + if (!pdf_is_indirect(val) && pdf_is_array(val)) + fmt->indent ++; + fmt_obj(fmt, val); + fmt_putc(fmt, '\n'); + if (!pdf_is_indirect(val) && pdf_is_array(val)) + fmt->indent --; + } + fmt->indent --; + fmt_indent(fmt); + fmt_puts(fmt, ">>"); + } +} + +static void fmt_obj(struct fmt *fmt, pdf_obj *obj) +{ + char buf[256]; + + if (!obj) + fmt_puts(fmt, ""); + else if (pdf_is_indirect(obj)) + { + sprintf(buf, "%d %d R", pdf_to_num(obj), pdf_to_gen(obj)); + fmt_puts(fmt, buf); + } + else if (pdf_is_null(obj)) + fmt_puts(fmt, "null"); + else if (pdf_is_bool(obj)) + fmt_puts(fmt, pdf_to_bool(obj) ? "true" : "false"); + else if (pdf_is_int(obj)) + { + sprintf(buf, "%d", pdf_to_int(obj)); + fmt_puts(fmt, buf); + } + else if (pdf_is_real(obj)) + { + sprintf(buf, "%g", pdf_to_real(obj)); + if (strchr(buf, 'e')) /* bad news! */ + sprintf(buf, fabsf(pdf_to_real(obj)) > 1 ? "%1.1f" : "%1.8f", pdf_to_real(obj)); + fmt_puts(fmt, buf); + } + else if (pdf_is_string(obj)) + { + char *str = pdf_to_str_buf(obj); + int len = pdf_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 + fmt_hex(fmt, obj); + } + else if (pdf_is_name(obj)) + fmt_name(fmt, obj); + else if (pdf_is_array(obj)) + fmt_array(fmt, obj); + else if (pdf_is_dict(obj)) + fmt_dict(fmt, obj); + else + fmt_puts(fmt, ""); +} + +static int +pdf_sprint_obj(char *s, int n, pdf_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 +pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight) +{ + char buf[1024]; + char *ptr; + int n; + + n = pdf_sprint_obj(NULL, 0, obj, tight); + if ((n + 1) < sizeof buf) + { + pdf_sprint_obj(buf, sizeof buf, obj, tight); + fputs(buf, fp); + fputc('\n', fp); + } + else + { + ptr = fz_malloc(obj->ctx, n + 1); + pdf_sprint_obj(ptr, n + 1, obj, tight); + fputs(ptr, fp); + fputc('\n', fp); + fz_free(obj->ctx, ptr); + } + return n; +} + +void +pdf_debug_obj(pdf_obj *obj) +{ + pdf_fprint_obj(stdout, obj, 0); +} + +void +pdf_debug_ref(pdf_obj *ref) +{ + pdf_debug_obj(pdf_resolve_indirect(ref)); +} diff --git a/pdf/mupdf.h b/pdf/mupdf.h index 93682083..5d775044 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -5,6 +5,85 @@ #error "fitz.h must be included before mupdf.h" #endif +/* + * Dynamic objects. + * The same type of objects as found in PDF and PostScript. + * Used by the filters and the mupdf parser. + */ + +typedef struct pdf_obj_s pdf_obj; + +pdf_obj *pdf_new_null(fz_context *ctx); +pdf_obj *pdf_new_bool(fz_context *ctx, int b); +pdf_obj *pdf_new_int(fz_context *ctx, int i); +pdf_obj *pdf_new_real(fz_context *ctx, float f); +pdf_obj *fz_new_name(fz_context *ctx, char *str); +pdf_obj *pdf_new_string(fz_context *ctx, char *str, int len); +pdf_obj *pdf_new_indirect(fz_context *ctx, int num, int gen, void *doc); + +pdf_obj *pdf_new_array(fz_context *ctx, int initialcap); +pdf_obj *pdf_new_dict(fz_context *ctx, int initialcap); +pdf_obj *pdf_copy_array(fz_context *ctx, pdf_obj *array); +pdf_obj *pdf_copy_dict(fz_context *ctx, pdf_obj *dict); + +pdf_obj *pdf_keep_obj(pdf_obj *obj); +void pdf_drop_obj(pdf_obj *obj); + +/* type queries */ +int pdf_is_null(pdf_obj *obj); +int pdf_is_bool(pdf_obj *obj); +int pdf_is_int(pdf_obj *obj); +int pdf_is_real(pdf_obj *obj); +int pdf_is_name(pdf_obj *obj); +int pdf_is_string(pdf_obj *obj); +int pdf_is_array(pdf_obj *obj); +int pdf_is_dict(pdf_obj *obj); +int pdf_is_indirect(pdf_obj *obj); + +int pdf_objcmp(pdf_obj *a, pdf_obj *b); + +/* dict marking and unmarking functions - to avoid infinite recursions */ +int pdf_dict_marked(pdf_obj *obj); +int pdf_dict_mark(pdf_obj *obj); +void pdf_dict_unmark(pdf_obj *obj); + +/* safe, silent failure, no error reporting on type mismatches */ +int pdf_to_bool(pdf_obj *obj); +int pdf_to_int(pdf_obj *obj); +float pdf_to_real(pdf_obj *obj); +char *pdf_to_name(pdf_obj *obj); +char *pdf_to_str_buf(pdf_obj *obj); +pdf_obj *pdf_to_dict(pdf_obj *obj); +int pdf_to_str_len(pdf_obj *obj); +int pdf_to_num(pdf_obj *obj); +int pdf_to_gen(pdf_obj *obj); + +int pdf_array_len(pdf_obj *array); +pdf_obj *pdf_array_get(pdf_obj *array, int i); +void pdf_array_put(pdf_obj *array, int i, pdf_obj *obj); +void pdf_array_push(pdf_obj *array, pdf_obj *obj); +void pdf_array_insert(pdf_obj *array, pdf_obj *obj); +int pdf_array_contains(pdf_obj *array, pdf_obj *obj); + +int pdf_dict_len(pdf_obj *dict); +pdf_obj *pdf_dict_get_key(pdf_obj *dict, int idx); +pdf_obj *pdf_dict_get_val(pdf_obj *dict, int idx); +pdf_obj *pdf_dict_get(pdf_obj *dict, pdf_obj *key); +pdf_obj *pdf_dict_gets(pdf_obj *dict, char *key); +pdf_obj *pdf_dict_getsa(pdf_obj *dict, char *key, char *abbrev); +void fz_dict_put(pdf_obj *dict, pdf_obj *key, pdf_obj *val); +void pdf_dict_puts(pdf_obj *dict, char *key, pdf_obj *val); +void pdf_dict_del(pdf_obj *dict, pdf_obj *key); +void pdf_dict_dels(pdf_obj *dict, char *key); +void pdf_sort_dict(pdf_obj *dict); + +int pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight); +void pdf_debug_obj(pdf_obj *obj); +void pdf_debug_ref(pdf_obj *obj); + +void pdf_set_str_len(pdf_obj *obj, int newlen); /* private */ +void *pdf_get_indirect_document(pdf_obj *obj); /* private */ + /* * PDF Images */ @@ -132,16 +211,16 @@ struct pdf_lexbuf_large_s int pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf); -fz_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); -fz_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); -fz_obj *pdf_parse_stm_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); -fz_obj *pdf_parse_ind_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int *stm_ofs); +pdf_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); +pdf_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); +pdf_obj *pdf_parse_stm_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf); +pdf_obj *pdf_parse_ind_obj(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf, int *num, int *gen, int *stm_ofs); -fz_rect pdf_to_rect(fz_context *ctx, fz_obj *array); -fz_matrix pdf_to_matrix(fz_context *ctx, fz_obj *array); -char *pdf_to_utf8(fz_context *ctx, fz_obj *src); -unsigned short *pdf_to_ucs2(fz_context *ctx, fz_obj *src); -fz_obj *pdf_to_utf8_name(fz_context *ctx, fz_obj *src); +fz_rect pdf_to_rect(fz_context *ctx, pdf_obj *array); +fz_matrix pdf_to_matrix(fz_context *ctx, pdf_obj *array); +char *pdf_to_utf8(fz_context *ctx, pdf_obj *src); +unsigned short *pdf_to_ucs2(fz_context *ctx, pdf_obj *src); +pdf_obj *pdf_to_utf8_name(fz_context *ctx, pdf_obj *src); char *pdf_from_ucs2(fz_context *ctx, unsigned short *str); /* @@ -158,7 +237,7 @@ struct pdf_xref_entry_s int ofs; /* file offset / objstm object number */ int gen; /* generation / objstm index */ int stm_ofs; /* on-disk stream */ - fz_obj *obj; /* stored/cached object */ + pdf_obj *obj; /* stored/cached object */ int type; /* 0=unset (f)ree i(n)use (o)bjstm */ }; @@ -173,7 +252,7 @@ struct pdf_ocg_descriptor_s { int len; pdf_ocg_entry *ocgs; - fz_obj *intent; + pdf_obj *intent; }; struct pdf_document_s @@ -187,7 +266,7 @@ struct pdf_document_s int startxref; int file_size; pdf_crypt *crypt; - fz_obj *trailer; + pdf_obj *trailer; pdf_ocg_descriptor *ocg; int len; @@ -195,26 +274,26 @@ struct pdf_document_s int page_len; int page_cap; - fz_obj **page_objs; - fz_obj **page_refs; + pdf_obj **page_objs; + pdf_obj **page_refs; pdf_lexbuf_large lexbuf; }; -fz_obj *pdf_resolve_indirect(fz_obj *ref); +pdf_obj *pdf_resolve_indirect(pdf_obj *ref); void pdf_cache_object(pdf_document *doc, int num, int gen); -fz_obj *pdf_load_object(pdf_document *doc, int num, int gen); -void pdf_update_object(pdf_document *doc, int num, int gen, fz_obj *newobj); +pdf_obj *pdf_load_object(pdf_document *doc, int num, int gen); +void pdf_update_object(pdf_document *doc, int num, int gen, pdf_obj *newobj); int pdf_is_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_inline_stream(pdf_document *doc, fz_obj *stmobj, int length, fz_stream *chain, pdf_image_params *params); +fz_stream *pdf_open_inline_stream(pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, pdf_image_params *params); fz_buffer *pdf_load_raw_stream(pdf_document *doc, int num, int gen); fz_buffer *pdf_load_stream(pdf_document *doc, int num, int gen); fz_buffer *pdf_load_image_stream(pdf_document *doc, int num, int gen, pdf_image_params *params); fz_stream *pdf_open_raw_stream(pdf_document *doc, int num, int gen); fz_stream *pdf_open_image_stream(pdf_document *doc, int num, int gen, pdf_image_params *params); fz_stream *pdf_open_stream(pdf_document *doc, int num, int gen); -fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, fz_obj *dict, int stm_ofs); +fz_stream *pdf_open_stream_with_offset(pdf_document *doc, int num, int gen, pdf_obj *dict, int stm_ofs); fz_stream *pdf_open_image_decomp_stream(fz_context *ctx, fz_buffer *, pdf_image_params *params, int *factor); /* @@ -280,10 +359,10 @@ enum PDF_DEFAULT_PERM_FLAGS = 0xfffc }; -pdf_crypt *pdf_new_crypt(fz_context *ctx, fz_obj *enc, fz_obj *id); +pdf_crypt *pdf_new_crypt(fz_context *ctx, pdf_obj *enc, pdf_obj *id); void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt); -void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, int num, int gen); +void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen); fz_stream *pdf_open_crypt(fz_stream *chain, pdf_crypt *crypt, int num, int gen); fz_stream *pdf_open_crypt_with_filter(fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen); @@ -304,20 +383,20 @@ void pdf_debug_crypt(pdf_crypt *crypt); typedef struct pdf_function_s pdf_function; -pdf_function *pdf_load_function(pdf_document *doc, fz_obj *ref); +pdf_function *pdf_load_function(pdf_document *doc, pdf_obj *ref); void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen); pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func); void pdf_drop_function(fz_context *ctx, pdf_function *func); unsigned int pdf_function_size(pdf_function *func); -fz_colorspace *pdf_load_colorspace(pdf_document *doc, fz_obj *obj); +fz_colorspace *pdf_load_colorspace(pdf_document *doc, pdf_obj *obj); fz_pixmap *pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src); -fz_shade *pdf_load_shading(pdf_document *doc, fz_obj *obj); +fz_shade *pdf_load_shading(pdf_document *doc, pdf_obj *obj); -fz_image *pdf_load_inline_image(pdf_document *doc, fz_obj *rdb, fz_obj *dict, fz_stream *file); -fz_image *pdf_load_image(pdf_document *doc, fz_obj *obj); -int pdf_is_jpx_image(fz_context *ctx, fz_obj *dict); +fz_image *pdf_load_inline_image(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *file); +fz_image *pdf_load_image(pdf_document *doc, pdf_obj *obj); +int pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict); /* * Pattern @@ -333,11 +412,11 @@ struct pdf_pattern_s float ystep; fz_matrix matrix; fz_rect bbox; - fz_obj *resources; + pdf_obj *resources; fz_buffer *contents; }; -pdf_pattern *pdf_load_pattern(pdf_document *doc, fz_obj *obj); +pdf_pattern *pdf_load_pattern(pdf_document *doc, pdf_obj *obj); pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat); void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat); @@ -356,12 +435,12 @@ struct pdf_xobject_s int knockout; int transparency; fz_colorspace *colorspace; - fz_obj *resources; + pdf_obj *resources; fz_buffer *contents; - fz_obj *me; + pdf_obj *me; }; -pdf_xobject *pdf_load_xobject(pdf_document *doc, fz_obj *obj); +pdf_xobject *pdf_load_xobject(pdf_document *doc, pdf_obj *obj); pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj); void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj); @@ -434,7 +513,7 @@ pdf_cmap *pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes); pdf_cmap *pdf_load_cmap(fz_context *ctx, fz_stream *file); pdf_cmap *pdf_load_system_cmap(fz_context *ctx, char *name); pdf_cmap *pdf_load_builtin_cmap(fz_context *ctx, char *name); -pdf_cmap *pdf_load_embedded_cmap(pdf_document *doc, fz_obj *ref); +pdf_cmap *pdf_load_embedded_cmap(pdf_document *doc, pdf_obj *ref); /* * Font @@ -536,7 +615,7 @@ void pdf_end_vmtx(fz_context *ctx, pdf_font_desc *font); pdf_hmtx pdf_get_hmtx(fz_context *ctx, pdf_font_desc *font, int cid); pdf_vmtx pdf_get_vmtx(fz_context *ctx, pdf_font_desc *font, int cid); -void pdf_load_to_unicode(pdf_document *doc, pdf_font_desc *font, char **strings, char *collection, fz_obj *cmapstm); +void pdf_load_to_unicode(pdf_document *doc, pdf_font_desc *font, char **strings, char *collection, pdf_obj *cmapstm); int pdf_font_cid_to_gid(fz_context *ctx, pdf_font_desc *fontdesc, int cid); @@ -544,8 +623,8 @@ unsigned char *pdf_find_builtin_font(char *name, unsigned int *len); unsigned char *pdf_find_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len); unsigned char *pdf_find_substitute_cjk_font(int ros, int serif, unsigned int *len); -pdf_font_desc *pdf_load_type3_font(pdf_document *doc, fz_obj *rdb, fz_obj *obj); -pdf_font_desc *pdf_load_font(pdf_document *doc, fz_obj *rdb, fz_obj *obj); +pdf_font_desc *pdf_load_type3_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); +pdf_font_desc *pdf_load_font(pdf_document *doc, pdf_obj *rdb, pdf_obj *obj); pdf_font_desc *pdf_new_font_desc(fz_context *ctx); pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc); @@ -561,24 +640,24 @@ typedef struct pdf_annot_s pdf_annot; struct pdf_annot_s { - fz_obj *obj; + pdf_obj *obj; fz_rect rect; pdf_xobject *ap; fz_matrix matrix; pdf_annot *next; }; -fz_link_dest pdf_parse_link_dest(pdf_document *doc, fz_obj *dest); -fz_link_dest pdf_parse_action(pdf_document *doc, fz_obj *action); -fz_obj *pdf_lookup_dest(pdf_document *doc, fz_obj *needle); -fz_obj *pdf_lookup_name(pdf_document *doc, char *which, fz_obj *needle); -fz_obj *pdf_load_name_tree(pdf_document *doc, char *which); +fz_link_dest pdf_parse_link_dest(pdf_document *doc, pdf_obj *dest); +fz_link_dest pdf_parse_action(pdf_document *doc, pdf_obj *action); +pdf_obj *pdf_lookup_dest(pdf_document *doc, pdf_obj *needle); +pdf_obj *pdf_lookup_name(pdf_document *doc, char *which, pdf_obj *needle); +pdf_obj *pdf_load_name_tree(pdf_document *doc, char *which); fz_outline *pdf_load_outline(pdf_document *doc); -fz_link *pdf_load_link_annots(pdf_document *, fz_obj *annots, fz_matrix page_ctm); +fz_link *pdf_load_link_annots(pdf_document *, pdf_obj *annots, fz_matrix page_ctm); -pdf_annot *pdf_load_annots(pdf_document *, fz_obj *annots); +pdf_annot *pdf_load_annots(pdf_document *, pdf_obj *annots); void pdf_free_annot(fz_context *ctx, pdf_annot *link); /* @@ -593,13 +672,13 @@ struct pdf_page_s fz_rect mediabox; int rotate; int transparency; - fz_obj *resources; + pdf_obj *resources; fz_buffer *contents; fz_link *links; pdf_annot *annots; }; -int pdf_find_page_number(pdf_document *doc, fz_obj *pageobj); +int pdf_find_page_number(pdf_document *doc, pdf_obj *pageobj); int pdf_count_pages(pdf_document *doc); /* @@ -652,14 +731,14 @@ void pdf_free_page(pdf_document *doc, pdf_page *page); void pdf_run_page(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie); -void pdf_run_glyph(pdf_document *doc, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); +void pdf_run_glyph(pdf_document *doc, pdf_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate); /* * PDF interface to store */ -void pdf_store_item(fz_context *ctx, fz_obj *key, void *val, unsigned int itemsize); -void *pdf_find_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key); -void pdf_remove_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key); +void pdf_store_item(fz_context *ctx, pdf_obj *key, void *val, unsigned int itemsize); +void *pdf_find_item(fz_context *ctx, fz_store_free_fn *free, pdf_obj *key); +void pdf_remove_item(fz_context *ctx, fz_store_free_fn *free, pdf_obj *key); #endif diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index ae03f2b6..81e5d887 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -1,46 +1,46 @@ #include "fitz.h" #include "mupdf.h" -static fz_obj * -resolve_dest_rec(pdf_document *xref, fz_obj *dest, int depth) +static pdf_obj * +resolve_dest_rec(pdf_document *xref, pdf_obj *dest, int depth) { if (depth > 10) /* Arbitrary to avoid infinite recursion */ return NULL; - if (fz_is_name(dest) || fz_is_string(dest)) + if (pdf_is_name(dest) || pdf_is_string(dest)) { dest = pdf_lookup_dest(xref, dest); return resolve_dest_rec(xref, dest, depth+1); } - else if (fz_is_array(dest)) + else if (pdf_is_array(dest)) { return dest; } - else if (fz_is_dict(dest)) + else if (pdf_is_dict(dest)) { - dest = fz_dict_gets(dest, "D"); + dest = pdf_dict_gets(dest, "D"); return resolve_dest_rec(xref, dest, depth+1); } - else if (fz_is_indirect(dest)) + else if (pdf_is_indirect(dest)) return dest; return NULL; } -static fz_obj * -resolve_dest(pdf_document *xref, fz_obj *dest) +static pdf_obj * +resolve_dest(pdf_document *xref, pdf_obj *dest) { return resolve_dest_rec(xref, dest, 0); } fz_link_dest -pdf_parse_link_dest(pdf_document *xref, fz_obj *dest) +pdf_parse_link_dest(pdf_document *xref, pdf_obj *dest) { fz_link_dest ld; - fz_obj *obj; + pdf_obj *obj; int l_from_2 = 0; int b_from_3 = 0; @@ -51,14 +51,14 @@ pdf_parse_link_dest(pdf_document *xref, fz_obj *dest) int z_from_4 = 0; dest = resolve_dest(xref, dest); - if (dest == NULL || !fz_is_array(dest)) + if (dest == NULL || !pdf_is_array(dest)) { ld.kind = FZ_LINK_NONE; return ld; } - obj = fz_array_get(dest, 0); - if (fz_is_int(obj)) - ld.ld.gotor.page = fz_to_int(obj); + obj = pdf_array_get(dest, 0); + if (pdf_is_int(obj)) + ld.ld.gotor.page = pdf_to_int(obj); else ld.ld.gotor.page = pdf_find_page_number(xref, obj); @@ -71,31 +71,31 @@ pdf_parse_link_dest(pdf_document *xref, fz_obj *dest) ld.ld.gotor.file_spec = NULL; ld.ld.gotor.new_window = 0; - obj = fz_array_get(dest, 1); - if (!fz_is_name(obj)) + obj = pdf_array_get(dest, 1); + if (!pdf_is_name(obj)) return ld; - if (!strcmp("XYZ", fz_to_name(obj))) + if (!strcmp("XYZ", pdf_to_name(obj))) { l_from_2 = t_from_3 = z_from_4 = 1; ld.ld.gotor.flags |= fz_link_flag_r_is_zoom; } - else if ((!strcmp("Fit", fz_to_name(obj))) || (!strcmp("FitB", fz_to_name(obj)))) + else if ((!strcmp("Fit", pdf_to_name(obj))) || (!strcmp("FitB", pdf_to_name(obj)))) { ld.ld.gotor.flags |= fz_link_flag_fit_h; ld.ld.gotor.flags |= fz_link_flag_fit_v; } - else if ((!strcmp("FitH", fz_to_name(obj))) || (!strcmp("FitBH", fz_to_name(obj)))) + else if ((!strcmp("FitH", pdf_to_name(obj))) || (!strcmp("FitBH", pdf_to_name(obj)))) { t_from_2 = 1; ld.ld.gotor.flags |= fz_link_flag_fit_h; } - else if ((!strcmp("FitV", fz_to_name(obj))) || (!strcmp("FitBV", fz_to_name(obj)))) + else if ((!strcmp("FitV", pdf_to_name(obj))) || (!strcmp("FitBV", pdf_to_name(obj)))) { l_from_2 = 1; ld.ld.gotor.flags |= fz_link_flag_fit_v; } - else if (!strcmp("FitR", fz_to_name(obj))) + else if (!strcmp("FitR", pdf_to_name(obj))) { l_from_2 = b_from_3 = r_from_4 = t_from_5 = 1; ld.ld.gotor.flags |= fz_link_flag_fit_h; @@ -104,77 +104,77 @@ pdf_parse_link_dest(pdf_document *xref, fz_obj *dest) if (l_from_2) { - obj = fz_array_get(dest, 2); - if (fz_is_int(obj)) + obj = pdf_array_get(dest, 2); + if (pdf_is_int(obj)) { ld.ld.gotor.flags |= fz_link_flag_l_valid; - ld.ld.gotor.lt.x = fz_to_int(obj); + ld.ld.gotor.lt.x = pdf_to_int(obj); } - else if (fz_is_real(obj)) + else if (pdf_is_real(obj)) { ld.ld.gotor.flags |= fz_link_flag_l_valid; - ld.ld.gotor.lt.x = fz_to_real(obj); + ld.ld.gotor.lt.x = pdf_to_real(obj); } } if (b_from_3) { - obj = fz_array_get(dest, 3); - if (fz_is_int(obj)) + obj = pdf_array_get(dest, 3); + if (pdf_is_int(obj)) { ld.ld.gotor.flags |= fz_link_flag_b_valid; - ld.ld.gotor.rb.y = fz_to_int(obj); + ld.ld.gotor.rb.y = pdf_to_int(obj); } - else if (fz_is_real(obj)) + else if (pdf_is_real(obj)) { ld.ld.gotor.flags |= fz_link_flag_b_valid; - ld.ld.gotor.rb.y = fz_to_real(obj); + ld.ld.gotor.rb.y = pdf_to_real(obj); } } if (r_from_4) { - obj = fz_array_get(dest, 4); - if (fz_is_int(obj)) + obj = pdf_array_get(dest, 4); + if (pdf_is_int(obj)) { ld.ld.gotor.flags |= fz_link_flag_r_valid; - ld.ld.gotor.rb.x = fz_to_int(obj); + ld.ld.gotor.rb.x = pdf_to_int(obj); } - else if (fz_is_real(obj)) + else if (pdf_is_real(obj)) { ld.ld.gotor.flags |= fz_link_flag_r_valid; - ld.ld.gotor.rb.x = fz_to_real(obj); + ld.ld.gotor.rb.x = pdf_to_real(obj); } } if (t_from_5 || t_from_3 || t_from_2) { if (t_from_5) - obj = fz_array_get(dest, 5); + obj = pdf_array_get(dest, 5); else if (t_from_3) - obj = fz_array_get(dest, 3); + obj = pdf_array_get(dest, 3); else - obj = fz_array_get(dest, 2); - if (fz_is_int(obj)) + obj = pdf_array_get(dest, 2); + if (pdf_is_int(obj)) { ld.ld.gotor.flags |= fz_link_flag_t_valid; - ld.ld.gotor.lt.y = fz_to_int(obj); + ld.ld.gotor.lt.y = pdf_to_int(obj); } - else if (fz_is_real(obj)) + else if (pdf_is_real(obj)) { ld.ld.gotor.flags |= fz_link_flag_t_valid; - ld.ld.gotor.lt.y = fz_to_real(obj); + ld.ld.gotor.lt.y = pdf_to_real(obj); } } if (z_from_4) { - obj = fz_array_get(dest, 4); - if (fz_is_int(obj)) + obj = pdf_array_get(dest, 4); + if (pdf_is_int(obj)) { ld.ld.gotor.flags |= fz_link_flag_r_valid; - ld.ld.gotor.rb.x = fz_to_int(obj); + ld.ld.gotor.rb.x = pdf_to_int(obj); } - else if (fz_is_real(obj)) + else if (pdf_is_real(obj)) { ld.ld.gotor.flags |= fz_link_flag_r_valid; - ld.ld.gotor.rb.x = fz_to_real(obj); + ld.ld.gotor.rb.x = pdf_to_real(obj); } } @@ -192,10 +192,10 @@ pdf_parse_link_dest(pdf_document *xref, fz_obj *dest) } fz_link_dest -pdf_parse_action(pdf_document *xref, fz_obj *action) +pdf_parse_action(pdf_document *xref, pdf_obj *action) { fz_link_dest ld; - fz_obj *obj, *dest; + pdf_obj *obj, *dest; fz_context *ctx = xref->ctx; ld.kind = FZ_LINK_NONE; @@ -203,53 +203,53 @@ pdf_parse_action(pdf_document *xref, fz_obj *action) if (!action) return ld; - obj = fz_dict_gets(action, "S"); - if (!strcmp(fz_to_name(obj), "GoTo")) + obj = pdf_dict_gets(action, "S"); + if (!strcmp(pdf_to_name(obj), "GoTo")) { - dest = fz_dict_gets(action, "D"); + dest = pdf_dict_gets(action, "D"); ld = pdf_parse_link_dest(xref, dest); } - else if (!strcmp(fz_to_name(obj), "URI")) + else if (!strcmp(pdf_to_name(obj), "URI")) { ld.kind = FZ_LINK_URI; - ld.ld.uri.is_map = fz_to_bool(fz_dict_gets(action, "IsMap")); - ld.ld.uri.uri = pdf_to_utf8(ctx, fz_dict_gets(action, "URI")); + ld.ld.uri.is_map = pdf_to_bool(pdf_dict_gets(action, "IsMap")); + ld.ld.uri.uri = pdf_to_utf8(ctx, pdf_dict_gets(action, "URI")); } - else if (!strcmp(fz_to_name(obj), "Launch")) + else if (!strcmp(pdf_to_name(obj), "Launch")) { ld.kind = FZ_LINK_LAUNCH; - ld.ld.launch.file_spec = pdf_to_utf8(ctx, fz_dict_gets(action, "F")); - ld.ld.launch.new_window = fz_to_int(fz_dict_gets(action, "NewWindow")); + ld.ld.launch.file_spec = pdf_to_utf8(ctx, pdf_dict_gets(action, "F")); + ld.ld.launch.new_window = pdf_to_int(pdf_dict_gets(action, "NewWindow")); } - else if (!strcmp(fz_to_name(obj), "Named")) + else if (!strcmp(pdf_to_name(obj), "Named")) { ld.kind = FZ_LINK_NAMED; - ld.ld.named.named = pdf_to_utf8(ctx, fz_dict_gets(action, "N")); + ld.ld.named.named = pdf_to_utf8(ctx, pdf_dict_gets(action, "N")); } - else if (!strcmp(fz_to_name(obj), "GoToR")) + else if (!strcmp(pdf_to_name(obj), "GoToR")) { - dest = fz_dict_gets(action, "D"); + dest = pdf_dict_gets(action, "D"); ld = pdf_parse_link_dest(xref, dest); ld.kind = FZ_LINK_GOTOR; - ld.ld.gotor.file_spec = pdf_to_utf8(ctx, fz_dict_gets(action, "F")); - ld.ld.gotor.new_window = fz_to_int(fz_dict_gets(action, "NewWindow")); + ld.ld.gotor.file_spec = pdf_to_utf8(ctx, pdf_dict_gets(action, "F")); + ld.ld.gotor.new_window = pdf_to_int(pdf_dict_gets(action, "NewWindow")); } return ld; } static fz_link * -pdf_load_link(pdf_document *xref, fz_obj *dict, fz_matrix page_ctm) +pdf_load_link(pdf_document *xref, pdf_obj *dict, fz_matrix page_ctm) { - fz_obj *dest = NULL; - fz_obj *action; - fz_obj *obj; + pdf_obj *dest = NULL; + pdf_obj *action; + pdf_obj *obj; fz_rect bbox; fz_context *ctx = xref->ctx; fz_link_dest ld; dest = NULL; - obj = fz_dict_gets(dict, "Rect"); + obj = pdf_dict_gets(dict, "Rect"); if (obj) bbox = pdf_to_rect(ctx, obj); else @@ -257,7 +257,7 @@ pdf_load_link(pdf_document *xref, fz_obj *dict, fz_matrix page_ctm) bbox = fz_transform_rect(page_ctm, bbox); - obj = fz_dict_gets(dict, "Dest"); + obj = pdf_dict_gets(dict, "Dest"); if (obj) { dest = resolve_dest(xref, obj); @@ -265,10 +265,10 @@ pdf_load_link(pdf_document *xref, fz_obj *dict, fz_matrix page_ctm) } else { - action = fz_dict_gets(dict, "A"); + action = pdf_dict_gets(dict, "A"); /* fall back to additional action button's down/up action */ if (!action) - action = fz_dict_getsa(fz_dict_gets(dict, "AA"), "U", "D"); + action = pdf_dict_getsa(pdf_dict_gets(dict, "AA"), "U", "D"); ld = pdf_parse_action(xref, action); } @@ -278,19 +278,19 @@ pdf_load_link(pdf_document *xref, fz_obj *dict, fz_matrix page_ctm) } fz_link * -pdf_load_link_annots(pdf_document *xref, fz_obj *annots, fz_matrix page_ctm) +pdf_load_link_annots(pdf_document *xref, pdf_obj *annots, fz_matrix page_ctm) { fz_link *link, *head, *tail; - fz_obj *obj; + pdf_obj *obj; int i, n; head = tail = NULL; link = NULL; - n = fz_array_len(annots); + n = pdf_array_len(annots); for (i = 0; i < n; i++) { - obj = fz_array_get(annots, i); + obj = pdf_array_get(annots, i); link = pdf_load_link(xref, obj, page_ctm); if (link) { @@ -318,7 +318,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(annot->obj); + pdf_drop_obj(annot->obj); fz_free(ctx, annot); annot = next; } @@ -349,10 +349,10 @@ pdf_transform_annot(pdf_annot *annot) } pdf_annot * -pdf_load_annots(pdf_document *xref, fz_obj *annots) +pdf_load_annots(pdf_document *xref, pdf_obj *annots) { pdf_annot *annot, *head, *tail; - fz_obj *obj, *ap, *as, *n, *rect; + pdf_obj *obj, *ap, *as, *n, *rect; pdf_xobject *form; int i, len; fz_context *ctx = xref->ctx; @@ -360,23 +360,23 @@ pdf_load_annots(pdf_document *xref, fz_obj *annots) head = tail = NULL; annot = NULL; - len = fz_array_len(annots); + len = pdf_array_len(annots); for (i = 0; i < len; i++) { - obj = fz_array_get(annots, i); + obj = pdf_array_get(annots, i); - rect = fz_dict_gets(obj, "Rect"); - ap = fz_dict_gets(obj, "AP"); - as = fz_dict_gets(obj, "AS"); - if (fz_is_dict(ap)) + rect = pdf_dict_gets(obj, "Rect"); + ap = pdf_dict_gets(obj, "AP"); + as = pdf_dict_gets(obj, "AS"); + if (pdf_is_dict(ap)) { - n = fz_dict_gets(ap, "N"); /* normal state */ + n = pdf_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(n, as); + if (!pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n))) + n = pdf_dict_get(n, as); - if (pdf_is_stream(xref, fz_to_num(n), fz_to_gen(n))) + if (pdf_is_stream(xref, pdf_to_num(n), pdf_to_gen(n))) { fz_try(ctx) { @@ -389,7 +389,7 @@ pdf_load_annots(pdf_document *xref, fz_obj *annots) } annot = fz_malloc_struct(ctx, pdf_annot); - annot->obj = fz_keep_obj(obj); + annot->obj = pdf_keep_obj(obj); annot->rect = pdf_to_rect(ctx, rect); annot->ap = form; annot->next = NULL; diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c index 9e6b13ce..d4e161c8 100644 --- a/pdf/pdf_cmap_load.c +++ b/pdf/pdf_cmap_load.c @@ -16,13 +16,13 @@ pdf_cmap_size(fz_context *ctx, pdf_cmap *cmap) * Load CMap stream in PDF file */ pdf_cmap * -pdf_load_embedded_cmap(pdf_document *xref, fz_obj *stmobj) +pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj) { fz_stream *file = NULL; pdf_cmap *cmap = NULL; pdf_cmap *usecmap; - fz_obj *wmode; - fz_obj *obj = NULL; + pdf_obj *wmode; + pdf_obj *obj = NULL; fz_context *ctx = xref->ctx; int phase = 0; @@ -38,24 +38,24 @@ pdf_load_embedded_cmap(pdf_document *xref, fz_obj *stmobj) fz_try(ctx) { - file = pdf_open_stream(xref, fz_to_num(stmobj), fz_to_gen(stmobj)); + file = pdf_open_stream(xref, pdf_to_num(stmobj), pdf_to_gen(stmobj)); phase = 1; cmap = pdf_load_cmap(ctx, file); phase = 2; fz_close(file); file = NULL; - wmode = fz_dict_gets(stmobj, "WMode"); - if (fz_is_int(wmode)) - pdf_set_wmode(ctx, cmap, fz_to_int(wmode)); - obj = fz_dict_gets(stmobj, "UseCMap"); - if (fz_is_name(obj)) + wmode = pdf_dict_gets(stmobj, "WMode"); + if (pdf_is_int(wmode)) + pdf_set_wmode(ctx, cmap, pdf_to_int(wmode)); + obj = pdf_dict_gets(stmobj, "UseCMap"); + if (pdf_is_name(obj)) { - usecmap = pdf_load_system_cmap(ctx, fz_to_name(obj)); + usecmap = pdf_load_system_cmap(ctx, pdf_to_name(obj)); pdf_set_usecmap(ctx, cmap, usecmap); pdf_drop_cmap(ctx, usecmap); } - else if (fz_is_indirect(obj)) + else if (pdf_is_indirect(obj)) { phase = 3; usecmap = pdf_load_embedded_cmap(xref, obj); @@ -72,13 +72,13 @@ pdf_load_embedded_cmap(pdf_document *xref, fz_obj *stmobj) if (cmap) pdf_drop_cmap(ctx, cmap); if (phase < 1) - fz_throw(ctx, "cannot open cmap stream (%d %d R)", fz_to_num(stmobj), fz_to_gen(stmobj)); + fz_throw(ctx, "cannot open cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj)); else if (phase < 2) - fz_throw(ctx, "cannot parse cmap stream (%d %d R)", fz_to_num(stmobj), fz_to_gen(stmobj)); + fz_throw(ctx, "cannot parse cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj)); else if (phase < 3) - fz_throw(ctx, "cannot load system usecmap '%s'", fz_to_name(obj)); + fz_throw(ctx, "cannot load system usecmap '%s'", pdf_to_name(obj)); else - fz_throw(ctx, "cannot load embedded usecmap (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); + fz_throw(ctx, "cannot load embedded usecmap (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } return cmap; diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index a6515d42..0e9423b4 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -4,11 +4,11 @@ /* ICCBased */ static fz_colorspace * -load_icc_based(pdf_document *xref, fz_obj *dict) +load_icc_based(pdf_document *xref, pdf_obj *dict) { int n; - n = fz_to_int(fz_dict_gets(dict, "N")); + n = pdf_to_int(pdf_dict_gets(dict, "N")); switch (n) { @@ -91,14 +91,14 @@ free_separation(fz_context *ctx, fz_colorspace *cs) } static fz_colorspace * -load_separation(pdf_document *xref, fz_obj *array) +load_separation(pdf_document *xref, pdf_obj *array) { fz_colorspace *cs; struct separation *sep = NULL; fz_context *ctx = xref->ctx; - fz_obj *nameobj = fz_array_get(array, 1); - fz_obj *baseobj = fz_array_get(array, 2); - fz_obj *tintobj = fz_array_get(array, 3); + pdf_obj *nameobj = pdf_array_get(array, 1); + pdf_obj *baseobj = pdf_array_get(array, 2); + pdf_obj *tintobj = pdf_array_get(array, 3); fz_colorspace *base; pdf_function *tint = NULL; int n; @@ -106,8 +106,8 @@ load_separation(pdf_document *xref, fz_obj *array) fz_var(tint); fz_var(sep); - if (fz_is_array(nameobj)) - n = fz_array_len(nameobj); + if (pdf_is_array(nameobj)) + n = pdf_array_len(nameobj); else n = 1; @@ -115,13 +115,13 @@ load_separation(pdf_document *xref, fz_obj *array) fz_throw(ctx, "too many components in colorspace"); base = pdf_load_colorspace(xref, baseobj); - /* RJW: "cannot load base colorspace (%d %d R)", fz_to_num(baseobj), fz_to_gen(baseobj) */ + /* RJW: "cannot load base colorspace (%d %d R)", pdf_to_num(baseobj), pdf_to_gen(baseobj) */ fz_try(ctx) { tint = pdf_load_function(xref, tintobj); /* RJW: fz_drop_colorspace(ctx, base); - * "cannot load tint function (%d %d R)", fz_to_num(tintobj), fz_to_gen(tintobj) */ + * "cannot load tint function (%d %d R)", pdf_to_num(tintobj), pdf_to_gen(tintobj) */ sep = fz_malloc_struct(ctx, struct separation); sep->base = base; @@ -218,13 +218,13 @@ pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src) } static fz_colorspace * -load_indexed(pdf_document *xref, fz_obj *array) +load_indexed(pdf_document *xref, pdf_obj *array) { struct indexed *idx = NULL; fz_context *ctx = xref->ctx; - fz_obj *baseobj = fz_array_get(array, 1); - fz_obj *highobj = fz_array_get(array, 2); - fz_obj *lookup = fz_array_get(array, 3); + pdf_obj *baseobj = pdf_array_get(array, 1); + pdf_obj *highobj = pdf_array_get(array, 2); + pdf_obj *lookup = pdf_array_get(array, 3); fz_colorspace *base = NULL; fz_colorspace *cs = NULL; int i, n; @@ -236,12 +236,12 @@ load_indexed(pdf_document *xref, fz_obj *array) fz_try(ctx) { base = pdf_load_colorspace(xref, baseobj); - /* "cannot load base colorspace (%d %d R)", fz_to_num(baseobj), fz_to_gen(baseobj) */ + /* "cannot load base colorspace (%d %d R)", pdf_to_num(baseobj), pdf_to_gen(baseobj) */ idx = fz_malloc_struct(ctx, struct indexed); idx->lookup = NULL; idx->base = base; - idx->high = fz_to_int(highobj); + idx->high = pdf_to_int(highobj); idx->high = CLAMP(idx->high, 0, 255); n = base->n * (idx->high + 1); idx->lookup = fz_malloc_array(ctx, 1, n); @@ -252,30 +252,30 @@ load_indexed(pdf_document *xref, fz_obj *array) cs->data = idx; cs->size += sizeof(*idx) + n + (base ? base->size : 0); - if (fz_is_string(lookup) && fz_to_str_len(lookup) == n) + if (pdf_is_string(lookup) && pdf_to_str_len(lookup) == n) { - unsigned char *buf = (unsigned char *) fz_to_str_buf(lookup); + unsigned char *buf = (unsigned char *) pdf_to_str_buf(lookup); for (i = 0; i < n; i++) idx->lookup[i] = buf[i]; } - else if (fz_is_indirect(lookup)) + else if (pdf_is_indirect(lookup)) { fz_stream *file = NULL; fz_try(ctx) { - file = pdf_open_stream(xref, fz_to_num(lookup), fz_to_gen(lookup)); + file = pdf_open_stream(xref, pdf_to_num(lookup), pdf_to_gen(lookup)); } fz_catch(ctx) { - fz_throw(ctx, "cannot open colorspace lookup table (%d 0 R)", fz_to_num(lookup)); + fz_throw(ctx, "cannot open colorspace lookup table (%d 0 R)", pdf_to_num(lookup)); } i = fz_read(file, idx->lookup, n); if (i < 0) { fz_close(file); - fz_throw(ctx, "cannot read colorspace lookup table (%d 0 R)", fz_to_num(lookup)); + fz_throw(ctx, "cannot read colorspace lookup table (%d 0 R)", pdf_to_num(lookup)); } fz_close(file); @@ -304,93 +304,93 @@ load_indexed(pdf_document *xref, fz_obj *array) /* Parse and create colorspace from PDF object */ static fz_colorspace * -pdf_load_colorspace_imp(pdf_document *xref, fz_obj *obj) +pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) { - if (fz_is_name(obj)) + if (pdf_is_name(obj)) { - if (!strcmp(fz_to_name(obj), "Pattern")) + if (!strcmp(pdf_to_name(obj), "Pattern")) return fz_device_gray; - else if (!strcmp(fz_to_name(obj), "G")) + else if (!strcmp(pdf_to_name(obj), "G")) return fz_device_gray; - else if (!strcmp(fz_to_name(obj), "RGB")) + else if (!strcmp(pdf_to_name(obj), "RGB")) return fz_device_rgb; - else if (!strcmp(fz_to_name(obj), "CMYK")) + else if (!strcmp(pdf_to_name(obj), "CMYK")) return fz_device_cmyk; - else if (!strcmp(fz_to_name(obj), "DeviceGray")) + else if (!strcmp(pdf_to_name(obj), "DeviceGray")) return fz_device_gray; - else if (!strcmp(fz_to_name(obj), "DeviceRGB")) + else if (!strcmp(pdf_to_name(obj), "DeviceRGB")) return fz_device_rgb; - else if (!strcmp(fz_to_name(obj), "DeviceCMYK")) + else if (!strcmp(pdf_to_name(obj), "DeviceCMYK")) return fz_device_cmyk; else - fz_throw(xref->ctx, "unknown colorspace: %s", fz_to_name(obj)); + fz_throw(xref->ctx, "unknown colorspace: %s", pdf_to_name(obj)); } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { - fz_obj *name = fz_array_get(obj, 0); + pdf_obj *name = pdf_array_get(obj, 0); - if (fz_is_name(name)) + if (pdf_is_name(name)) { /* load base colorspace instead */ - if (!strcmp(fz_to_name(name), "Pattern")) + if (!strcmp(pdf_to_name(name), "Pattern")) { - obj = fz_array_get(obj, 1); + obj = pdf_array_get(obj, 1); if (!obj) { return fz_device_gray; } return pdf_load_colorspace(xref, obj); - /* RJW: "cannot load pattern (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ + /* RJW: "cannot load pattern (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ } - else if (!strcmp(fz_to_name(name), "G")) + else if (!strcmp(pdf_to_name(name), "G")) return fz_device_gray; - else if (!strcmp(fz_to_name(name), "RGB")) + else if (!strcmp(pdf_to_name(name), "RGB")) return fz_device_rgb; - else if (!strcmp(fz_to_name(name), "CMYK")) + else if (!strcmp(pdf_to_name(name), "CMYK")) return fz_device_cmyk; - else if (!strcmp(fz_to_name(name), "DeviceGray")) + else if (!strcmp(pdf_to_name(name), "DeviceGray")) return fz_device_gray; - else if (!strcmp(fz_to_name(name), "DeviceRGB")) + else if (!strcmp(pdf_to_name(name), "DeviceRGB")) return fz_device_rgb; - else if (!strcmp(fz_to_name(name), "DeviceCMYK")) + else if (!strcmp(pdf_to_name(name), "DeviceCMYK")) return fz_device_cmyk; - else if (!strcmp(fz_to_name(name), "CalGray")) + else if (!strcmp(pdf_to_name(name), "CalGray")) return fz_device_gray; - else if (!strcmp(fz_to_name(name), "CalRGB")) + else if (!strcmp(pdf_to_name(name), "CalRGB")) return fz_device_rgb; - else if (!strcmp(fz_to_name(name), "CalCMYK")) + else if (!strcmp(pdf_to_name(name), "CalCMYK")) return fz_device_cmyk; - else if (!strcmp(fz_to_name(name), "Lab")) + else if (!strcmp(pdf_to_name(name), "Lab")) return fz_device_lab; - else if (!strcmp(fz_to_name(name), "ICCBased")) - return load_icc_based(xref, fz_array_get(obj, 1)); + else if (!strcmp(pdf_to_name(name), "ICCBased")) + return load_icc_based(xref, pdf_array_get(obj, 1)); - else if (!strcmp(fz_to_name(name), "Indexed")) + else if (!strcmp(pdf_to_name(name), "Indexed")) return load_indexed(xref, obj); - else if (!strcmp(fz_to_name(name), "I")) + else if (!strcmp(pdf_to_name(name), "I")) return load_indexed(xref, obj); - else if (!strcmp(fz_to_name(name), "Separation")) + else if (!strcmp(pdf_to_name(name), "Separation")) return load_separation(xref, obj); - else if (!strcmp(fz_to_name(name), "DeviceN")) + else if (!strcmp(pdf_to_name(name), "DeviceN")) return load_separation(xref, obj); else - fz_throw(xref->ctx, "syntaxerror: unknown colorspace %s", fz_to_name(name)); + fz_throw(xref->ctx, "syntaxerror: unknown colorspace %s", pdf_to_name(name)); } } - fz_throw(xref->ctx, "syntaxerror: could not parse color space (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); + fz_throw(xref->ctx, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); return NULL; /* Stupid MSVC */ } fz_colorspace * -pdf_load_colorspace(pdf_document *xref, fz_obj *obj) +pdf_load_colorspace(pdf_document *xref, pdf_obj *obj) { fz_context *ctx = xref->ctx; fz_colorspace *cs; @@ -401,7 +401,7 @@ pdf_load_colorspace(pdf_document *xref, fz_obj *obj) } cs = pdf_load_colorspace_imp(xref, obj); - /* RJW: "cannot load colorspace (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ + /* RJW: "cannot load colorspace (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ pdf_store_item(ctx, obj, cs, cs->size); diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index 59423a38..c99e696c 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -20,11 +20,11 @@ struct pdf_crypt_filter_s struct pdf_crypt_s { - fz_obj *id; + pdf_obj *id; int v; int length; - fz_obj *cf; + pdf_obj *cf; pdf_crypt_filter stmf; pdf_crypt_filter strf; @@ -40,7 +40,7 @@ struct pdf_crypt_s fz_context *ctx; }; -static void pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, fz_obj *dict, char *name, int defaultlength); +static void pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_obj *dict, char *name, int defaultlength); /* * Create crypt object for decrypting strings and streams @@ -48,31 +48,31 @@ static void pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, fz_obj */ pdf_crypt * -pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) +pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) { pdf_crypt *crypt; - fz_obj *obj; + pdf_obj *obj; crypt = fz_malloc_struct(ctx, pdf_crypt); /* Common to all security handlers (PDF 1.7 table 3.18) */ - obj = fz_dict_gets(dict, "Filter"); - if (!fz_is_name(obj)) + obj = pdf_dict_gets(dict, "Filter"); + if (!pdf_is_name(obj)) { pdf_free_crypt(ctx, crypt); fz_throw(ctx, "unspecified encryption handler"); } - if (strcmp(fz_to_name(obj), "Standard") != 0) + if (strcmp(pdf_to_name(obj), "Standard") != 0) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "unknown encryption handler: '%s'", fz_to_name(obj)); + fz_throw(ctx, "unknown encryption handler: '%s'", pdf_to_name(obj)); } crypt->v = 0; - obj = fz_dict_gets(dict, "V"); - if (fz_is_int(obj)) - crypt->v = fz_to_int(obj); + obj = pdf_dict_gets(dict, "V"); + if (pdf_is_int(obj)) + crypt->v = pdf_to_int(obj); if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4 && crypt->v != 5) { pdf_free_crypt(ctx, crypt); @@ -82,9 +82,9 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) crypt->length = 40; if (crypt->v == 2 || crypt->v == 4) { - obj = fz_dict_gets(dict, "Length"); - if (fz_is_int(obj)) - crypt->length = fz_to_int(obj); + obj = pdf_dict_gets(dict, "Length"); + if (pdf_is_int(obj)) + crypt->length = pdf_to_int(obj); /* work-around for pdf generators that assume length is in bytes */ if (crypt->length < 40) @@ -122,10 +122,10 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) crypt->strf.method = PDF_CRYPT_NONE; crypt->strf.length = crypt->length; - obj = fz_dict_gets(dict, "CF"); - if (fz_is_dict(obj)) + obj = pdf_dict_gets(dict, "CF"); + if (pdf_is_dict(obj)) { - crypt->cf = fz_keep_obj(obj); + crypt->cf = pdf_keep_obj(obj); } else { @@ -134,18 +134,18 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) fz_try(ctx) { - obj = fz_dict_gets(dict, "StmF"); - if (fz_is_name(obj)) - pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt->cf, fz_to_name(obj), crypt->length); + obj = pdf_dict_gets(dict, "StmF"); + if (pdf_is_name(obj)) + pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt->cf, pdf_to_name(obj), crypt->length); - obj = fz_dict_gets(dict, "StrF"); - if (fz_is_name(obj)) - pdf_parse_crypt_filter(ctx, &crypt->strf, crypt->cf, fz_to_name(obj), crypt->length); + obj = pdf_dict_gets(dict, "StrF"); + if (pdf_is_name(obj)) + pdf_parse_crypt_filter(ctx, &crypt->strf, crypt->cf, pdf_to_name(obj), crypt->length); } fz_catch(ctx) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "cannot parse string crypt filter (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); + fz_throw(ctx, "cannot parse string crypt filter (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } /* in crypt revision 4, the crypt filter determines the key length */ @@ -155,36 +155,36 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) /* Standard security handler (PDF 1.7 table 3.19) */ - obj = fz_dict_gets(dict, "R"); - if (fz_is_int(obj)) - crypt->r = fz_to_int(obj); + obj = pdf_dict_gets(dict, "R"); + if (pdf_is_int(obj)) + crypt->r = pdf_to_int(obj); else { pdf_free_crypt(ctx, crypt); fz_throw(ctx, "encryption dictionary missing revision value"); } - 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); + obj = pdf_dict_gets(dict, "O"); + if (pdf_is_string(obj) && pdf_to_str_len(obj) == 32) + memcpy(crypt->o, pdf_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(obj) && fz_to_str_len(obj) >= 48) - memcpy(crypt->o, fz_to_str_buf(obj), 48); + else if (crypt->r == 5 && pdf_is_string(obj) && pdf_to_str_len(obj) >= 48) + memcpy(crypt->o, pdf_to_str_buf(obj), 48); else { pdf_free_crypt(ctx, crypt); fz_throw(ctx, "encryption dictionary missing owner password"); } - 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) + obj = pdf_dict_gets(dict, "U"); + if (pdf_is_string(obj) && pdf_to_str_len(obj) == 32) + memcpy(crypt->u, pdf_to_str_buf(obj), 32); + else if (pdf_is_string(obj) && pdf_to_str_len(obj) >= 48 && crypt->r == 5) + memcpy(crypt->u, pdf_to_str_buf(obj), 48); + else if (pdf_is_string(obj) && pdf_to_str_len(obj) < 32) { - fz_warn(ctx, "encryption password key too short (%d)", fz_to_str_len(obj)); - memcpy(crypt->u, fz_to_str_buf(obj), fz_to_str_len(obj)); + fz_warn(ctx, "encryption password key too short (%d)", pdf_to_str_len(obj)); + memcpy(crypt->u, pdf_to_str_buf(obj), pdf_to_str_len(obj)); } else { @@ -192,9 +192,9 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) fz_throw(ctx, "encryption dictionary missing user password"); } - obj = fz_dict_gets(dict, "P"); - if (fz_is_int(obj)) - crypt->p = fz_to_int(obj); + obj = pdf_dict_gets(dict, "P"); + if (pdf_is_int(obj)) + crypt->p = pdf_to_int(obj); else { pdf_free_crypt(ctx, crypt); @@ -203,35 +203,35 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) if (crypt->r == 5) { - obj = fz_dict_gets(dict, "OE"); - if (!fz_is_string(obj) || fz_to_str_len(obj) != 32) + obj = pdf_dict_gets(dict, "OE"); + if (!pdf_is_string(obj) || pdf_to_str_len(obj) != 32) { pdf_free_crypt(ctx, crypt); fz_throw(ctx, "encryption dictionary missing owner encryption key"); } - memcpy(crypt->oe, fz_to_str_buf(obj), 32); + memcpy(crypt->oe, pdf_to_str_buf(obj), 32); - obj = fz_dict_gets(dict, "UE"); - if (!fz_is_string(obj) || fz_to_str_len(obj) != 32) + obj = pdf_dict_gets(dict, "UE"); + if (!pdf_is_string(obj) || pdf_to_str_len(obj) != 32) { pdf_free_crypt(ctx, crypt); fz_throw(ctx, "encryption dictionary missing user encryption key"); } - memcpy(crypt->ue, fz_to_str_buf(obj), 32); + memcpy(crypt->ue, pdf_to_str_buf(obj), 32); } crypt->encrypt_metadata = 1; - obj = fz_dict_gets(dict, "EncryptMetadata"); - if (fz_is_bool(obj)) - crypt->encrypt_metadata = fz_to_bool(obj); + obj = pdf_dict_gets(dict, "EncryptMetadata"); + if (pdf_is_bool(obj)) + crypt->encrypt_metadata = pdf_to_bool(obj); /* Extract file identifier string */ - if (fz_is_array(id) && fz_array_len(id) == 2) + if (pdf_is_array(id) && pdf_array_len(id) == 2) { - obj = fz_array_get(id, 0); - if (fz_is_string(obj)) - crypt->id = fz_keep_obj(obj); + obj = pdf_array_get(id, 0); + if (pdf_is_string(obj)) + crypt->id = pdf_keep_obj(obj); } else fz_warn(ctx, "missing file identifier, may not be able to do decryption"); @@ -242,8 +242,8 @@ pdf_new_crypt(fz_context *ctx, fz_obj *dict, fz_obj *id) void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt) { - if (crypt->id) fz_drop_obj(crypt->id); - if (crypt->cf) fz_drop_obj(crypt->cf); + if (crypt->id) pdf_drop_obj(crypt->id); + if (crypt->cf) pdf_drop_obj(crypt->cf); fz_free(ctx, crypt); } @@ -252,15 +252,15 @@ pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt) */ static void -pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, fz_obj *cf_obj, char *name, int defaultlength) +pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_obj *cf_obj, char *name, int defaultlength) { - fz_obj *obj; - fz_obj *dict; + pdf_obj *obj; + pdf_obj *dict; int is_identity = (strcmp(name, "Identity") == 0); int is_stdcf = (!is_identity && (strcmp(name, "StdCF") == 0)); if (!is_identity && !is_stdcf) - fz_throw(ctx, "Crypt Filter not Identity or StdCF (%d %d R)", fz_to_num(cf_obj), fz_to_gen(cf_obj)); + fz_throw(ctx, "Crypt Filter not Identity or StdCF (%d %d R)", pdf_to_num(cf_obj), pdf_to_gen(cf_obj)); cf->method = PDF_CRYPT_NONE; cf->length = defaultlength; @@ -271,28 +271,28 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, fz_obj *cf_obj, ch return; } - dict = fz_dict_gets(cf_obj, name); - if (!fz_is_dict(dict)) - fz_throw(ctx, "cannot parse crypt filter (%d %d R)", fz_to_num(cf_obj), fz_to_gen(cf_obj)); + dict = pdf_dict_gets(cf_obj, name); + if (!pdf_is_dict(dict)) + fz_throw(ctx, "cannot parse crypt filter (%d %d R)", pdf_to_num(cf_obj), pdf_to_gen(cf_obj)); - obj = fz_dict_gets(dict, "CFM"); - if (fz_is_name(obj)) + obj = pdf_dict_gets(dict, "CFM"); + if (pdf_is_name(obj)) { - if (!strcmp(fz_to_name(obj), "None")) + if (!strcmp(pdf_to_name(obj), "None")) cf->method = PDF_CRYPT_NONE; - else if (!strcmp(fz_to_name(obj), "V2")) + else if (!strcmp(pdf_to_name(obj), "V2")) cf->method = PDF_CRYPT_RC4; - else if (!strcmp(fz_to_name(obj), "AESV2")) + else if (!strcmp(pdf_to_name(obj), "AESV2")) cf->method = PDF_CRYPT_AESV2; - else if (!strcmp(fz_to_name(obj), "AESV3")) + else if (!strcmp(pdf_to_name(obj), "AESV3")) cf->method = PDF_CRYPT_AESV3; else - fz_warn(ctx, "unknown encryption method: %s", fz_to_name(obj)); + fz_warn(ctx, "unknown encryption method: %s", pdf_to_name(obj)); } - obj = fz_dict_gets(dict, "Length"); - if (fz_is_int(obj)) - cf->length = fz_to_int(obj); + obj = pdf_dict_gets(dict, "Length"); + if (pdf_is_int(obj)) + cf->length = pdf_to_int(obj); /* the length for crypt filters is supposed to be in bytes not bits */ if (cf->length < 40) @@ -346,7 +346,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->id), fz_to_str_len(crypt->id)); + fz_md5_update(&md5, (unsigned char *)pdf_to_str_buf(crypt->id), pdf_to_str_len(crypt->id)); /* Step 6 (revision 4 or greater) - if metadata is not encrypted pass 0xFFFFFFFF */ if (crypt->r >= 4) @@ -455,7 +455,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->id), fz_to_str_len(crypt->id)); + fz_md5_update(&md5, (unsigned char*)pdf_to_str_buf(crypt->id), pdf_to_str_len(crypt->id)); fz_md5_final(&md5, digest); fz_arc4_init(&arc4, crypt->key, n); @@ -697,18 +697,18 @@ pdf_compute_object_key(pdf_crypt *crypt, pdf_crypt_filter *cf, int num, int gen, */ static void -pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, unsigned char *key, int keylen) +pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, unsigned char *key, int keylen) { unsigned char *s; int i, n; - if (fz_is_indirect(obj)) + if (pdf_is_indirect(obj)) return; - if (fz_is_string(obj)) + if (pdf_is_string(obj)) { - s = (unsigned char *)fz_to_str_buf(obj); - n = fz_to_str_len(obj); + s = (unsigned char *)pdf_to_str_buf(obj); + n = pdf_to_str_len(obj); if (crypt->strf.method == PDF_CRYPT_RC4) { @@ -736,32 +736,32 @@ 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(ctx, "aes padding out of range"); else - fz_set_str_len(obj, n - 16 - s[n - 17]); + pdf_set_str_len(obj, n - 16 - s[n - 17]); } } } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { - n = fz_array_len(obj); + n = pdf_array_len(obj); for (i = 0; i < n; i++) { - pdf_crypt_obj_imp(ctx, crypt, fz_array_get(obj, i), key, keylen); + pdf_crypt_obj_imp(ctx, crypt, pdf_array_get(obj, i), key, keylen); } } - else if (fz_is_dict(obj)) + else if (pdf_is_dict(obj)) { - n = fz_dict_len(obj); + n = pdf_dict_len(obj); for (i = 0; i < n; i++) { - pdf_crypt_obj_imp(ctx, crypt, fz_dict_get_val(obj, i), key, keylen); + pdf_crypt_obj_imp(ctx, crypt, pdf_dict_get_val(obj, i), key, keylen); } } } void -pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, int num, int gen) +pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen) { unsigned char key[32]; int len; diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index fd2afab2..5e54e0bb 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -5,7 +5,7 @@ #include FT_FREETYPE_H #include FT_XFREE86_H -static void pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *dict, char *collection, char *basefont); +static void pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *dict, char *collection, char *basefont); static char *base_font_names[14][7] = { @@ -268,18 +268,18 @@ pdf_load_system_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, c } static void -pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *stmref) +pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *stmref) { fz_buffer *buf; fz_context *ctx = xref->ctx; fz_try(ctx) { - buf = pdf_load_stream(xref, fz_to_num(stmref), fz_to_gen(stmref)); + buf = pdf_load_stream(xref, pdf_to_num(stmref), pdf_to_gen(stmref)); } fz_catch(ctx) { - fz_throw(ctx, "cannot load font stream (%d %d R)", fz_to_num(stmref), fz_to_gen(stmref)); + fz_throw(ctx, "cannot load font stream (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref)); } fz_try(ctx) @@ -289,7 +289,7 @@ pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *stmr fz_catch(ctx) { fz_drop_buffer(ctx, buf); - fz_throw(ctx, "cannot load embedded font (%d %d R)", fz_to_num(stmref), fz_to_gen(stmref)); + fz_throw(ctx, "cannot load embedded font (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref)); } fontdesc->size += buf->len; @@ -394,11 +394,11 @@ pdf_new_font_desc(fz_context *ctx) */ static pdf_font_desc * -pdf_load_simple_font(pdf_document *xref, fz_obj *dict) +pdf_load_simple_font(pdf_document *xref, pdf_obj *dict) { - fz_obj *descriptor; - fz_obj *encoding; - fz_obj *widths; + pdf_obj *descriptor; + pdf_obj *encoding; + pdf_obj *widths; unsigned short *etable = NULL; pdf_font_desc *fontdesc = NULL; FT_Face face; @@ -417,7 +417,7 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) fz_var(fontdesc); fz_var(etable); - basefont = fz_to_name(fz_dict_gets(dict, "BaseFont")); + basefont = pdf_to_name(pdf_dict_gets(dict, "BaseFont")); fontname = clean_font_name(basefont); /* Load font file */ @@ -425,7 +425,7 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) { fontdesc = pdf_new_font_desc(ctx); - descriptor = fz_dict_gets(dict, "FontDescriptor"); + descriptor = pdf_dict_gets(dict, "FontDescriptor"); if (descriptor) pdf_load_font_descriptor(fontdesc, xref, descriptor, NULL, basefont); else @@ -433,9 +433,9 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) /* Some chinese documents mistakenly consider WinAnsiEncoding to be codepage 936 */ if (!*fontdesc->font->name && - !fz_dict_gets(dict, "ToUnicode") && - !strcmp(fz_to_name(fz_dict_gets(dict, "Encoding")), "WinAnsiEncoding") && - fz_to_int(fz_dict_gets(descriptor, "Flags")) == 4) + !pdf_dict_gets(dict, "ToUnicode") && + !strcmp(pdf_to_name(pdf_dict_gets(dict, "Encoding")), "WinAnsiEncoding") && + pdf_to_int(pdf_dict_gets(descriptor, "Flags")) == 4) { /* note: without the comma, pdf_load_font_descriptor would prefer /FontName over /BaseFont */ char *cp936fonts[] = { @@ -514,34 +514,34 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) etable[i] = 0; } - encoding = fz_dict_gets(dict, "Encoding"); + encoding = pdf_dict_gets(dict, "Encoding"); if (encoding) { - if (fz_is_name(encoding)) - pdf_load_encoding(estrings, fz_to_name(encoding)); + if (pdf_is_name(encoding)) + pdf_load_encoding(estrings, pdf_to_name(encoding)); - if (fz_is_dict(encoding)) + if (pdf_is_dict(encoding)) { - fz_obj *base, *diff, *item; + pdf_obj *base, *diff, *item; - base = fz_dict_gets(encoding, "BaseEncoding"); - if (fz_is_name(base)) - pdf_load_encoding(estrings, fz_to_name(base)); + base = pdf_dict_gets(encoding, "BaseEncoding"); + if (pdf_is_name(base)) + pdf_load_encoding(estrings, pdf_to_name(base)); else if (!fontdesc->is_embedded && !symbolic) pdf_load_encoding(estrings, "StandardEncoding"); - diff = fz_dict_gets(encoding, "Differences"); - if (fz_is_array(diff)) + diff = pdf_dict_gets(encoding, "Differences"); + if (pdf_is_array(diff)) { - n = fz_array_len(diff); + n = pdf_array_len(diff); k = 0; for (i = 0; i < n; i++) { - 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); + item = pdf_array_get(diff, i); + if (pdf_is_int(item)) + k = pdf_to_int(item); + if (pdf_is_name(item)) + estrings[k++] = pdf_to_name(item); if (k < 0) k = 0; if (k > 255) k = 255; } @@ -654,7 +654,7 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) fontdesc->cid_to_gid_len = 256; fontdesc->cid_to_gid = etable; - pdf_load_to_unicode(xref, fontdesc, estrings, NULL, fz_dict_gets(dict, "ToUnicode")); + pdf_load_to_unicode(xref, fontdesc, estrings, NULL, pdf_dict_gets(dict, "ToUnicode")); /* RJW: "cannot load to_unicode" */ skip_encoding: @@ -663,20 +663,20 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) pdf_set_default_hmtx(ctx, fontdesc, fontdesc->missing_width); - widths = fz_dict_gets(dict, "Widths"); + widths = pdf_dict_gets(dict, "Widths"); if (widths) { int first, last; - first = fz_to_int(fz_dict_gets(dict, "FirstChar")); - last = fz_to_int(fz_dict_gets(dict, "LastChar")); + first = pdf_to_int(pdf_dict_gets(dict, "FirstChar")); + last = pdf_to_int(pdf_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(fz_array_get(widths, i)); + int wid = pdf_to_int(pdf_array_get(widths, i)); pdf_add_hmtx(ctx, fontdesc, i + first, i + first, wid); } } @@ -700,7 +700,7 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) if (fontdesc && etable != fontdesc->cid_to_gid) fz_free(ctx, etable); pdf_drop_font(ctx, fontdesc); - fz_throw(ctx, "cannot load simple font (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); + fz_throw(ctx, "cannot load simple font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return fontdesc; } @@ -710,17 +710,17 @@ pdf_load_simple_font(pdf_document *xref, fz_obj *dict) */ static pdf_font_desc * -load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_unicode) +load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_unicode) { - fz_obj *widths; - fz_obj *descriptor; + pdf_obj *widths; + pdf_obj *descriptor; pdf_font_desc *fontdesc; FT_Face face; int kind; char collection[256]; char *basefont; int i, k, fterr; - fz_obj *obj; + pdf_obj *obj; int dw; fz_context *ctx = xref->ctx; @@ -730,28 +730,28 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni { /* Get font name and CID collection */ - basefont = fz_to_name(fz_dict_gets(dict, "BaseFont")); + basefont = pdf_to_name(pdf_dict_gets(dict, "BaseFont")); { - fz_obj *cidinfo; + pdf_obj *cidinfo; char tmpstr[64]; int tmplen; - cidinfo = fz_dict_gets(dict, "CIDSystemInfo"); + cidinfo = pdf_dict_gets(dict, "CIDSystemInfo"); if (!cidinfo) fz_throw(ctx, "cid font is missing info"); - obj = fz_dict_gets(cidinfo, "Registry"); - tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(obj)); - memcpy(tmpstr, fz_to_str_buf(obj), tmplen); + obj = pdf_dict_gets(cidinfo, "Registry"); + tmplen = MIN(sizeof tmpstr - 1, pdf_to_str_len(obj)); + memcpy(tmpstr, pdf_to_str_buf(obj), tmplen); tmpstr[tmplen] = '\0'; fz_strlcpy(collection, tmpstr, sizeof collection); fz_strlcat(collection, "-", sizeof collection); - obj = fz_dict_gets(cidinfo, "Ordering"); - tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(obj)); - memcpy(tmpstr, fz_to_str_buf(obj), tmplen); + obj = pdf_dict_gets(cidinfo, "Ordering"); + tmplen = MIN(sizeof tmpstr - 1, pdf_to_str_len(obj)); + memcpy(tmpstr, pdf_to_str_buf(obj), tmplen); tmpstr[tmplen] = '\0'; fz_strlcat(collection, tmpstr, sizeof collection); } @@ -760,7 +760,7 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni fontdesc = pdf_new_font_desc(ctx); - descriptor = fz_dict_gets(dict, "FontDescriptor"); + descriptor = pdf_dict_gets(dict, "FontDescriptor"); if (!descriptor) fz_throw(ctx, "syntaxerror: missing font descriptor"); pdf_load_font_descriptor(fontdesc, xref, descriptor, collection, basefont); @@ -770,16 +770,16 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni /* Encoding */ - if (fz_is_name(encoding)) + if (pdf_is_name(encoding)) { - if (!strcmp(fz_to_name(encoding), "Identity-H")) + if (!strcmp(pdf_to_name(encoding), "Identity-H")) fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 2); - else if (!strcmp(fz_to_name(encoding), "Identity-V")) + else if (!strcmp(pdf_to_name(encoding), "Identity-V")) fontdesc->encoding = pdf_new_identity_cmap(ctx, 1, 2); else - fontdesc->encoding = pdf_load_system_cmap(ctx, fz_to_name(encoding)); + fontdesc->encoding = pdf_load_system_cmap(ctx, pdf_to_name(encoding)); } - else if (fz_is_indirect(encoding)) + else if (pdf_is_indirect(encoding)) { fontdesc->encoding = pdf_load_embedded_cmap(xref, encoding); } @@ -793,14 +793,14 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni if (kind == TRUETYPE) { - fz_obj *cidtogidmap; + pdf_obj *cidtogidmap; - cidtogidmap = fz_dict_gets(dict, "CIDToGIDMap"); - if (fz_is_indirect(cidtogidmap)) + cidtogidmap = pdf_dict_gets(dict, "CIDToGIDMap"); + if (pdf_is_indirect(cidtogidmap)) { fz_buffer *buf; - buf = pdf_load_stream(xref, fz_to_num(cidtogidmap), fz_to_gen(cidtogidmap)); + buf = pdf_load_stream(xref, pdf_to_num(cidtogidmap), pdf_to_gen(cidtogidmap)); fontdesc->cid_to_gid_len = (buf->len) / 2; fontdesc->cid_to_gid = fz_malloc_array(ctx, fontdesc->cid_to_gid_len, sizeof(unsigned short)); @@ -842,35 +842,35 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni /* Horizontal */ dw = 1000; - obj = fz_dict_gets(dict, "DW"); + obj = pdf_dict_gets(dict, "DW"); if (obj) - dw = fz_to_int(obj); + dw = pdf_to_int(obj); pdf_set_default_hmtx(ctx, fontdesc, dw); - widths = fz_dict_gets(dict, "W"); + widths = pdf_dict_gets(dict, "W"); if (widths) { int c0, c1, w, n, m; - n = fz_array_len(widths); + n = pdf_array_len(widths); for (i = 0; i < n; ) { - c0 = fz_to_int(fz_array_get(widths, i)); - obj = fz_array_get(widths, i + 1); - if (fz_is_array(obj)) + c0 = pdf_to_int(pdf_array_get(widths, i)); + obj = pdf_array_get(widths, i + 1); + if (pdf_is_array(obj)) { - m = fz_array_len(obj); + m = pdf_array_len(obj); for (k = 0; k < m; k++) { - w = fz_to_int(fz_array_get(obj, k)); + w = pdf_to_int(pdf_array_get(obj, k)); pdf_add_hmtx(ctx, fontdesc, c0 + k, c0 + k, w); } i += 2; } else { - c1 = fz_to_int(obj); - w = fz_to_int(fz_array_get(widths, i + 2)); + c1 = pdf_to_int(obj); + w = pdf_to_int(pdf_array_get(widths, i + 2)); pdf_add_hmtx(ctx, fontdesc, c0, c1, w); i += 3; } @@ -886,43 +886,43 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni int dw2y = 880; int dw2w = -1000; - obj = fz_dict_gets(dict, "DW2"); + obj = pdf_dict_gets(dict, "DW2"); if (obj) { - dw2y = fz_to_int(fz_array_get(obj, 0)); - dw2w = fz_to_int(fz_array_get(obj, 1)); + dw2y = pdf_to_int(pdf_array_get(obj, 0)); + dw2w = pdf_to_int(pdf_array_get(obj, 1)); } pdf_set_default_vmtx(ctx, fontdesc, dw2y, dw2w); - widths = fz_dict_gets(dict, "W2"); + widths = pdf_dict_gets(dict, "W2"); if (widths) { int c0, c1, w, x, y, n; - n = fz_array_len(widths); + n = pdf_array_len(widths); for (i = 0; i < n; ) { - c0 = fz_to_int(fz_array_get(widths, i)); - obj = fz_array_get(widths, i + 1); - if (fz_is_array(obj)) + c0 = pdf_to_int(pdf_array_get(widths, i)); + obj = pdf_array_get(widths, i + 1); + if (pdf_is_array(obj)) { - int m = fz_array_len(obj); + int m = pdf_array_len(obj); for (k = 0; k * 3 < m; k ++) { - 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)); + w = pdf_to_int(pdf_array_get(obj, k * 3 + 0)); + x = pdf_to_int(pdf_array_get(obj, k * 3 + 1)); + y = pdf_to_int(pdf_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(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)); + c1 = pdf_to_int(obj); + w = pdf_to_int(pdf_array_get(widths, i + 2)); + x = pdf_to_int(pdf_array_get(widths, i + 3)); + y = pdf_to_int(pdf_array_get(widths, i + 4)); pdf_add_vmtx(ctx, fontdesc, c0, c1, x, y, w); i += 5; } @@ -935,38 +935,38 @@ load_cid_font(pdf_document *xref, fz_obj *dict, fz_obj *encoding, fz_obj *to_uni fz_catch(ctx) { pdf_drop_font(ctx, fontdesc); - fz_throw(ctx, "cannot load cid font (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); + fz_throw(ctx, "cannot load cid font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return fontdesc; } static pdf_font_desc * -pdf_load_type0_font(pdf_document *xref, fz_obj *dict) +pdf_load_type0_font(pdf_document *xref, pdf_obj *dict) { - fz_obj *dfonts; - fz_obj *dfont; - fz_obj *subtype; - fz_obj *encoding; - fz_obj *to_unicode; + pdf_obj *dfonts; + pdf_obj *dfont; + pdf_obj *subtype; + pdf_obj *encoding; + pdf_obj *to_unicode; - dfonts = fz_dict_gets(dict, "DescendantFonts"); + dfonts = pdf_dict_gets(dict, "DescendantFonts"); if (!dfonts) fz_throw(xref->ctx, "cid font is missing descendant fonts"); - dfont = fz_array_get(dfonts, 0); + dfont = pdf_array_get(dfonts, 0); - subtype = fz_dict_gets(dfont, "Subtype"); - encoding = fz_dict_gets(dict, "Encoding"); - to_unicode = fz_dict_gets(dict, "ToUnicode"); + subtype = pdf_dict_gets(dfont, "Subtype"); + encoding = pdf_dict_gets(dict, "Encoding"); + to_unicode = pdf_dict_gets(dict, "ToUnicode"); - if (fz_is_name(subtype) && !strcmp(fz_to_name(subtype), "CIDFontType0")) + if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType0")) return load_cid_font(xref, dfont, encoding, to_unicode); - else if (fz_is_name(subtype) && !strcmp(fz_to_name(subtype), "CIDFontType2")) + else if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType2")) return load_cid_font(xref, dfont, encoding, to_unicode); else fz_throw(xref->ctx, "syntaxerror: unknown cid font type"); - /* RJW: "cannot load descendant font (%d %d R)", fz_to_num(dfont), fz_to_gen(dfont) */ + /* RJW: "cannot load descendant font (%d %d R)", pdf_to_num(dfont), pdf_to_gen(dfont) */ return NULL; /* Stupid MSVC */ } @@ -975,34 +975,34 @@ pdf_load_type0_font(pdf_document *xref, fz_obj *dict) */ static void -pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *dict, char *collection, char *basefont) +pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *dict, char *collection, char *basefont) { - fz_obj *obj1, *obj2, *obj3, *obj; + pdf_obj *obj1, *obj2, *obj3, *obj; char *fontname; char *origname; FT_Face face; fz_context *ctx = xref->ctx; if (!strchr(basefont, ',') || strchr(basefont, '+')) - origname = fz_to_name(fz_dict_gets(dict, "FontName")); + origname = pdf_to_name(pdf_dict_gets(dict, "FontName")); else origname = basefont; fontname = clean_font_name(origname); - 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"); + fontdesc->flags = pdf_to_int(pdf_dict_gets(dict, "Flags")); + fontdesc->italic_angle = pdf_to_real(pdf_dict_gets(dict, "ItalicAngle")); + fontdesc->ascent = pdf_to_real(pdf_dict_gets(dict, "Ascent")); + fontdesc->descent = pdf_to_real(pdf_dict_gets(dict, "Descent")); + fontdesc->cap_height = pdf_to_real(pdf_dict_gets(dict, "CapHeight")); + fontdesc->x_height = pdf_to_real(pdf_dict_gets(dict, "XHeight")); + fontdesc->missing_width = pdf_to_real(pdf_dict_gets(dict, "MissingWidth")); + + obj1 = pdf_dict_gets(dict, "FontFile"); + obj2 = pdf_dict_gets(dict, "FontFile2"); + obj3 = pdf_dict_gets(dict, "FontFile3"); obj = obj1 ? obj1 : obj2 ? obj2 : obj3; - if (fz_is_indirect(obj)) + if (pdf_is_indirect(obj)) { fz_try(ctx) { @@ -1015,7 +1015,7 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *di pdf_load_builtin_font(ctx, fontdesc, fontname); else pdf_load_system_font(ctx, fontdesc, fontname, collection); - /* RJW: "cannot load font descriptor (%d %d R)", fz_to_num(dict), fz_to_gen(dict) */ + /* RJW: "cannot load font descriptor (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */ } } else @@ -1024,7 +1024,7 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, fz_obj *di pdf_load_builtin_font(ctx, fontdesc, fontname); else pdf_load_system_font(ctx, fontdesc, fontname, collection); - /* RJW: "cannot load font descriptor (%d %d R)", fz_to_num(dict), fz_to_gen(dict) */ + /* RJW: "cannot load font descriptor (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */ } fz_strlcpy(fontdesc->font->name, fontname, sizeof fontdesc->font->name); @@ -1073,11 +1073,11 @@ pdf_make_width_table(fz_context *ctx, pdf_font_desc *fontdesc) } pdf_font_desc * -pdf_load_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict) +pdf_load_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) { char *subtype; - fz_obj *dfonts; - fz_obj *charprocs; + pdf_obj *dfonts; + pdf_obj *charprocs; fz_context *ctx = xref->ctx; pdf_font_desc *fontdesc; @@ -1086,9 +1086,9 @@ pdf_load_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict) return fontdesc; } - subtype = fz_to_name(fz_dict_gets(dict, "Subtype")); - dfonts = fz_dict_gets(dict, "DescendantFonts"); - charprocs = fz_dict_gets(dict, "CharProcs"); + subtype = pdf_to_name(pdf_dict_gets(dict, "Subtype")); + dfonts = pdf_dict_gets(dict, "DescendantFonts"); + charprocs = pdf_dict_gets(dict, "CharProcs"); if (subtype && !strcmp(subtype, "Type0")) fontdesc = pdf_load_type0_font(xref, dict); @@ -1115,7 +1115,7 @@ pdf_load_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict) fz_warn(ctx, "unknown font format, guessing type1 or truetype."); fontdesc = pdf_load_simple_font(xref, dict); } - /* RJW: "cannot load font (%d %d R)", fz_to_num(dict), fz_to_gen(dict) */ + /* RJW: "cannot load font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict) */ /* Save the widths to stretch non-CJK substitute fonts */ if (fontdesc->font->ft_substitute && !fontdesc->to_ttf_cmap) diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 17373f42..4273bbc6 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -828,7 +828,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr) } static void -load_postscript_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, int gen) +load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, int gen) { fz_stream *stream = NULL; int codeptr; @@ -900,37 +900,37 @@ eval_postscript_func(fz_context *ctx, pdf_function *func, float *in, float *out) */ static void -load_sample_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, int gen) +load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, int gen) { fz_context *ctx = xref->ctx; fz_stream *stream; - fz_obj *obj; + pdf_obj *obj; int samplecount; int bps; int i; func->u.sa.samples = NULL; - obj = fz_dict_gets(dict, "Size"); - if (!fz_is_array(obj) || fz_array_len(obj) != func->m) + obj = pdf_dict_gets(dict, "Size"); + if (!pdf_is_array(obj) || pdf_array_len(obj) != func->m) fz_throw(ctx, "malformed /Size"); for (i = 0; i < func->m; i++) - func->u.sa.size[i] = fz_to_int(fz_array_get(obj, i)); + func->u.sa.size[i] = pdf_to_int(pdf_array_get(obj, i)); - obj = fz_dict_gets(dict, "BitsPerSample"); - if (!fz_is_int(obj)) + obj = pdf_dict_gets(dict, "BitsPerSample"); + if (!pdf_is_int(obj)) fz_throw(ctx, "malformed /BitsPerSample"); - func->u.sa.bps = bps = fz_to_int(obj); + func->u.sa.bps = bps = pdf_to_int(obj); - obj = fz_dict_gets(dict, "Encode"); - if (fz_is_array(obj)) + obj = pdf_dict_gets(dict, "Encode"); + if (pdf_is_array(obj)) { - if (fz_array_len(obj) != func->m * 2) + if (pdf_array_len(obj) != func->m * 2) fz_throw(ctx, "malformed /Encode"); for (i = 0; i < func->m; i++) { - 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)); + func->u.sa.encode[i][0] = pdf_to_real(pdf_array_get(obj, i*2+0)); + func->u.sa.encode[i][1] = pdf_to_real(pdf_array_get(obj, i*2+1)); } } else @@ -942,15 +942,15 @@ load_sample_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, } } - obj = fz_dict_gets(dict, "Decode"); - if (fz_is_array(obj)) + obj = pdf_dict_gets(dict, "Decode"); + if (pdf_is_array(obj)) { - if (fz_array_len(obj) != func->n * 2) + if (pdf_array_len(obj) != func->n * 2) fz_throw(ctx, "malformed /Decode"); for (i = 0; i < func->n; i++) { - 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)); + func->u.sa.decode[i][0] = pdf_to_real(pdf_array_get(obj, i*2+0)); + func->u.sa.decode[i][1] = pdf_to_real(pdf_array_get(obj, i*2+1)); } } else @@ -1111,27 +1111,27 @@ eval_sample_func(fz_context *ctx, pdf_function *func, float *in, float *out) */ static void -load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict) +load_exponential_func(fz_context *ctx, pdf_function *func, pdf_obj *dict) { - fz_obj *obj; + pdf_obj *obj; int i; if (func->m != 1) fz_throw(ctx, "/Domain must be one dimension (%d)", func->m); - obj = fz_dict_gets(dict, "N"); - if (!fz_is_int(obj) && !fz_is_real(obj)) + obj = pdf_dict_gets(dict, "N"); + if (!pdf_is_int(obj) && !pdf_is_real(obj)) fz_throw(ctx, "malformed /N"); - func->u.e.n = fz_to_real(obj); + func->u.e.n = pdf_to_real(obj); - obj = fz_dict_gets(dict, "C0"); - if (fz_is_array(obj)) + obj = pdf_dict_gets(dict, "C0"); + if (pdf_is_array(obj)) { - func->n = fz_array_len(obj); + func->n = pdf_array_len(obj); if (func->n >= MAXN) fz_throw(ctx, "exponential function result array out of range"); for (i = 0; i < func->n; i++) - func->u.e.c0[i] = fz_to_real(fz_array_get(obj, i)); + func->u.e.c0[i] = pdf_to_real(pdf_array_get(obj, i)); } else { @@ -1139,13 +1139,13 @@ load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict) func->u.e.c0[0] = 0; } - obj = fz_dict_gets(dict, "C1"); - if (fz_is_array(obj)) + obj = pdf_dict_gets(dict, "C1"); + if (pdf_is_array(obj)) { - if (fz_array_len(obj) != func->n) + if (pdf_array_len(obj) != func->n) fz_throw(ctx, "/C1 must match /C0 length"); for (i = 0; i < func->n; i++) - func->u.e.c1[i] = fz_to_real(fz_array_get(obj, i)); + func->u.e.c1[i] = pdf_to_real(pdf_array_get(obj, i)); } else { @@ -1185,13 +1185,13 @@ eval_exponential_func(fz_context *ctx, pdf_function *func, float in, float *out) */ static void -load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict) +load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) { fz_context *ctx = xref->ctx; pdf_function **funcs; - fz_obj *obj; - fz_obj *sub; - fz_obj *num; + pdf_obj *obj; + pdf_obj *sub; + pdf_obj *num; int k; int i; @@ -1200,11 +1200,11 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict) if (func->m != 1) fz_throw(ctx, "/Domain must be one dimension (%d)", func->m); - obj = fz_dict_gets(dict, "Functions"); - if (!fz_is_array(obj)) + obj = pdf_dict_gets(dict, "Functions"); + if (!pdf_is_array(obj)) fz_throw(ctx, "stitching function has no input functions"); { - k = fz_array_len(obj); + k = pdf_array_len(obj); func->u.st.funcs = fz_malloc_array(ctx, k, sizeof(pdf_function*)); func->u.st.bounds = fz_malloc_array(ctx, k - 1, sizeof(float)); @@ -1213,9 +1213,9 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict) for (i = 0; i < k; i++) { - sub = fz_array_get(obj, i); + sub = pdf_array_get(obj, i); funcs[i] = pdf_load_function(xref, sub); - /* RJW: "cannot load sub function %d (%d %d R)", i, fz_to_num(sub), fz_to_gen(sub) */ + /* RJW: "cannot load sub function %d (%d %d R)", i, pdf_to_num(sub), pdf_to_gen(sub) */ if (funcs[i]->m != 1 || funcs[i]->n != funcs[0]->n) fz_throw(ctx, "sub function %d /Domain or /Range mismatch", i); func->size += pdf_function_size(funcs[i]); @@ -1228,19 +1228,19 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict) fz_throw(ctx, "sub function /Domain or /Range mismatch"); } - obj = fz_dict_gets(dict, "Bounds"); - if (!fz_is_array(obj)) + obj = pdf_dict_gets(dict, "Bounds"); + if (!pdf_is_array(obj)) fz_throw(ctx, "stitching function has no bounds"); { - if (fz_array_len(obj) != k - 1) + if (pdf_array_len(obj) != k - 1) fz_throw(ctx, "malformed /Bounds (wrong length)"); for (i = 0; i < k-1; i++) { - num = fz_array_get(obj, i); - if (!fz_is_int(num) && !fz_is_real(num)) + num = pdf_array_get(obj, i); + if (!pdf_is_int(num) && !pdf_is_real(num)) fz_throw(ctx, "malformed /Bounds (item not real)"); - func->u.st.bounds[i] = fz_to_real(num); + func->u.st.bounds[i] = pdf_to_real(num); if (i && func->u.st.bounds[i-1] > func->u.st.bounds[i]) fz_throw(ctx, "malformed /Bounds (item not monotonic)"); } @@ -1250,16 +1250,16 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict) fz_warn(ctx, "malformed shading function bounds (domain mismatch), proceeding anyway."); } - obj = fz_dict_gets(dict, "Encode"); - if (!fz_is_array(obj)) + obj = pdf_dict_gets(dict, "Encode"); + if (!pdf_is_array(obj)) fz_throw(ctx, "stitching function is missing encoding"); { - if (fz_array_len(obj) != k * 2) + if (pdf_array_len(obj) != k * 2) fz_throw(ctx, "malformed /Encode"); for (i = 0; i < k; i++) { - 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)); + func->u.st.encode[i*2+0] = pdf_to_real(pdf_array_get(obj, i*2+0)); + func->u.st.encode[i*2+1] = pdf_to_real(pdf_array_get(obj, i*2+1)); } } } @@ -1356,11 +1356,11 @@ pdf_function_size(pdf_function *func) } pdf_function * -pdf_load_function(pdf_document *xref, fz_obj *dict) +pdf_load_function(pdf_document *xref, pdf_obj *dict) { fz_context *ctx = xref->ctx; pdf_function *func; - fz_obj *obj; + pdf_obj *obj; int i; if ((func = pdf_find_item(ctx, pdf_free_function_imp, dict))) @@ -1372,28 +1372,28 @@ pdf_load_function(pdf_document *xref, fz_obj *dict) FZ_INIT_STORABLE(func, 1, pdf_free_function_imp); func->size = sizeof(*func); - obj = fz_dict_gets(dict, "FunctionType"); - func->type = fz_to_int(obj); + obj = pdf_dict_gets(dict, "FunctionType"); + func->type = pdf_to_int(obj); /* required for all */ - obj = fz_dict_gets(dict, "Domain"); - func->m = fz_array_len(obj) / 2; + obj = pdf_dict_gets(dict, "Domain"); + func->m = pdf_array_len(obj) / 2; for (i = 0; i < func->m; i++) { - 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)); + func->domain[i][0] = pdf_to_real(pdf_array_get(obj, i * 2 + 0)); + func->domain[i][1] = pdf_to_real(pdf_array_get(obj, i * 2 + 1)); } /* required for type0 and type4, optional otherwise */ - obj = fz_dict_gets(dict, "Range"); - if (fz_is_array(obj)) + obj = pdf_dict_gets(dict, "Range"); + if (pdf_is_array(obj)) { func->has_range = 1; - func->n = fz_array_len(obj) / 2; + func->n = pdf_array_len(obj) / 2; for (i = 0; i < func->n; i++) { - 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)); + func->range[i][0] = pdf_to_real(pdf_array_get(obj, i * 2 + 0)); + func->range[i][1] = pdf_to_real(pdf_array_get(obj, i * 2 + 1)); } } else @@ -1413,7 +1413,7 @@ pdf_load_function(pdf_document *xref, fz_obj *dict) switch(func->type) { case SAMPLE: - load_sample_func(func, xref, dict, fz_to_num(dict), fz_to_gen(dict)); + load_sample_func(func, xref, dict, pdf_to_num(dict), pdf_to_gen(dict)); break; case EXPONENTIAL: @@ -1425,12 +1425,12 @@ pdf_load_function(pdf_document *xref, fz_obj *dict) break; case POSTSCRIPT: - load_postscript_func(func, xref, dict, fz_to_num(dict), fz_to_gen(dict)); + load_postscript_func(func, xref, dict, pdf_to_num(dict), pdf_to_gen(dict)); break; default: fz_free(ctx, func); - fz_throw(ctx, "unknown function type (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); + fz_throw(ctx, "unknown function type (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } pdf_store_item(ctx, dict, func, func->size); @@ -1445,7 +1445,7 @@ pdf_load_function(pdf_document *xref, fz_obj *dict) type == STITCHING ? "stitching" : type == POSTSCRIPT ? "calculator" : "unknown", - fz_to_num(dict), fz_to_gen(dict)); + pdf_to_num(dict), pdf_to_gen(dict)); } return func; diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 22cca81d..cd2726a5 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -9,7 +9,7 @@ struct pdf_image_key_s { int factor; }; -static void pdf_load_jpx(pdf_document *xref, fz_obj *dict, pdf_image *image); +static void pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image); static void pdf_mask_color_key(fz_pixmap *pix, int n, int *colorkey) @@ -77,12 +77,21 @@ pdf_cmp_image_key(void *k0_, void *k1_) return k0->image == k1->image && k0->factor == k1->factor; } +static void +pdf_debug_image(void *key_) +{ + pdf_image_key *key = (pdf_image_key *)key_; + + printf("(image %d x %d sf=%d) ", key->image->w, key->image->h, key->factor); +} + static fz_store_type pdf_image_store_type = { pdf_make_hash_image_key, pdf_keep_image_key, pdf_drop_image_key, - pdf_cmp_image_key + pdf_cmp_image_key, + pdf_debug_image }; static fz_pixmap * @@ -281,11 +290,11 @@ pdf_image_get_pixmap(fz_context *ctx, fz_image *image_, int w, int h) } static pdf_image * -pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cstm, int forcemask) +pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *cstm, int forcemask) { fz_stream *stm = NULL; pdf_image *image = NULL; - fz_obj *obj, *res; + pdf_obj *obj, *res; int w, h, bpc, n; int imagemask; @@ -321,11 +330,11 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst break; /* Out of fz_try */ } - 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")); + w = pdf_to_int(pdf_dict_getsa(dict, "Width", "W")); + h = pdf_to_int(pdf_dict_getsa(dict, "Height", "H")); + bpc = pdf_to_int(pdf_dict_getsa(dict, "BitsPerComponent", "BPC")); + imagemask = pdf_to_bool(pdf_dict_getsa(dict, "ImageMask", "IM")); + interpolate = pdf_to_bool(pdf_dict_getsa(dict, "Interpolate", "I")); indexed = 0; usecolorkey = 0; @@ -347,13 +356,13 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst if (h > (1 << 16)) fz_throw(ctx, "image is too high"); - obj = fz_dict_getsa(dict, "ColorSpace", "CS"); + obj = pdf_dict_getsa(dict, "ColorSpace", "CS"); if (obj && !imagemask && !forcemask) { /* colorspace resource lookup is only done for inline images */ - if (fz_is_name(obj)) + if (pdf_is_name(obj)) { - res = fz_dict_get(fz_dict_gets(rdb, "ColorSpace"), obj); + res = pdf_dict_get(pdf_dict_gets(rdb, "ColorSpace"), obj); if (res) obj = res; } @@ -371,11 +380,11 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst n = 1; } - obj = fz_dict_getsa(dict, "Decode", "D"); + obj = pdf_dict_getsa(dict, "Decode", "D"); if (obj) { for (i = 0; i < n * 2; i++) - image->decode[i] = fz_to_real(fz_array_get(obj, i)); + image->decode[i] = pdf_to_real(pdf_array_get(obj, i)); } else { @@ -384,8 +393,8 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst image->decode[i] = i & 1 ? maxval : 0; } - obj = fz_dict_getsa(dict, "SMask", "Mask"); - if (fz_is_dict(obj)) + obj = pdf_dict_getsa(dict, "SMask", "Mask"); + if (pdf_is_dict(obj)) { /* Not allowed for inline images */ if (!cstm) @@ -394,17 +403,17 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst /* RJW: "cannot load image mask/softmask" */ } } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { usecolorkey = 1; for (i = 0; i < n * 2; i++) { - if (!fz_is_int(fz_array_get(obj, i))) + if (!pdf_is_int(pdf_array_get(obj, i))) { fz_warn(ctx, "invalid value in color key mask"); usecolorkey = 0; } - image->colorkey[i] = fz_to_int(fz_array_get(obj, i)); + image->colorkey[i] = pdf_to_int(pdf_array_get(obj, i)); } } @@ -425,7 +434,7 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst { /* Just load the compressed image data now and we can * decode it on demand. */ - image->buffer = pdf_load_image_stream(xref, fz_to_num(dict), fz_to_gen(dict), &image->params); + image->buffer = pdf_load_image_stream(xref, pdf_to_num(dict), pdf_to_gen(dict), &image->params); break; /* Out of fz_try */ } @@ -437,8 +446,8 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst } else { - stm = pdf_open_stream(xref, fz_to_num(dict), fz_to_gen(dict)); - /* RJW: "cannot open image data stream (%d 0 R)", fz_to_num(dict) */ + stm = pdf_open_stream(xref, pdf_to_num(dict), pdf_to_gen(dict)); + /* RJW: "cannot open image data stream (%d 0 R)", pdf_to_num(dict) */ } image->tile = decomp_image_from_stream(ctx, stm, image, cstm != NULL, indexed, 1); @@ -452,35 +461,35 @@ pdf_load_image_imp(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cst } fz_image * -pdf_load_inline_image(pdf_document *xref, fz_obj *rdb, fz_obj *dict, fz_stream *file) +pdf_load_inline_image(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *file) { return (fz_image *)pdf_load_image_imp(xref, rdb, dict, file, 0); /* RJW: "cannot load inline image" */ } int -pdf_is_jpx_image(fz_context *ctx, fz_obj *dict) +pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict) { - fz_obj *filter; + pdf_obj *filter; int i, n; - filter = fz_dict_gets(dict, "Filter"); - if (!strcmp(fz_to_name(filter), "JPXDecode")) + filter = pdf_dict_gets(dict, "Filter"); + if (!strcmp(pdf_to_name(filter), "JPXDecode")) return 1; - n = fz_array_len(filter); + n = pdf_array_len(filter); for (i = 0; i < n; i++) - if (!strcmp(fz_to_name(fz_array_get(filter, i)), "JPXDecode")) + if (!strcmp(pdf_to_name(pdf_array_get(filter, i)), "JPXDecode")) return 1; return 0; } static void -pdf_load_jpx(pdf_document *xref, fz_obj *dict, pdf_image *image) +pdf_load_jpx(pdf_document *xref, pdf_obj *dict, pdf_image *image) { fz_buffer *buf = NULL; fz_colorspace *colorspace = NULL; fz_pixmap *img = NULL; - fz_obj *obj; + pdf_obj *obj; fz_context *ctx = xref->ctx; int indexed = 0; @@ -488,13 +497,13 @@ pdf_load_jpx(pdf_document *xref, fz_obj *dict, pdf_image *image) fz_var(buf); fz_var(colorspace); - buf = pdf_load_stream(xref, fz_to_num(dict), fz_to_gen(dict)); + buf = pdf_load_stream(xref, pdf_to_num(dict), pdf_to_gen(dict)); /* RJW: "cannot load jpx image data" */ /* FIXME: We can't handle decode arrays for indexed images currently */ fz_try(ctx) { - obj = fz_dict_gets(dict, "ColorSpace"); + obj = pdf_dict_gets(dict, "ColorSpace"); if (obj) { colorspace = pdf_load_colorspace(xref, obj); @@ -511,21 +520,21 @@ pdf_load_jpx(pdf_document *xref, fz_obj *dict, pdf_image *image) fz_drop_buffer(ctx, buf); buf = NULL; - obj = fz_dict_getsa(dict, "SMask", "Mask"); - if (fz_is_dict(obj)) + obj = pdf_dict_getsa(dict, "SMask", "Mask"); + if (pdf_is_dict(obj)) { image->base.mask = (fz_image *)pdf_load_image_imp(xref, NULL, obj, NULL, 1); /* RJW: "cannot load image mask/softmask" */ } - obj = fz_dict_getsa(dict, "Decode", "D"); + obj = pdf_dict_getsa(dict, "Decode", "D"); if (obj && !indexed) { float decode[FZ_MAX_COLORS * 2]; int i; for (i = 0; i < img->n * 2; i++) - decode[i] = fz_to_real(fz_array_get(obj, i)); + decode[i] = pdf_to_real(pdf_array_get(obj, i)); fz_decode_tile(img, decode); } @@ -562,7 +571,7 @@ pdf_image_size(fz_context *ctx, pdf_image *im) } fz_image * -pdf_load_image(pdf_document *xref, fz_obj *dict) +pdf_load_image(pdf_document *xref, pdf_obj *dict) { fz_context *ctx = xref->ctx; pdf_image *image; @@ -573,7 +582,7 @@ pdf_load_image(pdf_document *xref, fz_obj *dict) } image = pdf_load_image_imp(xref, NULL, dict, NULL, 0); - /* RJW: "cannot load image (%d 0 R)", fz_to_num(dict) */ + /* RJW: "cannot load image (%d 0 R)", pdf_to_num(dict) */ pdf_store_item(ctx, dict, image, pdf_image_size(ctx, image)); diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 1cfe6a96..d2270eaa 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -70,7 +70,7 @@ struct pdf_csi_s char *event; /* "View", "Print", "Export" */ /* interpreter stack */ - fz_obj *obj; + pdf_obj *obj; char name[256]; unsigned char string[256]; int string_len; @@ -104,8 +104,8 @@ struct pdf_csi_s fz_cookie *cookie; }; -static void pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents); -static void pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix transform); +static void pdf_run_buffer(pdf_csi *csi, pdf_obj *rdb, fz_buffer *contents); +static void pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, fz_matrix transform); static void pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what); static int @@ -120,20 +120,20 @@ ocg_intents_include(pdf_ocg_descriptor *desc, char *name) if (!desc->intent) return (strcmp(name, "View") == 0); - if (fz_is_name(desc->intent)) + if (pdf_is_name(desc->intent)) { - char *intent = fz_to_name(desc->intent); + char *intent = pdf_to_name(desc->intent); if (strcmp(intent, "All") == 0) return 1; return (strcmp(intent, name) == 0); } - if (!fz_is_array(desc->intent)) + if (!pdf_is_array(desc->intent)) return 0; - len = fz_array_len(desc->intent); + len = pdf_array_len(desc->intent); for (i=0; i < len; i++) { - char *intent = fz_to_name(fz_array_get(desc->intent, i)); + char *intent = pdf_to_name(pdf_array_get(desc->intent, i)); if (strcmp(intent, "All") == 0) return 1; if (strcmp(intent, name) == 0) @@ -143,10 +143,10 @@ ocg_intents_include(pdf_ocg_descriptor *desc, char *name) } static int -pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) +pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) { char event_state[16]; - fz_obj *obj, *obj2; + pdf_obj *obj, *obj2; char *type; pdf_ocg_descriptor *desc = csi->xref->ocg; @@ -155,9 +155,9 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) return 0; /* If we've been handed a name, look it up in the properties. */ - if (fz_is_name(ocg)) + if (pdf_is_name(ocg)) { - ocg = fz_dict_gets(fz_dict_gets(rdb, "Properties"), fz_to_name(ocg)); + ocg = pdf_dict_gets(pdf_dict_gets(rdb, "Properties"), pdf_to_name(ocg)); } /* If we haven't been given an ocg at all, then we're visible */ if (!ocg) @@ -166,13 +166,13 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) fz_strlcpy(event_state, csi->event, sizeof event_state); fz_strlcat(event_state, "State", sizeof event_state); - type = fz_to_name(fz_dict_gets(ocg, "Type")); + type = pdf_to_name(pdf_dict_gets(ocg, "Type")); if (strcmp(type, "OCG") == 0) { /* An Optional Content Group */ - int num = fz_to_num(ocg); - int gen = fz_to_gen(ocg); + int num = pdf_to_num(ocg); + int gen = pdf_to_gen(ocg); int len = desc->len; int i; @@ -188,19 +188,19 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) /* Check Intents; if our intent is not part of the set given * by the current config, we should ignore it. */ - obj = fz_dict_gets(ocg, "Intent"); - if (fz_is_name(obj)) + obj = pdf_dict_gets(ocg, "Intent"); + if (pdf_is_name(obj)) { /* If it doesn't match, it's hidden */ - if (ocg_intents_include(desc, fz_to_name(obj)) == 0) + if (ocg_intents_include(desc, pdf_to_name(obj)) == 0) return 1; } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { int match = 0; - len = fz_array_len(obj); + len = pdf_array_len(obj); for (i=0; i