diff options
Diffstat (limited to 'pdf/pdf_interpret.c')
-rw-r--r-- | pdf/pdf_interpret.c | 394 |
1 files changed, 200 insertions, 194 deletions
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index ea7f7692..3888b35f 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -1,5 +1,5 @@ -#include "fitz.h" -#include "mupdf.h" +#include "fitz-internal.h" +#include "mupdf-internal.h" #define TILE @@ -70,7 +70,7 @@ struct pdf_csi_s char *event; /* "View", "Print", "Export" */ /* interpreter stack */ - fz_obj *obj; + pdf_obj *obj; char name[256]; unsigned char string[256]; int string_len; @@ -104,8 +104,8 @@ struct pdf_csi_s fz_cookie *cookie; }; -static void pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents); -static void pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix transform); +static void pdf_run_buffer(pdf_csi *csi, pdf_obj *rdb, fz_buffer *contents); +static void pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, fz_matrix transform); static void pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what); static int @@ -120,20 +120,20 @@ ocg_intents_include(pdf_ocg_descriptor *desc, char *name) if (!desc->intent) return (strcmp(name, "View") == 0); - if (fz_is_name(desc->intent)) + if (pdf_is_name(desc->intent)) { - char *intent = fz_to_name(desc->intent); + char *intent = pdf_to_name(desc->intent); if (strcmp(intent, "All") == 0) return 1; return (strcmp(intent, name) == 0); } - if (!fz_is_array(desc->intent)) + if (!pdf_is_array(desc->intent)) return 0; - len = fz_array_len(desc->intent); + len = pdf_array_len(desc->intent); for (i=0; i < len; i++) { - char *intent = fz_to_name(fz_array_get(desc->intent, i)); + char *intent = pdf_to_name(pdf_array_get(desc->intent, i)); if (strcmp(intent, "All") == 0) return 1; if (strcmp(intent, name) == 0) @@ -143,10 +143,10 @@ ocg_intents_include(pdf_ocg_descriptor *desc, char *name) } static int -pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) +pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) { char event_state[16]; - fz_obj *obj, *obj2; + pdf_obj *obj, *obj2; char *type; pdf_ocg_descriptor *desc = csi->xref->ocg; @@ -155,9 +155,9 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) return 0; /* If we've been handed a name, look it up in the properties. */ - if (fz_is_name(ocg)) + if (pdf_is_name(ocg)) { - ocg = fz_dict_gets(fz_dict_gets(rdb, "Properties"), fz_to_name(ocg)); + ocg = pdf_dict_gets(pdf_dict_gets(rdb, "Properties"), pdf_to_name(ocg)); } /* If we haven't been given an ocg at all, then we're visible */ if (!ocg) @@ -166,13 +166,13 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) fz_strlcpy(event_state, csi->event, sizeof event_state); fz_strlcat(event_state, "State", sizeof event_state); - type = fz_to_name(fz_dict_gets(ocg, "Type")); + type = pdf_to_name(pdf_dict_gets(ocg, "Type")); if (strcmp(type, "OCG") == 0) { /* An Optional Content Group */ - int num = fz_to_num(ocg); - int gen = fz_to_gen(ocg); + int num = pdf_to_num(ocg); + int gen = pdf_to_gen(ocg); int len = desc->len; int i; @@ -188,19 +188,19 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) /* Check Intents; if our intent is not part of the set given * by the current config, we should ignore it. */ - obj = fz_dict_gets(ocg, "Intent"); - if (fz_is_name(obj)) + obj = pdf_dict_gets(ocg, "Intent"); + if (pdf_is_name(obj)) { /* If it doesn't match, it's hidden */ - if (ocg_intents_include(desc, fz_to_name(obj)) == 0) + if (ocg_intents_include(desc, pdf_to_name(obj)) == 0) return 1; } - else if (fz_is_array(obj)) + else if (pdf_is_array(obj)) { int match = 0; - len = fz_array_len(obj); + len = pdf_array_len(obj); for (i=0; i<len; i++) { - match |= ocg_intents_include(desc, fz_to_name(fz_array_get(obj, i))); + match |= ocg_intents_include(desc, pdf_to_name(pdf_array_get(obj, i))); if (match) break; } @@ -224,15 +224,15 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) * correspond to entries in the AS list in the OCG config. * Given that we don't handle Zoom or User, or Language * dicts, this is not really a problem. */ - obj = fz_dict_gets(ocg, "Usage"); - if (!fz_is_dict(obj)) + obj = pdf_dict_gets(ocg, "Usage"); + if (!pdf_is_dict(obj)) return 0; /* FIXME: Should look at Zoom (and return hidden if out of * max/min range) */ /* FIXME: Could provide hooks to the caller to check if * User is appropriate - if not return hidden. */ - obj2 = fz_dict_gets(obj, csi->event); - if (strcmp(fz_to_name(fz_dict_gets(obj2, event_state)), "OFF") == 0) + obj2 = pdf_dict_gets(obj, csi->event); + if (strcmp(pdf_to_name(pdf_dict_gets(obj2, event_state)), "OFF") == 0) { return 1; } @@ -244,12 +244,12 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) char *name; int combine, on; - obj = fz_dict_gets(ocg, "VE"); - if (fz_is_array(obj)) { + obj = pdf_dict_gets(ocg, "VE"); + if (pdf_is_array(obj)) { /* FIXME: Calculate visibility from array */ return 0; } - name = fz_to_name(fz_dict_gets(ocg, "P")); + name = pdf_to_name(pdf_dict_gets(ocg, "P")); /* Set combine; Bit 0 set => AND, Bit 1 set => true means * Off, otherwise true means On */ if (strcmp(name, "AllOn") == 0) @@ -269,15 +269,15 @@ pdf_is_hidden_ocg(fz_obj *ocg, pdf_csi *csi, fz_obj *rdb) combine = 0; } - obj = fz_dict_gets(ocg, "OCGs"); + obj = pdf_dict_gets(ocg, "OCGs"); on = combine & 1; - if (fz_is_array(obj)) { + if (pdf_is_array(obj)) { int i, len; - len = fz_array_len(obj); + len = pdf_array_len(obj); for (i = 0; i < len; i++) { int hidden; - hidden = pdf_is_hidden_ocg(fz_array_get(obj, i), csi, rdb); + hidden = pdf_is_hidden_ocg(pdf_array_get(obj, i), csi, rdb); if ((combine & 1) == 0) hidden = !hidden; if (combine & 2) @@ -362,7 +362,7 @@ pdf_show_shade(pdf_csi *csi, fz_shade *shd) } static void -pdf_show_image(pdf_csi *csi, fz_pixmap *image) +pdf_show_image(pdf_csi *csi, fz_image *image) { pdf_gstate *gstate = csi->gstate + csi->gtop; fz_matrix image_ctm; @@ -709,7 +709,7 @@ pdf_show_char(pdf_csi *csi, int cid) if (fontdesc->wmode == 1) { - v = pdf_get_vmtx(ctx, fontdesc, cid); + v = pdf_lookup_vmtx(ctx, fontdesc, cid); tsm.e -= v.x * gstate->size * 0.001f; tsm.f -= v.y * gstate->size * 0.001f; } @@ -767,7 +767,7 @@ pdf_show_char(pdf_csi *csi, int cid) if (fontdesc->wmode == 0) { - h = pdf_get_hmtx(ctx, fontdesc, cid); + h = pdf_lookup_hmtx(ctx, fontdesc, cid); w0 = h.w * 0.001f; tx = (w0 * gstate->size + gstate->char_space) * gstate->scale; csi->tm = fz_concat(fz_translate(tx, 0), csi->tm); @@ -819,6 +819,7 @@ pdf_show_string(pdf_csi *csi, unsigned char *buf, int len) { int w = pdf_decode_cmap(fontdesc->encoding, buf, &cpt); buf += w; + cid = pdf_lookup_cmap(fontdesc->encoding, cpt); if (cid >= 0) pdf_show_char(csi, cid); @@ -830,26 +831,26 @@ pdf_show_string(pdf_csi *csi, unsigned char *buf, int len) } static void -pdf_show_text(pdf_csi *csi, fz_obj *text) +pdf_show_text(pdf_csi *csi, pdf_obj *text) { pdf_gstate *gstate = csi->gstate + csi->gtop; int i; - if (fz_is_array(text)) + if (pdf_is_array(text)) { - int n = fz_array_len(text); + int n = pdf_array_len(text); for (i = 0; i < n; i++) { - 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)); + pdf_obj *item = pdf_array_get(text, i); + if (pdf_is_string(item)) + pdf_show_string(csi, (unsigned char *)pdf_to_str_buf(item), pdf_to_str_len(item)); else - pdf_show_space(csi, - fz_to_real(item) * gstate->size * 0.001f); + pdf_show_space(csi, - pdf_to_real(item) * gstate->size * 0.001f); } } - else if (fz_is_string(text)) + else if (pdf_is_string(text)) { - pdf_show_string(csi, (unsigned char *)fz_to_str_buf(text), fz_to_str_len(text)); + pdf_show_string(csi, (unsigned char *)pdf_to_str_buf(text), pdf_to_str_len(text)); } } @@ -1003,7 +1004,7 @@ pdf_clear_stack(pdf_csi *csi) int i; if (csi->obj) - fz_drop_obj(csi->obj); + pdf_drop_obj(csi->obj); csi->obj = NULL; csi->name[0] = 0; @@ -1334,7 +1335,7 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what) } static void -pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix transform) +pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, fz_matrix transform) { fz_context *ctx = csi->dev->ctx; pdf_gstate *gstate = NULL; @@ -1343,7 +1344,7 @@ pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix tr int popmask; /* Avoid infinite recursion */ - if (xobj == NULL || fz_dict_mark(xobj->me)) + if (xobj == NULL || pdf_dict_mark(xobj->me)) return; fz_var(gstate); @@ -1424,7 +1425,7 @@ pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix tr pdf_grestore(csi); } - fz_dict_unmark(xobj->me); + pdf_dict_unmark(xobj->me); } fz_catch(ctx) { @@ -1441,7 +1442,7 @@ pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix tr } static void -pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) +pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) { fz_context *ctx = csi->dev->ctx; pdf_gstate *gstate = csi->gstate + csi->gtop; @@ -1450,18 +1451,18 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) pdf_flush_text(csi); - n = fz_dict_len(extgstate); + n = pdf_dict_len(extgstate); for (i = 0; i < n; i++) { - fz_obj *key = fz_dict_get_key(extgstate, i); - fz_obj *val = fz_dict_get_val(extgstate, i); - char *s = fz_to_name(key); + pdf_obj *key = pdf_dict_get_key(extgstate, i); + pdf_obj *val = pdf_dict_get_val(extgstate, i); + char *s = pdf_to_name(key); if (!strcmp(s, "Font")) { - if (fz_is_array(val) && fz_array_len(val) == 2) + if (pdf_is_array(val) && pdf_array_len(val) == 2) { - fz_obj *font = fz_array_get(val, 0); + pdf_obj *font = pdf_array_get(val, 0); if (gstate->font) { @@ -1470,10 +1471,10 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) } gstate->font = pdf_load_font(csi->xref, rdb, font); - /* RJW: "cannot load font (%d %d R)", fz_to_num(font), fz_to_gen(font) */ + /* RJW: "cannot load font (%d %d R)", pdf_to_num(font), pdf_to_gen(font) */ if (!gstate->font) fz_throw(ctx, "cannot find font in store"); - gstate->size = fz_to_real(fz_array_get(val, 1)); + gstate->size = pdf_to_real(pdf_array_get(val, 1)); } else fz_throw(ctx, "malformed /Font dictionary"); @@ -1482,59 +1483,59 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) else if (!strcmp(s, "LC")) { csi->dev->flags &= ~(FZ_DEVFLAG_STARTCAP_UNDEFINED | FZ_DEVFLAG_DASHCAP_UNDEFINED | FZ_DEVFLAG_ENDCAP_UNDEFINED); - 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); + gstate->stroke_state.start_cap = pdf_to_int(val); + gstate->stroke_state.dash_cap = pdf_to_int(val); + gstate->stroke_state.end_cap = pdf_to_int(val); } else if (!strcmp(s, "LW")) { csi->dev->flags &= ~FZ_DEVFLAG_LINEWIDTH_UNDEFINED; - gstate->stroke_state.linewidth = fz_to_real(val); + gstate->stroke_state.linewidth = pdf_to_real(val); } else if (!strcmp(s, "LJ")) { csi->dev->flags &= ~FZ_DEVFLAG_LINEJOIN_UNDEFINED; - gstate->stroke_state.linejoin = fz_to_int(val); + gstate->stroke_state.linejoin = pdf_to_int(val); } else if (!strcmp(s, "ML")) { csi->dev->flags &= ~FZ_DEVFLAG_MITERLIMIT_UNDEFINED; - gstate->stroke_state.miterlimit = fz_to_real(val); + gstate->stroke_state.miterlimit = pdf_to_real(val); } else if (!strcmp(s, "D")) { - if (fz_is_array(val) && fz_array_len(val) == 2) + if (pdf_is_array(val) && pdf_array_len(val) == 2) { - fz_obj *dashes = fz_array_get(val, 0); - gstate->stroke_state.dash_len = MAX(fz_array_len(dashes), 32); + pdf_obj *dashes = pdf_array_get(val, 0); + gstate->stroke_state.dash_len = MAX(pdf_array_len(dashes), 32); for (k = 0; k < gstate->stroke_state.dash_len; k++) - 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)); + gstate->stroke_state.dash_list[k] = pdf_to_real(pdf_array_get(dashes, k)); + gstate->stroke_state.dash_phase = pdf_to_real(pdf_array_get(val, 1)); } else fz_throw(ctx, "malformed /D"); } else if (!strcmp(s, "CA")) - gstate->stroke.alpha = fz_to_real(val); + gstate->stroke.alpha = pdf_to_real(val); else if (!strcmp(s, "ca")) - gstate->fill.alpha = fz_to_real(val); + gstate->fill.alpha = pdf_to_real(val); else if (!strcmp(s, "BM")) { - if (fz_is_array(val)) - val = fz_array_get(val, 0); - gstate->blendmode = fz_find_blendmode(fz_to_name(val)); + if (pdf_is_array(val)) + val = pdf_array_get(val, 0); + gstate->blendmode = fz_lookup_blendmode(pdf_to_name(val)); } else if (!strcmp(s, "SMask")) { - if (fz_is_dict(val)) + if (pdf_is_dict(val)) { pdf_xobject *xobj; - fz_obj *group, *luminosity, *bc; + pdf_obj *group, *luminosity, *bc; if (gstate->softmask) { @@ -1542,11 +1543,11 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) gstate->softmask = NULL; } - group = fz_dict_gets(val, "G"); + group = pdf_dict_gets(val, "G"); if (!group) - fz_throw(ctx, "cannot load softmask xobject (%d %d R)", fz_to_num(val), fz_to_gen(val)); + fz_throw(ctx, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val)); xobj = pdf_load_xobject(csi->xref, group); - /* RJW: "cannot load xobject (%d %d R)", fz_to_num(val), fz_to_gen(val) */ + /* RJW: "cannot load xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val) */ colorspace = xobj->colorspace; if (!colorspace) @@ -1557,20 +1558,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(val, "BC"); - if (fz_is_array(bc)) + bc = pdf_dict_gets(val, "BC"); + if (pdf_is_array(bc)) { for (k = 0; k < colorspace->n; k++) - gstate->softmask_bc[k] = fz_to_real(fz_array_get(bc, k)); + gstate->softmask_bc[k] = pdf_to_real(pdf_array_get(bc, k)); } - luminosity = fz_dict_gets(val, "S"); - if (fz_is_name(luminosity) && !strcmp(fz_to_name(luminosity), "Luminosity")) + luminosity = pdf_dict_gets(val, "S"); + if (pdf_is_name(luminosity) && !strcmp(pdf_to_name(luminosity), "Luminosity")) gstate->luminosity = 1; else gstate->luminosity = 0; } - else if (fz_is_name(val) && !strcmp(fz_to_name(val), "None")) + else if (pdf_is_name(val) && !strcmp(pdf_to_name(val), "None")) { if (gstate->softmask) { @@ -1582,7 +1583,7 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) else if (!strcmp(s, "TR")) { - if (!fz_is_name(val) || strcmp(fz_to_name(val), "Identity")) + if (!pdf_is_name(val) || strcmp(pdf_to_name(val), "Identity")) fz_warn(ctx, "ignoring transfer function"); } } @@ -1592,9 +1593,9 @@ pdf_run_extgstate(pdf_csi *csi, fz_obj *rdb, fz_obj *extgstate) * Operators */ -static void pdf_run_BDC(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_BDC(pdf_csi *csi, pdf_obj *rdb) { - fz_obj *ocg; + pdf_obj *ocg; /* If we are already in a hidden OCG, then we'll still be hidden - * just increment the depth so we pop back to visibility when we've @@ -1605,14 +1606,14 @@ static void pdf_run_BDC(pdf_csi *csi, fz_obj *rdb) return; } - ocg = fz_dict_gets(fz_dict_gets(rdb, "Properties"), csi->name); + ocg = pdf_dict_gets(pdf_dict_gets(rdb, "Properties"), csi->name); if (!ocg) { /* No Properties array, or name not found in the properties * means visible. */ return; } - if (strcmp(fz_to_name(fz_dict_gets(ocg, "Type")), "OCG") != 0) + if (strcmp(pdf_to_name(pdf_dict_gets(ocg, "Type")), "OCG") != 0) { /* Wrong type of property */ return; @@ -1621,16 +1622,14 @@ static void pdf_run_BDC(pdf_csi *csi, fz_obj *rdb) csi->in_hidden_ocg++; } -static void pdf_run_BI(pdf_csi *csi, fz_obj *rdb, fz_stream *file) +static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) { fz_context *ctx = csi->dev->ctx; int ch; - char *buf = csi->xref->scratch; - int buflen = sizeof(csi->xref->scratch); - fz_pixmap *img; - fz_obj *obj; + fz_image *img; + pdf_obj *obj; - obj = pdf_parse_dict(csi->xref, file, buf, buflen); + obj = pdf_parse_dict(csi->xref, file, &csi->xref->lexbuf.base); /* RJW: "cannot parse inline image dictionary" */ /* read whitespace after ID keyword */ @@ -1640,12 +1639,12 @@ static void pdf_run_BI(pdf_csi *csi, fz_obj *rdb, fz_stream *file) fz_read_byte(file); img = pdf_load_inline_image(csi->xref, rdb, obj, file); - fz_drop_obj(obj); + pdf_drop_obj(obj); /* RJW: "cannot load inline image" */ pdf_show_image(csi, img); - fz_drop_pixmap(ctx, img); + fz_drop_image(ctx, img); /* find EI */ ch = fz_read_byte(file); @@ -1689,11 +1688,11 @@ static void pdf_run_Bstar(pdf_csi *csi) pdf_show_path(csi, 0, 1, 1, 1); } -static void pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what) +static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what) { fz_context *ctx = csi->dev->ctx; fz_colorspace *colorspace; - fz_obj *obj, *dict; + pdf_obj *obj, *dict; if (!strcmp(csi->name, "Pattern")) { @@ -1709,14 +1708,14 @@ static void pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what) colorspace = fz_device_cmyk; /* No fz_keep_colorspace as static */ else { - dict = fz_dict_gets(rdb, "ColorSpace"); + dict = pdf_dict_gets(rdb, "ColorSpace"); if (!dict) fz_throw(ctx, "cannot find ColorSpace dictionary"); - obj = fz_dict_gets(dict, csi->name); + obj = pdf_dict_gets(dict, csi->name); if (!obj) fz_throw(ctx, "cannot find colorspace resource '%s'", csi->name); colorspace = pdf_load_colorspace(csi->xref, obj); - /* RJW: "cannot load colorspace (%d 0 R)", fz_to_num(obj) */ + /* RJW: "cannot load colorspace (%d 0 R)", pdf_to_num(obj) */ } pdf_set_colorspace(csi, what, colorspace); @@ -1725,7 +1724,7 @@ static void pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what) } } -static void pdf_run_CS(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_CS(pdf_csi *csi, pdf_obj *rdb) { csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; @@ -1733,7 +1732,7 @@ static void pdf_run_CS(pdf_csi *csi, fz_obj *rdb) /* RJW: "cannot set colorspace" */ } -static void pdf_run_cs(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_cs(pdf_csi *csi, pdf_obj *rdb) { csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; @@ -1745,41 +1744,41 @@ static void pdf_run_DP(pdf_csi *csi) { } -static void pdf_run_Do(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) { fz_context *ctx = csi->dev->ctx; - fz_obj *dict; - fz_obj *obj; - fz_obj *subtype; + pdf_obj *dict; + pdf_obj *obj; + pdf_obj *subtype; - dict = fz_dict_gets(rdb, "XObject"); + dict = pdf_dict_gets(rdb, "XObject"); if (!dict) fz_throw(ctx, "cannot find XObject dictionary when looking for: '%s'", csi->name); - obj = fz_dict_gets(dict, csi->name); + obj = pdf_dict_gets(dict, csi->name); if (!obj) fz_throw(ctx, "cannot find xobject resource: '%s'", csi->name); - subtype = fz_dict_gets(obj, "Subtype"); - if (!fz_is_name(subtype)) + subtype = pdf_dict_gets(obj, "Subtype"); + if (!pdf_is_name(subtype)) fz_throw(ctx, "no XObject subtype specified"); - if (pdf_is_hidden_ocg(fz_dict_gets(obj, "OC"), csi, rdb)) + if (pdf_is_hidden_ocg(pdf_dict_gets(obj, "OC"), csi, rdb)) return; - if (!strcmp(fz_to_name(subtype), "Form") && fz_dict_gets(obj, "Subtype2")) - subtype = fz_dict_gets(obj, "Subtype2"); + if (!strcmp(pdf_to_name(subtype), "Form") && pdf_dict_gets(obj, "Subtype2")) + subtype = pdf_dict_gets(obj, "Subtype2"); - if (!strcmp(fz_to_name(subtype), "Form")) + if (!strcmp(pdf_to_name(subtype), "Form")) { pdf_xobject *xobj; xobj = pdf_load_xobject(csi->xref, obj); - /* RJW: "cannot load xobject (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ + /* RJW: "cannot load xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ /* Inherit parent resources, in case this one was empty XXX check where it's loaded */ if (!xobj->resources) - xobj->resources = fz_keep_obj(rdb); + xobj->resources = pdf_keep_obj(rdb); fz_try(ctx) { @@ -1788,40 +1787,41 @@ static void pdf_run_Do(pdf_csi *csi, fz_obj *rdb) fz_catch(ctx) { pdf_drop_xobject(ctx, xobj); - fz_throw(ctx, "cannot draw xobject (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); + fz_throw(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } pdf_drop_xobject(ctx, xobj); } - else if (!strcmp(fz_to_name(subtype), "Image")) + else if (!strcmp(pdf_to_name(subtype), "Image")) { if ((csi->dev->hints & FZ_IGNORE_IMAGE) == 0) { - fz_pixmap *img; - img = pdf_load_image(csi->xref, obj); - /* RJW: "cannot load image (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ + fz_image *img = pdf_load_image(csi->xref, obj); + /* RJW: "cannot load image (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ fz_try(ctx) { pdf_show_image(csi, img); } + fz_always(ctx) + { + fz_drop_image(ctx, img); + } fz_catch(ctx) { - fz_drop_pixmap(ctx, img); fz_rethrow(ctx); } - fz_drop_pixmap(ctx, img); } } - else if (!strcmp(fz_to_name(subtype), "PS")) + else if (!strcmp(pdf_to_name(subtype), "PS")) { fz_warn(ctx, "ignoring XObject with subtype PS"); } else { - fz_throw(ctx, "unknown XObject subtype: '%s'", fz_to_name(subtype)); + fz_throw(ctx, "unknown XObject subtype: '%s'", pdf_to_name(subtype)); } } @@ -1899,12 +1899,12 @@ static void pdf_run_S(pdf_csi *csi) pdf_show_path(csi, 0, 0, 1, 0); } -static void pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material *mat) +static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *mat) { fz_context *ctx = csi->dev->ctx; - fz_obj *patterntype; - fz_obj *dict; - fz_obj *obj; + pdf_obj *patterntype; + pdf_obj *dict; + pdf_obj *obj; int kind; kind = mat->kind; @@ -1921,35 +1921,35 @@ static void pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material *ma break; case PDF_MAT_PATTERN: - dict = fz_dict_gets(rdb, "Pattern"); + dict = pdf_dict_gets(rdb, "Pattern"); if (!dict) fz_throw(ctx, "cannot find Pattern dictionary"); - obj = fz_dict_gets(dict, csi->name); + obj = pdf_dict_gets(dict, csi->name); if (!obj) fz_throw(ctx, "cannot find pattern resource '%s'", csi->name); - patterntype = fz_dict_gets(obj, "PatternType"); + patterntype = pdf_dict_gets(obj, "PatternType"); - if (fz_to_int(patterntype) == 1) + if (pdf_to_int(patterntype) == 1) { pdf_pattern *pat; pat = pdf_load_pattern(csi->xref, obj); - /* RJW: "cannot load pattern (%d 0 R)", fz_to_num(obj) */ + /* RJW: "cannot load pattern (%d 0 R)", pdf_to_num(obj) */ pdf_set_pattern(csi, what, pat, csi->top > 0 ? csi->stack : NULL); pdf_drop_pattern(ctx, pat); } - else if (fz_to_int(patterntype) == 2) + else if (pdf_to_int(patterntype) == 2) { fz_shade *shd; shd = pdf_load_shading(csi->xref, obj); - /* RJW: "cannot load shading (%d 0 R)", fz_to_num(obj) */ + /* RJW: "cannot load shading (%d 0 R)", pdf_to_num(obj) */ pdf_set_shade(csi, what, shd); fz_drop_shade(ctx, shd); } else { - fz_throw(ctx, "unknown pattern type: %d", fz_to_int(patterntype)); + fz_throw(ctx, "unknown pattern type: %d", pdf_to_int(patterntype)); } break; @@ -1958,7 +1958,7 @@ static void pdf_run_SC_imp(pdf_csi *csi, fz_obj *rdb, int what, pdf_material *ma } } -static void pdf_run_SC(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_SC(pdf_csi *csi, pdf_obj *rdb) { pdf_gstate *gstate = csi->gstate + csi->gtop; csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED; @@ -1966,7 +1966,7 @@ static void pdf_run_SC(pdf_csi *csi, fz_obj *rdb) /* RJW: "cannot set color and colorspace" */ } -static void pdf_run_sc(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_sc(pdf_csi *csi, pdf_obj *rdb) { pdf_gstate *gstate = csi->gstate + csi->gtop; csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED; @@ -2000,28 +2000,28 @@ static void pdf_run_TL(pdf_csi *csi) gstate->leading = csi->stack[0]; } -static void pdf_run_Tf(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb) { fz_context *ctx = csi->dev->ctx; pdf_gstate *gstate = csi->gstate + csi->gtop; - fz_obj *dict; - fz_obj *obj; + pdf_obj *dict; + pdf_obj *obj; gstate->size = csi->stack[0]; if (gstate->font) pdf_drop_font(ctx, gstate->font); gstate->font = NULL; - dict = fz_dict_gets(rdb, "Font"); + dict = pdf_dict_gets(rdb, "Font"); if (!dict) fz_throw(ctx, "cannot find Font dictionary"); - obj = fz_dict_gets(dict, csi->name); + obj = pdf_dict_gets(dict, csi->name); if (!obj) fz_throw(ctx, "cannot find font resource: '%s'", csi->name); gstate->font = pdf_load_font(csi->xref, rdb, obj); - /* RJW: "cannot load font (%d 0 R)", fz_to_num(obj) */ + /* RJW: "cannot load font (%d 0 R)", pdf_to_num(obj) */ } static void pdf_run_Tr(pdf_csi *csi) @@ -2141,13 +2141,13 @@ static void pdf_run_cm(pdf_csi *csi) static void pdf_run_d(pdf_csi *csi) { pdf_gstate *gstate = csi->gstate + csi->gtop; - fz_obj *array; + pdf_obj *array; int i; array = csi->obj; - gstate->stroke_state.dash_len = MIN(fz_array_len(array), nelem(gstate->stroke_state.dash_list)); + gstate->stroke_state.dash_len = MIN(pdf_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(fz_array_get(array, i)); + gstate->stroke_state.dash_list[i] = pdf_to_real(pdf_array_get(array, i)); gstate->stroke_state.dash_phase = csi->stack[0]; } @@ -2186,22 +2186,22 @@ static void pdf_run_g(pdf_csi *csi) pdf_set_color(csi, PDF_FILL, csi->stack); } -static void pdf_run_gs(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_gs(pdf_csi *csi, pdf_obj *rdb) { - fz_obj *dict; - fz_obj *obj; + pdf_obj *dict; + pdf_obj *obj; fz_context *ctx = csi->dev->ctx; - dict = fz_dict_gets(rdb, "ExtGState"); + dict = pdf_dict_gets(rdb, "ExtGState"); if (!dict) fz_throw(ctx, "cannot find ExtGState dictionary"); - obj = fz_dict_gets(dict, csi->name); + obj = pdf_dict_gets(dict, csi->name); if (!obj) fz_throw(ctx, "cannot find extgstate resource '%s'", csi->name); pdf_run_extgstate(csi, rdb, obj); - /* RJW: "cannot set ExtGState (%d 0 R)", fz_to_num(obj) */ + /* RJW: "cannot set ExtGState (%d 0 R)", pdf_to_num(obj) */ } static void pdf_run_h(pdf_csi *csi) @@ -2286,25 +2286,25 @@ static void pdf_run(pdf_csi *csi) pdf_show_path(csi, 1, 0, 1, 0); } -static void pdf_run_sh(pdf_csi *csi, fz_obj *rdb) +static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb) { fz_context *ctx = csi->dev->ctx; - fz_obj *dict; - fz_obj *obj; + pdf_obj *dict; + pdf_obj *obj; fz_shade *shd; - dict = fz_dict_gets(rdb, "Shading"); + dict = pdf_dict_gets(rdb, "Shading"); if (!dict) fz_throw(ctx, "cannot find shading dictionary"); - obj = fz_dict_gets(dict, csi->name); + obj = pdf_dict_gets(dict, csi->name); if (!obj) fz_throw(ctx, "cannot find shading resource: '%s'", csi->name); if ((csi->dev->hints & FZ_IGNORE_SHADE) == 0) { shd = pdf_load_shading(csi->xref, obj); - /* RJW: "cannot load shading (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ + /* RJW: "cannot load shading (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj) */ fz_try(ctx) { pdf_show_shade(csi, shd); @@ -2384,7 +2384,7 @@ static void pdf_run_dquote(pdf_csi *csi) #define C(a,b,c) (a | b << 8 | c << 16) static void -pdf_run_keyword(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf) +pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf) { fz_context *ctx = csi->dev->ctx; int key; @@ -2522,10 +2522,10 @@ pdf_run_keyword(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf) } static void -pdf_run_stream(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf, int buflen) +pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) { fz_context *ctx = csi->dev->ctx; - int tok, len, in_array; + int tok, in_array; /* make sure we have a clean slate if we come here from flush_text */ pdf_clear_stack(csi); @@ -2550,7 +2550,7 @@ pdf_run_stream(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf, int buflen csi->cookie->progress++; } - tok = pdf_lex(file, buf, buflen, &len); + tok = pdf_lex(file, buf); /* RJW: "lexical error in content stream" */ if (in_array) @@ -2559,19 +2559,24 @@ pdf_run_stream(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf, int buflen { in_array = 0; } - else if (tok == PDF_TOK_INT || tok == PDF_TOK_REAL) + else if (tok == PDF_TOK_REAL) + { + pdf_gstate *gstate = csi->gstate + csi->gtop; + pdf_show_space(csi, -buf->f * gstate->size * 0.001f); + } + else if (tok == PDF_TOK_INT) { pdf_gstate *gstate = csi->gstate + csi->gtop; - pdf_show_space(csi, -fz_atof(buf) * gstate->size * 0.001f); + pdf_show_space(csi, -buf->i * gstate->size * 0.001f); } else if (tok == PDF_TOK_STRING) { - pdf_show_string(csi, (unsigned char *)buf, len); + pdf_show_string(csi, (unsigned char *)buf->scratch, buf->len); } else if (tok == PDF_TOK_KEYWORD) { - if (!strcmp(buf, "Tw") || !strcmp(buf, "Tc")) - fz_warn(ctx, "ignoring keyword '%s' inside array", buf); + if (!strcmp(buf->scratch, "Tw") || !strcmp(buf->scratch, "Tc")) + fz_warn(ctx, "ignoring keyword '%s' inside array", buf->scratch); else fz_throw(ctx, "syntax error in array"); } @@ -2590,7 +2595,7 @@ pdf_run_stream(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf, int buflen case PDF_TOK_OPEN_ARRAY: if (!csi->in_text) { - csi->obj = pdf_parse_array(csi->xref, file, buf, buflen); + csi->obj = pdf_parse_array(csi->xref, file, buf); /* RJW: "cannot parse array" */ } else @@ -2600,38 +2605,38 @@ pdf_run_stream(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf, int buflen break; case PDF_TOK_OPEN_DICT: - csi->obj = pdf_parse_dict(csi->xref, file, buf, buflen); + csi->obj = pdf_parse_dict(csi->xref, file, buf); /* RJW: "cannot parse dictionary" */ break; case PDF_TOK_NAME: - fz_strlcpy(csi->name, buf, sizeof(csi->name)); + fz_strlcpy(csi->name, buf->scratch, sizeof(csi->name)); break; case PDF_TOK_INT: - csi->stack[csi->top] = atoi(buf); + csi->stack[csi->top] = buf->i; csi->top ++; break; case PDF_TOK_REAL: - csi->stack[csi->top] = fz_atof(buf); + csi->stack[csi->top] = buf->f; csi->top ++; break; case PDF_TOK_STRING: - if (len <= sizeof(csi->string)) + if (buf->len <= sizeof(csi->string)) { - memcpy(csi->string, buf, len); - csi->string_len = len; + memcpy(csi->string, buf->scratch, buf->len); + csi->string_len = buf->len; } else { - csi->obj = fz_new_string(ctx, buf, len); + csi->obj = pdf_new_string(ctx, buf->scratch, buf->len); } break; case PDF_TOK_KEYWORD: - pdf_run_keyword(csi, rdb, file, buf); + pdf_run_keyword(csi, rdb, file, buf->scratch); /* RJW: "cannot run keyword" */ pdf_clear_stack(csi); break; @@ -2647,11 +2652,10 @@ pdf_run_stream(pdf_csi *csi, fz_obj *rdb, fz_stream *file, char *buf, int buflen */ static void -pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents) +pdf_run_buffer(pdf_csi *csi, pdf_obj *rdb, fz_buffer *contents) { fz_context *ctx = csi->dev->ctx; - int len = sizeof csi->xref->scratch; - char *buf = NULL; + pdf_lexbuf_large *buf; fz_stream * file = NULL; int save_in_text; @@ -2663,13 +2667,14 @@ pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents) fz_try(ctx) { - buf = fz_malloc(ctx, len); /* we must be re-entrant for type3 fonts */ + buf = fz_malloc(ctx, sizeof(*buf)); /* we must be re-entrant for type3 fonts */ + buf->base.size = PDF_LEXBUF_LARGE; file = fz_open_buffer(ctx, contents); save_in_text = csi->in_text; csi->in_text = 0; fz_try(ctx) { - pdf_run_stream(csi, rdb, file, buf, len); + pdf_run_stream(csi, rdb, file, &buf->base); } fz_catch(ctx) { @@ -2677,14 +2682,15 @@ pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents) } csi->in_text = save_in_text; } - fz_catch(ctx) + fz_always(ctx) { fz_close(file); fz_free(ctx, buf); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot parse context stream"); } - fz_close(file); - fz_free(ctx, buf); } void @@ -2730,7 +2736,7 @@ pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_m cookie->progress++; } - flags = fz_to_int(fz_dict_gets(annot->obj, "F")); + flags = pdf_to_int(pdf_dict_gets(annot->obj, "F")); /* TODO: NoZoom and NoRotate */ if (flags & (1 << 0)) /* Invisible */ @@ -2743,7 +2749,7 @@ pdf_run_page_with_usage(pdf_document *xref, pdf_page *page, fz_device *dev, fz_m continue; csi = pdf_new_csi(xref, dev, ctm, event, cookie, NULL); - if (!pdf_is_hidden_ocg(fz_dict_gets(annot->obj, "OC"), csi, page->resources)) + if (!pdf_is_hidden_ocg(pdf_dict_gets(annot->obj, "OC"), csi, page->resources)) { fz_try(ctx) { @@ -2769,7 +2775,7 @@ pdf_run_page(pdf_document *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, } void -pdf_run_glyph(pdf_document *xref, fz_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate) +pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate) { pdf_csi *csi = pdf_new_csi(xref, dev, ctm, "View", NULL, gstate); fz_context *ctx = xref->ctx; |