diff options
-rw-r--r-- | fitz/filt_basic.c | 48 | ||||
-rw-r--r-- | fitz/filt_dctd.c | 16 | ||||
-rw-r--r-- | fitz/filt_faxd.c | 16 | ||||
-rw-r--r-- | fitz/filt_flate.c | 12 | ||||
-rw-r--r-- | fitz/filt_jbig2d.c | 6 | ||||
-rw-r--r-- | fitz/filt_lzwd.c | 6 | ||||
-rw-r--r-- | fitz/filt_predict.c | 12 | ||||
-rw-r--r-- | fitz/fitz.h | 4 | ||||
-rw-r--r-- | fitz/stm_open.c | 39 | ||||
-rw-r--r-- | pdf/pdf_cmap_load.c | 18 | ||||
-rw-r--r-- | pdf/pdf_font.c | 5 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 128 | ||||
-rw-r--r-- | pdf/pdf_stream.c | 16 |
13 files changed, 161 insertions, 165 deletions
diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c index 1096f266..3e86514f 100644 --- a/fitz/filt_basic.c +++ b/fitz/filt_basic.c @@ -27,11 +27,11 @@ read_null(fz_stream *stm, unsigned char *buf, int len) } static void -close_null(fz_stream *stm) +close_null(fz_context *ctx, void *state_) { - struct null_filter *state = stm->state; + struct null_filter *state = (struct null_filter *)state_; fz_stream *chain = state->chain; - fz_free(stm->ctx, state); + fz_free(ctx, state); fz_close(chain); } @@ -39,7 +39,6 @@ fz_stream * fz_open_null(fz_stream *chain, int len) { struct null_filter *state; - fz_stream *stream; fz_context *ctx = chain->ctx; assert(chain); @@ -47,16 +46,7 @@ fz_open_null(fz_stream *chain, int len) state->chain = chain; state->remain = len; - fz_try(ctx) - { - stream = fz_new_stream(ctx, state, read_null, close_null); - } - fz_catch(ctx) - { - fz_free(ctx, state); - fz_rethrow(ctx); - } - return stream; + return fz_new_stream(ctx, state, read_null, close_null); } /* ASCII Hex Decode */ @@ -143,11 +133,11 @@ read_ahxd(fz_stream *stm, unsigned char *buf, int len) } static void -close_ahxd(fz_stream *stm) +close_ahxd(fz_context *ctx, void *state_) { - fz_ahxd *state = stm->state; + fz_ahxd *state = (fz_ahxd *)state_; fz_stream *chain = state->chain; - fz_free(stm->ctx, state); + fz_free(ctx, state); fz_close(chain); } @@ -279,12 +269,12 @@ read_a85d(fz_stream *stm, unsigned char *buf, int len) } static void -close_a85d(fz_stream *stm) +close_a85d(fz_context *ctx, void *state_) { - fz_a85d *state = stm->state; + fz_a85d *state = (fz_a85d *)state_; fz_stream *chain = state->chain; - fz_free(stm->ctx, state); + fz_free(ctx, state); fz_close(chain); } @@ -367,12 +357,12 @@ read_rld(fz_stream *stm, unsigned char *buf, int len) } static void -close_rld(fz_stream *stm) +close_rld(fz_context *ctx, void *state_) { - fz_rld *state = stm->state; + fz_rld *state = (void *)state_; fz_stream *chain = state->chain; - fz_free(stm->ctx, state); + fz_free(ctx, state); fz_close(chain); } @@ -411,12 +401,12 @@ read_arc4(fz_stream *stm, unsigned char *buf, int len) } static void -close_arc4(fz_stream *stm) +close_arc4(fz_context *ctx, void *state_) { - fz_arc4c *state = stm->state; + fz_arc4c *state = (fz_arc4c *)state_; fz_stream *chain = state->chain; - fz_free(stm->ctx, state); + fz_free(ctx, state); fz_close(chain); } @@ -493,12 +483,12 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len) } static void -close_aesd(fz_stream *stm) +close_aesd(fz_context *ctx, void *state_) { - fz_aesd *state = stm->state; + fz_aesd *state = (fz_aesd *)state_; fz_stream *chain = state->chain; - fz_free(stm->ctx, state); + fz_free(ctx, state); fz_close(chain); } diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 5fb1a933..bae91195 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -180,14 +180,15 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) } static void -close_dctd(fz_stream *stm) +close_dctd(fz_context *ctx, void *state_) { - fz_dctd *state = stm->state; + fz_dctd *state = (fz_dctd *)state_; if (setjmp(state->jb)) { - state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; - fz_warn(state->ctx, "jpeg error: %s", state->msg); + if (state->cinfo.src) + state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; + fz_warn(ctx, "jpeg error: %s", state->msg); goto skip; } @@ -195,11 +196,12 @@ close_dctd(fz_stream *stm) jpeg_finish_decompress(&state->cinfo); skip: - state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; + if (state->cinfo.src) + state->chain->rp = state->chain->wp - state->cinfo.src->bytes_in_buffer; jpeg_destroy_decompress(&state->cinfo); - fz_free(stm->ctx, state->scanline); + fz_free(ctx, state->scanline); fz_close(state->chain); - fz_free(stm->ctx, state); + fz_free(ctx, state); } fz_stream * diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index be88eda1..309844bf 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -643,9 +643,9 @@ rtc: } static void -close_faxd(fz_stream *stm) +close_faxd(fz_context *ctx, void *state_) { - fz_faxd *fax = stm->state; + fz_faxd *fax = (fz_faxd *)state_; int i; /* if we read any extra bytes, try to put them back */ @@ -654,9 +654,9 @@ close_faxd(fz_stream *stm) fz_unread_byte(fax->chain); fz_close(fax->chain); - fz_free(stm->ctx, fax->ref); - fz_free(stm->ctx, fax->dst); - fz_free(stm->ctx, fax); + fz_free(ctx, fax->ref); + fz_free(ctx, fax->dst); + fz_free(ctx, fax); } fz_stream * @@ -665,7 +665,6 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fz_faxd *fax; fz_obj *obj; fz_context *ctx; - fz_stream *stream; assert(chain); ctx = chain->ctx; @@ -724,8 +723,6 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) memset(fax->ref, 0, fax->stride); memset(fax->dst, 0, fax->stride); - - stream = fz_new_stream(ctx, fax, read_faxd, close_faxd); } fz_catch(ctx) { @@ -734,5 +731,6 @@ fz_open_faxd(fz_stream *chain, fz_obj *params) fz_free(ctx, fax); fz_rethrow(ctx); } - return stream; + + return fz_new_stream(ctx, fax, read_faxd, close_faxd); } diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index aafb0fc7..d83228a1 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -67,17 +67,17 @@ read_flated(fz_stream *stm, unsigned char *outbuf, int outlen) } static void -close_flated(fz_stream *stm) +close_flated(fz_context *ctx, void *state_) { - fz_flate *state = stm->state; + fz_flate *state = (fz_flate *)state_; int code; code = inflateEnd(&state->z); if (code != Z_OK) - fz_warn(stm->ctx, "zlib error: inflateEnd: %s", state->z.msg); + fz_warn(ctx, "zlib error: inflateEnd: %s", state->z.msg); fz_close(state->chain); - fz_free(stm->ctx, state); + fz_free(ctx, state); } fz_stream * @@ -86,7 +86,6 @@ fz_open_flated(fz_stream *chain) fz_flate *state; int code = Z_OK; fz_context *ctx = chain->ctx; - fz_stream *stream; fz_var(code); @@ -104,7 +103,6 @@ fz_open_flated(fz_stream *chain) code = inflateInit(&state->z); if (code != Z_OK) fz_throw(ctx, "zlib error: inflateInit: %s", state->z.msg); - stream = fz_new_stream(chain->ctx, state, read_flated, close_flated); } fz_catch(ctx) { @@ -113,5 +111,5 @@ fz_open_flated(fz_stream *chain) fz_free(ctx, state); fz_rethrow(ctx); } - return stream; + return fz_new_stream(chain->ctx, state, read_flated, close_flated); } diff --git a/fitz/filt_jbig2d.c b/fitz/filt_jbig2d.c index e90be9f8..69e3df50 100644 --- a/fitz/filt_jbig2d.c +++ b/fitz/filt_jbig2d.c @@ -29,16 +29,16 @@ struct fz_jbig2d_s }; static void -close_jbig2d(fz_stream *stm) +close_jbig2d(fz_context *ctx, void *state_) { - fz_jbig2d *state = stm->state; + fz_jbig2d *state = (fz_jbig2d *)state_; if (state->page) jbig2_release_page(state->ctx, state->page); if (state->gctx) jbig2_global_ctx_free(state->gctx); jbig2_ctx_free(state->ctx); fz_close(state->chain); - fz_free(stm->ctx, state); + fz_free(ctx, state); } static int diff --git a/fitz/filt_lzwd.c b/fitz/filt_lzwd.c index eda52669..1ac588c4 100644 --- a/fitz/filt_lzwd.c +++ b/fitz/filt_lzwd.c @@ -156,11 +156,11 @@ read_lzwd(fz_stream *stm, unsigned char *buf, int len) } static void -close_lzwd(fz_stream *stm) +close_lzwd(fz_context *ctx, void *state_) { - fz_lzwd *lzw = stm->state; + fz_lzwd *lzw = (fz_lzwd *)state_; fz_close(lzw->chain); - fz_free(stm->ctx, lzw); + fz_free(ctx, lzw); } fz_stream * diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c index 72b91439..ab4a2eaa 100644 --- a/fitz/filt_predict.c +++ b/fitz/filt_predict.c @@ -177,14 +177,14 @@ read_predict(fz_stream *stm, unsigned char *buf, int len) } static void -close_predict(fz_stream *stm) +close_predict(fz_context *ctx, void *state_) { - fz_predict *state = stm->state; + fz_predict *state = (fz_predict *)state_; fz_close(state->chain); - fz_free(stm->ctx, state->in); - fz_free(stm->ctx, state->out); - fz_free(stm->ctx, state->ref); - fz_free(stm->ctx, state); + fz_free(ctx, state->in); + fz_free(ctx, state->out); + fz_free(ctx, state->ref); + fz_free(ctx, state); } fz_stream * diff --git a/fitz/fitz.h b/fitz/fitz.h index b4c3cd15..589f22ee 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -550,7 +550,7 @@ struct fz_stream_s unsigned char *bp, *rp, *wp, *ep; void *state; int (*read)(fz_stream *stm, unsigned char *buf, int len); - void (*close)(fz_stream *stm); + void (*close)(fz_context *ctx, void *state); void (*seek)(fz_stream *stm, int offset, int whence); unsigned char buf[4096]; }; @@ -562,7 +562,7 @@ fz_stream *fz_open_buffer(fz_context *ctx, fz_buffer *buf); fz_stream *fz_open_memory(fz_context *ctx, unsigned char *data, int len); void fz_close(fz_stream *stm); -fz_stream *fz_new_stream(fz_context *ctx, void*, int(*)(fz_stream*, unsigned char*, int), void(*)(fz_stream *)); +fz_stream *fz_new_stream(fz_context *ctx, void*, int(*)(fz_stream*, unsigned char*, int), void(*)(fz_context *, void *)); fz_stream *fz_keep_stream(fz_stream *stm); void fz_fill_buffer(fz_stream *stm); diff --git a/fitz/stm_open.c b/fitz/stm_open.c index ae918667..fde4f964 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -3,11 +3,19 @@ fz_stream * fz_new_stream(fz_context *ctx, void *state, int(*read)(fz_stream *stm, unsigned char *buf, int len), - void(*close)(fz_stream *stm)) + void(*close)(fz_context *ctx, void *state)) { fz_stream *stm; - stm = fz_malloc_struct(ctx, fz_stream); + fz_try(ctx) + { + stm = fz_malloc_struct(ctx, fz_stream); + } + fz_catch(ctx) + { + close(ctx, state); + fz_rethrow(ctx); + } stm->refs = 1; stm->error = 0; @@ -47,7 +55,7 @@ fz_close(fz_stream *stm) if (stm->refs == 0) { if (stm->close) - stm->close(stm); + stm->close(stm->ctx, stm->state); fz_free(stm->ctx, stm); } } @@ -72,12 +80,12 @@ static void seek_file(fz_stream *stm, int offset, int whence) stm->wp = stm->bp; } -static void close_file(fz_stream *stm) +static void close_file(fz_context *ctx, void *state) { - int n = close(*(int*)stm->state); + int n = close(*(int*)state); if (n < 0) - fz_warn(stm->ctx, "close error: %s", strerror(errno)); - fz_free(stm->ctx, stm->state); + fz_warn(ctx, "close error: %s", strerror(errno)); + fz_free(ctx, state); } fz_stream * @@ -89,15 +97,7 @@ fz_open_fd(fz_context *ctx, int fd) state = fz_malloc_struct(ctx, int); *state = fd; - fz_try(ctx) - { - stm = fz_new_stream(ctx, state, read_file, close_file); - } - fz_catch(ctx) - { - fz_free(ctx, state); - fz_rethrow(ctx); - } + stm = fz_new_stream(ctx, state, read_file, close_file); stm->seek = seek_file; return stm; @@ -142,10 +142,11 @@ static void seek_buffer(fz_stream *stm, int offset, int whence) stm->wp = stm->ep; } -static void close_buffer(fz_stream *stm) +static void close_buffer(fz_context *ctx, void *state_) { - if (stm->state) - fz_drop_buffer(stm->ctx, stm->state); + fz_buffer *state = (fz_buffer *)state_; + if (state) + fz_drop_buffer(ctx, state); } fz_stream * diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c index 51949907..5cf70d9e 100644 --- a/pdf/pdf_cmap_load.c +++ b/pdf/pdf_cmap_load.c @@ -89,11 +89,19 @@ pdf_cmap * pdf_new_identity_cmap(fz_context *ctx, int wmode, int bytes) { pdf_cmap *cmap = pdf_new_cmap(ctx); - sprintf(cmap->cmap_name, "Identity-%c", wmode ? 'V' : 'H'); - pdf_add_codespace(ctx, cmap, 0x0000, 0xffff, bytes); - pdf_map_range_to_range(ctx, cmap, 0x0000, 0xffff, 0); - pdf_sort_cmap(ctx, cmap); - pdf_set_wmode(cmap, wmode); + fz_try(ctx) + { + sprintf(cmap->cmap_name, "Identity-%c", wmode ? 'V' : 'H'); + pdf_add_codespace(ctx, cmap, 0x0000, 0xffff, bytes); + pdf_map_range_to_range(ctx, cmap, 0x0000, 0xffff, 0); + pdf_sort_cmap(ctx, cmap); + pdf_set_wmode(cmap, wmode); + } + fz_catch(ctx) + { + pdf_drop_cmap(ctx, cmap); + fz_rethrow(ctx); + } return cmap; } diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index f590dcde..ccc5786b 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -411,15 +411,14 @@ pdf_load_simple_font(pdf_xref *xref, fz_obj *dict) int fterr; fz_context *ctx = xref->ctx; - fz_var(fontdesc); - basefont = fz_to_name(fz_dict_gets(dict, "BaseFont")); fontname = clean_font_name(basefont); + fontdesc = pdf_new_font_desc(ctx); + /* Load font file */ fz_try(ctx) { - fontdesc = pdf_new_font_desc(ctx); descriptor = fz_dict_gets(dict, "FontDescriptor"); if (descriptor) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 6478fb35..0d5e2aa2 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -560,80 +560,88 @@ pdf_flush_text(pdf_csi *csi) if (csi->in_hidden_ocg > 0) dostroke = dofill = 0; - bbox = fz_bound_text(text, gstate->ctm); + fz_try(ctx) + { + bbox = fz_bound_text(text, gstate->ctm); - pdf_begin_group(csi, bbox); + pdf_begin_group(csi, bbox); - if (doinvisible) - fz_ignore_text(csi->dev, text, gstate->ctm); + if (doinvisible) + fz_ignore_text(csi->dev, text, gstate->ctm); - if (doclip) - { - if (csi->accumulate < 2) - gstate->clip_depth++; - fz_clip_text(csi->dev, text, gstate->ctm, csi->accumulate); - csi->accumulate = 2; - } + if (doclip) + { + if (csi->accumulate < 2) + gstate->clip_depth++; + fz_clip_text(csi->dev, text, gstate->ctm, csi->accumulate); + csi->accumulate = 2; + } - if (dofill) - { - switch (gstate->fill.kind) + if (dofill) { - case PDF_MAT_NONE: - break; - case PDF_MAT_COLOR: - fz_fill_text(csi->dev, text, gstate->ctm, - gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha); - break; - case PDF_MAT_PATTERN: - if (gstate->fill.pattern) - { - fz_clip_text(csi->dev, text, gstate->ctm, 0); - pdf_show_pattern(csi, gstate->fill.pattern, bbox, PDF_FILL); - fz_pop_clip(csi->dev); - } - break; - case PDF_MAT_SHADE: - if (gstate->fill.shade) + switch (gstate->fill.kind) { - fz_clip_text(csi->dev, text, gstate->ctm, 0); - fz_fill_shade(csi->dev, gstate->fill.shade, csi->top_ctm, gstate->fill.alpha); - fz_pop_clip(csi->dev); + case PDF_MAT_NONE: + break; + case PDF_MAT_COLOR: + fz_fill_text(csi->dev, text, gstate->ctm, + gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha); + break; + case PDF_MAT_PATTERN: + if (gstate->fill.pattern) + { + fz_clip_text(csi->dev, text, gstate->ctm, 0); + pdf_show_pattern(csi, gstate->fill.pattern, bbox, PDF_FILL); + fz_pop_clip(csi->dev); + } + break; + case PDF_MAT_SHADE: + if (gstate->fill.shade) + { + fz_clip_text(csi->dev, text, gstate->ctm, 0); + fz_fill_shade(csi->dev, gstate->fill.shade, csi->top_ctm, gstate->fill.alpha); + fz_pop_clip(csi->dev); + } + break; } - break; } - } - if (dostroke) - { - switch (gstate->stroke.kind) + if (dostroke) { - case PDF_MAT_NONE: - break; - case PDF_MAT_COLOR: - fz_stroke_text(csi->dev, text, &gstate->stroke_state, gstate->ctm, - gstate->stroke.colorspace, gstate->stroke.v, gstate->stroke.alpha); - break; - case PDF_MAT_PATTERN: - if (gstate->stroke.pattern) - { - fz_clip_stroke_text(csi->dev, text, &gstate->stroke_state, gstate->ctm); - pdf_show_pattern(csi, gstate->stroke.pattern, bbox, PDF_FILL); - fz_pop_clip(csi->dev); - } - break; - case PDF_MAT_SHADE: - if (gstate->stroke.shade) + switch (gstate->stroke.kind) { - fz_clip_stroke_text(csi->dev, text, &gstate->stroke_state, gstate->ctm); - fz_fill_shade(csi->dev, gstate->stroke.shade, csi->top_ctm, gstate->stroke.alpha); - fz_pop_clip(csi->dev); + case PDF_MAT_NONE: + break; + case PDF_MAT_COLOR: + fz_stroke_text(csi->dev, text, &gstate->stroke_state, gstate->ctm, + gstate->stroke.colorspace, gstate->stroke.v, gstate->stroke.alpha); + break; + case PDF_MAT_PATTERN: + if (gstate->stroke.pattern) + { + fz_clip_stroke_text(csi->dev, text, &gstate->stroke_state, gstate->ctm); + pdf_show_pattern(csi, gstate->stroke.pattern, bbox, PDF_FILL); + fz_pop_clip(csi->dev); + } + break; + case PDF_MAT_SHADE: + if (gstate->stroke.shade) + { + fz_clip_stroke_text(csi->dev, text, &gstate->stroke_state, gstate->ctm); + fz_fill_shade(csi->dev, gstate->stroke.shade, csi->top_ctm, gstate->stroke.alpha); + fz_pop_clip(csi->dev); + } + break; } - break; } - } - pdf_end_group(csi); + pdf_end_group(csi); + } + fz_catch(ctx) + { + fz_free_text(ctx, text); + fz_rethrow(ctx); + } fz_free_text(ctx, text); } diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index 625fbc76..83131860 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -199,18 +199,10 @@ pdf_open_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int g chain = pdf_open_raw_filter(chain, xref, stmobj, num, gen); - fz_try(ctx) - { - if (fz_is_name(filters)) - chain = build_filter(chain, xref, filters, params, num, gen); - else if (fz_array_len(filters) > 0) - chain = build_filter_chain(chain, xref, filters, params, num, gen); - } - fz_catch(ctx) - { - fz_close(chain); - fz_rethrow(ctx); - } + if (fz_is_name(filters)) + chain = build_filter(chain, xref, filters, params, num, gen); + else if (fz_array_len(filters) > 0) + chain = build_filter_chain(chain, xref, filters, params, num, gen); return chain; } |