diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/pdf_annot.c | 61 | ||||
-rw-r--r-- | pdf/pdf_cmap_load.c | 14 | ||||
-rw-r--r-- | pdf/pdf_colorspace.c | 88 | ||||
-rw-r--r-- | pdf/pdf_crypt.c | 153 | ||||
-rw-r--r-- | pdf/pdf_font.c | 177 | ||||
-rw-r--r-- | pdf/pdf_function.c | 109 | ||||
-rw-r--r-- | pdf/pdf_image.c | 42 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 157 | ||||
-rw-r--r-- | pdf/pdf_nametree.c | 76 | ||||
-rw-r--r-- | pdf/pdf_outline.c | 25 | ||||
-rw-r--r-- | pdf/pdf_page.c | 118 | ||||
-rw-r--r-- | pdf/pdf_parse.c | 132 | ||||
-rw-r--r-- | pdf/pdf_pattern.c | 14 | ||||
-rw-r--r-- | pdf/pdf_repair.c | 87 | ||||
-rw-r--r-- | pdf/pdf_shade.c | 133 | ||||
-rw-r--r-- | pdf/pdf_store.c | 10 | ||||
-rw-r--r-- | pdf/pdf_stream.c | 75 | ||||
-rw-r--r-- | pdf/pdf_type3.c | 56 | ||||
-rw-r--r-- | pdf/pdf_xobject.c | 20 | ||||
-rw-r--r-- | pdf/pdf_xref.c | 109 |
20 files changed, 820 insertions, 836 deletions
diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index cc057d6f..aa640610 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -10,7 +10,7 @@ pdf_free_link(fz_context *ctx, pdf_link *link) { next = link->next; if (link->dest) - fz_drop_obj(ctx, link->dest); + fz_drop_obj(link->dest); fz_free(ctx, link); link = next; } @@ -20,20 +20,20 @@ pdf_free_link(fz_context *ctx, pdf_link *link) static fz_obj * resolve_dest(pdf_xref *xref, fz_obj *dest) { - if (fz_is_name(xref->ctx, dest) || fz_is_string(xref->ctx, dest)) + if (fz_is_name(dest) || fz_is_string(dest)) { dest = pdf_lookup_dest(xref, dest); return resolve_dest(xref, dest); } - else if (fz_is_array(xref->ctx, dest)) + else if (fz_is_array(dest)) { return dest; } - else if (fz_is_dict(xref->ctx, dest)) + else if (fz_is_dict(dest)) { - dest = fz_dict_gets(xref->ctx, dest, "D"); + dest = fz_dict_gets(dest, "D"); return resolve_dest(xref, dest); } @@ -55,49 +55,49 @@ pdf_load_link(pdf_xref *xref, fz_obj *dict) dest = NULL; - obj = fz_dict_gets(ctx, dict, "Rect"); + obj = fz_dict_gets(dict, "Rect"); if (obj) bbox = pdf_to_rect(ctx, obj); else bbox = fz_empty_rect; - obj = fz_dict_gets(ctx, dict, "Dest"); + obj = fz_dict_gets(dict, "Dest"); if (obj) { kind = PDF_LINK_GOTO; dest = resolve_dest(xref, obj); } - action = fz_dict_gets(ctx, dict, "A"); + action = fz_dict_gets(dict, "A"); /* fall back to additional action button's down/up action */ if (!action) - action = fz_dict_getsa(ctx, fz_dict_gets(ctx, dict, "AA"), "U", "D"); + action = fz_dict_getsa(fz_dict_gets(dict, "AA"), "U", "D"); if (action) { - obj = fz_dict_gets(ctx, action, "S"); - if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "GoTo")) + obj = fz_dict_gets(action, "S"); + if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "GoTo")) { kind = PDF_LINK_GOTO; - dest = resolve_dest(xref, fz_dict_gets(ctx, action, "D")); + dest = resolve_dest(xref, fz_dict_gets(action, "D")); } - else if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "URI")) + else if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "URI")) { kind = PDF_LINK_URI; - dest = fz_dict_gets(ctx, action, "URI"); + dest = fz_dict_gets(action, "URI"); } - else if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Launch")) + else if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Launch")) { kind = PDF_LINK_LAUNCH; - dest = fz_dict_gets(ctx, action, "F"); + dest = fz_dict_gets(action, "F"); } - else if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Named")) + else if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Named")) { kind = PDF_LINK_NAMED; - dest = fz_dict_gets(ctx, action, "N"); + dest = fz_dict_gets(action, "N"); } - else if (fz_is_name(ctx, obj) && (!strcmp(fz_to_name(ctx, obj), "GoToR"))) + else if (fz_is_name(obj) && (!strcmp(fz_to_name(obj), "GoToR"))) { kind = PDF_LINK_ACTION; dest = action; @@ -127,15 +127,14 @@ pdf_load_links(pdf_link **linkp, pdf_xref *xref, fz_obj *annots) pdf_link *link, *head, *tail; fz_obj *obj; int i, n; - fz_context *ctx = xref->ctx; head = tail = NULL; link = NULL; - n = fz_array_len(ctx, annots); + n = fz_array_len(annots); for (i = 0; i < n; i++) { - obj = fz_array_get(ctx, annots, i); + obj = fz_array_get(annots, i); link = pdf_load_link(xref, obj); if (link) { @@ -163,7 +162,7 @@ pdf_free_annot(fz_context *ctx, pdf_annot *annot) if (annot->ap) pdf_drop_xobject(ctx, annot->ap); if (annot->obj) - fz_drop_obj(ctx, annot->obj); + fz_drop_obj(annot->obj); fz_free(ctx, annot); annot = next; } @@ -200,21 +199,21 @@ pdf_load_annots(pdf_annot **annotp, pdf_xref *xref, fz_obj *annots) head = tail = NULL; annot = NULL; - len = fz_array_len(ctx, annots); + len = fz_array_len(annots); for (i = 0; i < len; i++) { - obj = fz_array_get(ctx, annots, i); + obj = fz_array_get(annots, i); - rect = fz_dict_gets(ctx, obj, "Rect"); - ap = fz_dict_gets(ctx, obj, "AP"); - as = fz_dict_gets(ctx, obj, "AS"); - if (fz_is_dict(ctx, ap)) + rect = fz_dict_gets(obj, "Rect"); + ap = fz_dict_gets(obj, "AP"); + as = fz_dict_gets(obj, "AS"); + if (fz_is_dict(ap)) { - n = fz_dict_gets(ctx, ap, "N"); /* normal state */ + n = fz_dict_gets(ap, "N"); /* normal state */ /* lookup current state in sub-dictionary */ if (!pdf_is_stream(xref, fz_to_num(n), fz_to_gen(n))) - n = fz_dict_get(ctx, n, as); + n = fz_dict_get(n, as); if (pdf_is_stream(xref, fz_to_num(n), fz_to_gen(n))) { diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c index b9c2a5f4..4329ad19 100644 --- a/pdf/pdf_cmap_load.c +++ b/pdf/pdf_cmap_load.c @@ -37,17 +37,17 @@ pdf_load_embedded_cmap(pdf_cmap **cmapp, pdf_xref *xref, fz_obj *stmobj) fz_close(file); - wmode = fz_dict_gets(ctx, stmobj, "WMode"); - if (fz_is_int(ctx, wmode)) - pdf_set_wmode(cmap, fz_to_int(ctx, wmode)); + wmode = fz_dict_gets(stmobj, "WMode"); + if (fz_is_int(wmode)) + pdf_set_wmode(cmap, fz_to_int(wmode)); - obj = fz_dict_gets(ctx, stmobj, "UseCMap"); - if (fz_is_name(ctx, obj)) + obj = fz_dict_gets(stmobj, "UseCMap"); + if (fz_is_name(obj)) { - error = pdf_load_system_cmap(ctx, &usecmap, fz_to_name(ctx, obj)); + error = pdf_load_system_cmap(ctx, &usecmap, fz_to_name(obj)); if (error) { - error = fz_error_note(error, "cannot load system usecmap '%s'", fz_to_name(ctx, obj)); + error = fz_error_note(error, "cannot load system usecmap '%s'", fz_to_name(obj)); goto cleanup; } pdf_set_usecmap(ctx, cmap, usecmap); diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index a83cde09..56a54e5c 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -8,7 +8,7 @@ load_icc_based(fz_colorspace **csp, pdf_xref *xref, fz_obj *dict) { int n; - n = fz_to_int(xref->ctx, fz_dict_gets(xref->ctx, dict, "N")); + n = fz_to_int(fz_dict_gets(dict, "N")); switch (n) { @@ -96,15 +96,15 @@ load_separation(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) fz_colorspace *cs; struct separation *sep; fz_context *ctx = xref->ctx; - fz_obj *nameobj = fz_array_get(ctx, array, 1); - fz_obj *baseobj = fz_array_get(ctx, array, 2); - fz_obj *tintobj = fz_array_get(ctx, array, 3); + fz_obj *nameobj = fz_array_get(array, 1); + fz_obj *baseobj = fz_array_get(array, 2); + fz_obj *tintobj = fz_array_get(array, 3); fz_colorspace *base; pdf_function *tint; int n; - if (fz_is_array(ctx, nameobj)) - n = fz_array_len(ctx, nameobj); + if (fz_is_array(nameobj)) + n = fz_array_len(nameobj); else n = 1; @@ -215,9 +215,9 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) fz_colorspace *cs; struct indexed *idx; fz_context *ctx = xref->ctx; - fz_obj *baseobj = fz_array_get(ctx, array, 1); - fz_obj *highobj = fz_array_get(ctx, array, 2); - fz_obj *lookup = fz_array_get(ctx, array, 3); + fz_obj *baseobj = fz_array_get(array, 1); + fz_obj *highobj = fz_array_get(array, 2); + fz_obj *lookup = fz_array_get(array, 3); fz_colorspace *base; int i, n; @@ -227,7 +227,7 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) idx = fz_malloc(ctx, sizeof(struct indexed)); idx->base = base; - idx->high = fz_to_int(ctx, highobj); + idx->high = fz_to_int(highobj); idx->high = CLAMP(idx->high, 0, 255); n = base->n * (idx->high + 1); idx->lookup = fz_calloc(ctx, 1, n); @@ -237,9 +237,9 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) cs->free_data = free_indexed; cs->data = idx; - if (fz_is_string(ctx, lookup) && fz_to_str_len(ctx, lookup) == n) + if (fz_is_string(lookup) && fz_to_str_len(lookup) == n) { - unsigned char *buf = (unsigned char *) fz_to_str_buf(ctx, lookup); + unsigned char *buf = (unsigned char *) fz_to_str_buf(lookup); for (i = 0; i < n; i++) idx->lookup[i] = buf[i]; } @@ -278,41 +278,39 @@ load_indexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array) static fz_error pdf_load_colorspace_imp(fz_colorspace **csp, pdf_xref *xref, fz_obj *obj) { - fz_context *ctx = xref->ctx; - - if (fz_is_name(ctx, obj)) + if (fz_is_name(obj)) { - if (!strcmp(fz_to_name(ctx, obj), "Pattern")) + if (!strcmp(fz_to_name(obj), "Pattern")) *csp = fz_device_gray; - else if (!strcmp(fz_to_name(ctx, obj), "G")) + else if (!strcmp(fz_to_name(obj), "G")) *csp = fz_device_gray; - else if (!strcmp(fz_to_name(ctx, obj), "RGB")) + else if (!strcmp(fz_to_name(obj), "RGB")) *csp = fz_device_rgb; - else if (!strcmp(fz_to_name(ctx, obj), "CMYK")) + else if (!strcmp(fz_to_name(obj), "CMYK")) *csp = fz_device_cmyk; - else if (!strcmp(fz_to_name(ctx, obj), "DeviceGray")) + else if (!strcmp(fz_to_name(obj), "DeviceGray")) *csp = fz_device_gray; - else if (!strcmp(fz_to_name(ctx, obj), "DeviceRGB")) + else if (!strcmp(fz_to_name(obj), "DeviceRGB")) *csp = fz_device_rgb; - else if (!strcmp(fz_to_name(ctx, obj), "DeviceCMYK")) + else if (!strcmp(fz_to_name(obj), "DeviceCMYK")) *csp = fz_device_cmyk; else - return fz_error_make("unknown colorspace: %s", fz_to_name(ctx, obj)); + return fz_error_make("unknown colorspace: %s", fz_to_name(obj)); return fz_okay; } - else if (fz_is_array(ctx, obj)) + else if (fz_is_array(obj)) { - fz_obj *name = fz_array_get(ctx, obj, 0); + fz_obj *name = fz_array_get(obj, 0); - if (fz_is_name(ctx, name)) + if (fz_is_name(name)) { /* load base colorspace instead */ - if (!strcmp(fz_to_name(ctx, name), "Pattern")) + if (!strcmp(fz_to_name(name), "Pattern")) { fz_error error; - obj = fz_array_get(ctx, obj, 1); + obj = fz_array_get(obj, 1); if (!obj) { *csp = fz_device_gray; @@ -324,43 +322,43 @@ pdf_load_colorspace_imp(fz_colorspace **csp, pdf_xref *xref, fz_obj *obj) return fz_error_note(error, "cannot load pattern (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); } - else if (!strcmp(fz_to_name(ctx, name), "G")) + else if (!strcmp(fz_to_name(name), "G")) *csp = fz_device_gray; - else if (!strcmp(fz_to_name(ctx, name), "RGB")) + else if (!strcmp(fz_to_name(name), "RGB")) *csp = fz_device_rgb; - else if (!strcmp(fz_to_name(ctx, name), "CMYK")) + else if (!strcmp(fz_to_name(name), "CMYK")) *csp = fz_device_cmyk; - else if (!strcmp(fz_to_name(ctx, name), "DeviceGray")) + else if (!strcmp(fz_to_name(name), "DeviceGray")) *csp = fz_device_gray; - else if (!strcmp(fz_to_name(ctx, name), "DeviceRGB")) + else if (!strcmp(fz_to_name(name), "DeviceRGB")) *csp = fz_device_rgb; - else if (!strcmp(fz_to_name(ctx, name), "DeviceCMYK")) + else if (!strcmp(fz_to_name(name), "DeviceCMYK")) *csp = fz_device_cmyk; - else if (!strcmp(fz_to_name(ctx, name), "CalGray")) + else if (!strcmp(fz_to_name(name), "CalGray")) *csp = fz_device_gray; - else if (!strcmp(fz_to_name(ctx, name), "CalRGB")) + else if (!strcmp(fz_to_name(name), "CalRGB")) *csp = fz_device_rgb; - else if (!strcmp(fz_to_name(ctx, name), "CalCMYK")) + else if (!strcmp(fz_to_name(name), "CalCMYK")) *csp = fz_device_cmyk; - else if (!strcmp(fz_to_name(ctx, name), "Lab")) + else if (!strcmp(fz_to_name(name), "Lab")) *csp = fz_device_lab; - else if (!strcmp(fz_to_name(ctx, name), "ICCBased")) - return load_icc_based(csp, xref, fz_array_get(ctx, obj, 1)); + else if (!strcmp(fz_to_name(name), "ICCBased")) + return load_icc_based(csp, xref, fz_array_get(obj, 1)); - else if (!strcmp(fz_to_name(ctx, name), "Indexed")) + else if (!strcmp(fz_to_name(name), "Indexed")) return load_indexed(csp, xref, obj); - else if (!strcmp(fz_to_name(ctx, name), "I")) + else if (!strcmp(fz_to_name(name), "I")) return load_indexed(csp, xref, obj); - else if (!strcmp(fz_to_name(ctx, name), "Separation")) + else if (!strcmp(fz_to_name(name), "Separation")) return load_separation(csp, xref, obj); - else if (!strcmp(fz_to_name(ctx, name), "DeviceN")) + else if (!strcmp(fz_to_name(name), "DeviceN")) return load_separation(csp, xref, obj); else - return fz_error_make("syntaxerror: unknown colorspace %s", fz_to_name(ctx, name)); + return fz_error_make("syntaxerror: unknown colorspace %s", fz_to_name(name)); return fz_okay; } diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index 81f3781a..7d5b7902 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -54,26 +54,27 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) fz_error error; fz_obj *obj; - crypt = fz_calloc(ctx, 1, sizeof(pdf_crypt)); + crypt = fz_malloc(ctx, sizeof(pdf_crypt)); + memset(crypt, 0, sizeof *crypt); /* Common to all security handlers (PDF 1.7 table 3.18) */ - obj = fz_dict_gets(ctx, dict, "Filter"); - if (!fz_is_name(ctx, obj)) + obj = fz_dict_gets(dict, "Filter"); + if (!fz_is_name(obj)) { pdf_free_crypt(ctx, crypt); return fz_error_make("unspecified encryption handler"); } - if (strcmp(fz_to_name(ctx, obj), "Standard") != 0) + if (strcmp(fz_to_name(obj), "Standard") != 0) { pdf_free_crypt(ctx, crypt); - return fz_error_make("unknown encryption handler: '%s'", fz_to_name(ctx, obj)); + return fz_error_make("unknown encryption handler: '%s'", fz_to_name(obj)); } crypt->v = 0; - obj = fz_dict_gets(ctx, dict, "V"); - if (fz_is_int(ctx, obj)) - crypt->v = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "V"); + if (fz_is_int(obj)) + crypt->v = fz_to_int(obj); if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4 && crypt->v != 5) { pdf_free_crypt(ctx, crypt); @@ -83,9 +84,9 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) crypt->length = 40; if (crypt->v == 2 || crypt->v == 4) { - obj = fz_dict_gets(ctx, dict, "Length"); - if (fz_is_int(ctx, obj)) - crypt->length = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "Length"); + if (fz_is_int(obj)) + crypt->length = fz_to_int(obj); /* work-around for pdf generators that assume length is in bytes */ if (crypt->length < 40) @@ -123,8 +124,8 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) crypt->strf.method = PDF_CRYPT_NONE; crypt->strf.length = crypt->length; - obj = fz_dict_gets(ctx, dict, "CF"); - if (fz_is_dict(ctx, obj)) + obj = fz_dict_gets(dict, "CF"); + if (fz_is_dict(obj)) { crypt->cf = fz_keep_obj(obj); } @@ -133,10 +134,10 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) crypt->cf = NULL; } - obj = fz_dict_gets(ctx, dict, "StmF"); - if (fz_is_name(ctx, obj)) + obj = fz_dict_gets(dict, "StmF"); + if (fz_is_name(obj)) { - error = pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt->cf, fz_to_name(ctx, obj), crypt->length); + error = pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt->cf, fz_to_name(obj), crypt->length); if (error) { pdf_free_crypt(ctx, crypt); @@ -144,10 +145,10 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) } } - obj = fz_dict_gets(ctx, dict, "StrF"); - if (fz_is_name(ctx, obj)) + obj = fz_dict_gets(dict, "StrF"); + if (fz_is_name(obj)) { - error = pdf_parse_crypt_filter(ctx, &crypt->strf, crypt->cf, fz_to_name(ctx, obj), crypt->length); + error = pdf_parse_crypt_filter(ctx, &crypt->strf, crypt->cf, fz_to_name(obj), crypt->length); if (error) { pdf_free_crypt(ctx, crypt); @@ -162,36 +163,36 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) /* Standard security handler (PDF 1.7 table 3.19) */ - obj = fz_dict_gets(ctx, dict, "R"); - if (fz_is_int(ctx, obj)) - crypt->r = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "R"); + if (fz_is_int(obj)) + crypt->r = fz_to_int(obj); else { pdf_free_crypt(ctx, crypt); return fz_error_make("encryption dictionary missing revision value"); } - obj = fz_dict_gets(ctx, dict, "O"); - if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) == 32) - memcpy(crypt->o, fz_to_str_buf(ctx, obj), 32); + obj = fz_dict_gets(dict, "O"); + if (fz_is_string(obj) && fz_to_str_len(obj) == 32) + memcpy(crypt->o, fz_to_str_buf(obj), 32); /* /O and /U are supposed to be 48 bytes long for revision 5, they're often longer, though */ - else if (crypt->r == 5 && fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) >= 48) - memcpy(crypt->o, fz_to_str_buf(ctx, obj), 48); + else if (crypt->r == 5 && fz_is_string(obj) && fz_to_str_len(obj) >= 48) + memcpy(crypt->o, fz_to_str_buf(obj), 48); else { pdf_free_crypt(ctx, crypt); return fz_error_make("encryption dictionary missing owner password"); } - obj = fz_dict_gets(ctx, dict, "U"); - if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) == 32) - memcpy(crypt->u, fz_to_str_buf(ctx, obj), 32); - else if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) >= 48 && crypt->r == 5) - memcpy(crypt->u, fz_to_str_buf(ctx, obj), 48); - else if (fz_is_string(ctx, obj) && fz_to_str_len(ctx, obj) < 32) + obj = fz_dict_gets(dict, "U"); + if (fz_is_string(obj) && fz_to_str_len(obj) == 32) + memcpy(crypt->u, fz_to_str_buf(obj), 32); + else if (fz_is_string(obj) && fz_to_str_len(obj) >= 48 && crypt->r == 5) + memcpy(crypt->u, fz_to_str_buf(obj), 48); + else if (fz_is_string(obj) && fz_to_str_len(obj) < 32) { - fz_warn("encryption password key too short (%d)", fz_to_str_len(ctx, obj)); - memcpy(crypt->u, fz_to_str_buf(ctx, obj), fz_to_str_len(ctx, obj)); + fz_warn("encryption password key too short (%d)", fz_to_str_len(obj)); + memcpy(crypt->u, fz_to_str_buf(obj), fz_to_str_len(obj)); } else { @@ -199,9 +200,9 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) return fz_error_make("encryption dictionary missing user password"); } - obj = fz_dict_gets(ctx, dict, "P"); - if (fz_is_int(ctx, obj)) - crypt->p = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "P"); + if (fz_is_int(obj)) + crypt->p = fz_to_int(obj); else { pdf_free_crypt(ctx, crypt); @@ -210,34 +211,34 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) if (crypt->r == 5) { - obj = fz_dict_gets(ctx, dict, "OE"); - if (!fz_is_string(ctx, obj) || fz_to_str_len(ctx, obj) != 32) + obj = fz_dict_gets(dict, "OE"); + if (!fz_is_string(obj) || fz_to_str_len(obj) != 32) { pdf_free_crypt(ctx, crypt); return fz_error_make("encryption dictionary missing owner encryption key"); } - memcpy(crypt->oe, fz_to_str_buf(ctx, obj), 32); + memcpy(crypt->oe, fz_to_str_buf(obj), 32); - obj = fz_dict_gets(ctx, dict, "UE"); - if (!fz_is_string(ctx, obj) || fz_to_str_len(ctx, obj) != 32) + obj = fz_dict_gets(dict, "UE"); + if (!fz_is_string(obj) || fz_to_str_len(obj) != 32) { pdf_free_crypt(ctx, crypt); return fz_error_make("encryption dictionary missing user encryption key"); } - memcpy(crypt->ue, fz_to_str_buf(ctx, obj), 32); + memcpy(crypt->ue, fz_to_str_buf(obj), 32); } crypt->encrypt_metadata = 1; - obj = fz_dict_gets(ctx, dict, "EncryptMetadata"); - if (fz_is_bool(ctx, obj)) - crypt->encrypt_metadata = fz_to_bool(ctx, obj); + obj = fz_dict_gets(dict, "EncryptMetadata"); + if (fz_is_bool(obj)) + crypt->encrypt_metadata = fz_to_bool(obj); /* Extract file identifier string */ - if (fz_is_array(ctx, id) && fz_array_len(ctx, id) == 2) + if (fz_is_array(id) && fz_array_len(id) == 2) { - obj = fz_array_get(ctx, id, 0); - if (fz_is_string(ctx, obj)) + obj = fz_array_get(id, 0); + if (fz_is_string(obj)) crypt->id = fz_keep_obj(obj); } else @@ -250,8 +251,8 @@ pdf_new_crypt(fz_context *ctx, pdf_crypt **cryptp, fz_obj *dict, fz_obj *id) void pdf_free_crypt(fz_context *ctx, pdf_crypt *crypt) { - if (crypt->id) fz_drop_obj(ctx, crypt->id); - if (crypt->cf) fz_drop_obj(ctx, crypt->cf); + if (crypt->id) fz_drop_obj(crypt->id); + if (crypt->cf) fz_drop_obj(crypt->cf); fz_free(ctx, crypt); } @@ -280,29 +281,29 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, fz_obj *cf_obj, ch return fz_okay; } - dict = fz_dict_gets(ctx, cf_obj, name); - if (!fz_is_dict(ctx, dict)) + dict = fz_dict_gets(cf_obj, name); + if (!fz_is_dict(dict)) { return fz_error_make("cannot parse crypt filter (%d %d R)", fz_to_num(cf_obj), fz_to_gen(cf_obj)); } - obj = fz_dict_gets(ctx, dict, "CFM"); - if (fz_is_name(ctx, obj)) + obj = fz_dict_gets(dict, "CFM"); + if (fz_is_name(obj)) { - if (!strcmp(fz_to_name(ctx, obj), "None")) + if (!strcmp(fz_to_name(obj), "None")) cf->method = PDF_CRYPT_NONE; - else if (!strcmp(fz_to_name(ctx, obj), "V2")) + else if (!strcmp(fz_to_name(obj), "V2")) cf->method = PDF_CRYPT_RC4; - else if (!strcmp(fz_to_name(ctx, obj), "AESV2")) + else if (!strcmp(fz_to_name(obj), "AESV2")) cf->method = PDF_CRYPT_AESV2; - else if (!strcmp(fz_to_name(ctx, obj), "AESV3")) + else if (!strcmp(fz_to_name(obj), "AESV3")) cf->method = PDF_CRYPT_AESV3; else - fz_error_make("unknown encryption method: %s", fz_to_name(ctx, obj)); + fz_error_make("unknown encryption method: %s", fz_to_name(obj)); } - obj = fz_dict_gets(ctx, dict, "Length"); - if (fz_is_int(ctx, obj)) - cf->length = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "Length"); + if (fz_is_int(obj)) + cf->length = fz_to_int(obj); /* the length for crypt filters is supposed to be in bytes not bits */ if (cf->length < 40) @@ -358,7 +359,7 @@ pdf_compute_encryption_key(pdf_crypt *crypt, unsigned char *password, int pwlen, fz_md5_update(&md5, buf, 4); /* Step 5 - pass first element of ID array */ - fz_md5_update(&md5, (unsigned char *)fz_to_str_buf(crypt->ctx, crypt->id), fz_to_str_len(crypt->ctx, crypt->id)); + fz_md5_update(&md5, (unsigned char *)fz_to_str_buf(crypt->id), fz_to_str_len(crypt->id)); /* Step 6 (revision 4 or greater) - if metadata is not encrypted pass 0xFFFFFFFF */ if (crypt->r >= 4) @@ -467,7 +468,7 @@ pdf_compute_user_password(pdf_crypt *crypt, unsigned char *password, int pwlen, fz_md5_init(&md5); fz_md5_update(&md5, padding, 32); - fz_md5_update(&md5, (unsigned char*)fz_to_str_buf(crypt->ctx, crypt->id), fz_to_str_len(crypt->ctx, crypt->id)); + fz_md5_update(&md5, (unsigned char*)fz_to_str_buf(crypt->id), fz_to_str_len(crypt->id)); fz_md5_final(&md5, digest); fz_arc4_init(&arc4, crypt->key, n); @@ -715,10 +716,10 @@ pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, unsigned char if (fz_is_indirect(obj)) return; - if (fz_is_string(ctx, obj)) + if (fz_is_string(obj)) { - s = (unsigned char *)fz_to_str_buf(ctx, obj); - n = fz_to_str_len(ctx, obj); + s = (unsigned char *)fz_to_str_buf(obj); + n = fz_to_str_len(obj); if (crypt->strf.method == PDF_CRYPT_RC4) { @@ -742,26 +743,26 @@ pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, fz_obj *obj, unsigned char if (s[n - 17] < 1 || s[n - 17] > 16) fz_warn("aes padding out of range"); else - fz_set_str_len(ctx, obj, n - 16 - s[n - 17]); + fz_set_str_len(obj, n - 16 - s[n - 17]); } } } - else if (fz_is_array(ctx, obj)) + else if (fz_is_array(obj)) { - n = fz_array_len(ctx, obj); + n = fz_array_len(obj); for (i = 0; i < n; i++) { - pdf_crypt_obj_imp(ctx, crypt, fz_array_get(ctx, obj, i), key, keylen); + pdf_crypt_obj_imp(ctx, crypt, fz_array_get(obj, i), key, keylen); } } - else if (fz_is_dict(ctx, obj)) + else if (fz_is_dict(obj)) { - n = fz_dict_len(ctx, obj); + n = fz_dict_len(obj); for (i = 0; i < n; i++) { - pdf_crypt_obj_imp(ctx, crypt, fz_dict_get_val(ctx, obj, i), key, keylen); + pdf_crypt_obj_imp(ctx, crypt, fz_dict_get_val(obj, i), key, keylen); } } } diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index 3b8322db..ad5b8d97 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -413,14 +413,14 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict) int fterr; fz_context *ctx = xref->ctx; - basefont = fz_to_name(ctx, fz_dict_gets(ctx, dict, "BaseFont")); + basefont = fz_to_name(fz_dict_gets(dict, "BaseFont")); fontname = clean_font_name(basefont); /* Load font file */ fontdesc = pdf_new_font_desc(ctx); - descriptor = fz_dict_gets(ctx, dict, "FontDescriptor"); + descriptor = fz_dict_gets(dict, "FontDescriptor"); if (descriptor) error = pdf_load_font_descriptor(fontdesc, xref, descriptor, NULL, basefont); else @@ -430,9 +430,9 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict) /* Some chinese documents mistakenly consider WinAnsiEncoding to be codepage 936 */ if (!*fontdesc->font->name && - !fz_dict_gets(ctx, dict, "ToUnicode") && - !strcmp(fz_to_name(ctx, fz_dict_gets(ctx, dict, "Encoding")), "WinAnsiEncoding") && - fz_to_int(ctx, fz_dict_gets(ctx, descriptor, "Flags")) == 4) + !fz_dict_gets(dict, "ToUnicode") && + !strcmp(fz_to_name(fz_dict_gets(dict, "Encoding")), "WinAnsiEncoding") && + fz_to_int(fz_dict_gets(descriptor, "Flags")) == 4) { /* note: without the comma, pdf_load_font_descriptor would prefer /FontName over /BaseFont */ char *cp936fonts[] = { @@ -511,34 +511,34 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict) etable[i] = 0; } - encoding = fz_dict_gets(ctx, dict, "Encoding"); + encoding = fz_dict_gets(dict, "Encoding"); if (encoding) { - if (fz_is_name(ctx, encoding)) - pdf_load_encoding(estrings, fz_to_name(ctx, encoding)); + if (fz_is_name(encoding)) + pdf_load_encoding(estrings, fz_to_name(encoding)); - if (fz_is_dict(ctx, encoding)) + if (fz_is_dict(encoding)) { fz_obj *base, *diff, *item; - base = fz_dict_gets(ctx, encoding, "BaseEncoding"); - if (fz_is_name(ctx, base)) - pdf_load_encoding(estrings, fz_to_name(ctx, base)); + base = fz_dict_gets(encoding, "BaseEncoding"); + if (fz_is_name(base)) + pdf_load_encoding(estrings, fz_to_name(base)); else if (!fontdesc->is_embedded && !symbolic) pdf_load_encoding(estrings, "StandardEncoding"); - diff = fz_dict_gets(ctx, encoding, "Differences"); - if (fz_is_array(ctx, diff)) + diff = fz_dict_gets(encoding, "Differences"); + if (fz_is_array(diff)) { - n = fz_array_len(ctx, diff); + n = fz_array_len(diff); k = 0; for (i = 0; i < n; i++) { - item = fz_array_get(ctx, diff, i); - if (fz_is_int(ctx, item)) - k = fz_to_int(ctx, item); - if (fz_is_name(ctx, item)) - estrings[k++] = fz_to_name(ctx, item); + item = fz_array_get(diff, i); + if (fz_is_int(item)) + k = fz_to_int(item); + if (fz_is_name(item)) + estrings[k++] = fz_to_name(item); if (k < 0) k = 0; if (k > 255) k = 255; } @@ -648,7 +648,7 @@ pdf_load_simple_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict) fontdesc->cid_to_gid_len = 256; fontdesc->cid_to_gid = etable; - error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(ctx, dict, "ToUnicode")); + error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(dict, "ToUnicode")); if (error) fz_error_handle(error, "cannot load to_unicode"); @@ -658,20 +658,20 @@ skip_encoding: pdf_set_default_hmtx(fontdesc, fontdesc->missing_width); - widths = fz_dict_gets(ctx, dict, "Widths"); + widths = fz_dict_gets(dict, "Widths"); if (widths) { int first, last; - first = fz_to_int(ctx, fz_dict_gets(ctx, dict, "FirstChar")); - last = fz_to_int(ctx, fz_dict_gets(ctx, dict, "LastChar")); + first = fz_to_int(fz_dict_gets(dict, "FirstChar")); + last = fz_to_int(fz_dict_gets(dict, "LastChar")); if (first < 0 || last > 255 || first > last) first = last = 0; for (i = 0; i < last - first + 1; i++) { - int wid = fz_to_int(ctx, fz_array_get(ctx, widths, i)); + int wid = fz_to_int(fz_array_get(widths, i)); pdf_add_hmtx(ctx, fontdesc, i + first, i + first, wid); } } @@ -720,28 +720,28 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e /* Get font name and CID collection */ - basefont = fz_to_name(ctx, fz_dict_gets(ctx, dict, "BaseFont")); + basefont = fz_to_name(fz_dict_gets(dict, "BaseFont")); { fz_obj *cidinfo; char tmpstr[64]; int tmplen; - cidinfo = fz_dict_gets(ctx, dict, "CIDSystemInfo"); + cidinfo = fz_dict_gets(dict, "CIDSystemInfo"); if (!cidinfo) return fz_error_make("cid font is missing info"); - obj = fz_dict_gets(ctx, cidinfo, "Registry"); - tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(ctx, obj)); - memcpy(tmpstr, fz_to_str_buf(ctx, obj), tmplen); + obj = fz_dict_gets(cidinfo, "Registry"); + tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(obj)); + memcpy(tmpstr, fz_to_str_buf(obj), tmplen); tmpstr[tmplen] = '\0'; fz_strlcpy(collection, tmpstr, sizeof collection); fz_strlcat(collection, "-", sizeof collection); - obj = fz_dict_gets(ctx, cidinfo, "Ordering"); - tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(ctx, obj)); - memcpy(tmpstr, fz_to_str_buf(ctx, obj), tmplen); + obj = fz_dict_gets(cidinfo, "Ordering"); + tmplen = MIN(sizeof tmpstr - 1, fz_to_str_len(obj)); + memcpy(tmpstr, fz_to_str_buf(obj), tmplen); tmpstr[tmplen] = '\0'; fz_strlcat(collection, tmpstr, sizeof collection); } @@ -750,7 +750,7 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e fontdesc = pdf_new_font_desc(ctx); - descriptor = fz_dict_gets(ctx, dict, "FontDescriptor"); + descriptor = fz_dict_gets(dict, "FontDescriptor"); if (descriptor) error = pdf_load_font_descriptor(fontdesc, xref, descriptor, collection, basefont); else @@ -764,14 +764,14 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e /* Encoding */ error = fz_okay; - if (fz_is_name(ctx, encoding)) + if (fz_is_name(encoding)) { - if (!strcmp(fz_to_name(ctx, encoding), "Identity-H")) + if (!strcmp(fz_to_name(encoding), "Identity-H")) fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 2); - else if (!strcmp(fz_to_name(ctx, encoding), "Identity-V")) + else if (!strcmp(fz_to_name(encoding), "Identity-V")) fontdesc->encoding = pdf_new_identity_cmap(ctx, 1, 2); else - error = pdf_load_system_cmap(ctx, &fontdesc->encoding, fz_to_name(ctx, encoding)); + error = pdf_load_system_cmap(ctx, &fontdesc->encoding, fz_to_name(encoding)); } else if (fz_is_indirect(encoding)) { @@ -790,7 +790,7 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e { fz_obj *cidtogidmap; - cidtogidmap = fz_dict_gets(ctx, dict, "CIDToGIDMap"); + cidtogidmap = fz_dict_gets(dict, "CIDToGIDMap"); if (fz_is_indirect(cidtogidmap)) { fz_buffer *buf; @@ -847,35 +847,35 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e /* Horizontal */ dw = 1000; - obj = fz_dict_gets(ctx, dict, "DW"); + obj = fz_dict_gets(dict, "DW"); if (obj) - dw = fz_to_int(ctx, obj); + dw = fz_to_int(obj); pdf_set_default_hmtx(fontdesc, dw); - widths = fz_dict_gets(ctx, dict, "W"); + widths = fz_dict_gets(dict, "W"); if (widths) { int c0, c1, w, n, m; - n = fz_array_len(ctx, widths); + n = fz_array_len(widths); for (i = 0; i < n; ) { - c0 = fz_to_int(ctx, fz_array_get(ctx, widths, i)); - obj = fz_array_get(ctx, widths, i + 1); - if (fz_is_array(ctx, obj)) + c0 = fz_to_int(fz_array_get(widths, i)); + obj = fz_array_get(widths, i + 1); + if (fz_is_array(obj)) { - m = fz_array_len(ctx, obj); + m = fz_array_len(obj); for (k = 0; k < m; k++) { - w = fz_to_int(ctx, fz_array_get(ctx, obj, k)); + w = fz_to_int(fz_array_get(obj, k)); pdf_add_hmtx(ctx, fontdesc, c0 + k, c0 + k, w); } i += 2; } else { - c1 = fz_to_int(ctx, obj); - w = fz_to_int(ctx, fz_array_get(ctx, widths, i + 2)); + c1 = fz_to_int(obj); + w = fz_to_int(fz_array_get(widths, i + 2)); pdf_add_hmtx(ctx, fontdesc, c0, c1, w); i += 3; } @@ -891,43 +891,43 @@ load_cid_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict, fz_obj *e int dw2y = 880; int dw2w = -1000; - obj = fz_dict_gets(ctx, dict, "DW2"); + obj = fz_dict_gets(dict, "DW2"); if (obj) { - dw2y = fz_to_int(ctx, fz_array_get(ctx, obj, 0)); - dw2w = fz_to_int(ctx, fz_array_get(ctx, obj, 1)); + dw2y = fz_to_int(fz_array_get(obj, 0)); + dw2w = fz_to_int(fz_array_get(obj, 1)); } pdf_set_default_vmtx(fontdesc, dw2y, dw2w); - widths = fz_dict_gets(ctx, dict, "W2"); + widths = fz_dict_gets(dict, "W2"); if (widths) { int c0, c1, w, x, y, n; - n = fz_array_len(ctx, widths); + n = fz_array_len(widths); for (i = 0; i < n; ) { - c0 = fz_to_int(ctx, fz_array_get(ctx, widths, i)); - obj = fz_array_get(ctx, widths, i + 1); - if (fz_is_array(ctx, obj)) + c0 = fz_to_int(fz_array_get(widths, i)); + obj = fz_array_get(widths, i + 1); + if (fz_is_array(obj)) { - int m = fz_array_len(ctx, obj); + int m = fz_array_len(obj); for (k = 0; k * 3 < m; k ++) { - w = fz_to_int(ctx, fz_array_get(ctx, obj, k * 3 + 0)); - x = fz_to_int(ctx, fz_array_get(ctx, obj, k * 3 + 1)); - y = fz_to_int(ctx, fz_array_get(ctx, obj, k * 3 + 2)); + w = fz_to_int(fz_array_get(obj, k * 3 + 0)); + x = fz_to_int(fz_array_get(obj, k * 3 + 1)); + y = fz_to_int(fz_array_get(obj, k * 3 + 2)); pdf_add_vmtx(ctx, fontdesc, c0 + k, c0 + k, x, y, w); } i += 2; } else { - c1 = fz_to_int(ctx, obj); - w = fz_to_int(ctx, fz_array_get(ctx, widths, i + 2)); - x = fz_to_int(ctx, fz_array_get(ctx, widths, i + 3)); - y = fz_to_int(ctx, fz_array_get(ctx, widths, i + 4)); + c1 = fz_to_int(obj); + w = fz_to_int(fz_array_get(widths, i + 2)); + x = fz_to_int(fz_array_get(widths, i + 3)); + y = fz_to_int(fz_array_get(widths, i + 4)); pdf_add_vmtx(ctx, fontdesc, c0, c1, x, y, w); i += 5; } @@ -954,21 +954,20 @@ pdf_load_type0_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *dict) fz_obj *subtype; fz_obj *encoding; fz_obj *to_unicode; - fz_context *ctx = xref->ctx; - dfonts = fz_dict_gets(ctx, dict, "DescendantFonts"); + dfonts = fz_dict_gets(dict, "DescendantFonts"); if (!dfonts) return fz_error_make("cid font is missing descendant fonts"); - dfont = fz_array_get(ctx, dfonts, 0); + dfont = fz_array_get(dfonts, 0); - subtype = fz_dict_gets(ctx, dfont, "Subtype"); - encoding = fz_dict_gets(ctx, dict, "Encoding"); - to_unicode = fz_dict_gets(ctx, dict, "ToUnicode"); + subtype = fz_dict_gets(dfont, "Subtype"); + encoding = fz_dict_gets(dict, "Encoding"); + to_unicode = fz_dict_gets(dict, "ToUnicode"); - if (fz_is_name(ctx, subtype) && !strcmp(fz_to_name(ctx, subtype), "CIDFontType0")) + if (fz_is_name(subtype) && !strcmp(fz_to_name(subtype), "CIDFontType0")) error = load_cid_font(fontdescp, xref, dfont, encoding, to_unicode); - else if (fz_is_name(ctx, subtype) && !strcmp(fz_to_name(ctx, subtype), "CIDFontType2")) + else if (fz_is_name(subtype) && !strcmp(fz_to_name(subtype), "CIDFontType2")) error = load_cid_font(fontdescp, xref, dfont, encoding, to_unicode); else error = fz_error_make("syntaxerror: unknown cid font type"); @@ -993,22 +992,22 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *dict, fz_context *ctx = xref->ctx; if (!strchr(basefont, ',') || strchr(basefont, '+')) - origname = fz_to_name(ctx, fz_dict_gets(ctx, dict, "FontName")); + origname = fz_to_name(fz_dict_gets(dict, "FontName")); else origname = basefont; fontname = clean_font_name(origname); - fontdesc->flags = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Flags")); - fontdesc->italic_angle = fz_to_real(ctx, fz_dict_gets(ctx, dict, "ItalicAngle")); - fontdesc->ascent = fz_to_real(ctx, fz_dict_gets(ctx, dict, "Ascent")); - fontdesc->descent = fz_to_real(ctx, fz_dict_gets(ctx, dict, "Descent")); - fontdesc->cap_height = fz_to_real(ctx, fz_dict_gets(ctx, dict, "CapHeight")); - fontdesc->x_height = fz_to_real(ctx, fz_dict_gets(ctx, dict, "XHeight")); - fontdesc->missing_width = fz_to_real(ctx, fz_dict_gets(ctx, dict, "MissingWidth")); - - obj1 = fz_dict_gets(ctx, dict, "FontFile"); - obj2 = fz_dict_gets(ctx, dict, "FontFile2"); - obj3 = fz_dict_gets(ctx, dict, "FontFile3"); + fontdesc->flags = fz_to_int(fz_dict_gets(dict, "Flags")); + fontdesc->italic_angle = fz_to_real(fz_dict_gets(dict, "ItalicAngle")); + fontdesc->ascent = fz_to_real(fz_dict_gets(dict, "Ascent")); + fontdesc->descent = fz_to_real(fz_dict_gets(dict, "Descent")); + fontdesc->cap_height = fz_to_real(fz_dict_gets(dict, "CapHeight")); + fontdesc->x_height = fz_to_real(fz_dict_gets(dict, "XHeight")); + fontdesc->missing_width = fz_to_real(fz_dict_gets(dict, "MissingWidth")); + + obj1 = fz_dict_gets(dict, "FontFile"); + obj2 = fz_dict_gets(dict, "FontFile2"); + obj3 = fz_dict_gets(dict, "FontFile3"); obj = obj1 ? obj1 : obj2 ? obj2 : obj3; if (fz_is_indirect(obj)) @@ -1097,9 +1096,9 @@ pdf_load_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_obj *di return fz_okay; } - subtype = fz_to_name(ctx, fz_dict_gets(ctx, dict, "Subtype")); - dfonts = fz_dict_gets(ctx, dict, "DescendantFonts"); - charprocs = fz_dict_gets(ctx, dict, "CharProcs"); + subtype = fz_to_name(fz_dict_gets(dict, "Subtype")); + dfonts = fz_dict_gets(dict, "DescendantFonts"); + charprocs = fz_dict_gets(dict, "CharProcs"); if (subtype && !strcmp(subtype, "Type0")) error = pdf_load_type0_font(fontdescp, xref, dict); diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 3905f75e..7ab681c3 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -906,26 +906,26 @@ load_sample_func(pdf_function *func, pdf_xref *xref, fz_obj *dict, int num, int func->u.sa.samples = NULL; - obj = fz_dict_gets(ctx, dict, "Size"); - if (!fz_is_array(ctx, obj) || fz_array_len(ctx, obj) != func->m) + obj = fz_dict_gets(dict, "Size"); + if (!fz_is_array(obj) || fz_array_len(obj) != func->m) return fz_error_make("malformed /Size"); for (i = 0; i < func->m; i++) - func->u.sa.size[i] = fz_to_int(ctx, fz_array_get(ctx, obj, i)); + func->u.sa.size[i] = fz_to_int(fz_array_get(obj, i)); - obj = fz_dict_gets(ctx, dict, "BitsPerSample"); - if (!fz_is_int(ctx, obj)) + obj = fz_dict_gets(dict, "BitsPerSample"); + if (!fz_is_int(obj)) return fz_error_make("malformed /BitsPerSample"); - func->u.sa.bps = bps = fz_to_int(ctx, obj); + func->u.sa.bps = bps = fz_to_int(obj); - obj = fz_dict_gets(ctx, dict, "Encode"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "Encode"); + if (fz_is_array(obj)) { - if (fz_array_len(ctx, obj) != func->m * 2) + if (fz_array_len(obj) != func->m * 2) return fz_error_make("malformed /Encode"); for (i = 0; i < func->m; i++) { - func->u.sa.encode[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+0)); - func->u.sa.encode[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+1)); + func->u.sa.encode[i][0] = fz_to_real(fz_array_get(obj, i*2+0)); + func->u.sa.encode[i][1] = fz_to_real(fz_array_get(obj, i*2+1)); } } else @@ -937,15 +937,15 @@ load_sample_func(pdf_function *func, pdf_xref *xref, fz_obj *dict, int num, int } } - obj = fz_dict_gets(ctx, dict, "Decode"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "Decode"); + if (fz_is_array(obj)) { - if (fz_array_len(ctx, obj) != func->n * 2) + if (fz_array_len(obj) != func->n * 2) return fz_error_make("malformed /Decode"); for (i = 0; i < func->n; i++) { - func->u.sa.decode[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+0)); - func->u.sa.decode[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+1)); + func->u.sa.decode[i][0] = fz_to_real(fz_array_get(obj, i*2+0)); + func->u.sa.decode[i][1] = fz_to_real(fz_array_get(obj, i*2+1)); } } else @@ -1116,19 +1116,19 @@ load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict) if (func->m != 1) return fz_error_make("/Domain must be one dimension (%d)", func->m); - obj = fz_dict_gets(ctx, dict, "N"); - if (!fz_is_int(ctx, obj) && !fz_is_real(ctx, obj)) + obj = fz_dict_gets(dict, "N"); + if (!fz_is_int(obj) && !fz_is_real(obj)) return fz_error_make("malformed /N"); - func->u.e.n = fz_to_real(ctx, obj); + func->u.e.n = fz_to_real(obj); - obj = fz_dict_gets(ctx, dict, "C0"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "C0"); + if (fz_is_array(obj)) { - func->n = fz_array_len(ctx, obj); + func->n = fz_array_len(obj); if (func->n >= MAXN) return fz_error_make("exponential function result array out of range"); for (i = 0; i < func->n; i++) - func->u.e.c0[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i)); + func->u.e.c0[i] = fz_to_real(fz_array_get(obj, i)); } else { @@ -1136,13 +1136,13 @@ load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict) func->u.e.c0[0] = 0; } - obj = fz_dict_gets(ctx, dict, "C1"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "C1"); + if (fz_is_array(obj)) { - if (fz_array_len(ctx, obj) != func->n) + if (fz_array_len(obj) != func->n) return fz_error_make("/C1 must match /C0 length"); for (i = 0; i < func->n; i++) - func->u.e.c1[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i)); + func->u.e.c1[i] = fz_to_real(fz_array_get(obj, i)); } else { @@ -1200,11 +1200,11 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict) if (func->m != 1) return fz_error_make("/Domain must be one dimension (%d)", func->m); - obj = fz_dict_gets(ctx, dict, "Functions"); - if (!fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "Functions"); + if (!fz_is_array(obj)) return fz_error_make("stitching function has no input functions"); { - k = fz_array_len(ctx, obj); + k = fz_array_len(obj); func->u.st.funcs = fz_calloc(ctx, k, sizeof(pdf_function*)); func->u.st.bounds = fz_calloc(ctx, k - 1, sizeof(float)); @@ -1213,7 +1213,7 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict) for (i = 0; i < k; i++) { - sub = fz_array_get(ctx, obj, i); + sub = fz_array_get(obj, i); error = pdf_load_function(&funcs[i], xref, sub); if (error) return fz_error_note(error, "cannot load sub function %d (%d %d R)", i, fz_to_num(sub), fz_to_gen(sub)); @@ -1228,19 +1228,19 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict) return fz_error_make("sub function /Domain or /Range mismatch"); } - obj = fz_dict_gets(ctx, dict, "Bounds"); - if (!fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "Bounds"); + if (!fz_is_array(obj)) return fz_error_make("stitching function has no bounds"); { - if (!fz_is_array(ctx, obj) || fz_array_len(ctx, obj) != k - 1) + if (!fz_is_array(obj) || fz_array_len(obj) != k - 1) return fz_error_make("malformed /Bounds (not array or wrong length)"); for (i = 0; i < k-1; i++) { - num = fz_array_get(ctx, obj, i); - if (!fz_is_int(ctx, num) && !fz_is_real(ctx, num)) + num = fz_array_get(obj, i); + if (!fz_is_int(num) && !fz_is_real(num)) return fz_error_make("malformed /Bounds (item not real)"); - func->u.st.bounds[i] = fz_to_real(ctx, num); + func->u.st.bounds[i] = fz_to_real(num); if (i && func->u.st.bounds[i-1] > func->u.st.bounds[i]) return fz_error_make("malformed /Bounds (item not monotonic)"); } @@ -1250,16 +1250,16 @@ load_stitching_func(pdf_function *func, pdf_xref *xref, fz_obj *dict) fz_warn("malformed shading function bounds (domain mismatch), proceeding anyway."); } - obj = fz_dict_gets(ctx, dict, "Encode"); - if (!fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "Encode"); + if (!fz_is_array(obj)) return fz_error_make("stitching function is missing encoding"); { - if (!fz_is_array(ctx, obj) || fz_array_len(ctx, obj) != k * 2) + if (!fz_is_array(obj) || fz_array_len(obj) != k * 2) return fz_error_make("malformed /Encode"); for (i = 0; i < k; i++) { - func->u.st.encode[i*2+0] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+0)); - func->u.st.encode[i*2+1] = fz_to_real(ctx, fz_array_get(ctx, obj, i*2+1)); + func->u.st.encode[i*2+0] = fz_to_real(fz_array_get(obj, i*2+0)); + func->u.st.encode[i*2+1] = fz_to_real(fz_array_get(obj, i*2+1)); } } @@ -1362,31 +1362,32 @@ pdf_load_function(pdf_function **funcp, pdf_xref *xref, fz_obj *dict) return fz_okay; } - func = fz_calloc(ctx, 1, sizeof(pdf_function)); + func = fz_malloc(ctx, sizeof(pdf_function)); + memset(func, 0, sizeof *func); func->refs = 1; - obj = fz_dict_gets(ctx, dict, "FunctionType"); - func->type = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "FunctionType"); + func->type = fz_to_int(obj); /* required for all */ - obj = fz_dict_gets(ctx, dict, "Domain"); - func->m = fz_array_len(ctx, obj) / 2; + obj = fz_dict_gets(dict, "Domain"); + func->m = fz_array_len(obj) / 2; for (i = 0; i < func->m; i++) { - func->domain[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 0)); - func->domain[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 1)); + func->domain[i][0] = fz_to_real(fz_array_get(obj, i * 2 + 0)); + func->domain[i][1] = fz_to_real(fz_array_get(obj, i * 2 + 1)); } /* required for type0 and type4, optional otherwise */ - obj = fz_dict_gets(ctx, dict, "Range"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "Range"); + if (fz_is_array(obj)) { func->has_range = 1; - func->n = fz_array_len(ctx, obj) / 2; + func->n = fz_array_len(obj) / 2; for (i = 0; i < func->n; i++) { - func->range[i][0] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 0)); - func->range[i][1] = fz_to_real(ctx, fz_array_get(ctx, obj, i * 2 + 1)); + func->range[i][0] = fz_to_real(fz_array_get(obj, i * 2 + 0)); + func->range[i][1] = fz_to_real(fz_array_get(obj, i * 2 + 1)); } } else diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 95f26c31..cb63309d 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -71,11 +71,11 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, return fz_okay; } - w = fz_to_int(ctx, fz_dict_getsa(ctx, dict, "Width", "W")); - h = fz_to_int(ctx, fz_dict_getsa(ctx, dict, "Height", "H")); - bpc = fz_to_int(ctx, fz_dict_getsa(ctx, dict, "BitsPerComponent", "BPC")); - imagemask = fz_to_bool(ctx, fz_dict_getsa(ctx, dict, "ImageMask", "IM")); - interpolate = fz_to_bool(ctx, fz_dict_getsa(ctx, dict, "Interpolate", "I")); + w = fz_to_int(fz_dict_getsa(dict, "Width", "W")); + h = fz_to_int(fz_dict_getsa(dict, "Height", "H")); + bpc = fz_to_int(fz_dict_getsa(dict, "BitsPerComponent", "BPC")); + imagemask = fz_to_bool(fz_dict_getsa(dict, "ImageMask", "IM")); + interpolate = fz_to_bool(fz_dict_getsa(dict, "Interpolate", "I")); indexed = 0; usecolorkey = 0; @@ -98,13 +98,13 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, if (h > (1 << 16)) return fz_error_make("image is too high"); - obj = fz_dict_getsa(ctx, dict, "ColorSpace", "CS"); + obj = fz_dict_getsa(dict, "ColorSpace", "CS"); if (obj && !imagemask && !forcemask) { /* colorspace resource lookup is only done for inline images */ - if (fz_is_name(ctx, obj)) + if (fz_is_name(obj)) { - res = fz_dict_get(ctx, fz_dict_gets(ctx, rdb, "ColorSpace"), obj); + res = fz_dict_get(fz_dict_gets(rdb, "ColorSpace"), obj); if (res) obj = res; } @@ -123,11 +123,11 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, n = 1; } - obj = fz_dict_getsa(ctx, dict, "Decode", "D"); + obj = fz_dict_getsa(dict, "Decode", "D"); if (obj) { for (i = 0; i < n * 2; i++) - decode[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i)); + decode[i] = fz_to_real(fz_array_get(obj, i)); } else { @@ -136,8 +136,8 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, decode[i] = i & 1 ? maxval : 0; } - obj = fz_dict_getsa(ctx, dict, "SMask", "Mask"); - if (fz_is_dict(ctx, obj)) + obj = fz_dict_getsa(dict, "SMask", "Mask"); + if (fz_is_dict(obj)) { /* Not allowed for inline images */ if (!cstm) @@ -151,11 +151,11 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, } } } - else if (fz_is_array(ctx, obj)) + else if (fz_is_array(obj)) { usecolorkey = 1; for (i = 0; i < n * 2; i++) - colorkey[i] = fz_to_int(ctx, fz_array_get(ctx, obj, i)); + colorkey[i] = fz_to_int(fz_array_get(obj, i)); } /* Allocate now, to fail early if we run out of memory */ @@ -274,12 +274,12 @@ pdf_is_jpx_image(fz_context *ctx, fz_obj *dict) fz_obj *filter; int i, n; - filter = fz_dict_gets(ctx, dict, "Filter"); - if (!strcmp(fz_to_name(ctx, filter), "JPXDecode")) + filter = fz_dict_gets(dict, "Filter"); + if (!strcmp(fz_to_name(filter), "JPXDecode")) return 1; - n = fz_array_len(ctx, filter); + n = fz_array_len(filter); for (i = 0; i < n; i++) - if (!strcmp(fz_to_name(ctx, fz_array_get(ctx, filter, i)), "JPXDecode")) + if (!strcmp(fz_to_name(fz_array_get(filter, i)), "JPXDecode")) return 1; return 0; } @@ -300,7 +300,7 @@ pdf_load_jpx_image(fz_pixmap **imgp, pdf_xref *xref, fz_obj *dict) if (error) return fz_error_note(error, "cannot load jpx image data"); - obj = fz_dict_gets(ctx, dict, "ColorSpace"); + obj = fz_dict_gets(dict, "ColorSpace"); if (obj) { error = pdf_load_colorspace(&colorspace, xref, obj); @@ -321,8 +321,8 @@ pdf_load_jpx_image(fz_pixmap **imgp, pdf_xref *xref, fz_obj *dict) fz_drop_colorspace(ctx, colorspace); fz_drop_buffer(ctx, buf); - obj = fz_dict_getsa(ctx, dict, "SMask", "Mask"); - if (fz_is_dict(ctx, obj)) + obj = fz_dict_getsa(dict, "SMask", "Mask"); + if (fz_is_dict(obj)) { error = pdf_load_image_imp(&img->mask, xref, NULL, obj, NULL, 1); if (error) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index d4d909bd..e3272edf 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -110,14 +110,14 @@ pdf_is_hidden_ocg(fz_context *ctx, fz_obj *xobj, char *target) fz_strlcpy(target_state, target, sizeof target_state); fz_strlcat(target_state, "State", sizeof target_state); - obj = fz_dict_gets(ctx, xobj, "OC"); - obj = fz_dict_gets(ctx, obj, "OCGs"); - if (fz_is_array(ctx, obj)) - obj = fz_array_get(ctx, obj, 0); - obj = fz_dict_gets(ctx, obj, "Usage"); - obj = fz_dict_gets(ctx, obj, target); - obj = fz_dict_gets(ctx, obj, target_state); - return !strcmp(fz_to_name(ctx, obj), "OFF"); + obj = fz_dict_gets(xobj, "OC"); + obj = fz_dict_gets(obj, "OCGs"); + if (fz_is_array(obj)) + obj = fz_array_get(obj, 0); + obj = fz_dict_gets(obj, "Usage"); + obj = fz_dict_gets(obj, target); + obj = fz_dict_gets(obj, target_state); + return !strcmp(fz_to_name(obj), "OFF"); } /* @@ -587,23 +587,22 @@ pdf_show_text(pdf_csi *csi, fz_obj *text) { pdf_gstate *gstate = csi->gstate + csi->gtop; int i; - fz_context *ctx = csi->dev->ctx; - if (fz_is_array(ctx, text)) + if (fz_is_array(text)) { - int n = fz_array_len(ctx, text); + int n = fz_array_len(text); for (i = 0; i < n; i++) { - fz_obj *item = fz_array_get(ctx, text, i); - if (fz_is_string(ctx, item)) - pdf_show_string(csi, (unsigned char *)fz_to_str_buf(ctx, item), fz_to_str_len(ctx, item)); + fz_obj *item = fz_array_get(text, i); + if (fz_is_string(item)) + pdf_show_string(csi, (unsigned char *)fz_to_str_buf(item), fz_to_str_len(item)); else - pdf_show_space(csi, - fz_to_real(ctx, item) * gstate->size * 0.001f); + pdf_show_space(csi, - fz_to_real(item) * gstate->size * 0.001f); } } - else if (fz_is_string(ctx, text)) + else if (fz_is_string(text)) { - pdf_show_string(csi, (unsigned char *)fz_to_str_buf(ctx, text), fz_to_str_len(ctx, text)); + pdf_show_string(csi, (unsigned char *)fz_to_str_buf(text), fz_to_str_len(text)); } } @@ -696,7 +695,7 @@ pdf_clear_stack(pdf_csi *csi) int i; if (csi->obj) - fz_drop_obj(csi->dev->ctx, csi->obj); + fz_drop_obj(csi->obj); csi->obj = NULL; csi->name[0] = 0; @@ -1129,19 +1128,19 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) pdf_flush_text(csi); - n = fz_dict_len(ctx, extgstate); + n = fz_dict_len(extgstate); for (i = 0; i < n; i++) { - fz_obj *key = fz_dict_get_key(ctx, extgstate, i); - fz_obj *val = fz_dict_get_val(ctx, extgstate, i); - char *s = fz_to_name(ctx, key); + fz_obj *key = fz_dict_get_key(extgstate, i); + fz_obj *val = fz_dict_get_val(extgstate, i); + char *s = fz_to_name(key); if (!strcmp(s, "Font")) { - if (fz_is_array(ctx, val) && fz_array_len(ctx, val) == 2) + if (fz_is_array(val) && fz_array_len(val) == 2) { fz_error error; - fz_obj *font = fz_array_get(ctx, val, 0); + fz_obj *font = fz_array_get(val, 0); if (gstate->font) { @@ -1154,7 +1153,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) return fz_error_note(error, "cannot load font (%d %d R)", fz_to_num(font), fz_to_gen(font)); if (!gstate->font) return fz_error_make("cannot find font in store"); - gstate->size = fz_to_real(ctx, fz_array_get(ctx, val, 1)); + gstate->size = fz_to_real(fz_array_get(val, 1)); } else return fz_error_make("malformed /Font dictionary"); @@ -1162,47 +1161,47 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) else if (!strcmp(s, "LC")) { - gstate->stroke_state.start_cap = fz_to_int(ctx, val); - gstate->stroke_state.dash_cap = fz_to_int(ctx, val); - gstate->stroke_state.end_cap = fz_to_int(ctx, val); + gstate->stroke_state.start_cap = fz_to_int(val); + gstate->stroke_state.dash_cap = fz_to_int(val); + gstate->stroke_state.end_cap = fz_to_int(val); } else if (!strcmp(s, "LW")) - gstate->stroke_state.linewidth = fz_to_real(ctx, val); + gstate->stroke_state.linewidth = fz_to_real(val); else if (!strcmp(s, "LJ")) - gstate->stroke_state.linejoin = fz_to_int(ctx, val); + gstate->stroke_state.linejoin = fz_to_int(val); else if (!strcmp(s, "ML")) - gstate->stroke_state.miterlimit = fz_to_real(ctx, val); + gstate->stroke_state.miterlimit = fz_to_real(val); else if (!strcmp(s, "D")) { - if (fz_is_array(ctx, val) && fz_array_len(ctx, val) == 2) + if (fz_is_array(val) && fz_array_len(val) == 2) { - fz_obj *dashes = fz_array_get(ctx, val, 0); - gstate->stroke_state.dash_len = MAX(fz_array_len(ctx, dashes), 32); + fz_obj *dashes = fz_array_get(val, 0); + gstate->stroke_state.dash_len = MAX(fz_array_len(dashes), 32); for (k = 0; k < gstate->stroke_state.dash_len; k++) - gstate->stroke_state.dash_list[k] = fz_to_real(ctx, fz_array_get(ctx, dashes, k)); - gstate->stroke_state.dash_phase = fz_to_real(ctx, fz_array_get(ctx, val, 1)); + gstate->stroke_state.dash_list[k] = fz_to_real(fz_array_get(dashes, k)); + gstate->stroke_state.dash_phase = fz_to_real(fz_array_get(val, 1)); } else return fz_error_make("malformed /D"); } else if (!strcmp(s, "CA")) - gstate->stroke.alpha = fz_to_real(ctx, val); + gstate->stroke.alpha = fz_to_real(val); else if (!strcmp(s, "ca")) - gstate->fill.alpha = fz_to_real(ctx, val); + gstate->fill.alpha = fz_to_real(val); else if (!strcmp(s, "BM")) { - if (fz_is_array(ctx, val)) - val = fz_array_get(ctx, val, 0); - gstate->blendmode = fz_find_blendmode(fz_to_name(ctx, val)); + if (fz_is_array(val)) + val = fz_array_get(val, 0); + gstate->blendmode = fz_find_blendmode(fz_to_name(val)); } else if (!strcmp(s, "SMask")) { - if (fz_is_dict(ctx, val)) + if (fz_is_dict(val)) { fz_error error; pdf_xobject *xobj; @@ -1214,7 +1213,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) gstate->softmask = NULL; } - group = fz_dict_gets(ctx, val, "G"); + group = fz_dict_gets(val, "G"); if (!group) return fz_error_make("cannot load softmask xobject (%d %d R)", fz_to_num(val), fz_to_gen(val)); error = pdf_load_xobject(&xobj, csi->xref, group); @@ -1230,20 +1229,20 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) for (k = 0; k < colorspace->n; k++) gstate->softmask_bc[k] = 0; - bc = fz_dict_gets(ctx, val, "BC"); - if (fz_is_array(ctx, bc)) + bc = fz_dict_gets(val, "BC"); + if (fz_is_array(bc)) { for (k = 0; k < colorspace->n; k++) - gstate->softmask_bc[k] = fz_to_real(ctx, fz_array_get(ctx, bc, k)); + gstate->softmask_bc[k] = fz_to_real(fz_array_get(bc, k)); } - luminosity = fz_dict_gets(ctx, val, "S"); - if (fz_is_name(ctx, luminosity) && !strcmp(fz_to_name(ctx, luminosity), "Luminosity")) + luminosity = fz_dict_gets(val, "S"); + if (fz_is_name(luminosity) && !strcmp(fz_to_name(luminosity), "Luminosity")) gstate->luminosity = 1; else gstate->luminosity = 0; } - else if (fz_is_name(ctx, val) && !strcmp(fz_to_name(ctx, val), "None")) + else if (fz_is_name(val) && !strcmp(fz_to_name(val), "None")) { if (gstate->softmask) { @@ -1255,7 +1254,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) else if (!strcmp(s, "TR")) { - if (fz_is_name(ctx, val) && strcmp(fz_to_name(ctx, val), "Identity")) + if (fz_is_name(val) && strcmp(fz_to_name(val), "Identity")) fz_warn("ignoring transfer function"); } } @@ -1292,7 +1291,7 @@ static fz_error pdf_run_BI(pdf_csi *csi, fz_obj *rdb, fz_stream *file) fz_read_byte(file); error = pdf_load_inline_image(&img, csi->xref, rdb, obj, file); - fz_drop_obj(ctx, obj); + fz_drop_obj(obj); if (error) return fz_error_note(error, "cannot load inline image"); @@ -1358,10 +1357,10 @@ static fz_error pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what) colorspace = fz_keep_colorspace(fz_device_cmyk); else { - dict = fz_dict_gets(ctx, rdb, "ColorSpace"); + dict = fz_dict_gets(rdb, "ColorSpace"); if (!dict) return fz_error_make("cannot find ColorSpace dictionary"); - obj = fz_dict_gets(ctx, dict, csi->name); + obj = fz_dict_gets(dict, csi->name); if (!obj) return fz_error_make("cannot find colorspace resource '%s'", csi->name); error = pdf_load_colorspace(&colorspace, csi->xref, obj); @@ -1404,25 +1403,25 @@ static fz_error pdf_run_Do(pdf_csi *csi, fz_obj *rdb) fz_error error; fz_context *ctx = csi->dev->ctx; - dict = fz_dict_gets(ctx, rdb, "XObject"); + dict = fz_dict_gets(rdb, "XObject"); if (!dict) return fz_error_make("cannot find XObject dictionary when looking for: '%s'", csi->name); - obj = fz_dict_gets(ctx, dict, csi->name); + obj = fz_dict_gets(dict, csi->name); if (!obj) return fz_error_make("cannot find xobject resource: '%s'", csi->name); - subtype = fz_dict_gets(ctx, obj, "Subtype"); - if (!fz_is_name(ctx, subtype)) + subtype = fz_dict_gets(obj, "Subtype"); + if (!fz_is_name(subtype)) return fz_error_make("no XObject subtype specified"); if (pdf_is_hidden_ocg(ctx, obj, csi->target)) return fz_okay; - if (!strcmp(fz_to_name(ctx, subtype), "Form") && fz_dict_gets(ctx, obj, "Subtype2")) - subtype = fz_dict_gets(ctx, obj, "Subtype2"); + if (!strcmp(fz_to_name(subtype), "Form") && fz_dict_gets(obj, "Subtype2")) + subtype = fz_dict_gets(obj, "Subtype2"); - if (!strcmp(fz_to_name(ctx, subtype), "Form")) + if (!strcmp(fz_to_name(subtype), "Form")) { pdf_xobject *xobj; @@ -1441,7 +1440,7 @@ static fz_error pdf_run_Do(pdf_csi *csi, fz_obj *rdb) pdf_drop_xobject(ctx, xobj); } - else if (!strcmp(fz_to_name(ctx, subtype), "Image")) + else if (!strcmp(fz_to_name(subtype), "Image")) { if ((csi->dev->hints & FZ_IGNORE_IMAGE) == 0) { @@ -1454,14 +1453,14 @@ static fz_error pdf_run_Do(pdf_csi *csi, fz_obj *rdb) } } - else if (!strcmp(fz_to_name(ctx, subtype), "PS")) + else if (!strcmp(fz_to_name(subtype), "PS")) { fz_warn("ignoring XObject with subtype PS"); } else { - return fz_error_make("unknown XObject subtype: '%s'", fz_to_name(ctx, subtype)); + return fz_error_make("unknown XObject subtype: '%s'", fz_to_name(subtype)); } return fz_okay; @@ -1557,17 +1556,17 @@ static fz_error pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material break; case PDF_MAT_PATTERN: - dict = fz_dict_gets(ctx, rdb, "Pattern"); + dict = fz_dict_gets(rdb, "Pattern"); if (!dict) return fz_error_make("cannot find Pattern dictionary"); - obj = fz_dict_gets(ctx, dict, csi->name); + obj = fz_dict_gets(dict, csi->name); if (!obj) return fz_error_make("cannot find pattern resource '%s'", csi->name); - patterntype = fz_dict_gets(ctx, obj, "PatternType"); + patterntype = fz_dict_gets(obj, "PatternType"); - if (fz_to_int(ctx, patterntype) == 1) + if (fz_to_int(patterntype) == 1) { pdf_pattern *pat; error = pdf_load_pattern(&pat, csi->xref, obj); @@ -1576,7 +1575,7 @@ static fz_error pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material pdf_set_pattern(csi, what, pat, csi->top > 0 ? csi->stack : NULL); pdf_drop_pattern(ctx, pat); } - else if (fz_to_int(ctx, patterntype) == 2) + else if (fz_to_int(patterntype) == 2) { fz_shade *shd; error = pdf_load_shading(&shd, csi->xref, obj); @@ -1587,7 +1586,7 @@ static fz_error pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material } else { - return fz_error_make("unknown pattern type: %d", fz_to_int(ctx, patterntype)); + return fz_error_make("unknown pattern type: %d", fz_to_int(patterntype)); } break; @@ -1655,11 +1654,11 @@ static fz_error pdf_run_Tf(pdf_csi *csi, fz_obj *rdb) pdf_drop_font(ctx, gstate->font); gstate->font = NULL; - dict = fz_dict_gets(ctx, rdb, "Font"); + dict = fz_dict_gets(rdb, "Font"); if (!dict) return fz_error_make("cannot find Font dictionary"); - obj = fz_dict_gets(ctx, dict, csi->name); + obj = fz_dict_gets(dict, csi->name); if (!obj) return fz_error_make("cannot find font resource: '%s'", csi->name); @@ -1787,12 +1786,11 @@ static void pdf_run_d(pdf_csi *csi) pdf_gstate *gstate = csi->gstate + csi->gtop; fz_obj *array; int i; - fz_context *ctx = csi->dev->ctx; array = csi->obj; - gstate->stroke_state.dash_len = MIN(fz_array_len(ctx, array), nelem(gstate->stroke_state.dash_list)); + gstate->stroke_state.dash_len = MIN(fz_array_len(array), nelem(gstate->stroke_state.dash_list)); for (i = 0; i < gstate->stroke_state.dash_len; i++) - gstate->stroke_state.dash_list[i] = fz_to_real(ctx, fz_array_get(ctx, array, i)); + gstate->stroke_state.dash_list[i] = fz_to_real(fz_array_get(array, i)); gstate->stroke_state.dash_phase = csi->stack[0]; } @@ -1827,13 +1825,12 @@ static fz_error pdf_run_gs(pdf_csi *csi, fz_obj *rdb) fz_error error; fz_obj *dict; fz_obj *obj; - fz_context *ctx = csi->dev->ctx; - dict = fz_dict_gets(ctx, rdb, "ExtGState"); + dict = fz_dict_gets(rdb, "ExtGState"); if (!dict) return fz_error_make("cannot find ExtGState dictionary"); - obj = fz_dict_gets(ctx, dict, csi->name); + obj = fz_dict_gets(dict, csi->name); if (!obj) return fz_error_make("cannot find extgstate resource '%s'", csi->name); @@ -1930,11 +1927,11 @@ static fz_error pdf_run_sh(pdf_csi *csi, fz_obj *rdb) fz_error error; fz_context *ctx = csi->dev->ctx; - dict = fz_dict_gets(ctx, rdb, "Shading"); + dict = fz_dict_gets(rdb, "Shading"); if (!dict) return fz_error_make("cannot find shading dictionary"); - obj = fz_dict_gets(ctx, dict, csi->name); + obj = fz_dict_gets(dict, csi->name); if (!obj) return fz_error_make("cannot find shading resource: '%s'", csi->name); @@ -2288,7 +2285,7 @@ pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matri for (annot = page->annots; annot; annot = annot->next) { - flags = fz_to_int(ctx, fz_dict_gets(ctx, annot->obj, "F")); + flags = fz_to_int(fz_dict_gets(annot->obj, "F")); /* TODO: NoZoom and NoRotate */ if (flags & (1 << 0)) /* Invisible */ diff --git a/pdf/pdf_nametree.c b/pdf/pdf_nametree.c index 838caa94..d84f2e8b 100644 --- a/pdf/pdf_nametree.c +++ b/pdf/pdf_nametree.c @@ -4,21 +4,21 @@ static fz_obj * pdf_lookup_name_imp(fz_context *ctx, fz_obj *node, fz_obj *needle) { - fz_obj *kids = fz_dict_gets(ctx, node, "Kids"); - fz_obj *names = fz_dict_gets(ctx, node, "Names"); + fz_obj *kids = fz_dict_gets(node, "Kids"); + fz_obj *names = fz_dict_gets(node, "Names"); - if (fz_is_array(ctx, kids)) + if (fz_is_array(kids)) { int l = 0; - int r = fz_array_len(ctx, kids) - 1; + int r = fz_array_len(kids) - 1; while (l <= r) { int m = (l + r) >> 1; - fz_obj *kid = fz_array_get(ctx, kids, m); - fz_obj *limits = fz_dict_gets(ctx, kid, "Limits"); - fz_obj *first = fz_array_get(ctx, limits, 0); - fz_obj *last = fz_array_get(ctx, limits, 1); + fz_obj *kid = fz_array_get(kids, m); + fz_obj *limits = fz_dict_gets(kid, "Limits"); + fz_obj *first = fz_array_get(limits, 0); + fz_obj *last = fz_array_get(limits, 1); if (fz_objcmp(needle, first) < 0) r = m - 1; @@ -29,17 +29,17 @@ pdf_lookup_name_imp(fz_context *ctx, fz_obj *node, fz_obj *needle) } } - if (fz_is_array(ctx, names)) + if (fz_is_array(names)) { int l = 0; - int r = (fz_array_len(ctx, names) / 2) - 1; + int r = (fz_array_len(names) / 2) - 1; while (l <= r) { int m = (l + r) >> 1; int c; - fz_obj *key = fz_array_get(ctx, names, m * 2); - fz_obj *val = fz_array_get(ctx, names, m * 2 + 1); + fz_obj *key = fz_array_get(names, m * 2); + fz_obj *val = fz_array_get(names, m * 2 + 1); c = fz_objcmp(needle, key); if (c < 0) @@ -59,9 +59,9 @@ pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *needle) { fz_context *ctx = xref->ctx; - fz_obj *root = fz_dict_gets(ctx, xref->trailer, "Root"); - fz_obj *names = fz_dict_gets(ctx, root, "Names"); - fz_obj *tree = fz_dict_gets(ctx, names, which); + fz_obj *root = fz_dict_gets(xref->trailer, "Root"); + fz_obj *names = fz_dict_gets(root, "Names"); + fz_obj *tree = fz_dict_gets(names, which); return pdf_lookup_name_imp(ctx, tree, needle); } @@ -70,24 +70,24 @@ pdf_lookup_dest(pdf_xref *xref, fz_obj *needle) { fz_context *ctx = xref->ctx; - fz_obj *root = fz_dict_gets(ctx, xref->trailer, "Root"); - fz_obj *dests = fz_dict_gets(ctx, root, "Dests"); - fz_obj *names = fz_dict_gets(ctx, root, "Names"); + fz_obj *root = fz_dict_gets(xref->trailer, "Root"); + fz_obj *dests = fz_dict_gets(root, "Dests"); + fz_obj *names = fz_dict_gets(root, "Names"); fz_obj *dest = NULL; /* PDF 1.1 has destinations in a dictionary */ if (dests) { - if (fz_is_name(ctx, needle)) - return fz_dict_get(ctx, dests, needle); + if (fz_is_name(needle)) + return fz_dict_get(dests, needle); else - return fz_dict_gets(ctx, dests, fz_to_str_buf(ctx, needle)); + return fz_dict_gets(dests, fz_to_str_buf(needle)); } /* PDF 1.2 has destinations in a name tree */ if (names && !dest) { - fz_obj *tree = fz_dict_gets(ctx, names, "Dests"); + fz_obj *tree = fz_dict_gets(names, "Dests"); return pdf_lookup_name_imp(ctx, tree, needle); } @@ -98,31 +98,31 @@ static void pdf_load_name_tree_imp(fz_obj *dict, pdf_xref *xref, fz_obj *node) { fz_context *ctx = xref->ctx; - fz_obj *kids = fz_dict_gets(ctx, node, "Kids"); - fz_obj *names = fz_dict_gets(ctx, node, "Names"); + fz_obj *kids = fz_dict_gets(node, "Kids"); + fz_obj *names = fz_dict_gets(node, "Names"); int i; if (kids) { - for (i = 0; i < fz_array_len(ctx, kids); i++) - pdf_load_name_tree_imp(dict, xref, fz_array_get(ctx, kids, i)); + for (i = 0; i < fz_array_len(kids); i++) + pdf_load_name_tree_imp(dict, xref, fz_array_get(kids, i)); } if (names) { - for (i = 0; i + 1 < fz_array_len(ctx, names); i += 2) + for (i = 0; i + 1 < fz_array_len(names); i += 2) { - fz_obj *key = fz_array_get(ctx, names, i); - fz_obj *val = fz_array_get(ctx, names, i + 1); - if (fz_is_string(ctx, key)) + fz_obj *key = fz_array_get(names, i); + fz_obj *val = fz_array_get(names, i + 1); + if (fz_is_string(key)) { key = pdf_to_utf8_name(ctx, key); - fz_dict_put(ctx, dict, key, val); - fz_drop_obj(ctx, key); + fz_dict_put(dict, key, val); + fz_drop_obj(key); } - else if (fz_is_name(ctx, key)) + else if (fz_is_name(key)) { - fz_dict_put(ctx, dict, key, val); + fz_dict_put(dict, key, val); } } } @@ -133,10 +133,10 @@ pdf_load_name_tree(pdf_xref *xref, char *which) { fz_context *ctx = xref->ctx; - fz_obj *root = fz_dict_gets(ctx, xref->trailer, "Root"); - fz_obj *names = fz_dict_gets(ctx, root, "Names"); - fz_obj *tree = fz_dict_gets(ctx, names, which); - if (fz_is_dict(ctx, tree)) + fz_obj *root = fz_dict_gets(xref->trailer, "Root"); + fz_obj *names = fz_dict_gets(root, "Names"); + fz_obj *tree = fz_dict_gets(names, which); + if (fz_is_dict(tree)) { fz_obj *dict = fz_new_dict(ctx, 100); pdf_load_name_tree_imp(dict, xref, tree); diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c index 0e6ab233..677a701f 100644 --- a/pdf/pdf_outline.c +++ b/pdf/pdf_outline.c @@ -4,11 +4,11 @@ static pdf_outline * pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict) { + fz_context *ctx = xref->ctx; pdf_outline *node; fz_obj *obj; - fz_context *ctx = xref->ctx; - if (fz_is_null(ctx, dict)) + if (fz_is_null(dict)) return NULL; node = fz_malloc(ctx, sizeof(pdf_outline)); @@ -18,22 +18,22 @@ pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict) node->next = NULL; node->count = 0; - obj = fz_dict_gets(ctx, dict, "Title"); + obj = fz_dict_gets(dict, "Title"); if (obj) node->title = pdf_to_utf8(ctx, obj); - obj = fz_dict_gets(ctx, dict, "Count"); + obj = fz_dict_gets(dict, "Count"); if (obj) - node->count = fz_to_int(ctx, obj); + node->count = fz_to_int(obj); - if (fz_dict_gets(ctx, dict, "Dest") || fz_dict_gets(ctx, dict, "A")) + if (fz_dict_gets(dict, "Dest") || fz_dict_gets(dict, "A")) node->link = pdf_load_link(xref, dict); - obj = fz_dict_gets(ctx, dict, "First"); + obj = fz_dict_gets(dict, "First"); if (obj) node->child = pdf_load_outline_imp(xref, obj); - obj = fz_dict_gets(ctx, dict, "Next"); + obj = fz_dict_gets(dict, "Next"); if (obj) node->next = pdf_load_outline_imp(xref, obj); @@ -44,11 +44,10 @@ pdf_outline * pdf_load_outline(pdf_xref *xref) { fz_obj *root, *obj, *first; - fz_context *ctx = xref->ctx; - root = fz_dict_gets(ctx, xref->trailer, "Root"); - obj = fz_dict_gets(ctx, root, "Outlines"); - first = fz_dict_gets(ctx, obj, "First"); + root = fz_dict_gets(xref->trailer, "Root"); + obj = fz_dict_gets(root, "Outlines"); + first = fz_dict_gets(obj, "First"); if (first) return pdf_load_outline_imp(xref, first); @@ -83,7 +82,7 @@ pdf_debug_outline(fz_context *ctx, pdf_outline *outline, int level) printf("<NULL> "); if (outline->link) - fz_debug_obj(ctx, outline->link->dest); + fz_debug_obj(outline->link->dest); else printf("<NULL>\n"); diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 724a4d13..88825531 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -34,52 +34,52 @@ pdf_load_page_tree_node(pdf_xref *xref, fz_obj *node, struct info info) fz_context *ctx = xref->ctx; /* prevent infinite recursion */ - if (fz_dict_gets(ctx, node, ".seen")) + if (fz_dict_gets(node, ".seen")) return; - kids = fz_dict_gets(ctx, node, "Kids"); - count = fz_dict_gets(ctx, node, "Count"); + kids = fz_dict_gets(node, "Kids"); + count = fz_dict_gets(node, "Count"); - if (fz_is_array(ctx, kids) && fz_is_int(ctx, count)) + if (fz_is_array(kids) && fz_is_int(count)) { - obj = fz_dict_gets(ctx, node, "Resources"); + obj = fz_dict_gets(node, "Resources"); if (obj) info.resources = obj; - obj = fz_dict_gets(ctx, node, "MediaBox"); + obj = fz_dict_gets(node, "MediaBox"); if (obj) info.mediabox = obj; - obj = fz_dict_gets(ctx, node, "CropBox"); + obj = fz_dict_gets(node, "CropBox"); if (obj) info.cropbox = obj; - obj = fz_dict_gets(ctx, node, "Rotate"); + obj = fz_dict_gets(node, "Rotate"); if (obj) info.rotate = obj; tmp = fz_new_null(ctx); - fz_dict_puts(ctx, node, ".seen", tmp); - fz_drop_obj(ctx, tmp); + fz_dict_puts(node, ".seen", tmp); + fz_drop_obj(tmp); - n = fz_array_len(ctx, kids); + n = fz_array_len(kids); for (i = 0; i < n; i++) { - obj = fz_array_get(ctx, kids, i); + obj = fz_array_get(kids, i); pdf_load_page_tree_node(xref, obj, info); } - fz_dict_dels(ctx, node, ".seen"); + fz_dict_dels(node, ".seen"); } else { - dict = fz_resolve_indirect(ctx, node); + dict = fz_resolve_indirect(node); - if (info.resources && !fz_dict_gets(ctx, dict, "Resources")) - fz_dict_puts(ctx, dict, "Resources", info.resources); - if (info.mediabox && !fz_dict_gets(ctx, dict, "MediaBox")) - fz_dict_puts(ctx, dict, "MediaBox", info.mediabox); - if (info.cropbox && !fz_dict_gets(ctx, dict, "CropBox")) - fz_dict_puts(ctx, dict, "CropBox", info.cropbox); - if (info.rotate && !fz_dict_gets(ctx, dict, "Rotate")) - fz_dict_puts(ctx, dict, "Rotate", info.rotate); + if (info.resources && !fz_dict_gets(dict, "Resources")) + fz_dict_puts(dict, "Resources", info.resources); + if (info.mediabox && !fz_dict_gets(dict, "MediaBox")) + fz_dict_puts(dict, "MediaBox", info.mediabox); + if (info.cropbox && !fz_dict_gets(dict, "CropBox")) + fz_dict_puts(dict, "CropBox", info.cropbox); + if (info.rotate && !fz_dict_gets(dict, "Rotate")) + fz_dict_puts(dict, "Rotate", info.rotate); if (xref->page_len == xref->page_cap) { @@ -100,16 +100,16 @@ pdf_load_page_tree(pdf_xref *xref) { struct info info; fz_context *ctx = xref->ctx; - fz_obj *catalog = fz_dict_gets(ctx, xref->trailer, "Root"); - fz_obj *pages = fz_dict_gets(ctx, catalog, "Pages"); - fz_obj *count = fz_dict_gets(ctx, pages, "Count"); + fz_obj *catalog = fz_dict_gets(xref->trailer, "Root"); + fz_obj *pages = fz_dict_gets(catalog, "Pages"); + fz_obj *count = fz_dict_gets(pages, "Count"); - if (!fz_is_dict(ctx, pages)) + if (!fz_is_dict(pages)) return fz_error_make("missing page tree"); - if (!fz_is_int(ctx, count)) + if (!fz_is_int(count)) return fz_error_make("missing page count"); - xref->page_cap = fz_to_int(ctx, count); + xref->page_cap = fz_to_int(count); xref->page_len = 0; xref->page_refs = fz_calloc(ctx, xref->page_cap, sizeof(fz_obj*)); xref->page_objs = fz_calloc(ctx, xref->page_cap, sizeof(fz_obj*)); @@ -131,8 +131,8 @@ static int pdf_resources_use_blending(fz_context *ctx, fz_obj *rdb); static int pdf_extgstate_uses_blending(fz_context *ctx, fz_obj *dict) { - fz_obj *obj = fz_dict_gets(ctx, dict, "BM"); - if (fz_is_name(ctx, obj) && strcmp(fz_to_name(ctx, obj), "Normal")) + fz_obj *obj = fz_dict_gets(dict, "BM"); + if (fz_is_name(obj) && strcmp(fz_to_name(obj), "Normal")) return 1; return 0; } @@ -141,17 +141,17 @@ static int pdf_pattern_uses_blending(fz_context *ctx, fz_obj *dict) { fz_obj *obj; - obj = fz_dict_gets(ctx, dict, "Resources"); + obj = fz_dict_gets(dict, "Resources"); if (pdf_resources_use_blending(ctx, obj)) return 1; - obj = fz_dict_gets(ctx, dict, "ExtGState"); + obj = fz_dict_gets(dict, "ExtGState"); return pdf_extgstate_uses_blending(ctx, obj); } static int pdf_xobject_uses_blending(fz_context *ctx, fz_obj *dict) { - fz_obj *obj = fz_dict_gets(ctx, dict, "Resources"); + fz_obj *obj = fz_dict_gets(dict, "Resources"); return pdf_resources_use_blending(ctx, obj); } @@ -166,37 +166,37 @@ pdf_resources_use_blending(fz_context *ctx, fz_obj *rdb) return 0; /* stop on cyclic resource dependencies */ - if (fz_dict_gets(ctx, rdb, ".useBM")) - return fz_to_bool(ctx, fz_dict_gets(ctx, rdb, ".useBM")); + if (fz_dict_gets(rdb, ".useBM")) + return fz_to_bool(fz_dict_gets(rdb, ".useBM")); tmp = fz_new_bool(ctx, 0); - fz_dict_puts(ctx, rdb, ".useBM", tmp); - fz_drop_obj(ctx, tmp); + fz_dict_puts(rdb, ".useBM", tmp); + fz_drop_obj(tmp); - dict = fz_dict_gets(ctx, rdb, "ExtGState"); - n = fz_dict_len(ctx, dict); + dict = fz_dict_gets(rdb, "ExtGState"); + n = fz_dict_len(dict); for (i = 0; i < n; i++) - if (pdf_extgstate_uses_blending(ctx, fz_dict_get_val(ctx, dict, i))) + if (pdf_extgstate_uses_blending(ctx, fz_dict_get_val(dict, i))) goto found; - dict = fz_dict_gets(ctx, rdb, "Pattern"); - n = fz_dict_len(ctx, dict); + dict = fz_dict_gets(rdb, "Pattern"); + n = fz_dict_len(dict); for (i = 0; i < n; i++) - if (pdf_pattern_uses_blending(ctx, fz_dict_get_val(ctx, dict, i))) + if (pdf_pattern_uses_blending(ctx, fz_dict_get_val(dict, i))) goto found; - dict = fz_dict_gets(ctx, rdb, "XObject"); - n = fz_dict_len(ctx, dict); + dict = fz_dict_gets(rdb, "XObject"); + n = fz_dict_len(dict); for (i = 0; i < n; i++) - if (pdf_xobject_uses_blending(ctx, fz_dict_get_val(ctx, dict, i))) + if (pdf_xobject_uses_blending(ctx, fz_dict_get_val(dict, i))) goto found; return 0; found: tmp = fz_new_bool(ctx, 1); - fz_dict_puts(ctx, rdb, ".useBM", tmp); - fz_drop_obj(ctx, tmp); + fz_dict_puts(rdb, ".useBM", tmp); + fz_drop_obj(tmp); return 1; } @@ -213,10 +213,10 @@ pdf_load_page_contents_array(fz_buffer **bigbufp, pdf_xref *xref, fz_obj *list) big = fz_new_buffer(ctx, 32 * 1024); - n = fz_array_len(ctx, list); + n = fz_array_len(list); for (i = 0; i < n; i++) { - fz_obj *stm = fz_array_get(ctx, list, i); + fz_obj *stm = fz_array_get(list, i); error = pdf_load_stream(&one, xref, fz_to_num(stm), fz_to_gen(stm)); if (error) { @@ -249,7 +249,7 @@ pdf_load_page_contents(fz_buffer **bufp, pdf_xref *xref, fz_obj *obj) fz_error error; fz_context *ctx = xref->ctx; - if (fz_is_array(ctx, obj)) + if (fz_is_array(obj)) { error = pdf_load_page_contents_array(bufp, xref, obj); if (error) @@ -298,7 +298,7 @@ pdf_load_page(pdf_page **pagep, pdf_xref *xref, int number) page->links = NULL; page->annots = NULL; - obj = fz_dict_gets(ctx, pageobj, "MediaBox"); + obj = fz_dict_gets(pageobj, "MediaBox"); bbox = fz_round_rect(pdf_to_rect(ctx, obj)); if (fz_is_empty_rect(pdf_to_rect(ctx, obj))) { @@ -309,8 +309,8 @@ pdf_load_page(pdf_page **pagep, pdf_xref *xref, int number) bbox.y1 = 792; } - obj = fz_dict_gets(ctx, pageobj, "CropBox"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(pageobj, "CropBox"); + if (fz_is_array(obj)) { fz_bbox cropbox = fz_round_rect(pdf_to_rect(ctx, obj)); bbox = fz_intersect_bbox(bbox, cropbox); @@ -327,20 +327,20 @@ pdf_load_page(pdf_page **pagep, pdf_xref *xref, int number) page->mediabox = fz_unit_rect; } - page->rotate = fz_to_int(ctx, fz_dict_gets(ctx, pageobj, "Rotate")); + page->rotate = fz_to_int(fz_dict_gets(pageobj, "Rotate")); - obj = fz_dict_gets(ctx, pageobj, "Annots"); + obj = fz_dict_gets(pageobj, "Annots"); if (obj) { pdf_load_links(&page->links, xref, obj); pdf_load_annots(&page->annots, xref, obj); } - page->resources = fz_dict_gets(ctx, pageobj, "Resources"); + page->resources = fz_dict_gets(pageobj, "Resources"); if (page->resources) fz_keep_obj(page->resources); - obj = fz_dict_gets(ctx, pageobj, "Contents"); + obj = fz_dict_gets(pageobj, "Contents"); error = pdf_load_page_contents(&page->contents, xref, obj); if (error) { @@ -363,7 +363,7 @@ void pdf_free_page(fz_context *ctx, pdf_page *page) { if (page->resources) - fz_drop_obj(ctx, page->resources); + fz_drop_obj(page->resources); if (page->contents) fz_drop_buffer(ctx, page->contents); if (page->links) diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index e01734d7..04c67eca 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -5,10 +5,10 @@ fz_rect pdf_to_rect(fz_context *ctx, fz_obj *array) { fz_rect r; - float a = fz_to_real(ctx, fz_array_get(ctx, array, 0)); - float b = fz_to_real(ctx, fz_array_get(ctx, array, 1)); - float c = fz_to_real(ctx, fz_array_get(ctx, array, 2)); - float d = fz_to_real(ctx, fz_array_get(ctx, array, 3)); + float a = fz_to_real(fz_array_get(array, 0)); + float b = fz_to_real(fz_array_get(array, 1)); + float c = fz_to_real(fz_array_get(array, 2)); + float d = fz_to_real(fz_array_get(array, 3)); r.x0 = MIN(a, c); r.y0 = MIN(b, d); r.x1 = MAX(a, c); @@ -20,12 +20,12 @@ fz_matrix pdf_to_matrix(fz_context *ctx, fz_obj *array) { fz_matrix m; - m.a = fz_to_real(ctx, fz_array_get(ctx, array, 0)); - m.b = fz_to_real(ctx, fz_array_get(ctx, array, 1)); - m.c = fz_to_real(ctx, fz_array_get(ctx, array, 2)); - m.d = fz_to_real(ctx, fz_array_get(ctx, array, 3)); - m.e = fz_to_real(ctx, fz_array_get(ctx, array, 4)); - m.f = fz_to_real(ctx, fz_array_get(ctx, array, 5)); + m.a = fz_to_real(fz_array_get(array, 0)); + m.b = fz_to_real(fz_array_get(array, 1)); + m.c = fz_to_real(fz_array_get(array, 2)); + m.d = fz_to_real(fz_array_get(array, 3)); + m.e = fz_to_real(fz_array_get(array, 4)); + m.f = fz_to_real(fz_array_get(array, 5)); return m; } @@ -33,9 +33,9 @@ pdf_to_matrix(fz_context *ctx, fz_obj *array) char * pdf_to_utf8(fz_context *ctx, fz_obj *src) { - unsigned char *srcptr = (unsigned char *) fz_to_str_buf(ctx, src); + unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src); char *dstptr, *dst; - int srclen = fz_to_str_len(ctx, src); + int srclen = fz_to_str_len(src); int dstlen = 0; int ucs; int i; @@ -94,9 +94,9 @@ pdf_to_utf8(fz_context *ctx, fz_obj *src) unsigned short * pdf_to_ucs2(fz_context *ctx, fz_obj *src) { - unsigned char *srcptr = (unsigned char *) fz_to_str_buf(ctx, src); + unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src); unsigned short *dstptr, *dst; - int srclen = fz_to_str_len(ctx, src); + int srclen = fz_to_str_len(src); int i; if (srclen >= 2 && srcptr[0] == 254 && srcptr[1] == 255) @@ -188,7 +188,7 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap error = pdf_lex(&tok, file, buf, cap, &len); if (error) { - fz_drop_obj(ctx, ary); + fz_drop_obj(ary); return fz_error_note(error, "cannot parse array"); } @@ -197,14 +197,14 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap if (n > 0) { obj = fz_new_int(ctx, a); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); } if (n > 1) { obj = fz_new_int(ctx, b); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); } n = 0; } @@ -212,8 +212,8 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap if (tok == PDF_TOK_INT && n == 2) { obj = fz_new_int(ctx, a); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); a = b; n --; } @@ -235,12 +235,12 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap case PDF_TOK_R: if (n != 2) { - fz_drop_obj(ctx, ary); + fz_drop_obj(ary); return fz_error_make("cannot parse indirect reference in array"); } obj = fz_new_indirect(ctx, a, b, xref); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); n = 0; break; @@ -248,57 +248,57 @@ pdf_parse_array(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap error = pdf_parse_array(&obj, xref, file, buf, cap); if (error) { - fz_drop_obj(ctx, ary); + fz_drop_obj(ary); return fz_error_note(error, "cannot parse array"); } - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_OPEN_DICT: error = pdf_parse_dict(&obj, xref, file, buf, cap); if (error) { - fz_drop_obj(ctx, ary); + fz_drop_obj(ary); return fz_error_note(error, "cannot parse array"); } - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_NAME: obj = fz_new_name(ctx, buf); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_REAL: obj = fz_new_real(ctx, fz_atof(buf)); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_STRING: obj = fz_new_string(ctx, buf, len); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_TRUE: obj = fz_new_bool(ctx, 1); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_FALSE: obj = fz_new_bool(ctx, 0); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; case PDF_TOK_NULL: obj = fz_new_null(ctx); - fz_array_push(ctx, ary, obj); - fz_drop_obj(ctx, obj); + fz_array_push(ary, obj); + fz_drop_obj(obj); break; default: - fz_drop_obj(ctx, ary); + fz_drop_obj(ary); return fz_error_make("cannot parse token in array"); } } @@ -323,7 +323,7 @@ pdf_parse_dict(fz_obj **op, pdf_xref *xref, fz_stream *file, char *buf, int cap) error = pdf_lex(&tok, file, buf, cap, &len); if (error) { - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); return fz_error_note(error, "cannot parse dict"); } @@ -343,7 +343,7 @@ skip: if (tok != PDF_TOK_NAME) { - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); return fz_error_make("invalid key in dict"); } @@ -352,8 +352,8 @@ skip: error = pdf_lex(&tok, file, buf, cap, &len); if (error) { - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_note(error, "cannot parse dict"); } @@ -363,8 +363,8 @@ skip: error = pdf_parse_array(&val, xref, file, buf, cap); if (error) { - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_note(error, "cannot parse dict"); } break; @@ -373,8 +373,8 @@ skip: error = pdf_parse_dict(&val, xref, file, buf, cap); if (error) { - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_note(error, "cannot parse dict"); } break; @@ -392,17 +392,17 @@ skip: error = pdf_lex(&tok, file, buf, cap, &len); if (error) { - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_note(error, "cannot parse dict"); } if (tok == PDF_TOK_CLOSE_DICT || tok == PDF_TOK_NAME || (tok == PDF_TOK_KEYWORD && !strcmp(buf, "ID"))) { val = fz_new_int(ctx, a); - fz_dict_put(ctx, dict, key, val); - fz_drop_obj(ctx, val); - fz_drop_obj(ctx, key); + fz_dict_put(dict, key, val); + fz_drop_obj(val); + fz_drop_obj(key); goto skip; } if (tok == PDF_TOK_INT) @@ -411,8 +411,8 @@ skip: error = pdf_lex(&tok, file, buf, cap, &len); if (error) { - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_note(error, "cannot parse dict"); } if (tok == PDF_TOK_R) @@ -421,19 +421,19 @@ skip: break; } } - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_make("invalid indirect reference in dict"); default: - fz_drop_obj(ctx, key); - fz_drop_obj(ctx, dict); + fz_drop_obj(key); + fz_drop_obj(dict); return fz_error_make("unknown token in dict"); } - fz_dict_put(ctx, dict, key, val); - fz_drop_obj(ctx, val); - fz_drop_obj(ctx, key); + fz_dict_put(dict, key, val); + fz_drop_obj(val); + fz_drop_obj(key); } } @@ -567,7 +567,7 @@ pdf_parse_ind_obj(fz_obj **op, pdf_xref *xref, error = pdf_lex(&tok, file, buf, cap, &len); if (error) { - fz_drop_obj(ctx, obj); + fz_drop_obj(obj); return fz_error_note(error, "cannot parse indirect object (%d %d R)", num, gen); } diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c index d058b2b5..c50f93ae 100644 --- a/pdf/pdf_pattern.c +++ b/pdf/pdf_pattern.c @@ -23,20 +23,20 @@ pdf_load_pattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict) /* Store pattern now, to avoid possible recursion if objects refer back to this one */ pdf_store_item(ctx, xref->store, (pdf_store_keep_fn *)pdf_keep_pattern, (pdf_store_drop_fn *)pdf_drop_pattern, dict, pat); - pat->ismask = fz_to_int(ctx, fz_dict_gets(ctx, dict, "PaintType")) == 2; - pat->xstep = fz_to_real(ctx, fz_dict_gets(ctx, dict, "XStep")); - pat->ystep = fz_to_real(ctx, fz_dict_gets(ctx, dict, "YStep")); + pat->ismask = fz_to_int(fz_dict_gets(dict, "PaintType")) == 2; + pat->xstep = fz_to_real(fz_dict_gets(dict, "XStep")); + pat->ystep = fz_to_real(fz_dict_gets(dict, "YStep")); - obj = fz_dict_gets(ctx, dict, "BBox"); + obj = fz_dict_gets(dict, "BBox"); pat->bbox = pdf_to_rect(ctx, obj); - obj = fz_dict_gets(ctx, dict, "Matrix"); + obj = fz_dict_gets(dict, "Matrix"); if (obj) pat->matrix = pdf_to_matrix(ctx, obj); else pat->matrix = fz_identity; - pat->resources = fz_dict_gets(ctx, dict, "Resources"); + pat->resources = fz_dict_gets(dict, "Resources"); if (pat->resources) fz_keep_obj(pat->resources); @@ -65,7 +65,7 @@ pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat) if (pat && --pat->refs == 0) { if (pat->resources) - fz_drop_obj(ctx, pat->resources); + fz_drop_obj(pat->resources); if (pat->contents) fz_drop_buffer(ctx, pat->contents); fz_free(ctx, pat); diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index e31822af..83b0d814 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -20,7 +20,6 @@ pdf_repair_obj(fz_stream *file, char *buf, int cap, int *stmofsp, int *stmlenp, int stm_len; int len; int n; - fz_context *ctx = file->ctx; *stmofsp = 0; *stmlenp = -1; @@ -39,31 +38,31 @@ pdf_repair_obj(fz_stream *file, char *buf, int cap, int *stmofsp, int *stmlenp, if (error) return fz_error_note(error, "cannot parse object"); - obj = fz_dict_gets(ctx, dict, "Type"); - if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "XRef")) + obj = fz_dict_gets(dict, "Type"); + if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "XRef")) { - obj = fz_dict_gets(ctx, dict, "Encrypt"); + obj = fz_dict_gets(dict, "Encrypt"); if (obj) { if (*encrypt) - fz_drop_obj(ctx, *encrypt); + fz_drop_obj(*encrypt); *encrypt = fz_keep_obj(obj); } - obj = fz_dict_gets(ctx, dict, "ID"); + obj = fz_dict_gets(dict, "ID"); if (obj) { if (*id) - fz_drop_obj(ctx, *id); + fz_drop_obj(*id); *id = fz_keep_obj(obj); } } - obj = fz_dict_gets(ctx, dict, "Length"); - if (fz_is_int(ctx, obj)) - stm_len = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "Length"); + if (fz_is_int(obj)) + stm_len = fz_to_int(obj); - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); } while ( tok != PDF_TOK_STREAM && @@ -135,15 +134,14 @@ pdf_repair_obj_stm(pdf_xref *xref, int num, int gen) int tok; int i, n, count; char buf[256]; - fz_context *ctx = xref->ctx; error = pdf_load_object(&obj, xref, num, gen); if (error) return fz_error_note(error, "cannot load object stream object (%d %d R)", num, gen); - count = fz_to_int(ctx, fz_dict_gets(ctx, obj, "N")); + count = fz_to_int(fz_dict_gets(obj, "N")); - fz_drop_obj(ctx, obj); + fz_drop_obj(obj); error = pdf_open_stream(&stm, xref, num, gen); if (error) @@ -297,39 +295,39 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize) goto cleanup; } - obj = fz_dict_gets(ctx, dict, "Encrypt"); + obj = fz_dict_gets(dict, "Encrypt"); if (obj) { if (encrypt) - fz_drop_obj(ctx, encrypt); + fz_drop_obj(encrypt); encrypt = fz_keep_obj(obj); } - obj = fz_dict_gets(ctx, dict, "ID"); + obj = fz_dict_gets(dict, "ID"); if (obj) { if (id) - fz_drop_obj(ctx, id); + fz_drop_obj(id); id = fz_keep_obj(obj); } - obj = fz_dict_gets(ctx, dict, "Root"); + obj = fz_dict_gets(dict, "Root"); if (obj) { if (root) - fz_drop_obj(ctx, root); + fz_drop_obj(root); root = fz_keep_obj(obj); } - obj = fz_dict_gets(ctx, dict, "Info"); + obj = fz_dict_gets(dict, "Info"); if (obj) { if (info) - fz_drop_obj(ctx, info); + fz_drop_obj(info); info = fz_keep_obj(obj); } - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); } else if (tok == PDF_TOK_ERROR) @@ -362,10 +360,10 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize) } length = fz_new_int(ctx, list[i].stm_len); - fz_dict_puts(ctx, dict, "Length", length); - fz_drop_obj(ctx, length); + fz_dict_puts(dict, "Length", length); + fz_drop_obj(length); - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); } } @@ -393,18 +391,18 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize) xref->trailer = fz_new_dict(ctx, 5); obj = fz_new_int(ctx, maxnum + 1); - fz_dict_puts(ctx, xref->trailer, "Size", obj); - fz_drop_obj(ctx, obj); + fz_dict_puts(xref->trailer, "Size", obj); + fz_drop_obj(obj); if (root) { - fz_dict_puts(ctx, xref->trailer, "Root", root); - fz_drop_obj(ctx, root); + fz_dict_puts(xref->trailer, "Root", root); + fz_drop_obj(root); } if (info) { - fz_dict_puts(ctx, xref->trailer, "Info", info); - fz_drop_obj(ctx, info); + fz_dict_puts(xref->trailer, "Info", info); + fz_drop_obj(info); } if (encrypt) @@ -413,11 +411,11 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize) { /* create new reference with non-NULL xref pointer */ obj = fz_new_indirect(ctx, fz_to_num(encrypt), fz_to_gen(encrypt), xref); - fz_drop_obj(ctx, encrypt); + fz_drop_obj(encrypt); encrypt = obj; } - fz_dict_puts(ctx, xref->trailer, "Encrypt", encrypt); - fz_drop_obj(ctx, encrypt); + fz_dict_puts(xref->trailer, "Encrypt", encrypt); + fz_drop_obj(encrypt); } if (id) @@ -426,21 +424,21 @@ pdf_repair_xref(pdf_xref *xref, char *buf, int bufsize) { /* create new reference with non-NULL xref pointer */ obj = fz_new_indirect(ctx, fz_to_num(id), fz_to_gen(id), xref); - fz_drop_obj(ctx, id); + fz_drop_obj(id); id = obj; } - fz_dict_puts(ctx, xref->trailer, "ID", id); - fz_drop_obj(ctx, id); + fz_dict_puts(xref->trailer, "ID", id); + fz_drop_obj(id); } fz_free(ctx, list); return fz_okay; cleanup: - if (encrypt) fz_drop_obj(ctx, encrypt); - if (id) fz_drop_obj(ctx, id); - if (root) fz_drop_obj(ctx, root); - if (info) fz_drop_obj(ctx, info); + if (encrypt) fz_drop_obj(encrypt); + if (id) fz_drop_obj(id); + if (root) fz_drop_obj(root); + if (info) fz_drop_obj(info); fz_free(ctx, list); return error; /* already rethrown */ } @@ -450,16 +448,15 @@ pdf_repair_obj_stms(pdf_xref *xref) { fz_obj *dict; int i; - fz_context *ctx = xref->ctx; for (i = 0; i < xref->len; i++) { if (xref->table[i].stm_ofs) { pdf_load_object(&dict, xref, i, 0); - if (!strcmp(fz_to_name(ctx, fz_dict_gets(ctx, dict, "Type")), "ObjStm")) + if (!strcmp(fz_to_name(fz_dict_gets(dict, "Type")), "ObjStm")) pdf_repair_obj_stm(xref, i, 0); - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); } } diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index 53d5700d..a6819521 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -377,18 +377,18 @@ pdf_load_function_based_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, p x0 = y0 = 0; x1 = y1 = 1; - obj = fz_dict_gets(ctx, dict, "Domain"); - if (fz_array_len(ctx, obj) == 4) + obj = fz_dict_gets(dict, "Domain"); + if (fz_array_len(obj) == 4) { - x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0)); - x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1)); - y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 2)); - y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3)); + x0 = fz_to_real(fz_array_get(obj, 0)); + x1 = fz_to_real(fz_array_get(obj, 1)); + y0 = fz_to_real(fz_array_get(obj, 2)); + y1 = fz_to_real(fz_array_get(obj, 3)); } matrix = fz_identity; - obj = fz_dict_gets(ctx, dict, "Matrix"); - if (fz_array_len(ctx, obj) == 6) + obj = fz_dict_gets(dict, "Matrix"); + if (fz_array_len(obj) == 6) matrix = pdf_to_matrix(ctx, obj); for (yy = 0; yy < FUNSEGS; yy++) @@ -437,27 +437,27 @@ pdf_load_axial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs, struct vertex p1, p2; fz_context *ctx = xref->ctx; - obj = fz_dict_gets(ctx, dict, "Coords"); - x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0)); - y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 1)); - x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 2)); - y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3)); + obj = fz_dict_gets(dict, "Coords"); + x0 = fz_to_real(fz_array_get(obj, 0)); + y0 = fz_to_real(fz_array_get(obj, 1)); + x1 = fz_to_real(fz_array_get(obj, 2)); + y1 = fz_to_real(fz_array_get(obj, 3)); d0 = 0; d1 = 1; - obj = fz_dict_gets(ctx, dict, "Domain"); - if (fz_array_len(ctx, obj) == 2) + obj = fz_dict_gets(dict, "Domain"); + if (fz_array_len(obj) == 2) { - d0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0)); - d1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1)); + d0 = fz_to_real(fz_array_get(obj, 0)); + d1 = fz_to_real(fz_array_get(obj, 1)); } e0 = e1 = 0; - obj = fz_dict_gets(ctx, dict, "Extend"); - if (fz_array_len(ctx, obj) == 2) + obj = fz_dict_gets(dict, "Extend"); + if (fz_array_len(obj) == 2) { - e0 = fz_to_bool(ctx, fz_array_get(ctx, obj, 0)); - e1 = fz_to_bool(ctx, fz_array_get(ctx, obj, 1)); + e0 = fz_to_bool(fz_array_get(obj, 0)); + e1 = fz_to_bool(fz_array_get(obj, 1)); } pdf_sample_shade_function(shade, funcs, func, d0, d1); @@ -488,29 +488,29 @@ pdf_load_radial_shading(fz_shade *shade, pdf_xref *xref, fz_obj *dict, int funcs struct vertex p1, p2; fz_context *ctx = xref->ctx; - obj = fz_dict_gets(ctx, dict, "Coords"); - x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0)); - y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 1)); - r0 = fz_to_real(ctx, fz_array_get(ctx, obj, 2)); - x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3)); - y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 4)); - r1 = fz_to_real(ctx, fz_array_get(ctx, obj, 5)); + obj = fz_dict_gets(dict, "Coords"); + x0 = fz_to_real(fz_array_get(obj, 0)); + y0 = fz_to_real(fz_array_get(obj, 1)); + r0 = fz_to_real(fz_array_get(obj, 2)); + x1 = fz_to_real(fz_array_get(obj, 3)); + y1 = fz_to_real(fz_array_get(obj, 4)); + r1 = fz_to_real(fz_array_get(obj, 5)); d0 = 0; d1 = 1; - obj = fz_dict_gets(ctx, dict, "Domain"); - if (fz_array_len(ctx, obj) == 2) + obj = fz_dict_gets(dict, "Domain"); + if (fz_array_len(obj) == 2) { - d0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0)); - d1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1)); + d0 = fz_to_real(fz_array_get(obj, 0)); + d1 = fz_to_real(fz_array_get(obj, 1)); } e0 = e1 = 0; - obj = fz_dict_gets(ctx, dict, "Extend"); - if (fz_array_len(ctx, obj) == 2) + obj = fz_dict_gets(dict, "Extend"); + if (fz_array_len(obj) == 2) { - e0 = fz_to_bool(ctx, fz_array_get(ctx, obj, 0)); - e1 = fz_to_bool(ctx, fz_array_get(ctx, obj, 1)); + e0 = fz_to_bool(fz_array_get(obj, 0)); + e1 = fz_to_bool(fz_array_get(obj, 1)); } pdf_sample_shade_function(shade, funcs, func, d0, d1); @@ -557,7 +557,6 @@ pdf_load_mesh_params(pdf_xref *xref, fz_obj *dict, struct mesh_params *p) { fz_obj *obj; int i, n; - fz_context *ctx = xref->ctx; p->x0 = p->y0 = 0; p->x1 = p->y1 = 1; @@ -567,23 +566,23 @@ pdf_load_mesh_params(pdf_xref *xref, fz_obj *dict, struct mesh_params *p) p->c1[i] = 1; } - p->vprow = fz_to_int(ctx, fz_dict_gets(ctx, dict, "VerticesPerRow")); - p->bpflag = fz_to_int(ctx, fz_dict_gets(ctx, dict, "BitsPerFlag")); - p->bpcoord = fz_to_int(ctx, fz_dict_gets(ctx, dict, "BitsPerCoordinate")); - p->bpcomp = fz_to_int(ctx, fz_dict_gets(ctx, dict, "BitsPerComponent")); + p->vprow = fz_to_int(fz_dict_gets(dict, "VerticesPerRow")); + p->bpflag = fz_to_int(fz_dict_gets(dict, "BitsPerFlag")); + p->bpcoord = fz_to_int(fz_dict_gets(dict, "BitsPerCoordinate")); + p->bpcomp = fz_to_int(fz_dict_gets(dict, "BitsPerComponent")); - obj = fz_dict_gets(ctx, dict, "Decode"); - if (fz_array_len(ctx, obj) >= 6) + obj = fz_dict_gets(dict, "Decode"); + if (fz_array_len(obj) >= 6) { - n = (fz_array_len(ctx, obj) - 4) / 2; - p->x0 = fz_to_real(ctx, fz_array_get(ctx, obj, 0)); - p->x1 = fz_to_real(ctx, fz_array_get(ctx, obj, 1)); - p->y0 = fz_to_real(ctx, fz_array_get(ctx, obj, 2)); - p->y1 = fz_to_real(ctx, fz_array_get(ctx, obj, 3)); + n = (fz_array_len(obj) - 4) / 2; + p->x0 = fz_to_real(fz_array_get(obj, 0)); + p->x1 = fz_to_real(fz_array_get(obj, 1)); + p->y0 = fz_to_real(fz_array_get(obj, 2)); + p->y1 = fz_to_real(fz_array_get(obj, 3)); for (i = 0; i < n; i++) { - p->c0[i] = fz_to_real(ctx, fz_array_get(ctx, obj, 4 + i * 2)); - p->c1[i] = fz_to_real(ctx, fz_array_get(ctx, obj, 5 + i * 2)); + p->c0[i] = fz_to_real(fz_array_get(obj, 4 + i * 2)); + p->c1[i] = fz_to_real(fz_array_get(obj, 5 + i * 2)); } } @@ -989,10 +988,10 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix funcs = 0; - obj = fz_dict_gets(ctx, dict, "ShadingType"); - type = fz_to_int(ctx, obj); + obj = fz_dict_gets(dict, "ShadingType"); + type = fz_to_int(obj); - obj = fz_dict_gets(ctx, dict, "ColorSpace"); + obj = fz_dict_gets(dict, "ColorSpace"); if (!obj) { fz_drop_shade(ctx, shade); @@ -1005,22 +1004,22 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix return fz_error_note(error, "cannot load colorspace (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); } - obj = fz_dict_gets(ctx, dict, "Background"); + obj = fz_dict_gets(dict, "Background"); if (obj) { shade->use_background = 1; for (i = 0; i < shade->colorspace->n; i++) - shade->background[i] = fz_to_real(ctx, fz_array_get(ctx, obj, i)); + shade->background[i] = fz_to_real(fz_array_get(obj, i)); } - obj = fz_dict_gets(ctx, dict, "BBox"); - if (fz_is_array(ctx, obj)) + obj = fz_dict_gets(dict, "BBox"); + if (fz_is_array(obj)) { shade->bbox = pdf_to_rect(ctx, obj); } - obj = fz_dict_gets(ctx, dict, "Function"); - if (fz_is_dict(ctx, obj)) + obj = fz_dict_gets(dict, "Function"); + if (fz_is_dict(obj)) { funcs = 1; @@ -1031,9 +1030,9 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix goto cleanup; } } - else if (fz_is_array(ctx, obj)) + else if (fz_is_array(obj)) { - funcs = fz_array_len(ctx, obj); + funcs = fz_array_len(obj); if (funcs != 1 && funcs != shade->colorspace->n) { error = fz_error_make("incorrect number of shading functions"); @@ -1042,7 +1041,7 @@ pdf_load_shading_dict(fz_shade **shadep, pdf_xref *xref, fz_obj *dict, fz_matrix for (i = 0; i < funcs; i++) { - error = pdf_load_function(&func[i], xref, fz_array_get(ctx, obj, i)); + error = pdf_load_function(&func[i], xref, fz_array_get(obj, i)); if (error) { error = fz_error_note(error, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); @@ -1110,24 +1109,24 @@ pdf_load_shading(fz_shade **shadep, pdf_xref *xref, fz_obj *dict) } /* Type 2 pattern dictionary */ - if (fz_dict_gets(ctx, dict, "PatternType")) + if (fz_dict_gets(dict, "PatternType")) { - obj = fz_dict_gets(ctx, dict, "Matrix"); + obj = fz_dict_gets(dict, "Matrix"); if (obj) mat = pdf_to_matrix(ctx, obj); else mat = fz_identity; - obj = fz_dict_gets(ctx, dict, "ExtGState"); + obj = fz_dict_gets(dict, "ExtGState"); if (obj) { - if (fz_dict_gets(ctx, obj, "CA") || fz_dict_gets(ctx, obj, "ca")) + if (fz_dict_gets(obj, "CA") || fz_dict_gets(obj, "ca")) { fz_warn("shading with alpha not supported"); } } - obj = fz_dict_gets(ctx, dict, "Shading"); + obj = fz_dict_gets(dict, "Shading"); if (!obj) return fz_error_make("syntaxerror: missing shading dictionary"); diff --git a/pdf/pdf_store.c b/pdf/pdf_store.c index 346afc5d..c8b8ba1c 100644 --- a/pdf/pdf_store.c +++ b/pdf/pdf_store.c @@ -120,7 +120,7 @@ pdf_remove_item(fz_context *ctx, pdf_store *store, pdf_store_drop_fn *drop_func, { fz_hash_remove(store->hash, &refkey); item->drop_func(ctx, item->val); - fz_drop_obj(ctx, item->key); + fz_drop_obj(item->key); fz_free(ctx, item); } } @@ -137,7 +137,7 @@ pdf_remove_item(fz_context *ctx, pdf_store *store, pdf_store_drop_fn *drop_func, else prev->next = next; item->drop_func(ctx, item->val); - fz_drop_obj(ctx, item->key); + fz_drop_obj(item->key); fz_free(ctx, item); } else @@ -162,7 +162,7 @@ pdf_age_store(fz_context *ctx, pdf_store *store, int maxage) { fz_hash_remove(store->hash, refkey); item->drop_func(ctx, item->val); - fz_drop_obj(ctx, item->key); + fz_drop_obj(item->key); fz_free(ctx, item); i--; /* items with same hash may move into place */ } @@ -179,7 +179,7 @@ pdf_age_store(fz_context *ctx, pdf_store *store, int maxage) else prev->next = next; item->drop_func(ctx, item->val); - fz_drop_obj(ctx, item->key); + fz_drop_obj(item->key); fz_free(ctx, item); } else @@ -218,7 +218,7 @@ pdf_debug_store(fz_context *ctx, pdf_store *store) { next = item->next; printf("store[*] "); - fz_debug_obj(ctx, item->key); + fz_debug_obj(item->key); printf(" = %p\n", item->val); } } diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index 4fb9adce..ccf96da9 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -32,18 +32,18 @@ pdf_stream_has_crypt(fz_context *ctx, fz_obj *stm) fz_obj *obj; int i; - filters = fz_dict_getsa(ctx, stm, "Filter", "F"); + filters = fz_dict_getsa(stm, "Filter", "F"); if (filters) { - if (!strcmp(fz_to_name(ctx, filters), "Crypt")) + if (!strcmp(fz_to_name(filters), "Crypt")) return 1; - if (fz_is_array(ctx, filters)) + if (fz_is_array(filters)) { - int n = fz_array_len(ctx, filters); + int n = fz_array_len(filters); for (i = 0; i < n; i++) { - obj = fz_array_get(ctx, filters, i); - if (!strcmp(fz_to_name(ctx, obj), "Crypt")) + obj = fz_array_get(filters, i); + if (!strcmp(fz_to_name(obj), "Crypt")) return 1; } } @@ -61,7 +61,7 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num, char *s; fz_context *ctx = chain->ctx; - s = fz_to_name(ctx, f); + s = fz_to_name(f); if (!strcmp(s, "ASCIIHexDecode") || !strcmp(s, "AHx")) return fz_open_ahxd(chain); @@ -80,23 +80,23 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num, else if (!strcmp(s, "FlateDecode") || !strcmp(s, "Fl")) { - fz_obj *obj = fz_dict_gets(ctx, p, "Predictor"); - if (fz_to_int(ctx, obj) > 1) + fz_obj *obj = fz_dict_gets(p, "Predictor"); + if (fz_to_int(obj) > 1) return fz_open_predict(fz_open_flated(chain), p); return fz_open_flated(chain); } else if (!strcmp(s, "LZWDecode") || !strcmp(s, "LZW")) { - fz_obj *obj = fz_dict_gets(ctx, p, "Predictor"); - if (fz_to_int(ctx, obj) > 1) + fz_obj *obj = fz_dict_gets(p, "Predictor"); + if (fz_to_int(obj) > 1) return fz_open_predict(fz_open_lzwd(chain, p), p); return fz_open_lzwd(chain, p); } else if (!strcmp(s, "JBIG2Decode")) { - fz_obj *obj = fz_dict_gets(ctx, p, "JBIG2Globals"); + fz_obj *obj = fz_dict_gets(p, "JBIG2Globals"); if (obj) { fz_buffer *globals; @@ -123,9 +123,9 @@ build_filter(fz_stream *chain, pdf_xref * xref, fz_obj * f, fz_obj * p, int num, return chain; } - name = fz_dict_gets(ctx, p, "Name"); - if (fz_is_name(ctx, name)) - return pdf_open_crypt_with_filter(chain, xref->crypt, fz_to_name(ctx, name), num, gen); + name = fz_dict_gets(p, "Name"); + if (fz_is_name(name)) + return pdf_open_crypt_with_filter(chain, xref->crypt, fz_to_name(name), num, gen); return chain; } @@ -145,13 +145,12 @@ build_filter_chain(fz_stream *chain, pdf_xref *xref, fz_obj *fs, fz_obj *ps, int fz_obj *f; fz_obj *p; int i, n; - fz_context *ctx = chain->ctx; - n = fz_array_len(ctx, fs); + n = fz_array_len(fs); for (i = 0; i < n; i++) { - f = fz_array_get(ctx, fs, i); - p = fz_array_get(ctx, ps, i); + f = fz_array_get(fs, i); + p = fz_array_get(ps, i); chain = build_filter(chain, xref, f, p, num, gen); } @@ -173,7 +172,7 @@ pdf_open_raw_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, i /* don't close chain when we close this filter */ fz_keep_stream(chain); - len = fz_to_int(ctx, fz_dict_gets(ctx, stmobj, "Length")); + len = fz_to_int(fz_dict_gets(stmobj, "Length")); chain = fz_open_null(chain, len); hascrypt = pdf_stream_has_crypt(ctx, stmobj); @@ -192,16 +191,15 @@ pdf_open_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int g { fz_obj *filters; fz_obj *params; - fz_context *ctx = chain->ctx; - filters = fz_dict_getsa(ctx, stmobj, "Filter", "F"); - params = fz_dict_getsa(ctx, stmobj, "DecodeParms", "DP"); + filters = fz_dict_getsa(stmobj, "Filter", "F"); + params = fz_dict_getsa(stmobj, "DecodeParms", "DP"); chain = pdf_open_raw_filter(chain, xref, stmobj, num, gen); - if (fz_is_name(ctx, filters)) + if (fz_is_name(filters)) return build_filter(chain, xref, filters, params, num, gen); - if (fz_array_len(ctx, filters) > 0) + if (fz_array_len(filters) > 0) return build_filter_chain(chain, xref, filters, params, num, gen); return chain; @@ -216,17 +214,16 @@ pdf_open_inline_stream(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int len { fz_obj *filters; fz_obj *params; - fz_context *ctx = chain->ctx; - filters = fz_dict_getsa(ctx, stmobj, "Filter", "F"); - params = fz_dict_getsa(ctx, stmobj, "DecodeParms", "DP"); + filters = fz_dict_getsa(stmobj, "Filter", "F"); + params = fz_dict_getsa(stmobj, "DecodeParms", "DP"); /* don't close chain when we close this filter */ fz_keep_stream(chain); - if (fz_is_name(ctx, filters)) + if (fz_is_name(filters)) return build_filter(chain, xref, filters, params, 0, 0); - if (fz_array_len(ctx, filters) > 0) + if (fz_array_len(filters) > 0) return build_filter_chain(chain, xref, filters, params, 0, 0); return fz_open_null(chain, length); @@ -313,15 +310,14 @@ pdf_load_raw_stream(fz_buffer **bufp, pdf_xref *xref, int num, int gen) fz_stream *stm; fz_obj *dict; int len; - fz_context *ctx = xref->ctx; error = pdf_load_object(&dict, xref, num, gen); if (error) return fz_error_note(error, "cannot load stream dictionary (%d %d R)", num, gen); - len = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Length")); + len = fz_to_int(fz_dict_gets(dict, "Length")); - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); error = pdf_open_raw_stream(&stm, xref, num, gen); if (error) @@ -364,7 +360,6 @@ pdf_load_stream(fz_buffer **bufp, pdf_xref *xref, int num, int gen) fz_stream *stm; fz_obj *dict, *obj; int i, len, n; - fz_context *ctx = xref->ctx; error = pdf_open_stream(&stm, xref, num, gen); if (error) @@ -374,14 +369,14 @@ pdf_load_stream(fz_buffer **bufp, pdf_xref *xref, int num, int gen) if (error) return fz_error_note(error, "cannot load stream dictionary (%d %d R)", num, gen); - len = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Length")); - obj = fz_dict_gets(ctx, dict, "Filter"); - len = pdf_guess_filter_length(len, fz_to_name(ctx, obj)); - n = fz_array_len(ctx, obj); + len = fz_to_int(fz_dict_gets(dict, "Length")); + obj = fz_dict_gets(dict, "Filter"); + len = pdf_guess_filter_length(len, fz_to_name(obj)); + n = fz_array_len(obj); for (i = 0; i < n; i++) - len = pdf_guess_filter_length(len, fz_to_name(ctx, fz_array_get(ctx, obj, i))); + len = pdf_guess_filter_length(len, fz_to_name(fz_array_get(obj, i))); - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); error = fz_read_all(bufp, stm, len); if (error) diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c index 7f055f9f..b6306b47 100644 --- a/pdf/pdf_type3.c +++ b/pdf/pdf_type3.c @@ -24,18 +24,18 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o fz_matrix matrix; fz_context *ctx = xref->ctx; - obj = fz_dict_gets(ctx, dict, "Name"); - if (fz_is_name(ctx, obj)) - fz_strlcpy(buf, fz_to_name(ctx, obj), sizeof buf); + obj = fz_dict_gets(dict, "Name"); + if (fz_is_name(obj)) + fz_strlcpy(buf, fz_to_name(obj), sizeof buf); else sprintf(buf, "Unnamed-T3"); fontdesc = pdf_new_font_desc(ctx); - obj = fz_dict_gets(ctx, dict, "FontMatrix"); + obj = fz_dict_gets(dict, "FontMatrix"); matrix = pdf_to_matrix(ctx, obj); - obj = fz_dict_gets(ctx, dict, "FontBBox"); + obj = fz_dict_gets(dict, "FontBBox"); bbox = pdf_to_rect(ctx, obj); fontdesc->font = fz_new_type3_font(ctx, buf, matrix); @@ -47,36 +47,36 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o for (i = 0; i < 256; i++) estrings[i] = NULL; - encoding = fz_dict_gets(ctx, dict, "Encoding"); + encoding = fz_dict_gets(dict, "Encoding"); if (!encoding) { error = fz_error_make("syntaxerror: Type3 font missing Encoding"); goto cleanup; } - if (fz_is_name(ctx, encoding)) - pdf_load_encoding(estrings, fz_to_name(ctx, encoding)); + if (fz_is_name(encoding)) + pdf_load_encoding(estrings, fz_to_name(encoding)); - if (fz_is_dict(ctx, encoding)) + if (fz_is_dict(encoding)) { fz_obj *base, *diff, *item; - base = fz_dict_gets(ctx, encoding, "BaseEncoding"); - if (fz_is_name(ctx, base)) - pdf_load_encoding(estrings, fz_to_name(ctx, base)); + base = fz_dict_gets(encoding, "BaseEncoding"); + if (fz_is_name(base)) + pdf_load_encoding(estrings, fz_to_name(base)); - diff = fz_dict_gets(ctx, encoding, "Differences"); - if (fz_is_array(ctx, diff)) + diff = fz_dict_gets(encoding, "Differences"); + if (fz_is_array(diff)) { - n = fz_array_len(ctx, diff); + n = fz_array_len(diff); k = 0; for (i = 0; i < n; i++) { - item = fz_array_get(ctx, diff, i); - if (fz_is_int(ctx, item)) - k = fz_to_int(ctx, item); - if (fz_is_name(ctx, item)) - estrings[k++] = fz_to_name(ctx, item); + item = fz_array_get(diff, i); + if (fz_is_int(item)) + k = fz_to_int(item); + if (fz_is_name(item)) + estrings[k++] = fz_to_name(item); if (k < 0) k = 0; if (k > 255) k = 255; } @@ -85,7 +85,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 1); - error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(ctx, dict, "ToUnicode")); + error = pdf_load_to_unicode(fontdesc, xref, estrings, NULL, fz_dict_gets(dict, "ToUnicode")); if (error) goto cleanup; @@ -93,10 +93,10 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o pdf_set_default_hmtx(fontdesc, 0); - first = fz_to_int(ctx, fz_dict_gets(ctx, dict, "FirstChar")); - last = fz_to_int(ctx, fz_dict_gets(ctx, dict, "LastChar")); + first = fz_to_int(fz_dict_gets(dict, "FirstChar")); + last = fz_to_int(fz_dict_gets(dict, "LastChar")); - widths = fz_dict_gets(ctx, dict, "Widths"); + widths = fz_dict_gets(dict, "Widths"); if (!widths) { error = fz_error_make("syntaxerror: Type3 font missing Widths"); @@ -105,7 +105,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o for (i = first; i <= last; i++) { - float w = fz_to_real(ctx, fz_array_get(ctx, widths, i - first)); + float w = fz_to_real(fz_array_get(widths, i - first)); w = fontdesc->font->t3matrix.a * w * 1000; fontdesc->font->t3widths[i] = w * 0.001f; pdf_add_hmtx(ctx, fontdesc, i, i, w); @@ -115,7 +115,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o /* Resources -- inherit page resources if the font doesn't have its own */ - fontdesc->font->t3resources = fz_dict_gets(ctx, dict, "Resources"); + fontdesc->font->t3resources = fz_dict_gets(dict, "Resources"); if (!fontdesc->font->t3resources) fontdesc->font->t3resources = rdb; if (fontdesc->font->t3resources) @@ -128,7 +128,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o /* CharProcs */ - charprocs = fz_dict_gets(ctx, dict, "CharProcs"); + charprocs = fz_dict_gets(dict, "CharProcs"); if (!charprocs) { error = fz_error_make("syntaxerror: Type3 font missing CharProcs"); @@ -139,7 +139,7 @@ pdf_load_type3_font(pdf_font_desc **fontdescp, pdf_xref *xref, fz_obj *rdb, fz_o { if (estrings[i]) { - obj = fz_dict_gets(ctx, charprocs, estrings[i]); + obj = fz_dict_gets(charprocs, estrings[i]); if (pdf_is_stream(xref, fz_to_num(obj), fz_to_gen(obj))) { error = pdf_load_stream(&fontdesc->font->t3procs[i], xref, fz_to_num(obj), fz_to_gen(obj)); diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index 1c1bd276..25503374 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -24,10 +24,10 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) /* Store item immediately, to avoid possible recursion if objects refer back to this one */ pdf_store_item(ctx, xref->store, (pdf_store_keep_fn *)pdf_keep_xobject, (pdf_store_drop_fn *)pdf_drop_xobject, dict, form); - obj = fz_dict_gets(ctx, dict, "BBox"); + obj = fz_dict_gets(dict, "BBox"); form->bbox = pdf_to_rect(ctx, obj); - obj = fz_dict_gets(ctx, dict, "Matrix"); + obj = fz_dict_gets(dict, "Matrix"); if (obj) form->matrix = pdf_to_matrix(ctx, obj); else @@ -37,19 +37,19 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) form->knockout = 0; form->transparency = 0; - obj = fz_dict_gets(ctx, dict, "Group"); + obj = fz_dict_gets(dict, "Group"); if (obj) { fz_obj *attrs = obj; - form->isolated = fz_to_bool(ctx, fz_dict_gets(ctx, attrs, "I")); - form->knockout = fz_to_bool(ctx, fz_dict_gets(ctx, attrs, "K")); + form->isolated = fz_to_bool(fz_dict_gets(attrs, "I")); + form->knockout = fz_to_bool(fz_dict_gets(attrs, "K")); - obj = fz_dict_gets(ctx, attrs, "S"); - if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Transparency")) + obj = fz_dict_gets(attrs, "S"); + if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Transparency")) form->transparency = 1; - obj = fz_dict_gets(ctx, attrs, "CS"); + obj = fz_dict_gets(attrs, "CS"); if (obj) { error = pdf_load_colorspace(&form->colorspace, xref, obj); @@ -58,7 +58,7 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) } } - form->resources = fz_dict_gets(ctx, dict, "Resources"); + form->resources = fz_dict_gets(dict, "Resources"); if (form->resources) fz_keep_obj(form->resources); @@ -89,7 +89,7 @@ pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj) if (xobj->colorspace) fz_drop_colorspace(ctx, xobj->colorspace); if (xobj->resources) - fz_drop_obj(ctx, xobj->resources); + fz_drop_obj(xobj->resources); if (xobj->contents) fz_drop_buffer(ctx, xobj->contents); fz_free(ctx, xobj); diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index 1dd591ab..d259e6d0 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -311,19 +311,18 @@ pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) int num, gen, stm_ofs; int size, w0, w1, w2; int t; - fz_context *ctx = xref->ctx; error = pdf_parse_ind_obj(&trailer, xref, xref->file, buf, cap, &num, &gen, &stm_ofs); if (error) return fz_error_note(error, "cannot parse compressed xref stream object"); - obj = fz_dict_gets(ctx, trailer, "Size"); + obj = fz_dict_gets(trailer, "Size"); if (!obj) { - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_make("xref stream missing Size entry (%d %d R)", num, gen); } - size = fz_to_int(ctx, obj); + size = fz_to_int(obj); if (size > xref->len) { @@ -332,25 +331,25 @@ pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) if (num < 0 || num >= xref->len) { - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_make("object id (%d %d R) out of range (0..%d)", num, gen, xref->len - 1); } - obj = fz_dict_gets(ctx, trailer, "W"); + obj = fz_dict_gets(trailer, "W"); if (!obj) { - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_make("xref stream missing W entry (%d %d R)", num, gen); } - w0 = fz_to_int(ctx, fz_array_get(ctx, obj, 0)); - w1 = fz_to_int(ctx, fz_array_get(ctx, obj, 1)); - w2 = fz_to_int(ctx, fz_array_get(ctx, obj, 2)); + w0 = fz_to_int(fz_array_get(obj, 0)); + w1 = fz_to_int(fz_array_get(obj, 1)); + w2 = fz_to_int(fz_array_get(obj, 2)); - index = fz_dict_gets(ctx, trailer, "Index"); + index = fz_dict_gets(trailer, "Index"); error = pdf_open_stream_at(&stm, xref, num, gen, trailer, stm_ofs); if (error) { - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_note(error, "cannot open compressed xref stream (%d %d R)", num, gen); } @@ -360,22 +359,22 @@ pdf_read_new_xref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap) if (error) { fz_close(stm); - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_note(error, "cannot read xref stream (%d %d R)", num, gen); } } else { - int n = fz_array_len(ctx, index); + int n = fz_array_len(index); for (t = 0; t < n; t += 2) { - int i0 = fz_to_int(ctx, fz_array_get(ctx, index, t + 0)); - int i1 = fz_to_int(ctx, fz_array_get(ctx, index, t + 1)); + int i0 = fz_to_int(fz_array_get(index, t + 0)); + int i1 = fz_to_int(fz_array_get(index, t + 1)); error = pdf_read_new_xref_section(xref, stm, i0, i1, w0, w1, w2); if (error) { fz_close(stm); - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_note(error, "cannot read xref stream section (%d %d R)", num, gen); } } @@ -427,36 +426,35 @@ pdf_read_xref_sections(pdf_xref *xref, int ofs, char *buf, int cap) fz_obj *trailer; fz_obj *prev; fz_obj *xrefstm; - fz_context *ctx = xref->ctx; error = pdf_read_xref(&trailer, xref, ofs, buf, cap); if (error) return fz_error_note(error, "cannot read xref section"); /* FIXME: do we overwrite free entries properly? */ - xrefstm = fz_dict_gets(ctx, trailer, "XRefStm"); + xrefstm = fz_dict_gets(trailer, "XRefStm"); if (xrefstm) { - error = pdf_read_xref_sections(xref, fz_to_int(ctx, xrefstm), buf, cap); + error = pdf_read_xref_sections(xref, fz_to_int(xrefstm), buf, cap); if (error) { - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_note(error, "cannot read /XRefStm xref section"); } } - prev = fz_dict_gets(ctx, trailer, "Prev"); + prev = fz_dict_gets(trailer, "Prev"); if (prev) { - error = pdf_read_xref_sections(xref, fz_to_int(ctx, prev), buf, cap); + error = pdf_read_xref_sections(xref, fz_to_int(prev), buf, cap); if (error) { - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_error_note(error, "cannot read /Prev xref section"); } } - fz_drop_obj(ctx, trailer); + fz_drop_obj(trailer); return fz_okay; } @@ -483,11 +481,11 @@ pdf_load_xref(pdf_xref *xref, char *buf, int bufsize) if (error) return fz_error_note(error, "cannot read trailer"); - size = fz_dict_gets(xref->ctx, xref->trailer, "Size"); + size = fz_dict_gets(xref->trailer, "Size"); if (!size) return fz_error_make("trailer missing Size entry"); - pdf_resize_xref(xref, fz_to_int(xref->ctx, size)); + pdf_resize_xref(xref, fz_to_int(size)); error = pdf_read_xref_sections(xref, xref->startxref, buf, bufsize); if (error) @@ -527,9 +525,10 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password) fz_context *ctx = file->ctx; /* install pdf specific callback */ - ctx->resolve_indirect = pdf_resolve_indirect; + fz_resolve_indirect = pdf_resolve_indirect; - xref = fz_calloc(ctx, 1, sizeof(pdf_xref)); + xref = fz_malloc(ctx, sizeof(pdf_xref)); + memset(xref, 0, sizeof *xref); xref->file = fz_keep_stream(file); xref->ctx = ctx; @@ -546,7 +545,7 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password) } if (xref->trailer) { - fz_drop_obj(ctx, xref->trailer); + fz_drop_obj(xref->trailer); xref->trailer = NULL; } error = pdf_repair_xref(xref, xref->scratch, sizeof xref->scratch); @@ -558,9 +557,9 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password) repaired = 1; } - encrypt = fz_dict_gets(ctx, xref->trailer, "Encrypt"); - id = fz_dict_gets(ctx, xref->trailer, "ID"); - if (fz_is_dict(ctx, encrypt)) + encrypt = fz_dict_gets(xref->trailer, "Encrypt"); + id = fz_dict_gets(xref->trailer, "ID"); + if (fz_is_dict(encrypt)) { error = pdf_new_crypt(ctx, &xref->crypt, encrypt, id); if (error) @@ -595,8 +594,8 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password) return fz_error_note(error, "cannot repair document"); } - hasroot = fz_dict_gets(ctx, xref->trailer, "Root") != NULL; - hasinfo = fz_dict_gets(ctx, xref->trailer, "Info") != NULL; + hasroot = fz_dict_gets(xref->trailer, "Root") != NULL; + hasinfo = fz_dict_gets(xref->trailer, "Info") != NULL; for (i = 1; i < xref->len; i++) { @@ -612,26 +611,26 @@ pdf_open_xref_with_stream(pdf_xref **xrefp, fz_stream *file, char *password) if (!hasroot) { - obj = fz_dict_gets(ctx, dict, "Type"); - if (fz_is_name(ctx, obj) && !strcmp(fz_to_name(ctx, obj), "Catalog")) + obj = fz_dict_gets(dict, "Type"); + if (fz_is_name(obj) && !strcmp(fz_to_name(obj), "Catalog")) { obj = fz_new_indirect(ctx, i, 0, xref); - fz_dict_puts(ctx, xref->trailer, "Root", obj); - fz_drop_obj(ctx, obj); + fz_dict_puts(xref->trailer, "Root", obj); + fz_drop_obj(obj); } } if (!hasinfo) { - if (fz_dict_gets(ctx, dict, "Creator") || fz_dict_gets(ctx, dict, "Producer")) + if (fz_dict_gets(dict, "Creator") || fz_dict_gets(dict, "Producer")) { obj = fz_new_indirect(ctx, i, 0, xref); - fz_dict_puts(ctx, xref->trailer, "Info", obj); - fz_drop_obj(ctx, obj); + fz_dict_puts(xref->trailer, "Info", obj); + fz_drop_obj(obj); } } - fz_drop_obj(ctx, dict); + fz_drop_obj(dict); } } @@ -654,7 +653,7 @@ pdf_free_xref(pdf_xref *xref) { if (xref->table[i].obj) { - fz_drop_obj(ctx, xref->table[i].obj); + fz_drop_obj(xref->table[i].obj); xref->table[i].obj = NULL; } } @@ -664,21 +663,21 @@ pdf_free_xref(pdf_xref *xref) if (xref->page_objs) { for (i = 0; i < xref->page_len; i++) - fz_drop_obj(ctx, xref->page_objs[i]); + fz_drop_obj(xref->page_objs[i]); fz_free(ctx, xref->page_objs); } if (xref->page_refs) { for (i = 0; i < xref->page_len; i++) - fz_drop_obj(ctx, xref->page_refs[i]); + fz_drop_obj(xref->page_refs[i]); fz_free(ctx, xref->page_refs); } if (xref->file) fz_close(xref->file); if (xref->trailer) - fz_drop_obj(ctx, xref->trailer); + fz_drop_obj(xref->trailer); if (xref->crypt) pdf_free_crypt(ctx, xref->crypt); @@ -724,8 +723,8 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap) if (error) return fz_error_note(error, "cannot load object stream object (%d %d R)", num, gen); - count = fz_to_int(ctx, fz_dict_gets(ctx, objstm, "N")); - first = fz_to_int(ctx, fz_dict_gets(ctx, objstm, "First")); + count = fz_to_int(fz_dict_gets(objstm, "N")); + first = fz_to_int(fz_dict_gets(objstm, "First")); numbuf = fz_calloc(ctx, count, sizeof(int)); ofsbuf = fz_calloc(ctx, count, sizeof(int)); @@ -771,7 +770,7 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap) if (numbuf[i] < 1 || numbuf[i] >= xref->len) { - fz_drop_obj(ctx, obj); + fz_drop_obj(obj); error = fz_error_make("object id (%d 0 R) out of range (0..%d)", numbuf[i], xref->len - 1); goto cleanupstm; } @@ -779,19 +778,19 @@ pdf_load_obj_stm(pdf_xref *xref, int num, int gen, char *buf, int cap) if (xref->table[numbuf[i]].type == 'o' && xref->table[numbuf[i]].ofs == num) { if (xref->table[numbuf[i]].obj) - fz_drop_obj(ctx, xref->table[numbuf[i]].obj); + fz_drop_obj(xref->table[numbuf[i]].obj); xref->table[numbuf[i]].obj = obj; } else { - fz_drop_obj(ctx, obj); + fz_drop_obj(obj); } } fz_close(stm); fz_free(xref->ctx, ofsbuf); fz_free(xref->ctx, numbuf); - fz_drop_obj(ctx, objstm); + fz_drop_obj(objstm); return fz_okay; cleanupstm: @@ -799,7 +798,7 @@ cleanupstm: cleanupbuf: fz_free(xref->ctx, ofsbuf); fz_free(xref->ctx, numbuf); - fz_drop_obj(ctx, objstm); + fz_drop_obj(objstm); return error; /* already rethrown */ } @@ -916,7 +915,7 @@ pdf_update_object(pdf_xref *xref, int num, int gen, fz_obj *newobj) x = &xref->table[num]; if (x->obj) - fz_drop_obj(xref->ctx, x->obj); + fz_drop_obj(x->obj); x->obj = fz_keep_obj(newobj); x->type = 'n'; |