diff options
Diffstat (limited to 'source/fitz')
48 files changed, 2031 insertions, 2262 deletions
diff --git a/source/fitz/bbox-device.c b/source/fitz/bbox-device.c index b8e63b56..b11a78a7 100644 --- a/source/fitz/bbox-device.c +++ b/source/fitz/bbox-device.c @@ -12,7 +12,7 @@ typedef struct fz_bbox_data_s } fz_bbox_data; static void -fz_bbox_add_rect(fz_device *dev, const fz_rect *rect, int clip) +fz_bbox_add_rect(fz_context *ctx, fz_device *dev, const fz_rect *rect, int clip) { fz_bbox_data *data = dev->user; fz_rect r = *rect; @@ -32,117 +32,117 @@ fz_bbox_add_rect(fz_device *dev, const fz_rect *rect, int clip) } static void -fz_bbox_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, +fz_bbox_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_path(dev->ctx, path, NULL, ctm, &r), 0); + fz_bbox_add_rect(ctx, dev, fz_bound_path(ctx, path, NULL, ctm, &r), 0); } static void -fz_bbox_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, +fz_bbox_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_path(dev->ctx, path, stroke, ctm, &r), 0); + fz_bbox_add_rect(ctx, dev, fz_bound_path(ctx, path, stroke, ctm, &r), 0); } static void -fz_bbox_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +fz_bbox_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_text(dev->ctx, text, NULL, ctm, &r), 0); + fz_bbox_add_rect(ctx, dev, fz_bound_text(ctx, text, NULL, ctm, &r), 0); } static void -fz_bbox_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, +fz_bbox_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_text(dev->ctx, text, stroke, ctm, &r), 0); + fz_bbox_add_rect(ctx, dev, fz_bound_text(ctx, text, stroke, ctm, &r), 0); } static void -fz_bbox_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +fz_bbox_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_shade(dev->ctx, shade, ctm, &r), 0); + fz_bbox_add_rect(ctx, dev, fz_bound_shade(ctx, shade, ctm, &r), 0); } static void -fz_bbox_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +fz_bbox_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { fz_rect r = fz_unit_rect; - fz_bbox_add_rect(dev, fz_transform_rect(&r, ctm), 0); + fz_bbox_add_rect(ctx, dev, fz_transform_rect(&r, ctm), 0); } static void -fz_bbox_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, +fz_bbox_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_rect r = fz_unit_rect; - fz_bbox_add_rect(dev, fz_transform_rect(&r, ctm), 0); + fz_bbox_add_rect(ctx, dev, fz_transform_rect(&r, ctm), 0); } static void -fz_bbox_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +fz_bbox_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_path(dev->ctx, path, NULL, ctm, &r), 1); + fz_bbox_add_rect(ctx, dev, fz_bound_path(ctx, path, NULL, ctm, &r), 1); } static void -fz_bbox_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_bbox_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_path(dev->ctx, path, stroke, ctm, &r), 1); + fz_bbox_add_rect(ctx, dev, fz_bound_path(ctx, path, stroke, ctm, &r), 1); } static void -fz_bbox_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) +fz_bbox_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { fz_rect r = fz_infinite_rect; if (accumulate) - fz_bbox_add_rect(dev, &r, accumulate != 2); + fz_bbox_add_rect(ctx, dev, &r, accumulate != 2); else - fz_bbox_add_rect(dev, fz_bound_text(dev->ctx, text, NULL, ctm, &r), 1); + fz_bbox_add_rect(ctx, dev, fz_bound_text(ctx, text, NULL, ctm, &r), 1); } static void -fz_bbox_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_bbox_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_rect r; - fz_bbox_add_rect(dev, fz_bound_text(dev->ctx, text, stroke, ctm, &r), 1); + fz_bbox_add_rect(ctx, dev, fz_bound_text(ctx, text, stroke, ctm, &r), 1); } static void -fz_bbox_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) +fz_bbox_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { fz_rect r = fz_unit_rect; - fz_bbox_add_rect(dev, fz_transform_rect(&r, ctm), 1); + fz_bbox_add_rect(ctx, dev, fz_transform_rect(&r, ctm), 1); } static void -fz_bbox_pop_clip(fz_device *dev) +fz_bbox_pop_clip(fz_context *ctx, fz_device *dev) { fz_bbox_data *data = dev->user; if (data->top > 0) data->top--; else - fz_warn(dev->ctx, "unexpected pop clip"); + fz_warn(ctx, "unexpected pop clip"); } static void -fz_bbox_begin_mask(fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *color) +fz_bbox_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *color) { fz_bbox_data *data = dev->user; - fz_bbox_add_rect(dev, rect, 1); + fz_bbox_add_rect(ctx, dev, rect, 1); data->ignore++; } static void -fz_bbox_end_mask(fz_device *dev) +fz_bbox_end_mask(fz_context *ctx, fz_device *dev) { fz_bbox_data *data = dev->user; assert(data->ignore > 0); @@ -150,29 +150,29 @@ fz_bbox_end_mask(fz_device *dev) } static void -fz_bbox_begin_group(fz_device *dev, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha) +fz_bbox_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha) { - fz_bbox_add_rect(dev, rect, 1); + fz_bbox_add_rect(ctx, dev, rect, 1); } static void -fz_bbox_end_group(fz_device *dev) +fz_bbox_end_group(fz_context *ctx, fz_device *dev) { - fz_bbox_pop_clip(dev); + fz_bbox_pop_clip(ctx, dev); } static int -fz_bbox_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) +fz_bbox_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { fz_bbox_data *data = dev->user; fz_rect r = *area; - fz_bbox_add_rect(dev, fz_transform_rect(&r, ctm), 0); + fz_bbox_add_rect(ctx, dev, fz_transform_rect(&r, ctm), 0); data->ignore++; return 0; } static void -fz_bbox_end_tile(fz_device *dev) +fz_bbox_end_tile(fz_context *ctx, fz_device *dev) { fz_bbox_data *data = dev->user; assert(data->ignore > 0); @@ -180,12 +180,12 @@ fz_bbox_end_tile(fz_device *dev) } static void -fz_bbox_drop_user(fz_device *dev) +fz_bbox_drop_user(fz_context *ctx, fz_device *dev) { fz_bbox_data *data = dev->user; if (data->top > 0) - fz_warn(dev->ctx, "items left on stack in bbox device: %d", data->top); - fz_free(dev->ctx, dev->user); + fz_warn(ctx, "items left on stack in bbox device: %d", data->top); + fz_free(ctx, dev->user); } fz_device * diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c index 12de453a..df0163f5 100644 --- a/source/fitz/buffer.c +++ b/source/fitz/buffer.c @@ -361,7 +361,7 @@ fz_test_buffer_write(fz_context *ctx) k = (rand() & 31)+1; if (k > j) k = j; - fz_write_buffer_bits(ctx, copy, fz_read_bits(stm, k), k); + fz_write_buffer_bits(ctx, copy, fz_read_bits(ctx, stm, k), k); j -= k; } while (j); diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c index f1dff20c..42aa6129 100644 --- a/source/fitz/colorspace.c +++ b/source/fitz/colorspace.c @@ -286,7 +286,7 @@ fz_set_device_cmyk(fz_context *ctx, fz_colorspace *cs) } int -fz_colorspace_is_indexed(fz_colorspace *cs) +fz_colorspace_is_indexed(fz_context *ctx, fz_colorspace *cs) { return (cs && !strcmp(cs->name, "Indexed")); } @@ -840,14 +840,14 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) { fz_color_converter cc; - fz_lookup_color_converter(&cc, ctx, ds, ss); + fz_lookup_color_converter(ctx, &cc, ds, ss); for (; xy > 0; xy--) { srcv[0] = *s++ / 255.0f * 100; srcv[1] = *s++ - 128; srcv[2] = *s++ - 128; - cc.convert(&cc, dstv, srcv); + cc.convert(ctx, &cc, dstv, srcv); for (k = 0; k < dstn; k++) *d++ = dstv[k] * 255; @@ -861,13 +861,13 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) { fz_color_converter cc; - fz_lookup_color_converter(&cc, ctx, ds, ss); + fz_lookup_color_converter(ctx, &cc, ds, ss); for (; xy > 0; xy--) { for (k = 0; k < srcn; k++) srcv[k] = *s++ / 255.0f; - cc.convert(&cc, dstv, srcv); + cc.convert(ctx, &cc, dstv, srcv); for (k = 0; k < dstn; k++) *d++ = dstv[k] * 255; @@ -882,11 +882,11 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) unsigned char lookup[FZ_MAX_COLORS * 256]; fz_color_converter cc; - fz_lookup_color_converter(&cc, ctx, ds, ss); + fz_lookup_color_converter(ctx, &cc, ds, ss); for (i = 0; i < 256; i++) { srcv[0] = i / 255.0f; - cc.convert(&cc, dstv, srcv); + cc.convert(ctx, &cc, dstv, srcv); for (k = 0; k < dstn; k++) lookup[i * dstn + k] = dstv[k] * 255; } @@ -909,7 +909,7 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) unsigned char *sold = &dummy; fz_color_converter cc; - fz_lookup_color_converter(&cc, ctx, ds, ss); + fz_lookup_color_converter(ctx, &cc, ds, ss); lookup = fz_new_hash_table(ctx, 509, srcn, -1); for (; xy > 0; xy--) @@ -937,7 +937,7 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *dst, fz_pixmap *src) { for (k = 0; k < srcn; k++) srcv[k] = *s++ / 255.0f; - cc.convert(&cc, dstv, srcv); + cc.convert(ctx, &cc, dstv, srcv); for (k = 0; k < dstn; k++) *d++ = dstv[k] * 255; @@ -1000,13 +1000,12 @@ fz_convert_pixmap(fz_context *ctx, fz_pixmap *dp, fz_pixmap *sp) /* Convert a single color */ static void -std_conv_color(fz_color_converter *cc, float *dstv, const float *srcv) +std_conv_color(fz_context *ctx, fz_color_converter *cc, float *dstv, const float *srcv) { float rgb[3]; int i; fz_colorspace *srcs = cc->ss; fz_colorspace *dsts = cc->ds; - fz_context *ctx = cc->ctx; if (srcs != dsts) { @@ -1024,7 +1023,7 @@ std_conv_color(fz_color_converter *cc, float *dstv, const float *srcv) } static void -g2rgb(fz_color_converter *cc, float *dv, const float *sv) +g2rgb(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { dv[0] = sv[0]; dv[1] = sv[0]; @@ -1032,7 +1031,7 @@ g2rgb(fz_color_converter *cc, float *dv, const float *sv) } static void -g2cmyk(fz_color_converter *cc, float *dv, const float *sv) +g2cmyk(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { dv[0] = 0; dv[1] = 0; @@ -1041,13 +1040,13 @@ g2cmyk(fz_color_converter *cc, float *dv, const float *sv) } static void -rgb2g(fz_color_converter *cc, float *dv, const float *sv) +rgb2g(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { dv[0] = sv[0] * 0.3f + sv[1] * 0.59f + sv[2] * 0.11f; } static void -rgb2bgr(fz_color_converter *cc, float *dv, const float *sv) +rgb2bgr(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { dv[0] = sv[2]; dv[1] = sv[1]; @@ -1055,7 +1054,7 @@ rgb2bgr(fz_color_converter *cc, float *dv, const float *sv) } static void -rgb2cmyk(fz_color_converter *cc, float *dv, const float *sv) +rgb2cmyk(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { float c = 1 - sv[0]; float m = 1 - sv[1]; @@ -1068,13 +1067,13 @@ rgb2cmyk(fz_color_converter *cc, float *dv, const float *sv) } static void -bgr2g(fz_color_converter *cc, float *dv, const float *sv) +bgr2g(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { dv[0] = sv[0] * 0.11f + sv[1] * 0.59f + sv[2] * 0.3f; } static void -bgr2cmyk(fz_color_converter *cc, float *dv, const float *sv) +bgr2cmyk(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { float c = 1 - sv[2]; float m = 1 - sv[1]; @@ -1087,7 +1086,7 @@ bgr2cmyk(fz_color_converter *cc, float *dv, const float *sv) } static void -cmyk2g(fz_color_converter *cc, float *dv, const float *sv) +cmyk2g(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { float c = sv[0] * 0.3f; float m = sv[1] * 0.59f; @@ -1096,10 +1095,10 @@ cmyk2g(fz_color_converter *cc, float *dv, const float *sv) } static void -cmyk2rgb(fz_color_converter *cc, float *dv, const float *sv) +cmyk2rgb(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { #ifdef SLOWCMYK - cmyk_to_rgb(cc->ctx, NULL, sv, dv); + cmyk_to_rgb(ctx, NULL, sv, dv); #else dv[0] = 1 - fz_min(sv[0] + sv[3], 1); dv[1] = 1 - fz_min(sv[1] + sv[3], 1); @@ -1108,11 +1107,11 @@ cmyk2rgb(fz_color_converter *cc, float *dv, const float *sv) } static void -cmyk2bgr(fz_color_converter *cc, float *dv, const float *sv) +cmyk2bgr(fz_context *ctx, fz_color_converter *cc, float *dv, const float *sv) { #ifdef SLOWCMYK float rgb[3]; - cmyk_to_rgb(cc->ctx, NULL, sv, rgb); + cmyk_to_rgb(ctx, NULL, sv, rgb); dv[0] = rgb[2]; dv[1] = rgb[1]; dv[2] = rgb[0]; @@ -1123,9 +1122,8 @@ cmyk2bgr(fz_color_converter *cc, float *dv, const float *sv) #endif } -void fz_lookup_color_converter(fz_color_converter *cc, fz_context *ctx, fz_colorspace *ds, fz_colorspace *ss) +void fz_lookup_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *ds, fz_colorspace *ss) { - cc->ctx = ctx; cc->ds = ds; cc->ss = ss; if (ss == fz_default_gray) @@ -1182,8 +1180,8 @@ void fz_convert_color(fz_context *ctx, fz_colorspace *ds, float *dv, fz_colorspace *ss, const float *sv) { fz_color_converter cc; - fz_lookup_color_converter(&cc, ctx, ds, ss); - cc.convert(&cc, dv, sv); + fz_lookup_color_converter(ctx, &cc, ds, ss); + cc.convert(ctx, &cc, dv, sv); } /* Indexed */ @@ -1293,10 +1291,9 @@ typedef struct fz_cached_color_converter } fz_cached_color_converter; -static void fz_cached_color_convert(fz_color_converter *cc_, float *ds, const float *ss) +static void fz_cached_color_convert(fz_context *ctx, fz_color_converter *cc_, float *ds, const float *ss) { fz_cached_color_converter *cc = cc_->opaque; - fz_context *ctx = cc->base.ctx; void *val = fz_hash_find(ctx, cc->hash, ss); int n = cc->base.ds->n * sizeof(float); fz_color_converter *base_cc = &cc->base; @@ -1307,7 +1304,7 @@ static void fz_cached_color_convert(fz_color_converter *cc_, float *ds, const fl return; } - base_cc->convert(base_cc, ds, ss); + base_cc->convert(ctx, base_cc, ds, ss); val = fz_malloc(ctx, n); memcpy(val, ds, n); fz_try(ctx) @@ -1327,10 +1324,9 @@ void fz_init_cached_color_converter(fz_context *ctx, fz_color_converter *cc, fz_ fz_try(ctx) { - fz_lookup_color_converter(&cached->base, ctx, ds, ss); + fz_lookup_color_converter(ctx, &cached->base, ds, ss); cached->hash = fz_new_hash_table(ctx, 256, n * sizeof(float), -1); cc->convert = fz_cached_color_convert; - cc->ctx = ctx; cc->ds = ds; cc->ss = ss; cc->opaque = cached; @@ -1342,10 +1338,9 @@ void fz_init_cached_color_converter(fz_context *ctx, fz_color_converter *cc, fz_ } } -void fz_fin_cached_color_converter(fz_color_converter *cc_) +void fz_fin_cached_color_converter(fz_context *ctx, fz_color_converter *cc_) { fz_cached_color_converter *cc; - fz_context *ctx; int i, n; if (cc_ == NULL) @@ -1354,7 +1349,6 @@ void fz_fin_cached_color_converter(fz_color_converter *cc_) if (cc == NULL) return; cc_->opaque = NULL; - ctx = cc_->ctx; n = fz_hash_len(ctx, cc->hash); for (i = 0; i < n; i++) diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c index 48f88eff..85890c72 100644 --- a/source/fitz/compressed-buffer.c +++ b/source/fitz/compressed-buffer.c @@ -28,7 +28,7 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *chain, fz_compression_pa { case FZ_IMAGE_FAX: *l2factor = 0; - return fz_open_faxd(chain, + return fz_open_faxd(ctx, chain, params->u.fax.k, params->u.fax.end_of_line, params->u.fax.encoded_byte_align, @@ -39,21 +39,21 @@ fz_open_image_decomp_stream(fz_context *ctx, fz_stream *chain, fz_compression_pa case FZ_IMAGE_JPEG: if (*l2factor > 3) *l2factor = 3; - return fz_open_dctd(chain, params->u.jpeg.color_transform, *l2factor, NULL); + return fz_open_dctd(ctx, chain, params->u.jpeg.color_transform, *l2factor, NULL); case FZ_IMAGE_RLD: *l2factor = 0; - return fz_open_rld(chain); + return fz_open_rld(ctx, chain); case FZ_IMAGE_FLATE: *l2factor = 0; - chain = fz_open_flated(chain, 15); + chain = fz_open_flated(ctx, chain, 15); if (params->u.flate.predictor > 1) - chain = fz_open_predict(chain, params->u.flate.predictor, params->u.flate.columns, params->u.flate.colors, params->u.flate.bpc); + chain = fz_open_predict(ctx, chain, params->u.flate.predictor, params->u.flate.columns, params->u.flate.colors, params->u.flate.bpc); return chain; case FZ_IMAGE_LZW: *l2factor = 0; - chain = fz_open_lzwd(chain, params->u.lzw.early_change); + chain = fz_open_lzwd(ctx, chain, params->u.lzw.early_change); if (params->u.lzw.predictor > 1) - chain = fz_open_predict(chain, params->u.lzw.predictor, params->u.lzw.columns, params->u.lzw.colors, params->u.lzw.bpc); + chain = fz_open_predict(ctx, chain, params->u.lzw.predictor, params->u.lzw.columns, params->u.lzw.colors, params->u.lzw.bpc); return chain; default: *l2factor = 0; diff --git a/source/fitz/device.c b/source/fitz/device.c index cb57256e..36a0f534 100644 --- a/source/fitz/device.c +++ b/source/fitz/device.c @@ -7,67 +7,56 @@ fz_new_device(fz_context *ctx, void *user) dev->hints = 0; dev->flags = 0; dev->user = user; - dev->ctx = ctx; dev->error_depth = 0; return dev; } void -fz_drop_device(fz_device *dev) +fz_drop_device(fz_context *ctx, fz_device *dev) { if (dev == NULL) return; if (dev->drop_user) - dev->drop_user(dev); - fz_free(dev->ctx, dev->container); - fz_free(dev->ctx, dev); + dev->drop_user(ctx, dev); + fz_free(ctx, dev->container); + fz_free(ctx, dev); } void -fz_enable_device_hints(fz_device *dev, int hints) +fz_enable_device_hints(fz_context *ctx, fz_device *dev, int hints) { dev->hints |= hints; } void -fz_disable_device_hints(fz_device *dev, int hints) +fz_disable_device_hints(fz_context *ctx, fz_device *dev, int hints) { dev->hints &= ~hints; } void -fz_rebind_device(fz_device *dev, fz_context *ctx) -{ - if (dev == NULL) - return; - dev->ctx = ctx; - if (dev->rebind) - dev->rebind(dev); -} - -void -fz_begin_page(fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) +fz_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) { if (dev->begin_page) - dev->begin_page(dev, rect, ctm); + dev->begin_page(ctx, dev, rect, ctm); } void -fz_end_page(fz_device *dev) +fz_end_page(fz_context *ctx, fz_device *dev) { if (dev->end_page) - dev->end_page(dev); + dev->end_page(ctx, dev); } static void -push_clip_stack(fz_device *dev, const fz_rect *rect, int flags) +push_clip_stack(fz_context *ctx, fz_device *dev, const fz_rect *rect, int flags) { if (dev->container_len == dev->container_cap) { int newmax = dev->container_cap * 2; if (newmax == 0) newmax = 4; - dev->container = fz_resize_array(dev->ctx, dev->container, newmax, sizeof(*dev->container)); + dev->container = fz_resize_array(ctx, dev->container, newmax, sizeof(*dev->container)); dev->container_cap = newmax; } if (dev->container_len == 0) @@ -83,7 +72,7 @@ push_clip_stack(fz_device *dev, const fz_rect *rect, int flags) } static void -push_clip_stack_accumulate(fz_device *dev, const fz_rect *rect, int accumulate) +push_clip_stack_accumulate(fz_context *ctx, fz_device *dev, const fz_rect *rect, int accumulate) { if (accumulate <= 1) { @@ -93,7 +82,7 @@ push_clip_stack_accumulate(fz_device *dev, const fz_rect *rect, int accumulate) int newmax = dev->container_cap * 2; if (newmax == 0) newmax = 4; - dev->container = fz_resize_array(dev->ctx, dev->container, newmax, sizeof(*dev->container)); + dev->container = fz_resize_array(ctx, dev->container, newmax, sizeof(*dev->container)); dev->container_cap = newmax; } if (dev->container_len > 0) @@ -115,37 +104,35 @@ push_clip_stack_accumulate(fz_device *dev, const fz_rect *rect, int accumulate) } static void -pop_clip_stack(fz_device *dev) +pop_clip_stack(fz_context *ctx, fz_device *dev) { if (dev->container_len > 0) dev->container_len--; } void -fz_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, +fz_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (dev->error_depth) return; if (dev->fill_path) - dev->fill_path(dev, path, even_odd, ctm, colorspace, color, alpha); + dev->fill_path(ctx, dev, path, even_odd, ctm, colorspace, color, alpha); } void -fz_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (dev->error_depth) return; if (dev->stroke_path) - dev->stroke_path(dev, path, stroke, ctm, colorspace, color, alpha); + dev->stroke_path(ctx, dev, path, stroke, ctm, colorspace, color, alpha); } void -fz_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +fz_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { dev->error_depth++; @@ -160,13 +147,13 @@ fz_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, c { fz_rect bbox; fz_bound_path(ctx, path, NULL, ctm, &bbox); - push_clip_stack(dev, &bbox, fz_device_container_stack_is_clip_path); + push_clip_stack(ctx, dev, &bbox, fz_device_container_stack_is_clip_path); } else - push_clip_stack(dev, rect, fz_device_container_stack_is_clip_path); + push_clip_stack(ctx, dev, rect, fz_device_container_stack_is_clip_path); } if (dev->clip_path) - dev->clip_path(dev, path, rect, even_odd, ctm); + dev->clip_path(ctx, dev, path, rect, even_odd, ctm); } fz_catch(ctx) { @@ -177,10 +164,8 @@ fz_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, c } void -fz_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { dev->error_depth++; @@ -195,13 +180,13 @@ fz_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_strok { fz_rect bbox; fz_bound_path(ctx, path, stroke, ctm, &bbox); - push_clip_stack(dev, &bbox, fz_device_container_stack_is_clip_stroke_path); + push_clip_stack(ctx, dev, &bbox, fz_device_container_stack_is_clip_stroke_path); } else - push_clip_stack(dev, rect, fz_device_container_stack_is_clip_stroke_path); + push_clip_stack(ctx, dev, rect, fz_device_container_stack_is_clip_stroke_path); } if (dev->clip_stroke_path) - dev->clip_stroke_path(dev, path, rect, stroke, ctm); + dev->clip_stroke_path(ctx, dev, path, rect, stroke, ctm); } fz_catch(ctx) { @@ -212,30 +197,28 @@ fz_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_strok } void -fz_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +fz_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (dev->error_depth) return; if (dev->fill_text) - dev->fill_text(dev, text, ctm, colorspace, color, alpha); + dev->fill_text(ctx, dev, text, ctm, colorspace, color, alpha); } void -fz_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (dev->error_depth) return; if (dev->stroke_text) - dev->stroke_text(dev, text, stroke, ctm, colorspace, color, alpha); + dev->stroke_text(ctx, dev, text, stroke, ctm, colorspace, color, alpha); } void -fz_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) +fz_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { if (accumulate == 0 || accumulate == 1) @@ -249,10 +232,10 @@ fz_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate { fz_rect bbox; fz_bound_text(ctx, text, NULL, ctm, &bbox); - push_clip_stack_accumulate(dev, &bbox, accumulate); + push_clip_stack_accumulate(ctx, dev, &bbox, accumulate); } if (dev->clip_text) - dev->clip_text(dev, text, ctm, accumulate); + dev->clip_text(ctx, dev, text, ctm, accumulate); } fz_catch(ctx) { @@ -265,10 +248,8 @@ fz_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate } void -fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { dev->error_depth++; @@ -281,10 +262,10 @@ fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, cons { fz_rect bbox; fz_bound_text(ctx, text, stroke, ctm, &bbox); - push_clip_stack(dev, &bbox, fz_device_container_stack_is_clip_stroke_text); + push_clip_stack(ctx, dev, &bbox, fz_device_container_stack_is_clip_stroke_text); } if (dev->clip_stroke_text) - dev->clip_stroke_text(dev, text, stroke, ctm); + dev->clip_stroke_text(ctx, dev, text, stroke, ctm); } fz_catch(ctx) { @@ -295,63 +276,61 @@ fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, cons } void -fz_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { if (dev->error_depth) return; if (dev->ignore_text) - dev->ignore_text(dev, text, ctm); + dev->ignore_text(ctx, dev, text, ctm); } void -fz_pop_clip(fz_device *dev) +fz_pop_clip(fz_context *ctx, fz_device *dev) { if (dev->error_depth) { dev->error_depth--; if (dev->error_depth == 0) - fz_throw(dev->ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); + fz_throw(ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); return; } if (dev->hints & FZ_MAINTAIN_CONTAINER_STACK) - pop_clip_stack(dev); + pop_clip_stack(ctx, dev); if (dev->pop_clip) - dev->pop_clip(dev); + dev->pop_clip(ctx, dev); } void -fz_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +fz_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { if (dev->error_depth) return; if (dev->fill_shade) - dev->fill_shade(dev, shade, ctm, alpha); + dev->fill_shade(ctx, dev, shade, ctm, alpha); } void -fz_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +fz_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { if (dev->error_depth) return; if (dev->fill_image) - dev->fill_image(dev, image, ctm, alpha); + dev->fill_image(ctx, dev, image, ctm, alpha); } void -fz_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, +fz_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (dev->error_depth) return; if (dev->fill_image_mask) - dev->fill_image_mask(dev, image, ctm, colorspace, color, alpha); + dev->fill_image_mask(ctx, dev, image, ctm, colorspace, color, alpha); } void -fz_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) +fz_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { dev->error_depth++; @@ -361,9 +340,9 @@ fz_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const f fz_try(ctx) { if (dev->hints & FZ_MAINTAIN_CONTAINER_STACK) - push_clip_stack(dev, rect, fz_device_container_stack_is_clip_image_mask); + push_clip_stack(ctx, dev, rect, fz_device_container_stack_is_clip_image_mask); if (dev->clip_image_mask) - dev->clip_image_mask(dev, image, rect, ctm); + dev->clip_image_mask(ctx, dev, image, rect, ctm); } fz_catch(ctx) { @@ -374,10 +353,8 @@ fz_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const f } void -fz_begin_mask(fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, float *bc) +fz_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, float *bc) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { dev->error_depth++; @@ -387,9 +364,9 @@ fz_begin_mask(fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace fz_try(ctx) { if (dev->hints & FZ_MAINTAIN_CONTAINER_STACK) - push_clip_stack(dev, area, fz_device_container_stack_in_mask); + push_clip_stack(ctx, dev, area, fz_device_container_stack_in_mask); if (dev->begin_mask) - dev->begin_mask(dev, area, luminosity, colorspace, bc); + dev->begin_mask(ctx, dev, area, luminosity, colorspace, bc); } fz_catch(ctx) { @@ -400,10 +377,8 @@ fz_begin_mask(fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace } void -fz_end_mask(fz_device *dev) +fz_end_mask(fz_context *ctx, fz_device *dev) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { /* Converts from mask to clip, so no change in stack depth */ @@ -417,7 +392,7 @@ fz_end_mask(fz_device *dev) fz_try(ctx) { if (dev->end_mask) - dev->end_mask(dev); + dev->end_mask(ctx, dev); } fz_catch(ctx) { @@ -428,10 +403,8 @@ fz_end_mask(fz_device *dev) } void -fz_begin_group(fz_device *dev, const fz_rect *area, int isolated, int knockout, int blendmode, float alpha) +fz_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *area, int isolated, int knockout, int blendmode, float alpha) { - fz_context *ctx = dev->ctx; - if (dev->error_depth) { dev->error_depth++; @@ -441,9 +414,9 @@ fz_begin_group(fz_device *dev, const fz_rect *area, int isolated, int knockout, fz_try(ctx) { if (dev->hints & FZ_MAINTAIN_CONTAINER_STACK) - push_clip_stack(dev, area, fz_device_container_stack_is_group); + push_clip_stack(ctx, dev, area, fz_device_container_stack_is_group); if (dev->begin_group) - dev->begin_group(dev, area, isolated, knockout, blendmode, alpha); + dev->begin_group(ctx, dev, area, isolated, knockout, blendmode, alpha); } fz_catch(ctx) { @@ -454,32 +427,31 @@ fz_begin_group(fz_device *dev, const fz_rect *area, int isolated, int knockout, } void -fz_end_group(fz_device *dev) +fz_end_group(fz_context *ctx, fz_device *dev) { if (dev->error_depth) { dev->error_depth--; if (dev->error_depth == 0) - fz_throw(dev->ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); + fz_throw(ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); return; } if (dev->end_group) - dev->end_group(dev); + dev->end_group(ctx, dev); if (dev->hints & FZ_MAINTAIN_CONTAINER_STACK) - pop_clip_stack(dev); + pop_clip_stack(ctx, dev); } void -fz_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm) +fz_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm) { - (void)fz_begin_tile_id(dev, area, view, xstep, ystep, ctm, 0); + (void)fz_begin_tile_id(ctx, dev, area, view, xstep, ystep, ctm, 0); } int -fz_begin_tile_id(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) +fz_begin_tile_id(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { - fz_context *ctx = dev->ctx; - int ret = 0; + int ret; if (dev->error_depth) { @@ -495,7 +467,7 @@ fz_begin_tile_id(fz_device *dev, const fz_rect *area, const fz_rect *view, float fz_try(ctx) { if (dev->begin_tile) - ret = dev->begin_tile(dev, area, view, xstep, ystep, ctm, id); + ret = dev->begin_tile(ctx, dev, area, view, xstep, ystep, ctm, id); } fz_catch(ctx) { @@ -507,15 +479,15 @@ fz_begin_tile_id(fz_device *dev, const fz_rect *area, const fz_rect *view, float } void -fz_end_tile(fz_device *dev) +fz_end_tile(fz_context *ctx, fz_device *dev) { if (dev->error_depth) { dev->error_depth--; if (dev->error_depth == 0) - fz_throw(dev->ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); + fz_throw(ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); return; } if (dev->end_tile) - dev->end_tile(dev); + dev->end_tile(ctx, dev); } diff --git a/source/fitz/document.c b/source/fitz/document.c index 64de1bc0..63c9fd29 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -142,128 +142,142 @@ fz_open_document(fz_context *ctx, const char *filename) return NULL; } -fz_document * -fz_keep_document(fz_document *doc) +void * +fz_new_document(fz_context *ctx, int size) { - ++doc->refs; + fz_document *doc = fz_calloc(ctx, 1, size); + doc->refs = 1; return doc; } -void -fz_drop_document(fz_document *doc) +fz_document * +fz_keep_document(fz_context *ctx, fz_document *doc) { - if (doc && --doc->refs == 0 && doc->close) - doc->close(doc); + ++doc->refs; + return doc; } void -fz_rebind_document(fz_document *doc, fz_context *ctx) +fz_drop_document(fz_context *ctx, fz_document *doc) { - if (doc != NULL && doc->rebind != NULL) - doc->rebind(doc, ctx); + if (doc && --doc->refs == 0 && doc->close) + doc->close(ctx, doc); } int -fz_needs_password(fz_document *doc) +fz_needs_password(fz_context *ctx, fz_document *doc) { if (doc && doc->needs_password) - return doc->needs_password(doc); + return doc->needs_password(ctx, doc); return 0; } int -fz_authenticate_password(fz_document *doc, const char *password) +fz_authenticate_password(fz_context *ctx, fz_document *doc, const char *password) { if (doc && doc->authenticate_password) - return doc->authenticate_password(doc, password); + return doc->authenticate_password(ctx, doc, password); return 1; } fz_outline * -fz_load_outline(fz_document *doc) +fz_load_outline(fz_context *ctx, fz_document *doc) { if (doc && doc->load_outline) - return doc->load_outline(doc); + return doc->load_outline(ctx, doc); return NULL; } void -fz_layout_document(fz_document *doc, float w, float h, float em) +fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, float em) { if (doc && doc->layout) - doc->layout(doc, w, h, em); + doc->layout(ctx, doc, w, h, em); } int -fz_count_pages(fz_document *doc) +fz_count_pages(fz_context *ctx, fz_document *doc) { if (doc && doc->count_pages) - return doc->count_pages(doc); + return doc->count_pages(ctx, doc); return 0; } +int +fz_meta(fz_context *ctx, fz_document *doc, int key, void *ptr, int size) +{ + if (doc && doc->meta) + return doc->meta(ctx, doc, key, ptr, size); + return FZ_META_UNKNOWN_KEY; +} + +void +fz_write_document(fz_context *ctx, fz_document *doc, char *filename, fz_write_options *opts) +{ + if (doc && doc->write) + doc->write(ctx, doc, filename, opts); +} + fz_page * -fz_load_page(fz_document *doc, int number) +fz_load_page(fz_context *ctx, fz_document *doc, int number) { if (doc && doc->load_page) - return doc->load_page(doc, number); + return doc->load_page(ctx, doc, number); return NULL; } fz_link * -fz_load_links(fz_document *doc, fz_page *page) +fz_load_links(fz_context *ctx, fz_page *page) { - if (doc && doc->load_links && page) - return doc->load_links(doc, page); + if (page && page->load_links && page) + return page->load_links(ctx, page); return NULL; } fz_rect * -fz_bound_page(fz_document *doc, fz_page *page, fz_rect *r) +fz_bound_page(fz_context *ctx, fz_page *page, fz_rect *r) { - if (doc && doc->bound_page && page && r) - return doc->bound_page(doc, page, r); + if (page && page->bound_page && page && r) + return page->bound_page(ctx, page, r); if (r) *r = fz_empty_rect; return r; } fz_annot * -fz_first_annot(fz_document *doc, fz_page *page) +fz_first_annot(fz_context *ctx, fz_page *page) { - if (doc && doc->first_annot && page) - return doc->first_annot(doc, page); + if (page && page->first_annot && page) + return page->first_annot(ctx, page); return NULL; } fz_annot * -fz_next_annot(fz_document *doc, fz_annot *annot) +fz_next_annot(fz_context *ctx, fz_page *page, fz_annot *annot) { - if (doc && doc->next_annot && annot) - return doc->next_annot(doc, annot); + if (page && page->next_annot && annot) + return page->next_annot(ctx, page, annot); return NULL; } fz_rect * -fz_bound_annot(fz_document *doc, fz_annot *annot, fz_rect *rect) +fz_bound_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_rect *rect) { - if (doc && doc->bound_annot && annot && rect) - return doc->bound_annot(doc, annot, rect); + if (page && page->bound_annot && annot && rect) + return page->bound_annot(ctx, page, annot, rect); if (rect) *rect = fz_empty_rect; return rect; } void -fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_page_contents(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { - if (doc && doc->run_page_contents && page) + if (page && page->run_page_contents && page) { - fz_context *ctx = dev->ctx; - fz_try(ctx) { - doc->run_page_contents(doc, page, dev, transform, cookie); + page->run_page_contents(ctx, page, dev, transform, cookie); } fz_catch(ctx) { @@ -274,15 +288,13 @@ fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, const fz_m } void -fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_annot(fz_context *ctx, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { - if (doc && doc->run_annot && page && annot) + if (page && page->run_annot && page && annot) { - fz_context *ctx = dev->ctx; - fz_try(ctx) { - doc->run_annot(doc, page, annot, dev, transform, cookie); + page->run_annot(ctx, page, annot, dev, transform, cookie); } fz_catch(ctx) { @@ -293,25 +305,25 @@ fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, c } void -fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) +fz_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { fz_annot *annot; fz_rect mediabox; - fz_bound_page(doc, page, &mediabox); - fz_begin_page(dev, &mediabox, transform); + fz_bound_page(ctx, page, &mediabox); + fz_begin_page(ctx, dev, &mediabox, transform); - fz_run_page_contents(doc, page, dev, transform, cookie); + fz_run_page_contents(ctx, page, dev, transform, cookie); if (cookie && cookie->progress_max != -1) { int count = 1; - for (annot = fz_first_annot(doc, page); annot; annot = fz_next_annot(doc, annot)) + for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, page, annot)) count++; cookie->progress_max += count; } - for (annot = fz_first_annot(doc, page); annot; annot = fz_next_annot(doc, annot)) + for (annot = fz_first_annot(ctx, page); annot; annot = fz_next_annot(ctx, page, annot)) { /* Check the cookie for aborting */ if (cookie) @@ -321,43 +333,46 @@ fz_run_page(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *tr cookie->progress++; } - fz_run_annot(doc, page, annot, dev, transform, cookie); + fz_run_annot(ctx, page, annot, dev, transform, cookie); } - fz_end_page(dev); + fz_end_page(ctx, dev); } -void -fz_free_page(fz_document *doc, fz_page *page) +void * +fz_new_page(fz_context *ctx, int size) { - if (doc && doc->free_page && page) - doc->free_page(doc, page); + fz_page *page = fz_calloc(ctx, 1, size); + page->refs = 1; + return page; } -int -fz_meta(fz_document *doc, int key, void *ptr, int size) +fz_page * +fz_keep_page(fz_context *ctx, fz_page *page) { - if (doc && doc->meta) - return doc->meta(doc, key, ptr, size); - return FZ_META_UNKNOWN_KEY; + if (page) + ++page->refs; + return page; +} + +void +fz_drop_page(fz_context *ctx, fz_page *page) +{ + if (page) { + if (--page->refs == 0 && page->drop_page_imp) + page->drop_page_imp(ctx, page); + } } fz_transition * -fz_page_presentation(fz_document *doc, fz_page *page, float *duration) +fz_page_presentation(fz_context *ctx, fz_page *page, float *duration) { float dummy; if (duration) *duration = 0; else duration = &dummy; - if (doc && doc->page_presentation && page) - return doc->page_presentation(doc, page, duration); + if (page && page->page_presentation && page) + return page->page_presentation(ctx, page, duration); return NULL; } - -void -fz_write_document(fz_document *doc, char *filename, fz_write_options *opts) -{ - if (doc && doc->write) - doc->write(doc, filename, opts); -} diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c index 8701cd31..18ea53d9 100644 --- a/source/fitz/draw-device.c +++ b/source/fitz/draw-device.c @@ -38,7 +38,6 @@ struct fz_draw_state_s { struct fz_draw_device_s { fz_gel *gel; - fz_context *ctx; int flags; int top; fz_scale_cache *cache_x; @@ -77,11 +76,11 @@ static void dump_spaces(int x, const char *s) #endif #ifdef DUMP_STACK_CHANGES -#define STACK_PUSHED(A) stack_change(dev, ">" ## A) -#define STACK_POPPED(A) stack_change(dev, "<" ## A) -#define STACK_CONVERT(A) stack_change(dev, A) +#define STACK_PUSHED(A) stack_change(ctx, dev, ">" ## A) +#define STACK_POPPED(A) stack_change(ctx, dev, "<" ## A) +#define STACK_CONVERT(A) stack_change(ctx, dev, A) -static void stack_change(fz_draw_device *dev, char *s) +static void stack_change(fz_context *ctx, fz_draw_device *dev, char *s) { int depth = dev->top; int n; @@ -100,19 +99,19 @@ static void stack_change(fz_draw_device *dev, char *s) #endif -static void fz_grow_stack(fz_draw_device *dev) +static void fz_grow_stack(fz_context *ctx, fz_draw_device *dev) { int max = dev->stack_cap * 2; fz_draw_state *stack; if (dev->stack == &dev->init_stack[0]) { - stack = Memento_label(fz_malloc(dev->ctx, sizeof(*stack) * max), "draw device stack"); + stack = Memento_label(fz_malloc_array(ctx, max, sizeof *stack), "draw device stack"); memcpy(stack, dev->stack, sizeof(*stack) * dev->stack_cap); } else { - stack = fz_resize_array(dev->ctx, dev->stack, max, sizeof(*stack)); + stack = fz_resize_array(ctx, dev->stack, max, sizeof(*stack)); } dev->stack = stack; dev->stack_cap = max; @@ -122,22 +121,20 @@ static void fz_grow_stack(fz_draw_device *dev) * already having been initialised to contain the same thing. Simply * change any contents of state[1] that you want to and continue. */ static fz_draw_state * -push_stack(fz_draw_device *dev) +push_stack(fz_context *ctx, fz_draw_device *dev) { fz_draw_state *state; if (dev->top == dev->stack_cap-1) - fz_grow_stack(dev); + fz_grow_stack(ctx, dev); state = &dev->stack[dev->top]; dev->top++; memcpy(&state[1], state, sizeof(*state)); return state; } -static void emergency_pop_stack(fz_draw_device *dev, fz_draw_state *state) +static void emergency_pop_stack(fz_context *ctx, fz_draw_device *dev, fz_draw_state *state) { - fz_context *ctx = dev->ctx; - if (state[1].mask != state[0].mask) fz_drop_pixmap(ctx, state[1].mask); if (state[1].dest != state[0].dest) @@ -150,9 +147,8 @@ static void emergency_pop_stack(fz_draw_device *dev, fz_draw_state *state) } static fz_draw_state * -fz_knockout_begin(fz_draw_device *dev) +fz_knockout_begin(fz_context *ctx, fz_draw_device *dev) { - fz_context *ctx = dev->ctx; fz_irect bbox; fz_pixmap *dest, *shape; fz_draw_state *state = &dev->stack[dev->top]; @@ -161,12 +157,12 @@ fz_knockout_begin(fz_draw_device *dev) if ((state->blendmode & FZ_BLEND_KNOCKOUT) == 0) return state; - state = push_stack(dev); + state = push_stack(ctx, dev); STACK_PUSHED("knockout"); - fz_pixmap_bbox(dev->ctx, state->dest, &bbox); + fz_pixmap_bbox(ctx, state->dest, &bbox); fz_intersect_irect(&bbox, &state->scissor); - dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, &bbox); + dest = fz_new_pixmap_with_bbox(ctx, state->dest->colorspace, &bbox); if (isolated) { @@ -197,8 +193,8 @@ fz_knockout_begin(fz_draw_device *dev) } else { - shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, shape); + shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, shape); } #ifdef DUMP_GROUP_BLENDS dump_spaces(dev->top-1, "Knockout begin\n"); @@ -211,12 +207,11 @@ fz_knockout_begin(fz_draw_device *dev) return &state[1]; } -static void fz_knockout_end(fz_draw_device *dev) +static void fz_knockout_end(fz_context *ctx, fz_draw_device *dev) { fz_draw_state *state; int blendmode; int isolated; - fz_context *ctx = dev->ctx; if (dev->top == 0) { @@ -233,12 +228,12 @@ static void fz_knockout_end(fz_draw_device *dev) #ifdef DUMP_GROUP_BLENDS dump_spaces(dev->top, ""); - fz_dump_blend(dev->ctx, state[1].dest, "Knockout end: blending "); + fz_dump_blend(ctx, state[1].dest, "Knockout end: blending "); if (state[1].shape) - fz_dump_blend(dev->ctx, state[1].shape, "/"); - fz_dump_blend(dev->ctx, state[0].dest, " onto "); + fz_dump_blend(ctx, state[1].shape, "/"); + fz_dump_blend(ctx, state[0].dest, " onto "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); if (blendmode != 0) printf(" (blend %d)", blendmode); if (isolated != 0) @@ -254,26 +249,28 @@ static void fz_knockout_end(fz_draw_device *dev) * errors can cause the stack to get out of sync, and this saves our * bacon. */ if (state[0].dest != state[1].dest) - fz_drop_pixmap(dev->ctx, state[1].dest); + fz_drop_pixmap(ctx, state[1].dest); if (state[0].shape != state[1].shape) { if (state[0].shape) fz_paint_pixmap(state[0].shape, state[1].shape, 255); - fz_drop_pixmap(dev->ctx, state[1].shape); + fz_drop_pixmap(ctx, state[1].shape); } #ifdef DUMP_GROUP_BLENDS - fz_dump_blend(dev->ctx, state[0].dest, " to get "); + fz_dump_blend(ctx, state[0].dest, " to get "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); printf("\n"); #endif } static void -fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, const fz_matrix *ctm, +fz_draw_fill_path(fz_context *ctx, fz_device *devp, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_draw_device *dev = devp->user; + fz_gel *gel = dev->gel; + float expansion = fz_matrix_expansion(ctm); float flatness = 0.3f / expansion; unsigned char colorbv[FZ_MAX_COLORS + 1]; @@ -284,48 +281,50 @@ fz_draw_fill_path(fz_device *devp, fz_path *path, int even_odd, const fz_matrix fz_colorspace *model = state->dest->colorspace; if (model == NULL) - model = fz_device_gray(dev->ctx); + model = fz_device_gray(ctx); if (flatness < 0.001f) flatness = 0.001f; - fz_reset_gel(dev->gel, &state->scissor); - fz_flatten_fill_path(dev->gel, path, ctm, flatness); - fz_sort_gel(dev->gel); + fz_reset_gel(ctx, gel, &state->scissor); + fz_flatten_fill_path(ctx, gel, path, ctm, flatness); + fz_sort_gel(ctx, gel); - fz_intersect_irect(fz_bound_gel(dev->gel, &bbox), &state->scissor); + fz_intersect_irect(fz_bound_gel(ctx, gel, &bbox), &state->scissor); if (fz_is_empty_irect(&bbox)) return; if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); - fz_convert_color(dev->ctx, model, colorfv, colorspace, color); + fz_convert_color(ctx, model, colorfv, colorspace, color); for (i = 0; i < model->n; i++) colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; - fz_scan_convert(dev->gel, even_odd, &bbox, state->dest, colorbv); + fz_scan_convert(ctx, gel, even_odd, &bbox, state->dest, colorbv); if (state->shape) { - fz_reset_gel(dev->gel, &state->scissor); - fz_flatten_fill_path(dev->gel, path, ctm, flatness); - fz_sort_gel(dev->gel); + fz_reset_gel(ctx, gel, &state->scissor); + fz_flatten_fill_path(ctx, gel, path, ctm, flatness); + fz_sort_gel(ctx, gel); colorbv[0] = alpha * 255; - fz_scan_convert(dev->gel, even_odd, &bbox, state->shape, colorbv); + fz_scan_convert(ctx, gel, even_odd, &bbox, state->shape, colorbv); } if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } static void -fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_draw_stroke_path(fz_context *ctx, fz_device *devp, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_draw_device *dev = devp->user; + fz_gel *gel = dev->gel; + float expansion = fz_matrix_expansion(ctm); float flatness = 0.3f / expansion; float linewidth = stroke->linewidth; @@ -337,81 +336,82 @@ fz_draw_stroke_path(fz_device *devp, fz_path *path, fz_stroke_state *stroke, con fz_colorspace *model = state->dest->colorspace; if (model == NULL) - model = fz_device_gray(dev->ctx); + model = fz_device_gray(ctx); if (linewidth * expansion < 0.1f) linewidth = 1 / expansion; if (flatness < 0.001f) flatness = 0.001f; - fz_reset_gel(dev->gel, &state->scissor); + fz_reset_gel(ctx, gel, &state->scissor); if (stroke->dash_len > 0) - fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_dash_path(ctx, gel, path, stroke, ctm, flatness, linewidth); else - fz_flatten_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); - fz_sort_gel(dev->gel); + fz_flatten_stroke_path(ctx, gel, path, stroke, ctm, flatness, linewidth); + fz_sort_gel(ctx, gel); - fz_intersect_irect(fz_bound_gel(dev->gel, &bbox), &state->scissor); + fz_intersect_irect(fz_bound_gel(ctx, gel, &bbox), &state->scissor); if (fz_is_empty_irect(&bbox)) return; if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); - fz_convert_color(dev->ctx, model, colorfv, colorspace, color); + fz_convert_color(ctx, model, colorfv, colorspace, color); for (i = 0; i < model->n; i++) colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; - fz_scan_convert(dev->gel, 0, &bbox, state->dest, colorbv); + fz_scan_convert(ctx, gel, 0, &bbox, state->dest, colorbv); if (state->shape) { - fz_reset_gel(dev->gel, &state->scissor); + fz_reset_gel(ctx, gel, &state->scissor); if (stroke->dash_len > 0) - fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_dash_path(ctx, gel, path, stroke, ctm, flatness, linewidth); else - fz_flatten_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); - fz_sort_gel(dev->gel); + fz_flatten_stroke_path(ctx, gel, path, stroke, ctm, flatness, linewidth); + fz_sort_gel(ctx, gel); colorbv[0] = 255; - fz_scan_convert(dev->gel, 0, &bbox, state->shape, colorbv); + fz_scan_convert(ctx, gel, 0, &bbox, state->shape, colorbv); } if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } static void -fz_draw_clip_path(fz_device *devp, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +fz_draw_clip_path(fz_context *ctx, fz_device *devp, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { fz_draw_device *dev = devp->user; + fz_gel *gel = dev->gel; + float expansion = fz_matrix_expansion(ctm); float flatness = 0.3f / expansion; fz_irect bbox; fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model; - fz_context *ctx = dev->ctx; if (flatness < 0.001f) flatness = 0.001f; - fz_reset_gel(dev->gel, &state->scissor); - fz_flatten_fill_path(dev->gel, path, ctm, flatness); - fz_sort_gel(dev->gel); + fz_reset_gel(ctx, gel, &state->scissor); + fz_flatten_fill_path(ctx, gel, path, ctm, flatness); + fz_sort_gel(ctx, gel); - state = push_stack(dev); + state = push_stack(ctx, dev); STACK_PUSHED("clip path"); model = state->dest->colorspace; - fz_intersect_irect(fz_bound_gel(dev->gel, &bbox), &state->scissor); + fz_intersect_irect(fz_bound_gel(ctx, gel, &bbox), &state->scissor); if (rect) { fz_irect bbox2; fz_intersect_irect(&bbox, fz_irect_from_rect(&bbox2, rect)); } - if (fz_is_empty_irect(&bbox) || fz_is_rect_gel(dev->gel)) + if (fz_is_empty_irect(&bbox) || fz_is_rect_gel(ctx, gel)) { state[1].scissor = bbox; state[1].mask = NULL; @@ -423,17 +423,17 @@ fz_draw_clip_path(fz_device *devp, fz_path *path, const fz_rect *rect, int even_ fz_try(ctx) { - state[1].mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, state[1].mask); - state[1].dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox); - fz_clear_pixmap(dev->ctx, state[1].dest); + state[1].mask = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, state[1].mask); + state[1].dest = fz_new_pixmap_with_bbox(ctx, model, &bbox); + fz_clear_pixmap(ctx, state[1].dest); if (state[1].shape) { - state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, state[1].shape); + state[1].shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, state[1].shape); } - fz_scan_convert(dev->gel, even_odd, &bbox, state[1].mask, NULL); + fz_scan_convert(ctx, gel, even_odd, &bbox, state[1].mask, NULL); state[1].blendmode |= FZ_BLEND_ISOLATED; state[1].scissor = bbox; @@ -443,39 +443,40 @@ fz_draw_clip_path(fz_device *devp, fz_path *path, const fz_rect *rect, int even_ } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } static void -fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_draw_clip_stroke_path(fz_context *ctx, fz_device *devp, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_draw_device *dev = devp->user; + fz_gel *gel = dev->gel; + float expansion = fz_matrix_expansion(ctm); float flatness = 0.3f / expansion; float linewidth = stroke->linewidth; fz_irect bbox; fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model; - fz_context *ctx = dev->ctx; if (linewidth * expansion < 0.1f) linewidth = 1 / expansion; if (flatness < 0.001f) flatness = 0.001f; - fz_reset_gel(dev->gel, &state->scissor); + fz_reset_gel(ctx, gel, &state->scissor); if (stroke->dash_len > 0) - fz_flatten_dash_path(dev->gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_dash_path(ctx, gel, path, stroke, ctm, flatness, linewidth); else - fz_flatten_stroke_path(dev->gel, path, stroke, ctm, flatness, linewidth); - fz_sort_gel(dev->gel); + fz_flatten_stroke_path(ctx, gel, path, stroke, ctm, flatness, linewidth); + fz_sort_gel(ctx, gel); - state = push_stack(dev); + state = push_stack(ctx, dev); STACK_PUSHED("clip stroke"); model = state->dest->colorspace; - fz_intersect_irect(fz_bound_gel(dev->gel, &bbox), &state->scissor); + fz_intersect_irect(fz_bound_gel(ctx, gel, &bbox), &state->scissor); if (rect) { fz_irect bbox2; @@ -484,18 +485,18 @@ fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, const fz_rect *rect, fz fz_try(ctx) { - state[1].mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, state[1].mask); - state[1].dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox); - fz_clear_pixmap(dev->ctx, state[1].dest); + state[1].mask = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, state[1].mask); + state[1].dest = fz_new_pixmap_with_bbox(ctx, model, &bbox); + fz_clear_pixmap(ctx, state[1].dest); if (state->shape) { - state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, state[1].shape); + state[1].shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, state[1].shape); } if (!fz_is_empty_irect(&bbox)) - fz_scan_convert(dev->gel, 0, &bbox, state[1].mask, NULL); + fz_scan_convert(ctx, gel, 0, &bbox, state[1].mask, NULL); state[1].blendmode |= FZ_BLEND_ISOLATED; state[1].scissor = bbox; @@ -505,7 +506,7 @@ fz_draw_clip_stroke_path(fz_device *devp, fz_path *path, const fz_rect *rect, fz } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } @@ -558,10 +559,11 @@ draw_glyph(unsigned char *colorbv, fz_pixmap *dst, fz_glyph *glyph, } static void -fz_draw_fill_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, +fz_draw_fill_text(fz_context *ctx, fz_device *devp, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_draw_device *dev = devp->user; + unsigned char colorbv[FZ_MAX_COLORS + 1]; unsigned char shapebv; float colorfv[FZ_MAX_COLORS]; @@ -572,9 +574,9 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, fz_colorspace *model = state->dest->colorspace; if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); - fz_convert_color(dev->ctx, model, colorfv, colorspace, color); + fz_convert_color(ctx, model, colorfv, colorspace, color); for (i = 0; i < model->n; i++) colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; @@ -592,7 +594,7 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, tm.f = text->items[i].y; fz_concat(&trm, &tm, ctm); - glyph = fz_render_glyph(dev->ctx, text->font, gid, &trm, model, &state->scissor); + glyph = fz_render_glyph(ctx, text->font, gid, &trm, model, &state->scissor); if (glyph) { fz_pixmap *pixmap = glyph->pixmap; @@ -611,33 +613,34 @@ fz_draw_fill_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, mat.e = x + pixmap->x; mat.f = y + pixmap->y; fz_paint_image(state->dest, &state->scissor, state->shape, pixmap, &mat, alpha * 255, !(devp->hints & FZ_DONT_INTERPOLATE_IMAGES)); } - fz_drop_glyph(dev->ctx, glyph); + fz_drop_glyph(ctx, glyph); } else { - fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &tm); + fz_path *path = fz_outline_glyph(ctx, text->font, gid, &tm); if (path) { - fz_draw_fill_path(devp, path, 0, ctm, colorspace, color, alpha); - fz_drop_path(dev->ctx, path); + fz_draw_fill_path(ctx, devp, path, 0, ctm, colorspace, color, alpha); + fz_drop_path(ctx, path); } else { - fz_warn(dev->ctx, "cannot render glyph"); + fz_warn(ctx, "cannot render glyph"); } } } if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } static void -fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, +fz_draw_stroke_text(fz_context *ctx, fz_device *devp, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_draw_device *dev = devp->user; + unsigned char colorbv[FZ_MAX_COLORS + 1]; float colorfv[FZ_MAX_COLORS]; fz_matrix tm, trm; @@ -647,9 +650,9 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, fz_colorspace *model = state->dest->colorspace; if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); - fz_convert_color(dev->ctx, model, colorfv, colorspace, color); + fz_convert_color(ctx, model, colorfv, colorspace, color); for (i = 0; i < model->n; i++) colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; @@ -666,7 +669,7 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, tm.f = text->items[i].y; fz_concat(&trm, &tm, ctm); - glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, &trm, ctm, stroke, &state->scissor); + glyph = fz_render_stroked_glyph(ctx, text->font, gid, &trm, ctm, stroke, &state->scissor); if (glyph) { int x = (int)trm.e; @@ -674,32 +677,31 @@ fz_draw_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, draw_glyph(colorbv, state->dest, glyph, x, y, &state->scissor); if (state->shape) draw_glyph(colorbv, state->shape, glyph, x, y, &state->scissor); - fz_drop_glyph(dev->ctx, glyph); + fz_drop_glyph(ctx, glyph); } else { - fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &tm); + fz_path *path = fz_outline_glyph(ctx, text->font, gid, &tm); if (path) { - fz_draw_stroke_path(devp, path, stroke, ctm, colorspace, color, alpha); - fz_drop_path(dev->ctx, path); + fz_draw_stroke_path(ctx, devp, path, stroke, ctm, colorspace, color, alpha); + fz_drop_path(ctx, path); } else { - fz_warn(dev->ctx, "cannot render glyph"); + fz_warn(ctx, "cannot render glyph"); } } } if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } static void -fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accumulate) +fz_draw_clip_text(fz_context *ctx, fz_device *devp, fz_text *text, const fz_matrix *ctm, int accumulate) { fz_draw_device *dev = devp->user; - fz_context *ctx = dev->ctx; fz_irect bbox; fz_pixmap *mask, *dest, *shape; fz_matrix tm, trm; @@ -712,7 +714,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu /* If accumulate == 1 then this text object is the first (or only) in a sequence */ /* If accumulate == 2 then this text object is a continuation */ - state = push_stack(dev); + state = push_stack(ctx, dev); STACK_PUSHED("clip text"); model = state->dest->colorspace; @@ -721,7 +723,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu /* make the mask the exact size needed */ fz_rect rect; - fz_irect_from_rect(&bbox, fz_bound_text(dev->ctx, text, NULL, ctm, &rect)); + fz_irect_from_rect(&bbox, fz_bound_text(ctx, text, NULL, ctm, &rect)); fz_intersect_irect(&bbox, &state->scissor); } else @@ -734,14 +736,14 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu { if (accumulate == 0 || accumulate == 1) { - mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, mask); - dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox); - fz_clear_pixmap(dev->ctx, dest); + mask = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, mask); + dest = fz_new_pixmap_with_bbox(ctx, model, &bbox); + fz_clear_pixmap(ctx, dest); if (state->shape) { - shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, shape); + shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, shape); } else shape = NULL; @@ -776,7 +778,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu tm.f = text->items[i].y; fz_concat(&trm, &tm, ctm); - glyph = fz_render_glyph(dev->ctx, text->font, gid, &trm, model, &state->scissor); + glyph = fz_render_glyph(ctx, text->font, gid, &trm, model, &state->scissor); if (glyph) { int x = (int)trm.e; @@ -784,11 +786,11 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu draw_glyph(NULL, mask, glyph, x, y, &bbox); if (state[1].shape) draw_glyph(NULL, state[1].shape, glyph, x, y, &bbox); - fz_drop_glyph(dev->ctx, glyph); + fz_drop_glyph(ctx, glyph); } else { - fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &tm); + fz_path *path = fz_outline_glyph(ctx, text->font, gid, &tm); if (path) { fz_pixmap *old_dest; @@ -799,13 +801,13 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu state[1].mask = NULL; fz_try(ctx) { - fz_draw_fill_path(devp, path, 0, ctm, fz_device_gray(ctx), &white, 1); + fz_draw_fill_path(ctx, devp, path, 0, ctm, fz_device_gray(ctx), &white, 1); } fz_always(ctx) { state[1].mask = state[1].dest; state[1].dest = old_dest; - fz_drop_path(dev->ctx, path); + fz_drop_path(ctx, path); } fz_catch(ctx) { @@ -814,7 +816,7 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu } else { - fz_warn(dev->ctx, "cannot render glyph for clipping"); + fz_warn(ctx, "cannot render glyph for clipping"); } } } @@ -823,40 +825,39 @@ fz_draw_clip_text(fz_device *devp, fz_text *text, const fz_matrix *ctm, int accu fz_catch(ctx) { if (accumulate == 0 || accumulate == 1) - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); fz_rethrow(ctx); } } static void -fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_draw_clip_stroke_text(fz_context *ctx, fz_device *devp, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_draw_device *dev = devp->user; - fz_context *ctx = dev->ctx; fz_irect bbox; fz_pixmap *mask, *dest, *shape; fz_matrix tm, trm; fz_glyph *glyph; int i, gid; - fz_draw_state *state = push_stack(dev); + fz_draw_state *state = push_stack(ctx, dev); fz_colorspace *model = state->dest->colorspace; fz_rect rect; STACK_PUSHED("clip stroke text"); /* make the mask the exact size needed */ - fz_irect_from_rect(&bbox, fz_bound_text(dev->ctx, text, stroke, ctm, &rect)); + fz_irect_from_rect(&bbox, fz_bound_text(ctx, text, stroke, ctm, &rect)); fz_intersect_irect(&bbox, &state->scissor); fz_try(ctx) { - state[1].mask = mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, mask); - state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox); - fz_clear_pixmap(dev->ctx, dest); + state[1].mask = mask = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, mask); + state[1].dest = dest = fz_new_pixmap_with_bbox(ctx, model, &bbox); + fz_clear_pixmap(ctx, dest); if (state->shape) { - state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, shape); + state[1].shape = shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, shape); } else shape = state->shape; @@ -881,7 +882,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke tm.f = text->items[i].y; fz_concat(&trm, &tm, ctm); - glyph = fz_render_stroked_glyph(dev->ctx, text->font, gid, &trm, ctm, stroke, &state->scissor); + glyph = fz_render_stroked_glyph(ctx, text->font, gid, &trm, ctm, stroke, &state->scissor); if (glyph) { int x = (int)trm.e; @@ -889,11 +890,11 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke draw_glyph(NULL, mask, glyph, x, y, &bbox); if (shape) draw_glyph(NULL, shape, glyph, x, y, &bbox); - fz_drop_glyph(dev->ctx, glyph); + fz_drop_glyph(ctx, glyph); } else { - fz_path *path = fz_outline_glyph(dev->ctx, text->font, gid, &tm); + fz_path *path = fz_outline_glyph(ctx, text->font, gid, &tm); if (path) { fz_pixmap *old_dest; @@ -905,13 +906,13 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke state[0].mask = NULL; fz_try(ctx) { - fz_draw_stroke_path(devp, path, stroke, ctm, fz_device_gray(ctx), &white, 1); + fz_draw_stroke_path(ctx, devp, path, stroke, ctm, fz_device_gray(ctx), &white, 1); } fz_always(ctx) { state[0].mask = state[0].dest; state[0].dest = old_dest; - fz_drop_path(dev->ctx, path); + fz_drop_path(ctx, path); } fz_catch(ctx) { @@ -920,7 +921,7 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke } else { - fz_warn(dev->ctx, "cannot render glyph for stroked clipping"); + fz_warn(ctx, "cannot render glyph for stroked clipping"); } } } @@ -928,17 +929,17 @@ fz_draw_clip_stroke_text(fz_device *devp, fz_text *text, fz_stroke_state *stroke } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } static void -fz_draw_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_draw_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { } static void -fz_draw_fill_shade(fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float alpha) +fz_draw_fill_shade(fz_context *ctx, fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float alpha) { fz_draw_device *dev = devp->user; fz_rect bounds; @@ -949,7 +950,7 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; - fz_bound_shade(dev->ctx, shade, ctm, &bounds); + fz_bound_shade(ctx, shade, ctm, &bounds); scissor = state->scissor; fz_intersect_irect(fz_irect_from_rect(&bbox, &bounds), &scissor); @@ -958,24 +959,24 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float if (!model) { - fz_warn(dev->ctx, "cannot render shading directly to an alpha mask"); + fz_warn(ctx, "cannot render shading directly to an alpha mask"); return; } if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); dest = state->dest; shape = state->shape; if (alpha < 1) { - dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, &bbox); - fz_clear_pixmap(dev->ctx, dest); + dest = fz_new_pixmap_with_bbox(ctx, state->dest->colorspace, &bbox); + fz_clear_pixmap(ctx, dest); if (shape) { - shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, shape); + shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, shape); } } @@ -983,7 +984,7 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float { unsigned char *s; int x, y, n, i; - fz_convert_color(dev->ctx, model, colorfv, shade->colorspace, shade->background); + fz_convert_color(ctx, model, colorfv, shade->colorspace, shade->background); for (i = 0; i < model->n; i++) colorbv[i] = colorfv[i] * 255; colorbv[i] = 255; @@ -1011,30 +1012,29 @@ fz_draw_fill_shade(fz_device *devp, fz_shade *shade, const fz_matrix *ctm, float } } - fz_paint_shade(dev->ctx, shade, ctm, dest, &bbox); + fz_paint_shade(ctx, shade, ctm, dest, &bbox); if (shape) - fz_clear_pixmap_rect_with_value(dev->ctx, shape, 255, &bbox); + fz_clear_pixmap_rect_with_value(ctx, shape, 255, &bbox); if (alpha < 1) { fz_paint_pixmap(state->dest, dest, alpha * 255); - fz_drop_pixmap(dev->ctx, dest); + fz_drop_pixmap(ctx, dest); if (shape) { fz_paint_pixmap(state->shape, shape, alpha * 255); - fz_drop_pixmap(dev->ctx, shape); + fz_drop_pixmap(ctx, shape); } } if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } static fz_pixmap * -fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int dy, int gridfit, const fz_irect *clip) +fz_transform_pixmap(fz_context *ctx, fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x, int y, int dx, int dy, int gridfit, const fz_irect *clip) { fz_pixmap *scaled; - fz_context *ctx = dev->ctx; if (ctm->a != 0 && ctm->b == 0 && ctm->c == 0 && ctm->d != 0) { @@ -1087,7 +1087,7 @@ fz_transform_pixmap(fz_draw_device *dev, fz_pixmap *image, fz_matrix *ctm, int x } static void -fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float alpha) +fz_draw_fill_image(fz_context *ctx, fz_device *devp, fz_image *image, const fz_matrix *ctm, float alpha) { fz_draw_device *dev = devp->user; fz_pixmap *converted = NULL; @@ -1096,7 +1096,6 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float fz_pixmap *orig_pixmap; int after; int dx, dy; - fz_context *ctx = dev->ctx; fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; fz_irect clip; @@ -1108,7 +1107,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float if (!model) { - fz_warn(dev->ctx, "cannot render image directly to an alpha mask"); + fz_warn(ctx, "cannot render image directly to an alpha mask"); return; } @@ -1128,7 +1127,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float fz_try(ctx) { if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); after = 0; if (pixmap->colorspace == fz_device_gray(ctx)) @@ -1146,7 +1145,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float if (dx < pixmap->w && dy < pixmap->h && !(devp->hints & FZ_DONT_INTERPOLATE_IMAGES)) { int gridfit = alpha == 1.0f && !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3); - scaled = fz_transform_pixmap(dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip); + scaled = fz_transform_pixmap(ctx, dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip); if (!scaled) { if (dx < 1) @@ -1179,7 +1178,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float fz_paint_image(state->dest, &state->scissor, state->shape, pixmap, &local_ctm, alpha * 255, !(devp->hints & FZ_DONT_INTERPOLATE_IMAGES)); if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } fz_always(ctx) { @@ -1194,7 +1193,7 @@ fz_draw_fill_image(fz_device *devp, fz_image *image, const fz_matrix *ctm, float } static void -fz_draw_fill_image_mask(fz_device *devp, fz_image *image, const fz_matrix *ctm, +fz_draw_fill_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_draw_device *dev = devp->user; @@ -1205,7 +1204,6 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, const fz_matrix *ctm, fz_pixmap *orig_pixmap; int dx, dy; int i; - fz_context *ctx = dev->ctx; fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; fz_irect clip; @@ -1225,25 +1223,25 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, const fz_matrix *ctm, fz_try(ctx) { if (state->blendmode & FZ_BLEND_KNOCKOUT) - state = fz_knockout_begin(dev); + state = fz_knockout_begin(ctx, dev); if (dx < pixmap->w && dy < pixmap->h) { int gridfit = alpha == 1.0f && !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3); - scaled = fz_transform_pixmap(dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip); + scaled = fz_transform_pixmap(ctx, dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip); if (!scaled) { if (dx < 1) dx = 1; if (dy < 1) dy = 1; - scaled = fz_scale_pixmap_cached(dev->ctx, pixmap, pixmap->x, pixmap->y, dx, dy, NULL, dev->cache_x, dev->cache_y); + scaled = fz_scale_pixmap_cached(ctx, pixmap, pixmap->x, pixmap->y, dx, dy, NULL, dev->cache_x, dev->cache_y); } if (scaled) pixmap = scaled; } - fz_convert_color(dev->ctx, model, colorfv, colorspace, color); + fz_convert_color(ctx, model, colorfv, colorspace, color); for (i = 0; i < model->n; i++) colorbv[i] = colorfv[i] * 255; colorbv[i] = alpha * 255; @@ -1251,14 +1249,14 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, const fz_matrix *ctm, fz_paint_image_with_color(state->dest, &state->scissor, state->shape, pixmap, &local_ctm, colorbv, !(devp->hints & FZ_DONT_INTERPOLATE_IMAGES)); if (scaled) - fz_drop_pixmap(dev->ctx, scaled); + fz_drop_pixmap(ctx, scaled); if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } fz_always(ctx) { - fz_drop_pixmap(dev->ctx, orig_pixmap); + fz_drop_pixmap(ctx, orig_pixmap); } fz_catch(ctx) { @@ -1267,10 +1265,9 @@ fz_draw_fill_image_mask(fz_device *devp, fz_image *image, const fz_matrix *ctm, } static void -fz_draw_clip_image_mask(fz_device *devp, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) +fz_draw_clip_image_mask(fz_context *ctx, fz_device *devp, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { fz_draw_device *dev = devp->user; - fz_context *ctx = dev->ctx; fz_irect bbox; fz_pixmap *mask = NULL; fz_pixmap *dest = NULL; @@ -1279,7 +1276,7 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, const fz_rect *rect, c fz_pixmap *pixmap = NULL; fz_pixmap *orig_pixmap = NULL; int dx, dy; - fz_draw_state *state = push_stack(dev); + fz_draw_state *state = push_stack(ctx, dev); fz_colorspace *model = state->dest->colorspace; fz_irect clip; fz_matrix local_ctm = *ctm; @@ -1326,15 +1323,15 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, const fz_rect *rect, c pixmap = fz_new_pixmap_from_image(ctx, image, dx, dy); orig_pixmap = pixmap; - state[1].mask = mask = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, mask); + state[1].mask = mask = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, mask); - state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox); - fz_clear_pixmap(dev->ctx, dest); + state[1].dest = dest = fz_new_pixmap_with_bbox(ctx, model, &bbox); + fz_clear_pixmap(ctx, dest); if (state->shape) { - state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, shape); + state[1].shape = shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, shape); } state[1].blendmode |= FZ_BLEND_ISOLATED; @@ -1343,14 +1340,14 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, const fz_rect *rect, c if (dx < pixmap->w && dy < pixmap->h) { int gridfit = !(dev->flags & FZ_DRAWDEV_FLAGS_TYPE3); - scaled = fz_transform_pixmap(dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip); + scaled = fz_transform_pixmap(ctx, dev, pixmap, &local_ctm, state->dest->x, state->dest->y, dx, dy, gridfit, &clip); if (!scaled) { if (dx < 1) dx = 1; if (dy < 1) dy = 1; - scaled = fz_scale_pixmap_cached(dev->ctx, pixmap, pixmap->x, pixmap->y, dx, dy, NULL, dev->cache_x, dev->cache_y); + scaled = fz_scale_pixmap_cached(ctx, pixmap, pixmap->x, pixmap->y, dx, dy, NULL, dev->cache_x, dev->cache_y); } if (scaled) pixmap = scaled; @@ -1364,15 +1361,14 @@ fz_draw_clip_image_mask(fz_device *devp, fz_image *image, const fz_rect *rect, c } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } static void -fz_draw_pop_clip(fz_device *devp) +fz_draw_pop_clip(fz_context *ctx, fz_device *devp) { fz_draw_device *dev = devp->user; - fz_context *ctx = dev->ctx; fz_draw_state *state; if (dev->top == 0) @@ -1390,31 +1386,31 @@ fz_draw_pop_clip(fz_device *devp) { #ifdef DUMP_GROUP_BLENDS dump_spaces(dev->top, ""); - fz_dump_blend(dev->ctx, state[1].dest, "Clipping "); + fz_dump_blend(ctx, state[1].dest, "Clipping "); if (state[1].shape) - fz_dump_blend(dev->ctx, state[1].shape, "/"); - fz_dump_blend(dev->ctx, state[0].dest, " onto "); + fz_dump_blend(ctx, state[1].shape, "/"); + fz_dump_blend(ctx, state[0].dest, " onto "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); - fz_dump_blend(dev->ctx, state[1].mask, " with "); + fz_dump_blend(ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[1].mask, " with "); #endif fz_paint_pixmap_with_mask(state[0].dest, state[1].dest, state[1].mask); if (state[0].shape != state[1].shape) { fz_paint_pixmap_with_mask(state[0].shape, state[1].shape, state[1].mask); - fz_drop_pixmap(dev->ctx, state[1].shape); + fz_drop_pixmap(ctx, state[1].shape); } /* The following tests should not be required, but just occasionally * errors can cause the stack to get out of sync, and this might save * our bacon. */ if (state[0].mask != state[1].mask) - fz_drop_pixmap(dev->ctx, state[1].mask); + fz_drop_pixmap(ctx, state[1].mask); if (state[0].dest != state[1].dest) - fz_drop_pixmap(dev->ctx, state[1].dest); + fz_drop_pixmap(ctx, state[1].dest); #ifdef DUMP_GROUP_BLENDS - fz_dump_blend(dev->ctx, state[0].dest, " to get "); + fz_dump_blend(ctx, state[0].dest, " to get "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); printf("\n"); #endif } @@ -1427,21 +1423,20 @@ fz_draw_pop_clip(fz_device *devp) } static void -fz_draw_begin_mask(fz_device *devp, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *colorfv) +fz_draw_begin_mask(fz_context *ctx, fz_device *devp, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *colorfv) { fz_draw_device *dev = devp->user; fz_pixmap *dest; fz_irect bbox; - fz_draw_state *state = push_stack(dev); + fz_draw_state *state = push_stack(ctx, dev); fz_pixmap *shape = state->shape; - fz_context *ctx = dev->ctx; STACK_PUSHED("mask"); fz_intersect_irect(fz_irect_from_rect(&bbox, rect), &state->scissor); fz_try(ctx) { - state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, fz_device_gray(ctx), &bbox); + state[1].dest = dest = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), &bbox); if (state->shape) { /* FIXME: If we ever want to support AIS true, then @@ -1458,16 +1453,16 @@ fz_draw_begin_mask(fz_device *devp, const fz_rect *rect, int luminosity, fz_colo float bc; if (!colorspace) colorspace = fz_device_gray(ctx); - fz_convert_color(dev->ctx, fz_device_gray(ctx), &bc, colorspace, colorfv); - fz_clear_pixmap_with_value(dev->ctx, dest, bc * 255); + fz_convert_color(ctx, fz_device_gray(ctx), &bc, colorspace, colorfv); + fz_clear_pixmap_with_value(ctx, dest, bc * 255); if (shape) - fz_clear_pixmap_with_value(dev->ctx, shape, 255); + fz_clear_pixmap_with_value(ctx, shape, 255); } else { - fz_clear_pixmap(dev->ctx, dest); + fz_clear_pixmap(ctx, dest); if (shape) - fz_clear_pixmap(dev->ctx, shape); + fz_clear_pixmap(ctx, shape); } #ifdef DUMP_GROUP_BLENDS @@ -1478,18 +1473,17 @@ fz_draw_begin_mask(fz_device *devp, const fz_rect *rect, int luminosity, fz_colo } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } static void -fz_draw_end_mask(fz_device *devp) +fz_draw_end_mask(fz_context *ctx, fz_device *devp) { fz_draw_device *dev = devp->user; fz_pixmap *temp, *dest; fz_irect bbox; int luminosity; - fz_context *ctx = dev->ctx; fz_draw_state *state; if (dev->top == 0) @@ -1508,21 +1502,21 @@ fz_draw_end_mask(fz_device *devp) fz_try(ctx) { /* convert to alpha mask */ - temp = fz_alpha_from_gray(dev->ctx, state[1].dest, luminosity); + temp = fz_alpha_from_gray(ctx, state[1].dest, luminosity); if (state[1].mask != state[0].mask) - fz_drop_pixmap(dev->ctx, state[1].mask); + fz_drop_pixmap(ctx, state[1].mask); state[1].mask = temp; if (state[1].dest != state[0].dest) - fz_drop_pixmap(dev->ctx, state[1].dest); + fz_drop_pixmap(ctx, state[1].dest); state[1].dest = NULL; if (state[1].shape != state[0].shape) - fz_drop_pixmap(dev->ctx, state[1].shape); + fz_drop_pixmap(ctx, state[1].shape); state[1].shape = NULL; /* create new dest scratch buffer */ fz_pixmap_bbox(ctx, temp, &bbox); - dest = fz_new_pixmap_with_bbox(dev->ctx, state->dest->colorspace, &bbox); - fz_clear_pixmap(dev->ctx, dest); + dest = fz_new_pixmap_with_bbox(ctx, state->dest->colorspace, &bbox); + fz_clear_pixmap(ctx, dest); /* push soft mask as clip mask */ state[1].dest = dest; @@ -1531,31 +1525,30 @@ fz_draw_end_mask(fz_device *devp) * clip mask when we pop. So create a new shape now. */ if (state[0].shape) { - state[1].shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, state[1].shape); + state[1].shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); + fz_clear_pixmap(ctx, state[1].shape); } state[1].scissor = bbox; } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } static void -fz_draw_begin_group(fz_device *devp, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha) +fz_draw_begin_group(fz_context *ctx, fz_device *devp, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha) { fz_draw_device *dev = devp->user; fz_irect bbox; fz_pixmap *dest; - fz_context *ctx = dev->ctx; fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_begin(dev); + fz_knockout_begin(ctx, dev); - state = push_stack(dev); + state = push_stack(ctx, dev); STACK_PUSHED("group"); fz_intersect_irect(fz_irect_from_rect(&bbox, rect), &state->scissor); @@ -1570,11 +1563,11 @@ fz_draw_begin_group(fz_device *devp, const fz_rect *rect, int isolated, int knoc if (isolated) { - fz_clear_pixmap(dev->ctx, dest); + fz_clear_pixmap(ctx, dest); } else { - fz_copy_pixmap_rect(dev->ctx, dest, state[0].dest, &bbox); + fz_copy_pixmap_rect(ctx, dest, state[0].dest, &bbox); } if (blendmode == 0 && alpha == 1.0 && isolated) @@ -1586,7 +1579,7 @@ fz_draw_begin_group(fz_device *devp, const fz_rect *rect, int isolated, int knoc else { state[1].shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); - fz_clear_pixmap(dev->ctx, state[1].shape); + fz_clear_pixmap(ctx, state[1].shape); } state[1].alpha = alpha; @@ -1599,18 +1592,17 @@ fz_draw_begin_group(fz_device *devp, const fz_rect *rect, int isolated, int knoc } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } } static void -fz_draw_end_group(fz_device *devp) +fz_draw_end_group(fz_context *ctx, fz_device *devp) { fz_draw_device *dev = devp->user; int blendmode; int isolated; float alpha; - fz_context *ctx = dev->ctx; fz_draw_state *state; if (dev->top == 0) @@ -1626,12 +1618,12 @@ fz_draw_end_group(fz_device *devp) isolated = state[1].blendmode & FZ_BLEND_ISOLATED; #ifdef DUMP_GROUP_BLENDS dump_spaces(dev->top, ""); - fz_dump_blend(dev->ctx, state[1].dest, "Group end: blending "); + fz_dump_blend(ctx, state[1].dest, "Group end: blending "); if (state[1].shape) - fz_dump_blend(dev->ctx, state[1].shape, "/"); - fz_dump_blend(dev->ctx, state[0].dest, " onto "); + fz_dump_blend(ctx, state[1].shape, "/"); + fz_dump_blend(ctx, state[0].dest, " onto "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); if (alpha != 1.0f) printf(" (alpha %g)", alpha); if (blendmode != 0) @@ -1650,22 +1642,22 @@ fz_draw_end_group(fz_device *devp) * errors can cause the stack to get out of sync, and this might save * our bacon. */ if (state[0].dest != state[1].dest) - fz_drop_pixmap(dev->ctx, state[1].dest); + fz_drop_pixmap(ctx, state[1].dest); if (state[0].shape != state[1].shape) { if (state[0].shape) fz_paint_pixmap(state[0].shape, state[1].shape, alpha * 255); - fz_drop_pixmap(dev->ctx, state[1].shape); + fz_drop_pixmap(ctx, state[1].shape); } #ifdef DUMP_GROUP_BLENDS - fz_dump_blend(dev->ctx, state[0].dest, " to get "); + fz_dump_blend(ctx, state[0].dest, " to get "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); printf("\n"); #endif if (state[0].blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } typedef struct @@ -1683,7 +1675,7 @@ typedef struct } tile_record; static int -fz_make_hash_tile_key(fz_store_hash *hash, void *key_) +fz_make_hash_tile_key(fz_context *ctx, fz_store_hash *hash, void *key_) { tile_key *key = (tile_key *)key_; @@ -1723,7 +1715,7 @@ fz_drop_tile_key(fz_context *ctx, void *key_) } static int -fz_cmp_tile_key(void *k0_, void *k1_) +fz_cmp_tile_key(fz_context *ctx, void *k0_, void *k1_) { tile_key *k0 = (tile_key *)k0_; tile_key *k1 = (tile_key *)k1_; @@ -1733,7 +1725,7 @@ fz_cmp_tile_key(void *k0_, void *k1_) #ifndef NDEBUG static void -fz_debug_tile(FILE *out, void *key_) +fz_debug_tile(fz_context *ctx, FILE *out, void *key_) { tile_key *key = (tile_key *)key_; @@ -1789,13 +1781,12 @@ fz_tile_size(fz_context *ctx, tile_record *tile) } static int -fz_draw_begin_tile(fz_device *devp, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) +fz_draw_begin_tile(fz_context *ctx, fz_device *devp, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { fz_draw_device *dev = devp->user; fz_pixmap *dest = NULL; fz_pixmap *shape; fz_irect bbox; - fz_context *ctx = dev->ctx; fz_draw_state *state = &dev->stack[dev->top]; fz_colorspace *model = state->dest->colorspace; fz_rect local_view = *view; @@ -1804,9 +1795,9 @@ fz_draw_begin_tile(fz_device *devp, const fz_rect *area, const fz_rect *view, fl /* ctm maps from pattern space to device space */ if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_begin(dev); + fz_knockout_begin(ctx, dev); - state = push_stack(dev); + state = push_stack(ctx, dev); STACK_PUSHED("tile"); fz_irect_from_rect(&bbox, fz_transform_rect(&local_view, ctm)); /* We should never have a bbox that entirely covers our destination. @@ -1851,12 +1842,12 @@ fz_draw_begin_tile(fz_device *devp, const fz_rect *area, const fz_rect *view, fl fz_try(ctx) { - state[1].dest = dest = fz_new_pixmap_with_bbox(dev->ctx, model, &bbox); + state[1].dest = dest = fz_new_pixmap_with_bbox(ctx, model, &bbox); fz_clear_pixmap(ctx, dest); shape = state[0].shape; if (shape) { - state[1].shape = shape = fz_new_pixmap_with_bbox(dev->ctx, NULL, &bbox); + state[1].shape = shape = fz_new_pixmap_with_bbox(ctx, NULL, &bbox); fz_clear_pixmap(ctx, shape); } state[1].blendmode |= FZ_BLEND_ISOLATED; @@ -1873,14 +1864,14 @@ fz_draw_begin_tile(fz_device *devp, const fz_rect *area, const fz_rect *view, fl } fz_catch(ctx) { - emergency_pop_stack(dev, state); + emergency_pop_stack(ctx, dev, state); } return 0; } static void -fz_draw_end_tile(fz_device *devp) +fz_draw_end_tile(fz_context *ctx, fz_device *devp) { fz_draw_device *dev = devp->user; float xstep, ystep; @@ -1888,7 +1879,6 @@ fz_draw_end_tile(fz_device *devp) fz_irect area, scissor; fz_rect scissor_tmp; int x0, y0, x1, y1, x, y; - fz_context *ctx = dev->ctx; fz_draw_state *state; tile_record *tile; tile_key *key; @@ -1940,12 +1930,12 @@ fz_draw_end_tile(fz_device *devp) #ifdef DUMP_GROUP_BLENDS dump_spaces(dev->top, ""); - fz_dump_blend(dev->ctx, state[1].dest, "Tiling "); + fz_dump_blend(ctx, state[1].dest, "Tiling "); if (state[1].shape) - fz_dump_blend(dev->ctx, state[1].shape, "/"); - fz_dump_blend(dev->ctx, state[0].dest, " onto "); + fz_dump_blend(ctx, state[1].shape, "/"); + fz_dump_blend(ctx, state[0].dest, " onto "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); #endif for (y = y0; y < y1; y++) @@ -2023,25 +2013,26 @@ fz_draw_end_tile(fz_device *devp) * errors can cause the stack to get out of sync, and this might save * our bacon. */ if (state[0].dest != state[1].dest) - fz_drop_pixmap(dev->ctx, state[1].dest); + fz_drop_pixmap(ctx, state[1].dest); if (state[0].shape != state[1].shape) - fz_drop_pixmap(dev->ctx, state[1].shape); + fz_drop_pixmap(ctx, state[1].shape); #ifdef DUMP_GROUP_BLENDS - fz_dump_blend(dev->ctx, state[0].dest, " to get "); + fz_dump_blend(ctx, state[0].dest, " to get "); if (state[0].shape) - fz_dump_blend(dev->ctx, state[0].shape, "/"); + fz_dump_blend(ctx, state[0].shape, "/"); printf("\n"); #endif if (state->blendmode & FZ_BLEND_KNOCKOUT) - fz_knockout_end(dev); + fz_knockout_end(ctx, dev); } static void -fz_draw_drop_user(fz_device *devp) +fz_draw_drop_user(fz_context *ctx, fz_device *devp) { fz_draw_device *dev = devp->user; - fz_context *ctx = dev->ctx; + fz_gel *gel = dev->gel; + /* pop and free the stacks */ if (dev->top > 0) fz_warn(ctx, "items left on stack in draw device: %d", dev->top+1); @@ -2064,7 +2055,7 @@ fz_draw_drop_user(fz_device *devp) fz_free(ctx, dev->stack); fz_drop_scale_cache(ctx, dev->cache_x); fz_drop_scale_cache(ctx, dev->cache_y); - fz_drop_gel(dev->gel); + fz_drop_gel(ctx, gel); fz_free(ctx, dev); } @@ -2079,7 +2070,6 @@ fz_new_draw_device(fz_context *ctx, fz_pixmap *dest) { ddev->gel = fz_new_gel(ctx); ddev->flags = 0; - ddev->ctx = ctx; ddev->top = 0; ddev->cache_x = fz_new_scale_cache(ctx); ddev->cache_y = fz_new_scale_cache(ctx); @@ -2100,7 +2090,7 @@ fz_new_draw_device(fz_context *ctx, fz_pixmap *dest) { fz_drop_scale_cache(ctx, ddev->cache_x); fz_drop_scale_cache(ctx, ddev->cache_y); - fz_drop_gel(ddev->gel); + fz_drop_gel(ctx, ddev->gel); fz_free(ctx, ddev); fz_rethrow(ctx); } @@ -2166,18 +2156,18 @@ fz_bound_path_accurate(fz_context *ctx, fz_irect *bbox, const fz_irect *scissor, { fz_gel *gel = fz_new_gel(ctx); - fz_reset_gel(gel, scissor); + fz_reset_gel(ctx, gel, scissor); if (stroke) { if (stroke->dash_len > 0) - fz_flatten_dash_path(gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_dash_path(ctx, gel, path, stroke, ctm, flatness, linewidth); else - fz_flatten_stroke_path(gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_stroke_path(ctx, gel, path, stroke, ctm, flatness, linewidth); } else - fz_flatten_fill_path(gel, path, ctm, flatness); - fz_bound_gel(gel, bbox); - fz_drop_gel(gel); + fz_flatten_fill_path(ctx, gel, path, ctm, flatness); + fz_bound_gel(ctx, gel, bbox); + fz_drop_gel(ctx, gel); return bbox; } diff --git a/source/fitz/draw-edge.c b/source/fitz/draw-edge.c index e1fd5f37..a4c0d02e 100644 --- a/source/fitz/draw-edge.c +++ b/source/fitz/draw-edge.c @@ -165,7 +165,6 @@ struct fz_gel_s fz_edge *edges; int acap, alen; fz_edge **active; - fz_context *ctx; }; fz_gel * @@ -177,7 +176,6 @@ fz_new_gel(fz_context *ctx) fz_try(ctx) { gel->edges = NULL; - gel->ctx = ctx; gel->cap = 512; gel->len = 0; gel->edges = fz_malloc_array(ctx, gel->cap, sizeof(fz_edge)); @@ -204,9 +202,9 @@ fz_new_gel(fz_context *ctx) } void -fz_reset_gel(fz_gel *gel, const fz_irect *clip) +fz_reset_gel(fz_context *ctx, fz_gel *gel, const fz_irect *clip) { - fz_aa_context *ctxaa = gel->ctx->aa; + fz_aa_context *ctxaa = ctx->aa; if (fz_is_infinite_irect(clip)) { @@ -228,19 +226,19 @@ fz_reset_gel(fz_gel *gel, const fz_irect *clip) } void -fz_drop_gel(fz_gel *gel) +fz_drop_gel(fz_context *ctx, fz_gel *gel) { if (gel == NULL) return; - fz_free(gel->ctx, gel->active); - fz_free(gel->ctx, gel->edges); - fz_free(gel->ctx, gel); + fz_free(ctx, gel->active); + fz_free(ctx, gel->edges); + fz_free(ctx, gel); } fz_irect * -fz_bound_gel(const fz_gel *gel, fz_irect *bbox) +fz_bound_gel(fz_context *ctx, const fz_gel *gel, fz_irect *bbox) { - fz_aa_context *ctxaa = gel->ctx->aa; + fz_aa_context *ctxaa = ctx->aa; if (gel->len == 0) { *bbox = fz_empty_irect; @@ -256,9 +254,9 @@ fz_bound_gel(const fz_gel *gel, fz_irect *bbox) } fz_rect * -fz_gel_scissor(const fz_gel *gel, fz_rect *r) +fz_gel_scissor(fz_context *ctx, const fz_gel *gel, fz_rect *r) { - fz_aa_context *ctxaa = gel->ctx->aa; + fz_aa_context *ctxaa = ctx->aa; r->x0 = gel->clip.x0 / fz_aa_hscale; r->x1 = gel->clip.x1 / fz_aa_vscale; @@ -298,7 +296,7 @@ clip_lerp_x(int val, int m, int x0, int y0, int x1, int y1, int *out) } static void -fz_insert_gel_raw(fz_gel *gel, int x0, int y0, int x1, int y1) +fz_insert_gel_raw(fz_context *ctx, fz_gel *gel, int x0, int y0, int x1, int y1) { fz_edge *edge; int dx, dy; @@ -327,7 +325,7 @@ fz_insert_gel_raw(fz_gel *gel, int x0, int y0, int x1, int y1) if (gel->len + 1 == gel->cap) { int new_cap = gel->cap * 2; - gel->edges = fz_resize_array(gel->ctx, gel->edges, new_cap, sizeof(fz_edge)); + gel->edges = fz_resize_array(ctx, gel->edges, new_cap, sizeof(fz_edge)); gel->cap = new_cap; } @@ -364,11 +362,11 @@ fz_insert_gel_raw(fz_gel *gel, int x0, int y0, int x1, int y1) } void -fz_insert_gel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) +fz_insert_gel(fz_context *ctx, fz_gel *gel, float fx0, float fy0, float fx1, float fy1) { int x0, y0, x1, y1; int d, v; - fz_aa_context *ctxaa = gel->ctx->aa; + fz_aa_context *ctxaa = ctx->aa; fx0 = floorf(fx0 * fz_aa_hscale); fx1 = floorf(fx1 * fz_aa_hscale); @@ -399,12 +397,12 @@ fz_insert_gel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) x0 = x1 = gel->clip.x0; } if (d == LEAVE) { - fz_insert_gel_raw(gel, gel->clip.x0, v, gel->clip.x0, y1); + fz_insert_gel_raw(ctx, gel, gel->clip.x0, v, gel->clip.x0, y1); x1 = gel->clip.x0; y1 = v; } if (d == ENTER) { - fz_insert_gel_raw(gel, gel->clip.x0, y0, gel->clip.x0, v); + fz_insert_gel_raw(ctx, gel, gel->clip.x0, y0, gel->clip.x0, v); x0 = gel->clip.x0; y0 = v; } @@ -414,20 +412,21 @@ fz_insert_gel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1) x0 = x1 = gel->clip.x1; } if (d == LEAVE) { - fz_insert_gel_raw(gel, gel->clip.x1, v, gel->clip.x1, y1); + fz_insert_gel_raw(ctx, gel, gel->clip.x1, v, gel->clip.x1, y1); x1 = gel->clip.x1; y1 = v; } if (d == ENTER) { - fz_insert_gel_raw(gel, gel->clip.x1, y0, gel->clip.x1, v); + fz_insert_gel_raw(ctx, gel, gel->clip.x1, y0, gel->clip.x1, v); x0 = gel->clip.x1; y0 = v; } - fz_insert_gel_raw(gel, x0, y0, x1, y1); + fz_insert_gel_raw(ctx, gel, x0, y0, x1, y1); } -static int cmpedge(const void *va, const void *vb) +static int +cmpedge(const void *va, const void *vb) { const fz_edge *a = va; const fz_edge *b = vb; @@ -435,7 +434,7 @@ static int cmpedge(const void *va, const void *vb) } void -fz_sort_gel(fz_gel *gel) +fz_sort_gel(fz_context *ctx, fz_gel *gel) { fz_edge *a = gel->edges; int n = gel->len; @@ -479,7 +478,7 @@ fz_sort_gel(fz_gel *gel) } int -fz_is_rect_gel(fz_gel *gel) +fz_is_rect_gel(fz_context *ctx, fz_gel *gel) { /* a rectangular path is converted into two vertical edges of identical height */ if (gel->len == 2) @@ -531,7 +530,7 @@ sort_active(fz_edge **a, int n) } static int -insert_active(fz_gel *gel, int y, int *e_) +insert_active(fz_context *ctx, fz_gel *gel, int y, int *e_) { int h_min = INT_MAX; int e = *e_; @@ -542,7 +541,7 @@ insert_active(fz_gel *gel, int y, int *e_) do { if (gel->alen + 1 == gel->acap) { int newcap = gel->acap + 64; - fz_edge **newactive = fz_resize_array(gel->ctx, gel->active, newcap, sizeof(fz_edge*)); + fz_edge **newactive = fz_resize_array(ctx, gel->active, newcap, sizeof(fz_edge*)); gel->active = newactive; gel->acap = newcap; } @@ -576,7 +575,7 @@ insert_active(fz_gel *gel, int y, int *e_) } static void -advance_active(fz_gel *gel, int inc) +advance_active(fz_context *ctx, fz_gel *gel, int inc) { fz_edge *edge; int i = 0; @@ -608,7 +607,8 @@ advance_active(fz_gel *gel, int inc) * Anti-aliased scan conversion. */ -static inline void add_span_aa(fz_aa_context *ctxaa, int *list, int x0, int x1, int xofs, int h) +static inline void +add_span_aa(fz_aa_context *ctxaa, int *list, int x0, int x1, int xofs, int h) { int x0pix, x0sub; int x1pix, x1sub; @@ -643,12 +643,13 @@ static inline void add_span_aa(fz_aa_context *ctxaa, int *list, int x0, int x1, } } -static inline void non_zero_winding_aa(fz_gel *gel, int *list, int xofs, int h) +static inline void +non_zero_winding_aa(fz_context *ctx, fz_gel *gel, int *list, int xofs, int h) { + fz_aa_context *ctxaa = ctx->aa; int winding = 0; int x = 0; int i; - fz_aa_context *ctxaa = gel->ctx->aa; for (i = 0; i < gel->alen; i++) { @@ -660,12 +661,13 @@ static inline void non_zero_winding_aa(fz_gel *gel, int *list, int xofs, int h) } } -static inline void even_odd_aa(fz_gel *gel, int *list, int xofs, int h) +static inline void +even_odd_aa(fz_context *ctx, fz_gel *gel, int *list, int xofs, int h) { + fz_aa_context *ctxaa = ctx->aa; int even = 0; int x = 0; int i; - fz_aa_context *ctxaa = gel->ctx->aa; for (i = 0; i < gel->alen; i++) { @@ -677,7 +679,8 @@ static inline void even_odd_aa(fz_gel *gel, int *list, int xofs, int h) } } -static inline void undelta_aa(fz_aa_context *ctxaa, unsigned char * restrict out, int * restrict in, int n) +static inline void +undelta_aa(fz_aa_context *ctxaa, unsigned char * restrict out, int * restrict in, int n) { int d = 0; while (n--) @@ -687,8 +690,8 @@ static inline void undelta_aa(fz_aa_context *ctxaa, unsigned char * restrict out } } -static inline void blit_aa(fz_pixmap *dst, int x, int y, - unsigned char *mp, int w, unsigned char *color) +static inline void +blit_aa(fz_pixmap *dst, int x, int y, unsigned char *mp, int w, unsigned char *color) { unsigned char *dp; dp = dst->samples + (unsigned int)(( (y - dst->y) * dst->w + (x - dst->x) ) * dst->n); @@ -699,15 +702,13 @@ static inline void blit_aa(fz_pixmap *dst, int x, int y, } static void -fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, - fz_pixmap *dst, unsigned char *color) +fz_scan_convert_aa(fz_context *ctx, fz_gel *gel, int eofill, const fz_irect *clip, fz_pixmap *dst, unsigned char *color) { + fz_aa_context *ctxaa = ctx->aa; unsigned char *alphas; int *deltas; int y, e; int yd, yc; - fz_context *ctx = gel->ctx; - fz_aa_context *ctxaa = ctx->aa; int height, h0, rh; int xmin = fz_idiv(gel->bbox.x0, fz_aa_hscale); @@ -761,7 +762,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, /* height = The number of subscanlines with identical edge * positions (i.e. 1 if we have any non vertical edges). */ - height = insert_active(gel, y, &e); + height = insert_active(ctx, gel, y, &e); h0 = height; if (h0 >= rh) { @@ -783,7 +784,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, h0 = 0; } height -= h0; - advance_active(gel, height); + advance_active(ctx, gel, height); y += height; } @@ -808,7 +809,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, /* height = The number of subscanlines with identical edge * positions (i.e. 1 if we have any non vertical edges). */ - height = insert_active(gel, y, &e); + height = insert_active(ctx, gel, y, &e); h0 = height; if (h0 > rh) { @@ -818,9 +819,9 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, * have more sub scanlines than will fit into * it. */ if (eofill) - even_odd_aa(gel, deltas, xofs, rh); + even_odd_aa(ctx, gel, deltas, xofs, rh); else - non_zero_winding_aa(gel, deltas, xofs, rh); + non_zero_winding_aa(ctx, gel, deltas, xofs, rh); undelta_aa(ctxaa, alphas, deltas, skipx + clipn); blit_aa(dst, xmin + skipx, yd, alphas + skipx, clipn, color); memset(deltas, 0, (skipx + clipn) * sizeof(int)); @@ -835,9 +836,9 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, * scanlines. */ h0 -= fz_aa_vscale; if (eofill) - even_odd_aa(gel, deltas, xofs, fz_aa_vscale); + even_odd_aa(ctx, gel, deltas, xofs, fz_aa_vscale); else - non_zero_winding_aa(gel, deltas, xofs, fz_aa_vscale); + non_zero_winding_aa(ctx, gel, deltas, xofs, fz_aa_vscale); undelta_aa(ctxaa, alphas, deltas, skipx + clipn); do { @@ -860,11 +861,11 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, } } if (eofill) - even_odd_aa(gel, deltas, xofs, h0); + even_odd_aa(ctx, gel, deltas, xofs, h0); else - non_zero_winding_aa(gel, deltas, xofs, h0); + non_zero_winding_aa(ctx, gel, deltas, xofs, h0); advance: - advance_active(gel, height); + advance_active(ctx, gel, height); y += height; } @@ -883,8 +884,8 @@ clip_ended: * Sharp (not anti-aliased) scan conversion */ -static inline void blit_sharp(int x0, int x1, int y, - const fz_irect *clip, fz_pixmap *dst, unsigned char *color) +static inline void +blit_sharp(int x0, int x1, int y, const fz_irect *clip, fz_pixmap *dst, unsigned char *color) { unsigned char *dp; x0 = fz_clampi(x0, dst->x, dst->x + dst->w); @@ -899,8 +900,8 @@ static inline void blit_sharp(int x0, int x1, int y, } } -static inline void non_zero_winding_sharp(fz_gel *gel, int y, - const fz_irect *clip, fz_pixmap *dst, unsigned char *color) +static inline void +non_zero_winding_sharp(fz_context *ctx, fz_gel *gel, int y, const fz_irect *clip, fz_pixmap *dst, unsigned char *color) { int winding = 0; int x = 0; @@ -915,8 +916,8 @@ static inline void non_zero_winding_sharp(fz_gel *gel, int y, } } -static inline void even_odd_sharp(fz_gel *gel, int y, - const fz_irect *clip, fz_pixmap *dst, unsigned char *color) +static inline void +even_odd_sharp(fz_context *ctx, fz_gel *gel, int y, const fz_irect *clip, fz_pixmap *dst, unsigned char *color) { int even = 0; int x = 0; @@ -932,7 +933,8 @@ static inline void even_odd_sharp(fz_gel *gel, int y, } static void -fz_scan_convert_sharp(fz_gel *gel, int eofill, const fz_irect *clip, +fz_scan_convert_sharp(fz_context *ctx, + fz_gel *gel, int eofill, const fz_irect *clip, fz_pixmap *dst, unsigned char *color) { int e = 0; @@ -946,7 +948,7 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, const fz_irect *clip, { while (gel->alen > 0 || e < gel->len) { - height = insert_active(gel, y, &e); + height = insert_active(ctx, gel, y, &e); y += height; if (y >= clip->y0) { @@ -959,7 +961,7 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, const fz_irect *clip, /* Now process as lines within the clip region */ while (gel->alen > 0 || e < gel->len) { - height = insert_active(gel, y, &e); + height = insert_active(ctx, gel, y, &e); if (gel->alen == 0) y += height; @@ -973,31 +975,30 @@ fz_scan_convert_sharp(fz_gel *gel, int eofill, const fz_irect *clip, while (h--) { if (eofill) - even_odd_sharp(gel, y, clip, dst, color); + even_odd_sharp(ctx, gel, y, clip, dst, color); else - non_zero_winding_sharp(gel, y, clip, dst, color); + non_zero_winding_sharp(ctx, gel, y, clip, dst, color); y++; } } if (y >= clip->y1) break; - advance_active(gel, height); + advance_active(ctx, gel, height); } } void -fz_scan_convert(fz_gel *gel, int eofill, const fz_irect *clip, - fz_pixmap *dst, unsigned char *color) +fz_scan_convert(fz_context *ctx, fz_gel *gel, int eofill, const fz_irect *clip, fz_pixmap *dst, unsigned char *color) { - fz_aa_context *ctxaa = gel->ctx->aa; + fz_aa_context *ctxaa = ctx->aa; fz_irect local_clip; if (fz_is_empty_irect(fz_intersect_irect(fz_pixmap_bbox_no_ctx(dst, &local_clip), clip))) return; if (fz_aa_bits > 0) - fz_scan_convert_aa(gel, eofill, &local_clip, dst, color); + fz_scan_convert_aa(ctx, gel, eofill, &local_clip, dst, color); else - fz_scan_convert_sharp(gel, eofill, &local_clip, dst, color); + fz_scan_convert_sharp(ctx, gel, eofill, &local_clip, dst, color); } diff --git a/source/fitz/draw-glyph.c b/source/fitz/draw-glyph.c index bb2de291..e7f8af30 100644 --- a/source/fitz/draw-glyph.c +++ b/source/fitz/draw-glyph.c @@ -131,7 +131,7 @@ fz_keep_glyph_cache(fz_context *ctx) } float -fz_subpixel_adjust(fz_matrix *ctm, fz_matrix *subpix_ctm, unsigned char *qe, unsigned char *qf) +fz_subpixel_adjust(fz_context *ctx, fz_matrix *ctm, fz_matrix *subpix_ctm, unsigned char *qe, unsigned char *qf) { float size = fz_matrix_expansion(ctm); int q; @@ -182,7 +182,7 @@ fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm, if (stroke->dash_len > 0) return NULL; - (void)fz_subpixel_adjust(trm, &subpix_trm, &qe, &qf); + (void)fz_subpixel_adjust(ctx, trm, &subpix_trm, &qe, &qf); return fz_render_ft_stroked_glyph(ctx, font, gid, &subpix_trm, ctm, stroke); } return fz_render_glyph(ctx, font, gid, trm, NULL, scissor); @@ -198,7 +198,7 @@ fz_render_stroked_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matri if (stroke->dash_len > 0) return NULL; - (void)fz_subpixel_adjust(trm, &subpix_trm, &qe, &qf); + (void)fz_subpixel_adjust(ctx, trm, &subpix_trm, &qe, &qf); return fz_render_ft_stroked_glyph_pixmap(ctx, font, gid, &subpix_trm, ctm, stroke); } return fz_render_glyph_pixmap(ctx, font, gid, trm, NULL, scissor); @@ -258,7 +258,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, fz_colo fz_var(val); memset(&key, 0, sizeof key); - size = fz_subpixel_adjust(ctm, &subpix_ctm, &key.e, &key.f); + size = fz_subpixel_adjust(ctx, ctm, &subpix_ctm, &key.e, &key.f); if (size <= MAX_GLYPH_SIZE) { scissor = &fz_infinite_irect; @@ -412,7 +412,7 @@ fz_render_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, fz_pixmap *val; unsigned char qe, qf; fz_matrix subpix_ctm; - float size = fz_subpixel_adjust(ctm, &subpix_ctm, &qe, &qf); + float size = fz_subpixel_adjust(ctx, ctm, &subpix_ctm, &qe, &qf); if (size <= MAX_GLYPH_SIZE) { diff --git a/source/fitz/draw-imp.h b/source/fitz/draw-imp.h index b5f4690d..ed457d34 100644 --- a/source/fitz/draw-imp.h +++ b/source/fitz/draw-imp.h @@ -8,19 +8,19 @@ typedef struct fz_gel_s fz_gel; fz_gel *fz_new_gel(fz_context *ctx); -void fz_insert_gel(fz_gel *gel, float x0, float y0, float x1, float y1); -void fz_reset_gel(fz_gel *gel, const fz_irect *clip); -void fz_sort_gel(fz_gel *gel); -fz_irect *fz_bound_gel(const fz_gel *gel, fz_irect *bbox); -void fz_drop_gel(fz_gel *gel); -int fz_is_rect_gel(fz_gel *gel); -fz_rect *fz_gel_scissor(const fz_gel *gel, fz_rect *rect); - -void fz_scan_convert(fz_gel *gel, int eofill, const fz_irect *clip, fz_pixmap *pix, unsigned char *colorbv); - -void fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float flatness); -void fz_flatten_stroke_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth); -void fz_flatten_dash_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth); +void fz_insert_gel(fz_context *ctx, fz_gel *gel, float x0, float y0, float x1, float y1); +void fz_reset_gel(fz_context *ctx, fz_gel *gel, const fz_irect *clip); +void fz_sort_gel(fz_context *ctx, fz_gel *gel); +fz_irect *fz_bound_gel(fz_context *ctx, const fz_gel *gel, fz_irect *bbox); +void fz_drop_gel(fz_context *ctx, fz_gel *gel); +int fz_is_rect_gel(fz_context *ctx, fz_gel *gel); +fz_rect *fz_gel_scissor(fz_context *ctx, const fz_gel *gel, fz_rect *rect); + +void fz_scan_convert(fz_context *ctx, fz_gel *gel, int eofill, const fz_irect *clip, fz_pixmap *pix, unsigned char *colorbv); + +void fz_flatten_fill_path(fz_context *ctx, fz_gel *gel, fz_path *path, const fz_matrix *ctm, float flatness); +void fz_flatten_stroke_path(fz_context *ctx, fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth); +void fz_flatten_dash_path(fz_context *ctx, fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth); fz_irect *fz_bound_path_accurate(fz_context *ctx, fz_irect *bbox, const fz_irect *scissor, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth); diff --git a/source/fitz/draw-mesh.c b/source/fitz/draw-mesh.c index 8b0d80a3..03cffd06 100644 --- a/source/fitz/draw-mesh.c +++ b/source/fitz/draw-mesh.c @@ -157,7 +157,6 @@ fz_paint_triangle(fz_pixmap *pix, float *v[3], int n, const fz_irect *bbox) struct paint_tri_data { - fz_context *ctx; fz_shade *shade; fz_pixmap *dest; const fz_irect *bbox; @@ -165,7 +164,7 @@ struct paint_tri_data }; static void -prepare_vertex(void *arg, fz_vertex *v, const float *input) +prepare_vertex(fz_context *ctx, void *arg, fz_vertex *v, const float *input) { struct paint_tri_data *ptd = (struct paint_tri_data *)arg; fz_shade *shade = ptd->shade; @@ -177,14 +176,14 @@ prepare_vertex(void *arg, fz_vertex *v, const float *input) output[0] = input[0] * 255; else { - ptd->cc.convert(&ptd->cc, output, input); + ptd->cc.convert(ctx, &ptd->cc, output, input); for (i = 0; i < dest->colorspace->n; i++) output[i] *= 255; } } static void -do_paint_tri(void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex *cv) +do_paint_tri(fz_context *ctx, void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex *cv) { struct paint_tri_data *ptd = (struct paint_tri_data *)arg; float *vertices[3]; @@ -219,10 +218,10 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap if (shade->use_function) { fz_color_converter cc; - fz_lookup_color_converter(&cc, ctx, dest->colorspace, shade->colorspace); + fz_lookup_color_converter(ctx, &cc, dest->colorspace, shade->colorspace); for (i = 0; i < 256; i++) { - cc.convert(&cc, color, shade->function[i]); + cc.convert(ctx, &cc, color, shade->function[i]); for (k = 0; k < dest->colorspace->n; k++) clut[i][k] = color[k] * 255; clut[i][k] = shade->function[i][shade->colorspace->n] * 255; @@ -236,7 +235,6 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap temp = dest; } - ptd.ctx = ctx; ptd.dest = temp; ptd.shade = shade; ptd.bbox = bbox; @@ -264,7 +262,7 @@ fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap } fz_always(ctx) { - fz_fin_cached_color_converter(&ptd.cc); + fz_fin_cached_color_converter(ctx, &ptd.cc); } fz_catch(ctx) { diff --git a/source/fitz/draw-path.c b/source/fitz/draw-path.c index d184fad2..8ad0b334 100644 --- a/source/fitz/draw-path.c +++ b/source/fitz/draw-path.c @@ -4,17 +4,17 @@ #define MAX_DEPTH 8 static void -line(fz_gel *gel, const fz_matrix *ctm, float x0, float y0, float x1, float y1) +line(fz_context *ctx, fz_gel *gel, const fz_matrix *ctm, float x0, float y0, float x1, float y1) { float tx0 = ctm->a * x0 + ctm->c * y0 + ctm->e; float ty0 = ctm->b * x0 + ctm->d * y0 + ctm->f; float tx1 = ctm->a * x1 + ctm->c * y1 + ctm->e; float ty1 = ctm->b * x1 + ctm->d * y1 + ctm->f; - fz_insert_gel(gel, tx0, ty0, tx1, ty1); + fz_insert_gel(ctx, gel, tx0, ty0, tx1, ty1); } static void -bezier(fz_gel *gel, const fz_matrix *ctm, float flatness, +bezier(fz_context *ctx, fz_gel *gel, const fz_matrix *ctm, float flatness, float xa, float ya, float xb, float yb, float xc, float yc, @@ -35,7 +35,7 @@ bezier(fz_gel *gel, const fz_matrix *ctm, float flatness, dmax = fz_max(dmax, fz_abs(yd - yc)); if (dmax < flatness || depth >= MAX_DEPTH) { - line(gel, ctm, xa, ya, xd, yd); + line(ctx, gel, ctm, xa, ya, xd, yd); return; } @@ -63,12 +63,12 @@ bezier(fz_gel *gel, const fz_matrix *ctm, float flatness, xabcd *= 0.125f; yabcd *= 0.125f; - bezier(gel, ctm, flatness, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd, depth + 1); - bezier(gel, ctm, flatness, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd, depth + 1); + bezier(ctx, gel, ctm, flatness, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd, depth + 1); + bezier(ctx, gel, ctm, flatness, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd, depth + 1); } void -fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float flatness) +fz_flatten_fill_path(fz_context *ctx, fz_gel *gel, fz_path *path, const fz_matrix *ctm, float flatness) { float x1, y1, x2, y2, x3, y3; float cx = 0; @@ -84,7 +84,7 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float fla case FZ_MOVETO: /* implicit closepath before moveto */ if (cx != bx || cy != by) - line(gel, ctm, cx, cy, bx, by); + line(ctx, gel, ctm, cx, cy, bx, by); x1 = path->coords[k++]; y1 = path->coords[k++]; cx = bx = x1; @@ -94,7 +94,7 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float fla case FZ_LINETO: x1 = path->coords[k++]; y1 = path->coords[k++]; - line(gel, ctm, cx, cy, x1, y1); + line(ctx, gel, ctm, cx, cy, x1, y1); cx = x1; cy = y1; break; @@ -106,13 +106,13 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float fla y2 = path->coords[k++]; x3 = path->coords[k++]; y3 = path->coords[k++]; - bezier(gel, ctm, flatness, cx, cy, x1, y1, x2, y2, x3, y3, 0); + bezier(ctx, gel, ctm, flatness, cx, cy, x1, y1, x2, y2, x3, y3, 0); cx = x3; cy = y3; break; case FZ_CLOSE_PATH: - line(gel, ctm, cx, cy, bx, by); + line(ctx, gel, ctm, cx, cy, bx, by); cx = bx; cy = by; break; @@ -120,7 +120,7 @@ fz_flatten_fill_path(fz_gel *gel, fz_path *path, const fz_matrix *ctm, float fla } if (cx != bx || cy != by) - line(gel, ctm, cx, cy, bx, by); + line(ctx, gel, ctm, cx, cy, bx, by); } struct sctx @@ -150,17 +150,17 @@ struct sctx }; static void -fz_add_line(struct sctx *s, float x0, float y0, float x1, float y1) +fz_add_line(fz_context *ctx, struct sctx *s, float x0, float y0, float x1, float y1) { float tx0 = s->ctm->a * x0 + s->ctm->c * y0 + s->ctm->e; float ty0 = s->ctm->b * x0 + s->ctm->d * y0 + s->ctm->f; float tx1 = s->ctm->a * x1 + s->ctm->c * y1 + s->ctm->e; float ty1 = s->ctm->b * x1 + s->ctm->d * y1 + s->ctm->f; - fz_insert_gel(s->gel, tx0, ty0, tx1, ty1); + fz_insert_gel(ctx, s->gel, tx0, ty0, tx1, ty1); } static void -fz_add_arc(struct sctx *s, +fz_add_arc(fz_context *ctx, struct sctx *s, float xc, float yc, float x0, float y0, float x1, float y1) @@ -195,28 +195,28 @@ fz_add_arc(struct sctx *s, theta = th0 + (th1 - th0) * i / n; nx = cosf(theta) * r; ny = sinf(theta) * r; - fz_add_line(s, xc + ox, yc + oy, xc + nx, yc + ny); + fz_add_line(ctx, s, xc + ox, yc + oy, xc + nx, yc + ny); ox = nx; oy = ny; } - fz_add_line(s, xc + ox, yc + oy, xc + x1, yc + y1); + fz_add_line(ctx, s, xc + ox, yc + oy, xc + x1, yc + y1); } static void -fz_add_line_stroke(struct sctx *s, fz_point a, fz_point b) +fz_add_line_stroke(fz_context *ctx, struct sctx *s, fz_point a, fz_point b) { float dx = b.x - a.x; float dy = b.y - a.y; float scale = s->linewidth / sqrtf(dx * dx + dy * dy); float dlx = dy * scale; float dly = -dx * scale; - fz_add_line(s, a.x - dlx, a.y - dly, b.x - dlx, b.y - dly); - fz_add_line(s, b.x + dlx, b.y + dly, a.x + dlx, a.y + dly); + fz_add_line(ctx, s, a.x - dlx, a.y - dly, b.x - dlx, b.y - dly); + fz_add_line(ctx, s, b.x + dlx, b.y + dly, a.x + dlx, a.y + dly); } static void -fz_add_line_join(struct sctx *s, fz_point a, fz_point b, fz_point c, int join_under) +fz_add_line_join(fz_context *ctx, struct sctx *s, fz_point a, fz_point b, fz_point c, int join_under) { float miterlimit = s->miterlimit; float linewidth = s->linewidth; @@ -284,12 +284,12 @@ fz_add_line_join(struct sctx *s, fz_point a, fz_point b, fz_point c, int join_un if (join_under) { - fz_add_line(s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); + fz_add_line(ctx, s, b.x + dlx1, b.y + dly1, b.x + dlx0, b.y + dly0); } else { - fz_add_line(s, b.x + dlx1, b.y + dly1, b.x, b.y); - fz_add_line(s, b.x, b.y, b.x + dlx0, b.y + dly0); + fz_add_line(ctx, s, b.x + dlx1, b.y + dly1, b.x, b.y); + fz_add_line(ctx, s, b.x, b.y, b.x + dlx0, b.y + dly0); } /* XPS miter joins are clipped at miterlength, rather than simply @@ -312,9 +312,9 @@ fz_add_line_join(struct sctx *s, fz_point a, fz_point b, fz_point c, int join_un t1x = b.x - dmx + k * (dmx - dlx1); t1y = b.y - dmy + k * (dmy - dly1); - fz_add_line(s, b.x - dlx0, b.y - dly0, t0x, t0y); - fz_add_line(s, t0x, t0y, t1x, t1y); - fz_add_line(s, t1x, t1y, b.x - dlx1, b.y - dly1); + fz_add_line(ctx, s, b.x - dlx0, b.y - dly0, t0x, t0y); + fz_add_line(ctx, s, t0x, t0y, t1x, t1y); + fz_add_line(ctx, s, t1x, t1y, b.x - dlx1, b.y - dly1); } } else if (linejoin == FZ_LINEJOIN_MITER) @@ -327,23 +327,23 @@ fz_add_line_join(struct sctx *s, fz_point a, fz_point b, fz_point c, int join_un dmx *= scale; dmy *= scale; - fz_add_line(s, b.x - dlx0, b.y - dly0, b.x - dmx, b.y - dmy); - fz_add_line(s, b.x - dmx, b.y - dmy, b.x - dlx1, b.y - dly1); + fz_add_line(ctx, s, b.x - dlx0, b.y - dly0, b.x - dmx, b.y - dmy); + fz_add_line(ctx, s, b.x - dmx, b.y - dmy, b.x - dlx1, b.y - dly1); } if (linejoin == FZ_LINEJOIN_BEVEL) { - fz_add_line(s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); + fz_add_line(ctx, s, b.x - dlx0, b.y - dly0, b.x - dlx1, b.y - dly1); } if (linejoin == FZ_LINEJOIN_ROUND) { - fz_add_arc(s, b.x, b.y, -dlx0, -dly0, -dlx1, -dly1); + fz_add_arc(ctx, s, b.x, b.y, -dlx0, -dly0, -dlx1, -dly1); } } static void -fz_add_line_cap(struct sctx *s, fz_point a, fz_point b, fz_linecap linecap) +fz_add_line_cap(fz_context *ctx, struct sctx *s, fz_point a, fz_point b, fz_linecap linecap) { float flatness = s->flatness; float linewidth = s->linewidth; @@ -356,7 +356,7 @@ fz_add_line_cap(struct sctx *s, fz_point a, fz_point b, fz_linecap linecap) float dly = -dx * scale; if (linecap == FZ_LINECAP_BUTT) - fz_add_line(s, b.x - dlx, b.y - dly, b.x + dlx, b.y + dly); + fz_add_line(ctx, s, b.x - dlx, b.y - dly, b.x + dlx, b.y + dly); if (linecap == FZ_LINECAP_ROUND) { @@ -371,20 +371,20 @@ fz_add_line_cap(struct sctx *s, fz_point a, fz_point b, fz_linecap linecap) float sth = sinf(theta); float nx = b.x - dlx * cth - dly * sth; float ny = b.y - dly * cth + dlx * sth; - fz_add_line(s, ox, oy, nx, ny); + fz_add_line(ctx, s, ox, oy, nx, ny); ox = nx; oy = ny; } - fz_add_line(s, ox, oy, b.x + dlx, b.y + dly); + fz_add_line(ctx, s, ox, oy, b.x + dlx, b.y + dly); } if (linecap == FZ_LINECAP_SQUARE) { - fz_add_line(s, b.x - dlx, b.y - dly, + fz_add_line(ctx, s, b.x - dlx, b.y - dly, b.x - dlx - dly, b.y - dly + dlx); - fz_add_line(s, b.x - dlx - dly, b.y - dly + dlx, + fz_add_line(ctx, s, b.x - dlx - dly, b.y - dly + dlx, b.x + dlx - dly, b.y + dly + dlx); - fz_add_line(s, b.x + dlx - dly, b.y + dly + dlx, + fz_add_line(ctx, s, b.x + dlx - dly, b.y + dly + dlx, b.x + dlx, b.y + dly); } @@ -392,13 +392,13 @@ fz_add_line_cap(struct sctx *s, fz_point a, fz_point b, fz_linecap linecap) { float mx = -dly; float my = dlx; - fz_add_line(s, b.x - dlx, b.y - dly, b.x + mx, b.y + my); - fz_add_line(s, b.x + mx, b.y + my, b.x + dlx, b.y + dly); + fz_add_line(ctx, s, b.x - dlx, b.y - dly, b.x + mx, b.y + my); + fz_add_line(ctx, s, b.x + mx, b.y + my, b.x + dlx, b.y + dly); } } static void -fz_add_line_dot(struct sctx *s, fz_point a) +fz_add_line_dot(fz_context *ctx, struct sctx *s, fz_point a) { float flatness = s->flatness; float linewidth = s->linewidth; @@ -414,30 +414,30 @@ fz_add_line_dot(struct sctx *s, fz_point a) float sth = sinf(theta); float nx = a.x - cth * linewidth; float ny = a.y + sth * linewidth; - fz_add_line(s, ox, oy, nx, ny); + fz_add_line(ctx, s, ox, oy, nx, ny); ox = nx; oy = ny; } - fz_add_line(s, ox, oy, a.x - linewidth, a.y); + fz_add_line(ctx, s, ox, oy, a.x - linewidth, a.y); } static void -fz_stroke_flush(struct sctx *s, fz_linecap start_cap, fz_linecap end_cap) +fz_stroke_flush(fz_context *ctx, struct sctx *s, fz_linecap start_cap, fz_linecap end_cap) { if (s->sn == 2) { - fz_add_line_cap(s, s->beg[1], s->beg[0], start_cap); - fz_add_line_cap(s, s->seg[0], s->seg[1], end_cap); + fz_add_line_cap(ctx, s, s->beg[1], s->beg[0], start_cap); + fz_add_line_cap(ctx, s, s->seg[0], s->seg[1], end_cap); } else if (s->dot) { - fz_add_line_dot(s, s->beg[0]); + fz_add_line_dot(ctx, s, s->beg[0]); } } static void -fz_stroke_moveto(struct sctx *s, fz_point cur) +fz_stroke_moveto(fz_context *ctx, struct sctx *s, fz_point cur) { s->seg[0] = cur; s->beg[0] = cur; @@ -447,7 +447,7 @@ fz_stroke_moveto(struct sctx *s, fz_point cur) } static void -fz_stroke_lineto(struct sctx *s, fz_point cur, int from_bezier) +fz_stroke_lineto(fz_context *ctx, struct sctx *s, fz_point cur, int from_bezier) { float dx = cur.x - s->seg[s->sn-1].x; float dy = cur.y - s->seg[s->sn-1].y; @@ -459,11 +459,11 @@ fz_stroke_lineto(struct sctx *s, fz_point cur, int from_bezier) return; } - fz_add_line_stroke(s, s->seg[s->sn-1], cur); + fz_add_line_stroke(ctx, s, s->seg[s->sn-1], cur); if (s->sn == 2) { - fz_add_line_join(s, s->seg[0], s->seg[1], cur, s->from_bezier & from_bezier); + fz_add_line_join(ctx, s, s->seg[0], s->seg[1], cur, s->from_bezier & from_bezier); s->seg[0] = s->seg[1]; s->seg[1] = cur; } @@ -477,19 +477,19 @@ fz_stroke_lineto(struct sctx *s, fz_point cur, int from_bezier) } static void -fz_stroke_closepath(struct sctx *s) +fz_stroke_closepath(fz_context *ctx, struct sctx *s) { if (s->sn == 2) { - fz_stroke_lineto(s, s->beg[0], 0); + fz_stroke_lineto(ctx, s, s->beg[0], 0); if (s->seg[1].x == s->beg[0].x && s->seg[1].y == s->beg[0].y) - fz_add_line_join(s, s->seg[0], s->beg[0], s->beg[1], 0); + fz_add_line_join(ctx, s, s->seg[0], s->beg[0], s->beg[1], 0); else - fz_add_line_join(s, s->seg[1], s->beg[0], s->beg[1], 0); + fz_add_line_join(ctx, s, s->seg[1], s->beg[0], s->beg[1], 0); } else if (s->dot) { - fz_add_line_dot(s, s->beg[0]); + fz_add_line_dot(ctx, s, s->beg[0]); } s->seg[0] = s->beg[0]; @@ -499,7 +499,7 @@ fz_stroke_closepath(struct sctx *s) } static void -fz_stroke_bezier(struct sctx *s, +fz_stroke_bezier(fz_context *ctx, struct sctx *s, float xa, float ya, float xb, float yb, float xc, float yc, @@ -523,7 +523,7 @@ fz_stroke_bezier(struct sctx *s, fz_point p; p.x = xd; p.y = yd; - fz_stroke_lineto(s, p, 1); + fz_stroke_lineto(ctx, s, p, 1); return; } @@ -551,12 +551,12 @@ fz_stroke_bezier(struct sctx *s, xabcd *= 0.125f; yabcd *= 0.125f; - fz_stroke_bezier(s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd, depth + 1); - fz_stroke_bezier(s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd, depth + 1); + fz_stroke_bezier(ctx, s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd, depth + 1); + fz_stroke_bezier(ctx, s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd, depth + 1); } void -fz_flatten_stroke_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth) +fz_flatten_stroke_path(fz_context *ctx, fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth) { struct sctx s; fz_point p0, p1, p2, p3; @@ -594,15 +594,15 @@ fz_flatten_stroke_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke case FZ_MOVETO: p1.x = path->coords[k++]; p1.y = path->coords[k++]; - fz_stroke_flush(&s, stroke->start_cap, stroke->end_cap); - fz_stroke_moveto(&s, p1); + fz_stroke_flush(ctx, &s, stroke->start_cap, stroke->end_cap); + fz_stroke_moveto(ctx, &s, p1); p0 = p1; break; case FZ_LINETO: p1.x = path->coords[k++]; p1.y = path->coords[k++]; - fz_stroke_lineto(&s, p1, 0); + fz_stroke_lineto(ctx, &s, p1, 0); p0 = p1; break; @@ -613,21 +613,21 @@ fz_flatten_stroke_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke p2.y = path->coords[k++]; p3.x = path->coords[k++]; p3.y = path->coords[k++]; - fz_stroke_bezier(&s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 0); + fz_stroke_bezier(ctx, &s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 0); p0 = p3; break; case FZ_CLOSE_PATH: - fz_stroke_closepath(&s); + fz_stroke_closepath(ctx, &s); break; } } - fz_stroke_flush(&s, stroke->start_cap, stroke->end_cap); + fz_stroke_flush(ctx, &s, stroke->start_cap, stroke->end_cap); } static void -fz_dash_moveto(struct sctx *s, fz_point a, fz_linecap start_cap, fz_linecap end_cap) +fz_dash_moveto(fz_context *ctx, struct sctx *s, fz_point a, fz_linecap start_cap, fz_linecap end_cap) { s->toggle = 1; s->offset = 0; @@ -646,14 +646,14 @@ fz_dash_moveto(struct sctx *s, fz_point a, fz_linecap start_cap, fz_linecap end_ if (s->toggle) { - fz_stroke_flush(s, s->cap, end_cap); + fz_stroke_flush(ctx, s, s->cap, end_cap); s->cap = start_cap; - fz_stroke_moveto(s, a); + fz_stroke_moveto(ctx, s, a); } } static void -fz_dash_lineto(struct sctx *s, fz_point b, int dash_cap, int from_bezier) +fz_dash_lineto(fz_context *ctx, struct sctx *s, fz_point b, int dash_cap, int from_bezier) { float dx, dy, d; float total, used, ratio, tail; @@ -736,13 +736,13 @@ a_moved_vertically: /* d and dy have the same sign */ /* Update the position in the dash array */ if (s->toggle) { - fz_stroke_lineto(s, a, from_bezier); + fz_stroke_lineto(ctx, s, a, from_bezier); } else { - fz_stroke_flush(s, s->cap, dash_cap); + fz_stroke_flush(ctx, s, s->cap, dash_cap); s->cap = dash_cap; - fz_stroke_moveto(s, a); + fz_stroke_moveto(ctx, s, a); } used += s->phase; n = used/s->dash_total; @@ -759,13 +759,13 @@ a_moved_vertically: /* d and dy have the same sign */ } if (s->toggle) { - fz_stroke_lineto(s, a, from_bezier); + fz_stroke_lineto(ctx, s, a, from_bezier); } else { - fz_stroke_flush(s, s->cap, dash_cap); + fz_stroke_flush(ctx, s, s->cap, dash_cap); s->cap = dash_cap; - fz_stroke_moveto(s, a); + fz_stroke_moveto(ctx, s, a); } s->phase = used; used = 0; @@ -819,13 +819,13 @@ b_moved_vertically: /* d and dy have the same sign */ if (s->toggle) { - fz_stroke_lineto(s, m, from_bezier); + fz_stroke_lineto(ctx, s, m, from_bezier); } else { - fz_stroke_flush(s, s->cap, dash_cap); + fz_stroke_flush(ctx, s, s->cap, dash_cap); s->cap = dash_cap; - fz_stroke_moveto(s, m); + fz_stroke_moveto(ctx, s, m); } s->toggle = !s->toggle; @@ -843,7 +843,7 @@ b_moved_vertically: /* d and dy have the same sign */ if (s->toggle) { - fz_stroke_lineto(s, b, from_bezier); + fz_stroke_lineto(ctx, s, b, from_bezier); } } else @@ -853,13 +853,13 @@ adjust_for_tail: /* Update the position in the dash array */ if (s->toggle) { - fz_stroke_lineto(s, old_b, from_bezier); + fz_stroke_lineto(ctx, s, old_b, from_bezier); } else { - fz_stroke_flush(s, s->cap, dash_cap); + fz_stroke_flush(ctx, s, s->cap, dash_cap); s->cap = dash_cap; - fz_stroke_moveto(s, old_b); + fz_stroke_moveto(ctx, s, old_b); } tail += s->phase; n = tail/s->dash_total; @@ -876,20 +876,20 @@ adjust_for_tail: } if (s->toggle) { - fz_stroke_lineto(s, old_b, from_bezier); + fz_stroke_lineto(ctx, s, old_b, from_bezier); } else { - fz_stroke_flush(s, s->cap, dash_cap); + fz_stroke_flush(ctx, s, s->cap, dash_cap); s->cap = dash_cap; - fz_stroke_moveto(s, old_b); + fz_stroke_moveto(ctx, s, old_b); } s->phase = tail; } } static void -fz_dash_bezier(struct sctx *s, +fz_dash_bezier(fz_context *ctx, struct sctx *s, float xa, float ya, float xb, float yb, float xc, float yc, @@ -914,7 +914,7 @@ fz_dash_bezier(struct sctx *s, fz_point p; p.x = xd; p.y = yd; - fz_dash_lineto(s, p, dash_cap, 1); + fz_dash_lineto(ctx, s, p, dash_cap, 1); return; } @@ -942,12 +942,12 @@ fz_dash_bezier(struct sctx *s, xabcd *= 0.125f; yabcd *= 0.125f; - fz_dash_bezier(s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd, depth + 1, dash_cap); - fz_dash_bezier(s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd, depth + 1, dash_cap); + fz_dash_bezier(ctx, s, xa, ya, xab, yab, xabc, yabc, xabcd, yabcd, depth + 1, dash_cap); + fz_dash_bezier(ctx, s, xabcd, yabcd, xbcd, ybcd, xcd, ycd, xd, yd, depth + 1, dash_cap); } void -fz_flatten_dash_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth) +fz_flatten_dash_path(fz_context *ctx, fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, float flatness, float linewidth) { struct sctx s; fz_point p0, p1, p2, p3, beg; @@ -982,7 +982,7 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, phase_len += stroke->dash_list[i]; if (stroke->dash_len > 0 && phase_len == 0) return; - fz_gel_scissor(gel, &s.rect); + fz_gel_scissor(ctx, gel, &s.rect); if (fz_try_invert_matrix(&inv, ctm)) return; fz_transform_rect(&s.rect, &inv); @@ -994,7 +994,7 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, max_expand = fz_matrix_max_expansion(ctm); if (phase_len < 0.01f || phase_len * max_expand < 0.5f) { - fz_flatten_stroke_path(gel, path, stroke, ctm, flatness, linewidth); + fz_flatten_stroke_path(ctx, gel, path, stroke, ctm, flatness, linewidth); return; } s.dash_total = phase_len; @@ -1009,14 +1009,14 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, case FZ_MOVETO: p1.x = path->coords[k++]; p1.y = path->coords[k++]; - fz_dash_moveto(&s, p1, stroke->start_cap, stroke->end_cap); + fz_dash_moveto(ctx, &s, p1, stroke->start_cap, stroke->end_cap); beg = p0 = p1; break; case FZ_LINETO: p1.x = path->coords[k++]; p1.y = path->coords[k++]; - fz_dash_lineto(&s, p1, stroke->dash_cap, 0); + fz_dash_lineto(ctx, &s, p1, stroke->dash_cap, 0); p0 = p1; break; @@ -1027,16 +1027,16 @@ fz_flatten_dash_path(fz_gel *gel, fz_path *path, const fz_stroke_state *stroke, p2.y = path->coords[k++]; p3.x = path->coords[k++]; p3.y = path->coords[k++]; - fz_dash_bezier(&s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 0, stroke->dash_cap); + fz_dash_bezier(ctx, &s, p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 0, stroke->dash_cap); p0 = p3; break; case FZ_CLOSE_PATH: - fz_dash_lineto(&s, beg, stroke->dash_cap, 0); + fz_dash_lineto(ctx, &s, beg, stroke->dash_cap, 0); p0 = p1 = beg; break; } } - fz_stroke_flush(&s, s.cap, stroke->end_cap); + fz_stroke_flush(ctx, &s, s.cap, stroke->end_cap); } diff --git a/source/fitz/draw-unpack.c b/source/fitz/draw-unpack.c index d862ea2a..806fe448 100644 --- a/source/fitz/draw-unpack.c +++ b/source/fitz/draw-unpack.c @@ -47,7 +47,7 @@ init_get1_tables(void) } void -fz_unpack_tile(fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale) +fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, int n, int depth, int stride, int scale) { int pad, x, y, k; int w = dst->w; @@ -172,7 +172,7 @@ fz_unpack_tile(fz_pixmap *dst, unsigned char * restrict src, int n, int depth, i /* Apply decode array */ void -fz_decode_indexed_tile(fz_pixmap *pix, float *decode, int maxval) +fz_decode_indexed_tile(fz_context *ctx, fz_pixmap *pix, float *decode, int maxval) { int add[FZ_MAX_COLORS]; int mul[FZ_MAX_COLORS]; @@ -207,7 +207,7 @@ fz_decode_indexed_tile(fz_pixmap *pix, float *decode, int maxval) } void -fz_decode_tile(fz_pixmap *pix, float *decode) +fz_decode_tile(fz_context *ctx, fz_pixmap *pix, float *decode) { int add[FZ_MAX_COLORS]; int mul[FZ_MAX_COLORS]; diff --git a/source/fitz/filter-basic.c b/source/fitz/filter-basic.c index 1b4eaefb..eb9e838e 100644 --- a/source/fitz/filter-basic.c +++ b/source/fitz/filter-basic.c @@ -3,9 +3,9 @@ /* Pretend we have a filter that just copies data forever */ fz_stream * -fz_open_copy(fz_stream *chain) +fz_open_copy(fz_context *ctx, fz_stream *chain) { - return fz_keep_stream(chain); + return fz_keep_stream(ctx, chain); } /* Null filter copies a specified amount of data */ @@ -19,15 +19,15 @@ struct null_filter }; static int -next_null(fz_stream *stm, int max) +next_null(fz_context *ctx, fz_stream *stm, int max) { struct null_filter *state = stm->state; int n; if (state->remain == 0) return EOF; - fz_seek(state->chain, state->offset, 0); - n = fz_available(state->chain, max); + fz_seek(ctx, state->chain, state->offset, 0); + n = fz_available(ctx, state->chain, max); if (n > state->remain) n = state->remain; if (n > sizeof(state->buffer)) @@ -50,21 +50,13 @@ close_null(fz_context *ctx, void *state_) struct null_filter *state = (struct null_filter *)state_; fz_stream *chain = state->chain; fz_free(ctx, state); - fz_drop_stream(chain); -} - -static fz_stream * -rebind_null(fz_stream *s) -{ - struct null_filter *state = s->state; - return state->chain; + fz_drop_stream(ctx, chain); } fz_stream * -fz_open_null(fz_stream *chain, int len, int offset) +fz_open_null(fz_context *ctx, fz_stream *chain, int len, int offset) { struct null_filter *state; - fz_context *ctx = chain->ctx; if (len < 0) len = 0; @@ -77,11 +69,11 @@ fz_open_null(fz_stream *chain, int len, int offset) } fz_catch(ctx) { - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_null, close_null, rebind_null); + return fz_new_stream(ctx, state, next_null, close_null); } /* Concat filter concatenates several streams into one */ @@ -97,7 +89,7 @@ struct concat_filter }; static int -next_concat(fz_stream *stm, int max) +next_concat(fz_context *ctx, fz_stream *stm, int max) { struct concat_filter *state = (struct concat_filter *)stm->state; int n; @@ -107,7 +99,7 @@ next_concat(fz_stream *stm, int max) /* Read the next block of underlying data. */ if (stm->wp == state->chain[state->current]->wp) state->chain[state->current]->rp = stm->wp; - n = fz_available(state->chain[state->current], max); + n = fz_available(ctx, state->chain[state->current], max); if (n) { stm->rp = state->chain[state->current]->rp; @@ -123,7 +115,7 @@ next_concat(fz_stream *stm, int max) break; } state->current++; - fz_drop_stream(state->chain[state->current-1]); + fz_drop_stream(ctx, state->chain[state->current-1]); if (state->pad) { stm->rp = (&state->ws_buf)+1; @@ -147,26 +139,11 @@ close_concat(fz_context *ctx, void *state_) for (i = state->current; i < state->count; i++) { - fz_drop_stream(state->chain[i]); + fz_drop_stream(ctx, state->chain[i]); } fz_free(ctx, state); } -static fz_stream * -rebind_concat(fz_stream *s) -{ - struct concat_filter *state = s->state; - int i; - - if (state->current >= state->count) - return NULL; - for (i = state->current; i < state->count-1; i++) - { - fz_rebind_stream(state->chain[i], s->ctx); - } - return state->chain[i]; -} - fz_stream * fz_open_concat(fz_context *ctx, int len, int pad) { @@ -179,16 +156,16 @@ fz_open_concat(fz_context *ctx, int len, int pad) state->pad = pad; state->ws_buf = 32; - return fz_new_stream(ctx, state, next_concat, close_concat, rebind_concat); + return fz_new_stream(ctx, state, next_concat, close_concat); } void -fz_concat_push(fz_stream *concat, fz_stream *chain) +fz_concat_push(fz_context *ctx, fz_stream *concat, fz_stream *chain) { struct concat_filter *state = (struct concat_filter *)concat->state; if (state->count == state->max) - fz_throw(concat->ctx, FZ_ERROR_GENERIC, "Concat filter size exceeded"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Concat filter size exceeded"); state->chain[state->count++] = chain; } @@ -230,7 +207,7 @@ static inline int unhex(int a) } static int -next_ahxd(fz_stream *stm, int max) +next_ahxd(fz_context *ctx, fz_stream *stm, int max) { fz_ahxd *state = stm->state; unsigned char *p = state->buffer; @@ -248,7 +225,7 @@ next_ahxd(fz_stream *stm, int max) if (state->eod) break; - c = fz_read_byte(state->chain); + c = fz_read_byte(ctx, state->chain); if (c < 0) break; @@ -275,7 +252,7 @@ next_ahxd(fz_stream *stm, int max) } else if (!iswhite(c)) { - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "bad data in ahxd: '%c'", c); + fz_throw(ctx, FZ_ERROR_GENERIC, "bad data in ahxd: '%c'", c); } } stm->rp = state->buffer; @@ -293,21 +270,13 @@ close_ahxd(fz_context *ctx, void *state_) fz_ahxd *state = (fz_ahxd *)state_; fz_stream *chain = state->chain; fz_free(ctx, state); - fz_drop_stream(chain); -} - -static fz_stream * -rebind_ahxd(fz_stream *s) -{ - fz_ahxd *state = s->state; - return state->chain; + fz_drop_stream(ctx, chain); } fz_stream * -fz_open_ahxd(fz_stream *chain) +fz_open_ahxd(fz_context *ctx, fz_stream *chain) { fz_ahxd *state; - fz_context *ctx = chain->ctx; fz_try(ctx) { @@ -317,11 +286,11 @@ fz_open_ahxd(fz_stream *chain) } fz_catch(ctx) { - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_ahxd, close_ahxd, rebind_ahxd); + return fz_new_stream(ctx, state, next_ahxd, close_ahxd); } /* ASCII 85 Decode */ @@ -336,7 +305,7 @@ struct fz_a85d_s }; static int -next_a85d(fz_stream *stm, int max) +next_a85d(fz_context *ctx, fz_stream *stm, int max) { fz_a85d *state = stm->state; unsigned char *p = state->buffer; @@ -354,7 +323,7 @@ next_a85d(fz_stream *stm, int max) ep = p + max; while (p < ep) { - c = fz_read_byte(state->chain); + c = fz_read_byte(ctx, state->chain); if (c < 0) break; @@ -389,9 +358,9 @@ next_a85d(fz_stream *stm, int max) else if (c == '~') { - c = fz_read_byte(state->chain); + c = fz_read_byte(ctx, state->chain); if (c != '>') - fz_warn(stm->ctx, "bad eod marker in a85d"); + fz_warn(ctx, "bad eod marker in a85d"); switch (count) { case 0: @@ -400,7 +369,7 @@ next_a85d(fz_stream *stm, int max) /* Specifically illegal in the spec, but adobe * and gs both cope. See normal_87.pdf for a * case where this matters. */ - fz_warn(stm->ctx, "partial final byte in a85d"); + fz_warn(ctx, "partial final byte in a85d"); break; case 2: word = word * (85 * 85 * 85) + 0xffffff; @@ -424,7 +393,7 @@ next_a85d(fz_stream *stm, int max) else if (!iswhite(c)) { - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "bad data in a85d: '%c'", c); + fz_throw(ctx, FZ_ERROR_GENERIC, "bad data in a85d: '%c'", c); } } @@ -445,21 +414,13 @@ close_a85d(fz_context *ctx, void *state_) fz_stream *chain = state->chain; fz_free(ctx, state); - fz_drop_stream(chain); -} - -static fz_stream * -rebind_a85d(fz_stream *s) -{ - fz_a85d *state = s->state; - return state->chain; + fz_drop_stream(ctx, chain); } fz_stream * -fz_open_a85d(fz_stream *chain) +fz_open_a85d(fz_context *ctx, fz_stream *chain) { fz_a85d *state; - fz_context *ctx = chain->ctx; fz_try(ctx) { @@ -469,11 +430,11 @@ fz_open_a85d(fz_stream *chain) } fz_catch(ctx) { - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_a85d, close_a85d, rebind_a85d); + return fz_new_stream(ctx, state, next_a85d, close_a85d); } /* Run Length Decode */ @@ -488,7 +449,7 @@ struct fz_rld_s }; static int -next_rld(fz_stream *stm, int max) +next_rld(fz_context *ctx, fz_stream *stm, int max) { fz_rld *state = stm->state; unsigned char *p = state->buffer; @@ -508,7 +469,7 @@ next_rld(fz_stream *stm, int max) if (state->n == 0) { - state->run = fz_read_byte(state->chain); + state->run = fz_read_byte(ctx, state->chain); if (state->run < 0) { state->run = 128; @@ -519,9 +480,9 @@ next_rld(fz_stream *stm, int max) if (state->run > 128) { state->n = 257 - state->run; - state->c = fz_read_byte(state->chain); + state->c = fz_read_byte(ctx, state->chain); if (state->c < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "premature end of data in run length decode"); + fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in run length decode"); } } @@ -529,9 +490,9 @@ next_rld(fz_stream *stm, int max) { while (p < ep && state->n) { - int c = fz_read_byte(state->chain); + int c = fz_read_byte(ctx, state->chain); if (c < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "premature end of data in run length decode"); + fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in run length decode"); *p++ = c; state->n--; } @@ -564,21 +525,13 @@ close_rld(fz_context *ctx, void *state_) fz_stream *chain = state->chain; fz_free(ctx, state); - fz_drop_stream(chain); -} - -static fz_stream * -rebind_rld(fz_stream *s) -{ - fz_rld *state = s->state; - return state->chain; + fz_drop_stream(ctx, chain); } fz_stream * -fz_open_rld(fz_stream *chain) +fz_open_rld(fz_context *ctx, fz_stream *chain) { fz_rld *state; - fz_context *ctx = chain->ctx; fz_try(ctx) { @@ -590,11 +543,11 @@ fz_open_rld(fz_stream *chain) } fz_catch(ctx) { - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_rld, close_rld, rebind_rld); + return fz_new_stream(ctx, state, next_rld, close_rld); } /* RC4 Filter */ @@ -609,10 +562,10 @@ struct fz_arc4c_s }; static int -next_arc4(fz_stream *stm, int max) +next_arc4(fz_context *ctx, fz_stream *stm, int max) { fz_arc4c *state = stm->state; - int n = fz_available(state->chain, max); + int n = fz_available(ctx, state->chain, max); if (n == 0) return EOF; @@ -635,21 +588,13 @@ close_arc4(fz_context *ctx, void *state_) fz_stream *chain = state->chain; fz_free(ctx, state); - fz_drop_stream(chain); -} - -static fz_stream * -rebind_arc4c(fz_stream *s) -{ - fz_arc4c *state = s->state; - return state->chain; + fz_drop_stream(ctx, chain); } fz_stream * -fz_open_arc4(fz_stream *chain, unsigned char *key, unsigned keylen) +fz_open_arc4(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen) { fz_arc4c *state; - fz_context *ctx = chain->ctx; fz_try(ctx) { @@ -659,11 +604,11 @@ fz_open_arc4(fz_stream *chain, unsigned char *key, unsigned keylen) } fz_catch(ctx) { - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_arc4, close_arc4, rebind_arc4c); + return fz_new_stream(ctx, state, next_arc4, close_arc4); } /* AES Filter */ @@ -682,7 +627,7 @@ struct fz_aesd_s }; static int -next_aesd(fz_stream *stm, int max) +next_aesd(fz_context *ctx, fz_stream *stm, int max) { fz_aesd *state = stm->state; unsigned char *p = state->buffer; @@ -694,9 +639,9 @@ next_aesd(fz_stream *stm, int max) while (state->ivcount < 16) { - int c = fz_read_byte(state->chain); + int c = fz_read_byte(ctx, state->chain); if (c < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "premature end in aes filter"); + fz_throw(ctx, FZ_ERROR_GENERIC, "premature end in aes filter"); state->iv[state->ivcount++] = c; } @@ -705,22 +650,22 @@ next_aesd(fz_stream *stm, int max) while (p < ep) { - int n = fz_read(state->chain, state->bp, 16); + int n = fz_read(ctx, state->chain, state->bp, 16); if (n == 0) break; else if (n < 16) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "partial block in aes filter"); + fz_throw(ctx, FZ_ERROR_GENERIC, "partial block in aes filter"); aes_crypt_cbc(&state->aes, AES_DECRYPT, 16, state->iv, state->bp, state->bp); state->rp = state->bp; state->wp = state->bp + 16; /* strip padding at end of file */ - if (fz_is_eof(state->chain)) + if (fz_is_eof(ctx, state->chain)) { int pad = state->bp[15]; if (pad < 1 || pad > 16) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "aes padding out of range: %d", pad); + fz_throw(ctx, FZ_ERROR_GENERIC, "aes padding out of range: %d", pad); state->wp -= pad; } @@ -745,21 +690,13 @@ close_aesd(fz_context *ctx, void *state_) fz_stream *chain = state->chain; fz_free(ctx, state); - fz_drop_stream(chain); -} - -static fz_stream * -rebind_aesd(fz_stream *s) -{ - fz_aesd *state = s->state; - return state->chain; + fz_drop_stream(ctx, chain); } fz_stream * -fz_open_aesd(fz_stream *chain, unsigned char *key, unsigned keylen) +fz_open_aesd(fz_context *ctx, fz_stream *chain, unsigned char *key, unsigned keylen) { fz_aesd *state = NULL; - fz_context *ctx = chain->ctx; fz_var(state); @@ -776,9 +713,9 @@ fz_open_aesd(fz_stream *chain, unsigned char *key, unsigned keylen) fz_catch(ctx) { fz_free(ctx, state); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_aesd, close_aesd, rebind_aesd); + return fz_new_stream(ctx, state, next_aesd, close_aesd); } diff --git a/source/fitz/filter-dct.c b/source/fitz/filter-dct.c index 9495b899..0d24de88 100644 --- a/source/fitz/filter-dct.c +++ b/source/fitz/filter-dct.c @@ -109,13 +109,13 @@ static boolean fill_input_buffer(j_decompress_ptr cinfo) { struct jpeg_source_mgr *src = cinfo->src; fz_dctd *state = JZ_DCT_STATE_FROM_CINFO(cinfo); + fz_context *ctx = state->ctx; fz_stream *curr_stm = state->curr_stm; - fz_context *ctx = curr_stm->ctx; curr_stm->rp = curr_stm->wp; fz_try(ctx) { - src->bytes_in_buffer = fz_available(curr_stm, 1); + src->bytes_in_buffer = fz_available(ctx, curr_stm, 1); } fz_catch(ctx) { @@ -151,7 +151,7 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) } static int -next_dctd(fz_stream *stm, int max) +next_dctd(fz_context *ctx, fz_stream *stm, int max) { fz_dctd *state = stm->state; j_decompress_ptr cinfo = &state->cinfo; @@ -166,7 +166,7 @@ next_dctd(fz_stream *stm, int max) { if (cinfo->src) state->curr_stm->rp = state->curr_stm->wp - cinfo->src->bytes_in_buffer; - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "jpeg error: %s", state->msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "jpeg error: %s", state->msg); } if (!state->init) @@ -183,8 +183,8 @@ next_dctd(fz_stream *stm, int max) state->init = 1; /* Skip over any stray returns at the start of the stream */ - while ((c = fz_peek_byte(state->chain)) == '\n' || c == '\r') - (void)fz_read_byte(state->chain); + while ((c = fz_peek_byte(ctx, state->chain)) == '\n' || c == '\r') + (void)fz_read_byte(ctx, state->chain); cinfo->src = &state->srcmgr; cinfo->src->init_source = init_source; @@ -244,7 +244,7 @@ next_dctd(fz_stream *stm, int max) jpeg_start_decompress(cinfo); state->stride = cinfo->output_width * cinfo->output_components; - state->scanline = fz_malloc(state->ctx, state->stride); + state->scanline = fz_malloc(ctx, state->stride); state->rp = state->scanline; state->wp = state->scanline; } @@ -308,30 +308,22 @@ skip: fz_dct_mem_term(state); fz_free(ctx, state->scanline); - fz_drop_stream(state->chain); - fz_drop_stream(state->jpegtables); + fz_drop_stream(ctx, state->chain); + fz_drop_stream(ctx, state->jpegtables); fz_free(ctx, state); } -static fz_stream * -rebind_dctd(fz_stream *s) -{ - fz_dctd *state = s->state; - return state->chain; -} - /* Default: color_transform = -1 (unset), l2factor = 0, jpegtables = NULL */ fz_stream * -fz_open_dctd(fz_stream *chain, int color_transform, int l2factor, fz_stream *jpegtables) +fz_open_dctd(fz_context *ctx, fz_stream *chain, int color_transform, int l2factor, fz_stream *jpegtables) { - fz_context *ctx = chain->ctx; fz_dctd *state = NULL; fz_var(state); fz_try(ctx) { - state = fz_malloc_struct(chain->ctx, fz_dctd); + state = fz_malloc_struct(ctx, fz_dctd); state->ctx = ctx; state->chain = chain; state->jpegtables = jpegtables; @@ -344,10 +336,10 @@ fz_open_dctd(fz_stream *chain, int color_transform, int l2factor, fz_stream *jpe fz_catch(ctx) { fz_free(ctx, state); - fz_drop_stream(chain); - fz_drop_stream(jpegtables); + fz_drop_stream(ctx, chain); + fz_drop_stream(ctx, jpegtables); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_dctd, close_dctd, rebind_dctd); + return fz_new_stream(ctx, state, next_dctd, close_dctd); } diff --git a/source/fitz/filter-fax.c b/source/fitz/filter-fax.c index 134c2ae5..f0a58160 100644 --- a/source/fitz/filter-fax.c +++ b/source/fitz/filter-fax.c @@ -321,7 +321,6 @@ enum struct fz_faxd_s { - fz_context *ctx; fz_stream *chain; int k; @@ -355,14 +354,14 @@ static inline void eat_bits(fz_faxd *fax, int nbits) } static int -fill_bits(fz_faxd *fax) +fill_bits(fz_context *ctx, fz_faxd *fax) { /* The longest length of bits we'll ever need is 13. Never read more * than we need to avoid unnecessary overreading of the end of the * stream. */ while (fax->bidx > (32-13)) { - int c = fz_read_byte(fax->chain); + int c = fz_read_byte(ctx, fax->chain); if (c == EOF) return EOF; fax->bidx -= 8; @@ -372,7 +371,7 @@ fill_bits(fz_faxd *fax) } static int -get_code(fz_faxd *fax, const cfd_node *table, int initialbits) +get_code(fz_context *ctx, fz_faxd *fax, const cfd_node *table, int initialbits) { unsigned int word = fax->word; int tidx = word >> (32 - initialbits); @@ -402,9 +401,9 @@ dec1d(fz_context *ctx, fz_faxd *fax) fax->a = 0; if (fax->c) - code = get_code(fax, cf_black_decode, cfd_black_initial_bits); + code = get_code(ctx, fax, cf_black_decode, cfd_black_initial_bits); else - code = get_code(fax, cf_white_decode, cfd_white_initial_bits); + code = get_code(ctx, fax, cf_white_decode, cfd_white_initial_bits); if (code == UNCOMPRESSED) fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); @@ -441,9 +440,9 @@ dec2d(fz_context *ctx, fz_faxd *fax) fax->a = 0; if (fax->c) - code = get_code(fax, cf_black_decode, cfd_black_initial_bits); + code = get_code(ctx, fax, cf_black_decode, cfd_black_initial_bits); else - code = get_code(fax, cf_white_decode, cfd_white_initial_bits); + code = get_code(ctx, fax, cf_white_decode, cfd_white_initial_bits); if (code == UNCOMPRESSED) fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); @@ -471,7 +470,7 @@ dec2d(fz_context *ctx, fz_faxd *fax) return; } - code = get_code(fax, cf_2d_decode, cfd_2d_initial_bits); + code = get_code(ctx, fax, cf_2d_decode, cfd_2d_initial_bits); switch (code) { @@ -556,9 +555,8 @@ dec2d(fz_context *ctx, fz_faxd *fax) } static int -next_faxd(fz_stream *stm, int max) +next_faxd(fz_context *ctx, fz_stream *stm, int max) { - fz_context *ctx = stm->ctx; fz_faxd *fax = stm->state; unsigned char *p = fax->buffer; unsigned char *ep; @@ -569,11 +567,11 @@ next_faxd(fz_stream *stm, int max) ep = p + max; if (fax->stage == STATE_INIT && fax->end_of_line) { - fill_bits(fax); + fill_bits(ctx, fax); if ((fax->word >> (32 - 12)) != 1) { fz_warn(ctx, "faxd stream doesn't start with EOL"); - while (!fill_bits(fax) && (fax->word >> (32 - 12)) != 1) + while (!fill_bits(ctx, fax) && (fax->word >> (32 - 12)) != 1) eat_bits(fax, 1); } if ((fax->word >> (32 - 12)) != 1) @@ -591,7 +589,7 @@ next_faxd(fz_stream *stm, int max) loop: - if (fill_bits(fax)) + if (fill_bits(ctx, fax)) { if (fax->bidx > 31) { @@ -776,28 +774,20 @@ close_faxd(fz_context *ctx, void *state_) /* if we read any extra bytes, try to put them back */ i = (32 - fax->bidx) / 8; while (i--) - fz_unread_byte(fax->chain); + fz_unread_byte(ctx, fax->chain); - fz_drop_stream(fax->chain); + fz_drop_stream(ctx, fax->chain); fz_free(ctx, fax->ref); fz_free(ctx, fax->dst); fz_free(ctx, fax); } -static fz_stream * -rebind_faxd(fz_stream *s) -{ - fz_faxd *state = s->state; - return state->chain; -} - /* Default: columns = 1728, end_of_block = 1, the rest = 0 */ fz_stream * -fz_open_faxd(fz_stream *chain, +fz_open_faxd(fz_context *ctx, fz_stream *chain, int k, int end_of_line, int encoded_byte_align, int columns, int rows, int end_of_block, int black_is_1) { - fz_context *ctx = chain->ctx; fz_faxd *fax = NULL; fz_var(fax); @@ -848,9 +838,9 @@ fz_open_faxd(fz_stream *chain, fz_free(ctx, fax->ref); } fz_free(ctx, fax); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, fax, next_faxd, close_faxd, rebind_faxd); + return fz_new_stream(ctx, fax, next_faxd, close_faxd); } diff --git a/source/fitz/filter-flate.c b/source/fitz/filter-flate.c index 764e819a..46ff6970 100644 --- a/source/fitz/filter-flate.c +++ b/source/fitz/filter-flate.c @@ -22,7 +22,7 @@ static void zfree(void *opaque, void *ptr) } static int -next_flated(fz_stream *stm, int required) +next_flated(fz_context *ctx, fz_stream *stm, int required) { fz_flate *state = stm->state; fz_stream *chain = state->chain; @@ -39,7 +39,7 @@ next_flated(fz_stream *stm, int required) while (zp->avail_out > 0) { - zp->avail_in = fz_available(chain, 1); + zp->avail_in = fz_available(ctx, chain, 1); zp->next_in = chain->rp; code = inflate(zp, Z_SYNC_FLUSH); @@ -52,23 +52,23 @@ next_flated(fz_stream *stm, int required) } else if (code == Z_BUF_ERROR) { - fz_warn(stm->ctx, "premature end of data in flate filter"); + fz_warn(ctx, "premature end of data in flate filter"); break; } else if (code == Z_DATA_ERROR && zp->avail_in == 0) { - fz_warn(stm->ctx, "ignoring zlib error: %s", zp->msg); + fz_warn(ctx, "ignoring zlib error: %s", zp->msg); break; } else if (code == Z_DATA_ERROR && !strcmp(zp->msg, "incorrect data check")) { - fz_warn(stm->ctx, "ignoring zlib error: %s", zp->msg); + fz_warn(ctx, "ignoring zlib error: %s", zp->msg); chain->rp = chain->wp; break; } else if (code != Z_OK) { - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "zlib error: %s", zp->msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: %s", zp->msg); } } @@ -93,23 +93,15 @@ close_flated(fz_context *ctx, void *state_) if (code != Z_OK) fz_warn(ctx, "zlib error: inflateEnd: %s", state->z.msg); - fz_drop_stream(state->chain); + fz_drop_stream(ctx, state->chain); fz_free(ctx, state); } -static fz_stream * -rebind_flated(fz_stream *s) -{ - fz_flate *state = s->state; - return state->chain; -} - fz_stream * -fz_open_flated(fz_stream *chain, int window_bits) +fz_open_flated(fz_context *ctx, fz_stream *chain, int window_bits) { fz_flate *state = NULL; int code = Z_OK; - fz_context *ctx = chain->ctx; fz_var(code); fz_var(state); @@ -134,8 +126,8 @@ fz_open_flated(fz_stream *chain, int window_bits) if (state && code == Z_OK) inflateEnd(&state->z); fz_free(ctx, state); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_flated, close_flated, rebind_flated); + return fz_new_stream(ctx, state, next_flated, close_flated); } diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c index 0e624da6..8aec1d67 100644 --- a/source/fitz/filter-jbig2.c +++ b/source/fitz/filter-jbig2.c @@ -35,12 +35,12 @@ close_jbig2d(fz_context *ctx, void *state_) if (state->gctx) fz_drop_jbig2_globals(ctx, state->gctx); jbig2_ctx_free(state->ctx); - fz_drop_stream(state->chain); + fz_drop_stream(ctx, state->chain); fz_free(ctx, state); } static int -next_jbig2d(fz_stream *stm, int len) +next_jbig2d(fz_context *ctx, fz_stream *stm, int len) { fz_jbig2d *state = stm->state; unsigned char tmp[4096]; @@ -58,7 +58,7 @@ next_jbig2d(fz_stream *stm, int len) { while (1) { - n = fz_read(state->chain, tmp, sizeof tmp); + n = fz_read(ctx, state->chain, tmp, sizeof tmp); if (n == 0) break; jbig2_data_in(state->ctx, tmp, n); @@ -68,7 +68,7 @@ next_jbig2d(fz_stream *stm, int len) state->page = jbig2_page_out(state->ctx); if (!state->page) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "jbig2_page_out failed"); + fz_throw(ctx, FZ_ERROR_GENERIC, "jbig2_page_out failed"); } s = state->page->data; @@ -86,13 +86,6 @@ next_jbig2d(fz_stream *stm, int len) return *stm->rp++; } -static fz_stream * -rebind_jbig2d(fz_stream *s) -{ - fz_jbig2d *state = s->state; - return state->chain; -} - static int error_callback(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx) { @@ -127,16 +120,15 @@ fz_drop_jbig2_globals_imp(fz_context *ctx, fz_storable *globals_) } fz_stream * -fz_open_jbig2d(fz_stream *chain, fz_jbig2_globals *globals) +fz_open_jbig2d(fz_context *ctx, fz_stream *chain, fz_jbig2_globals *globals) { fz_jbig2d *state = NULL; - fz_context *ctx = chain->ctx; fz_var(state); fz_try(ctx) { - state = fz_malloc_struct(chain->ctx, fz_jbig2d); + state = fz_malloc_struct(ctx, fz_jbig2d); state->ctx = NULL; state->gctx = globals; state->chain = chain; @@ -153,9 +145,9 @@ fz_open_jbig2d(fz_stream *chain, fz_jbig2_globals *globals) jbig2_ctx_free(state->ctx); } fz_free(ctx, state); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_jbig2d, close_jbig2d, rebind_jbig2d); + return fz_new_stream(ctx, state, next_jbig2d, close_jbig2d); } diff --git a/source/fitz/filter-leech.c b/source/fitz/filter-leech.c index 67a43a29..90e28565 100644 --- a/source/fitz/filter-leech.c +++ b/source/fitz/filter-leech.c @@ -11,18 +11,18 @@ struct fz_leech_s }; static int -next_leech(fz_stream *stm, int max) +next_leech(fz_context *ctx, fz_stream *stm, int max) { fz_leech *state = stm->state; fz_buffer *buffer = state->buffer; - int n = fz_available(state->chain, max); + int n = fz_available(ctx, state->chain, max); if (n > max) n = max; while (buffer->cap < buffer->len + n) { - fz_grow_buffer(stm->ctx, state->buffer); + fz_grow_buffer(ctx, state->buffer); } memcpy(buffer->data + buffer->len, state->chain->rp, n); stm->rp = buffer->data + buffer->len; @@ -40,22 +40,14 @@ close_leech(fz_context *ctx, void *state_) { fz_leech *state = (fz_leech *)state_; - fz_drop_stream(state->chain); + fz_drop_stream(ctx, state->chain); fz_free(ctx, state); } -static fz_stream * -rebind_leech(fz_stream *s) -{ - fz_leech *state = s->state; - return state->chain; -} - fz_stream * -fz_open_leecher(fz_stream *chain, fz_buffer *buffer) +fz_open_leecher(fz_context *ctx, fz_stream *chain, fz_buffer *buffer) { fz_leech *state = NULL; - fz_context *ctx = chain->ctx; fz_var(state); @@ -68,8 +60,8 @@ fz_open_leecher(fz_stream *chain, fz_buffer *buffer) fz_catch(ctx) { fz_free(ctx, state); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_leech, close_leech, rebind_leech); + return fz_new_stream(ctx, state, next_leech, close_leech); } diff --git a/source/fitz/filter-lzw.c b/source/fitz/filter-lzw.c index 4f8fdd31..257c6c86 100644 --- a/source/fitz/filter-lzw.c +++ b/source/fitz/filter-lzw.c @@ -46,7 +46,7 @@ struct fz_lzwd_s }; static int -next_lzwd(fz_stream *stm, int len) +next_lzwd(fz_context *ctx, fz_stream *stm, int len) { fz_lzwd *lzw = stm->state; lzw_code *table = lzw->table; @@ -73,9 +73,9 @@ next_lzwd(fz_stream *stm, int len) if (lzw->eod) return EOF; - code = fz_read_bits(lzw->chain, code_bits); + code = fz_read_bits(ctx, lzw->chain, code_bits); - if (fz_is_eof_bits(lzw->chain)) + if (fz_is_eof_bits(ctx, lzw->chain)) { lzw->eod = 1; break; @@ -89,7 +89,7 @@ next_lzwd(fz_stream *stm, int len) if (next_code > NUM_CODES && code != LZW_CLEAR) { - fz_warn(stm->ctx, "missing clear code in lzw decode"); + fz_warn(ctx, "missing clear code in lzw decode"); code = LZW_CLEAR; } @@ -109,12 +109,12 @@ next_lzwd(fz_stream *stm, int len) else if (next_code == NUM_CODES) { /* TODO: Ghostscript checks for a following LZW_CLEAR before tolerating */ - fz_warn(stm->ctx, "tolerating a single out of range code in lzw decode"); + fz_warn(ctx, "tolerating a single out of range code in lzw decode"); next_code++; } else if (code > next_code || next_code >= NUM_CODES) { - fz_warn(stm->ctx, "out of range code encountered in lzw decode"); + fz_warn(ctx, "out of range code encountered in lzw decode"); } else { @@ -127,7 +127,7 @@ next_lzwd(fz_stream *stm, int len) else if (code == next_code) table[next_code].value = table[next_code].first_char; else - fz_warn(stm->ctx, "out of range code encountered in lzw decode"); + fz_warn(ctx, "out of range code encountered in lzw decode"); next_code ++; @@ -188,23 +188,15 @@ static void close_lzwd(fz_context *ctx, void *state_) { fz_lzwd *lzw = (fz_lzwd *)state_; - fz_sync_bits(lzw->chain); - fz_drop_stream(lzw->chain); + fz_sync_bits(ctx, lzw->chain); + fz_drop_stream(ctx, lzw->chain); fz_free(ctx, lzw); } -static fz_stream * -rebind_lzwd(fz_stream *s) -{ - fz_lzwd *state = s->state; - return state->chain; -} - /* Default: early_change = 1 */ fz_stream * -fz_open_lzwd(fz_stream *chain, int early_change) +fz_open_lzwd(fz_context *ctx, fz_stream *chain, int early_change) { - fz_context *ctx = chain->ctx; fz_lzwd *lzw = NULL; int i; @@ -243,9 +235,9 @@ fz_open_lzwd(fz_stream *chain, int early_change) fz_catch(ctx) { fz_free(ctx, lzw); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, lzw, next_lzwd, close_lzwd, rebind_lzwd); + return fz_new_stream(ctx, lzw, next_lzwd, close_lzwd); } diff --git a/source/fitz/filter-predict.c b/source/fitz/filter-predict.c index a5c93bfd..3136c651 100644 --- a/source/fitz/filter-predict.c +++ b/source/fitz/filter-predict.c @@ -157,7 +157,7 @@ fz_predict_png(fz_predict *state, unsigned char *out, unsigned char *in, int len } static int -next_predict(fz_stream *stm, int len) +next_predict(fz_context *ctx, fz_stream *stm, int len) { fz_predict *state = stm->state; unsigned char *buf = state->buffer; @@ -175,7 +175,7 @@ next_predict(fz_stream *stm, int len) while (p < ep) { - n = fz_read(state->chain, state->in, state->stride + ispng); + n = fz_read(ctx, state->chain, state->in, state->stride + ispng); if (n == 0) break; @@ -209,25 +209,17 @@ static void close_predict(fz_context *ctx, void *state_) { fz_predict *state = (fz_predict *)state_; - fz_drop_stream(state->chain); + fz_drop_stream(ctx, state->chain); fz_free(ctx, state->in); fz_free(ctx, state->out); fz_free(ctx, state->ref); fz_free(ctx, state); } -static fz_stream * -rebind_predict(fz_stream *s) -{ - fz_predict *state = s->state; - return state->chain; -} - /* Default values: predictor = 1, columns = 1, colors = 1, bpc = 8 */ fz_stream * -fz_open_predict(fz_stream *chain, int predictor, int columns, int colors, int bpc) +fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, int colors, int bpc) { - fz_context *ctx = chain->ctx; fz_predict *state = NULL; fz_var(state); @@ -288,9 +280,9 @@ fz_open_predict(fz_stream *chain, int predictor, int columns, int colors, int bp fz_free(ctx, state->out); } fz_free(ctx, state); - fz_drop_stream(chain); + fz_drop_stream(ctx, chain); fz_rethrow(ctx); } - return fz_new_stream(ctx, state, next_predict, close_predict, rebind_predict); + return fz_new_stream(ctx, state, next_predict, close_predict); } diff --git a/source/fitz/font.c b/source/fitz/font.c index 08379b0f..e35f01fa 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -89,7 +89,7 @@ free_resources(fz_context *ctx, fz_font *font) if (font->t3resources) { - font->t3freeres(font->t3doc, font->t3resources); + font->t3freeres(ctx, font->t3doc, font->t3resources); font->t3resources = NULL; } @@ -1063,9 +1063,9 @@ fz_prepare_t3_glyph(fz_context *ctx, fz_font *font, int gid, int nested_depth) FZ_DEVFLAG_LINEJOIN_UNDEFINED | FZ_DEVFLAG_MITERLIMIT_UNDEFINED | FZ_DEVFLAG_LINEWIDTH_UNDEFINED; - font->t3run(font->t3doc, font->t3resources, contents, dev, &fz_identity, NULL, 0); + font->t3run(ctx, font->t3doc, font->t3resources, contents, dev, &fz_identity, NULL, 0); font->t3flags[gid] = dev->flags; - fz_drop_device(dev); + fz_drop_device(ctx, dev); } static fz_rect * @@ -1087,11 +1087,11 @@ fz_bound_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, dev = fz_new_bbox_device(ctx, bounds); fz_try(ctx) { - fz_run_display_list(list, dev, &ctm, &fz_infinite_rect, NULL); + fz_run_display_list(ctx, list, dev, &ctm, &fz_infinite_rect, NULL); } fz_always(ctx) { - fz_drop_device(dev); + fz_drop_device(ctx, dev); } fz_catch(ctx) { @@ -1117,7 +1117,7 @@ fz_run_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm, f return; fz_concat(&ctm, &font->t3matrix, trm); - fz_run_display_list(list, dev, &ctm, &fz_infinite_rect, NULL); + fz_run_display_list(ctx, list, dev, &ctm, &fz_infinite_rect, NULL); } fz_pixmap * @@ -1168,7 +1168,7 @@ fz_render_t3_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, const fz_matr } fz_always(ctx) { - fz_drop_device(dev); + fz_drop_device(ctx, dev); } fz_catch(ctx) { @@ -1230,7 +1230,7 @@ fz_render_t3_glyph_direct(fz_context *ctx, fz_device *dev, fz_font *font, int gi } fz_concat(&ctm, &font->t3matrix, trm); - font->t3run(font->t3doc, font->t3resources, contents, dev, &ctm, gstate, nested_depth); + font->t3run(ctx, font->t3doc, font->t3resources, contents, dev, &ctm, gstate, nested_depth); } #ifndef NDEBUG diff --git a/source/fitz/function.c b/source/fitz/function.c index 2623ff3d..5dbe9f9c 100644 --- a/source/fitz/function.c +++ b/source/fitz/function.c @@ -45,7 +45,7 @@ fz_drop_function(fz_context *ctx, fz_function *func) } unsigned int -fz_function_size(fz_function *func) +fz_function_size(fz_context *ctx, fz_function *func) { return (func ? func->size : 0); } diff --git a/source/fitz/image.c b/source/fitz/image.c index e7096ab4..4c82e2c7 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -31,7 +31,7 @@ struct fz_image_key_s { }; static int -fz_make_hash_image_key(fz_store_hash *hash, void *key_) +fz_make_hash_image_key(fz_context *ctx, fz_store_hash *hash, void *key_) { fz_image_key *key = (fz_image_key *)key_; @@ -71,7 +71,7 @@ fz_drop_image_key(fz_context *ctx, void *key_) } static int -fz_cmp_image_key(void *k0_, void *k1_) +fz_cmp_image_key(fz_context *ctx, void *k0_, void *k1_) { fz_image_key *k0 = (fz_image_key *)k0_; fz_image_key *k1 = (fz_image_key *)k1_; @@ -81,7 +81,7 @@ fz_cmp_image_key(void *k0_, void *k1_) #ifndef NDEBUG static void -fz_debug_image(FILE *out, void *key_) +fz_debug_image(fz_context *ctx, FILE *out, void *key_) { fz_image_key *key = (fz_image_key *)key_; @@ -169,7 +169,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in samples = fz_malloc_array(ctx, h, stride); - len = fz_read(stm, samples, h * stride); + len = fz_read(ctx, stm, samples, h * stride); /* Pad truncated images */ if (len < stride * h) @@ -188,7 +188,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in p[i] = ~p[i]; } - fz_unpack_tile(tile, samples, image->n, image->bpc, stride, indexed); + fz_unpack_tile(ctx, tile, samples, image->n, image->bpc, stride, indexed); fz_free(ctx, samples); samples = NULL; @@ -200,14 +200,14 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in if (indexed) { fz_pixmap *conv; - fz_decode_indexed_tile(tile, image->decode, (1 << image->bpc) - 1); + fz_decode_indexed_tile(ctx, tile, image->decode, (1 << image->bpc) - 1); conv = fz_expand_indexed_pixmap(ctx, tile); fz_drop_pixmap(ctx, tile); tile = conv; } else { - fz_decode_tile(tile, image->decode); + fz_decode_tile(ctx, tile, image->decode); } /* pre-blended matte color */ @@ -216,7 +216,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in } fz_always(ctx) { - fz_drop_stream(stm); + fz_drop_stream(ctx, stm); } fz_catch(ctx) { @@ -336,7 +336,7 @@ fz_image_get_pixmap(fz_context *ctx, fz_image *image, int w, int h) native_l2factor = l2factor; stm = fz_open_image_decomp_stream_from_buffer(ctx, image->buffer, &native_l2factor); - indexed = fz_colorspace_is_indexed(image->colorspace); + indexed = fz_colorspace_is_indexed(ctx, image->colorspace); tile = fz_decomp_image_from_stream(ctx, stm, image, indexed, l2factor, native_l2factor); /* CMYK JPEGs in XPS documents have to be inverted */ @@ -403,12 +403,11 @@ fz_new_image_from_pixmap(fz_context *ctx, fz_pixmap *pixmap, fz_image *mask) image->get_pixmap = fz_image_get_pixmap; image->xres = pixmap->xres; image->yres = pixmap->yres; - image->tile = pixmap; + image->tile = fz_keep_pixmap(ctx, pixmap); image->mask = mask; } fz_catch(ctx) { - fz_drop_pixmap(ctx, pixmap); fz_drop_image(ctx, mask); fz_rethrow(ctx); } @@ -445,7 +444,7 @@ fz_new_image(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, memcpy(image->decode, decode, sizeof(float)*image->n*2); else { - float maxval = fz_colorspace_is_indexed(colorspace) ? (1 << bpc) - 1 : 1; + float maxval = fz_colorspace_is_indexed(ctx, colorspace) ? (1 << bpc) - 1 : 1; int i; for (i = 0; i < image->n; i++) { diff --git a/source/fitz/list-device.c b/source/fitz/list-device.c index c6e8011f..f56bc879 100644 --- a/source/fitz/list-device.c +++ b/source/fitz/list-device.c @@ -229,9 +229,8 @@ fz_free_display_node(fz_context *ctx, fz_display_node *node) } static void -fz_list_begin_page(fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm) +fz_list_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm) { - fz_context *ctx = dev->ctx; fz_display_node *node = fz_new_display_node(ctx, FZ_CMD_BEGIN_PAGE, ctm, NULL, NULL, 0); node->rect = *mediabox; fz_transform_rect(&node->rect, ctm); @@ -239,24 +238,22 @@ fz_list_begin_page(fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm } static void -fz_list_end_page(fz_device *dev) +fz_list_end_page(fz_context *ctx, fz_device *dev) { - fz_context *ctx = dev->ctx; fz_display_node *node = fz_new_display_node(ctx, FZ_CMD_END_PAGE, &fz_identity, NULL, NULL, 0); fz_append_display_node(dev->user, node); } static void -fz_list_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, +fz_list_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_FILL_PATH, ctm, colorspace, color, alpha); fz_try(ctx) { - fz_bound_path(dev->ctx, path, NULL, ctm, &node->rect); - node->item.path = fz_keep_path(dev->ctx, path); + fz_bound_path(ctx, path, NULL, ctm, &node->rect); + node->item.path = fz_keep_path(ctx, path); node->flag = even_odd; } fz_catch(ctx) @@ -268,17 +265,16 @@ fz_list_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix * } static void -fz_list_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, +fz_list_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_STROKE_PATH, ctm, colorspace, color, alpha); fz_try(ctx) { - fz_bound_path(dev->ctx, path, stroke, ctm, &node->rect); - node->item.path = fz_keep_path(dev->ctx, path); - node->stroke = fz_keep_stroke_state(dev->ctx, stroke); + fz_bound_path(ctx, path, stroke, ctm, &node->rect); + node->item.path = fz_keep_path(ctx, path); + node->stroke = fz_keep_stroke_state(ctx, stroke); } fz_catch(ctx) { @@ -289,17 +285,16 @@ fz_list_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, } static void -fz_list_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +fz_list_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_CLIP_PATH, ctm, NULL, NULL, 0); fz_try(ctx) { - fz_bound_path(dev->ctx, path, NULL, ctm, &node->rect); + fz_bound_path(ctx, path, NULL, ctm, &node->rect); if (rect) fz_intersect_rect(&node->rect, rect); - node->item.path = fz_keep_path(dev->ctx, path); + node->item.path = fz_keep_path(ctx, path); node->flag = even_odd; } fz_catch(ctx) @@ -311,18 +306,17 @@ fz_list_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_o } static void -fz_list_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_list_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_CLIP_STROKE_PATH, ctm, NULL, NULL, 0); fz_try(ctx) { - fz_bound_path(dev->ctx, path, stroke, ctm, &node->rect); + fz_bound_path(ctx, path, stroke, ctm, &node->rect); if (rect) fz_intersect_rect(&node->rect, rect); - node->item.path = fz_keep_path(dev->ctx, path); - node->stroke = fz_keep_stroke_state(dev->ctx, stroke); + node->item.path = fz_keep_path(ctx, path); + node->stroke = fz_keep_stroke_state(ctx, stroke); } fz_catch(ctx) { @@ -333,16 +327,15 @@ fz_list_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_ } static void -fz_list_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +fz_list_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_FILL_TEXT, ctm, colorspace, color, alpha); fz_try(ctx) { - fz_bound_text(dev->ctx, text, NULL, ctm, &node->rect); - node->item.text = fz_keep_text(dev->ctx, text); + fz_bound_text(ctx, text, NULL, ctm, &node->rect); + node->item.text = fz_keep_text(ctx, text); } fz_catch(ctx) { @@ -353,18 +346,17 @@ fz_list_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, } static void -fz_list_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_list_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_STROKE_TEXT, ctm, colorspace, color, alpha); node->item.text = NULL; fz_try(ctx) { - fz_bound_text(dev->ctx, text, stroke, ctm, &node->rect); - node->item.text = fz_keep_text(dev->ctx, text); - node->stroke = fz_keep_stroke_state(dev->ctx, stroke); + fz_bound_text(ctx, text, stroke, ctm, &node->rect); + node->item.text = fz_keep_text(ctx, text); + node->stroke = fz_keep_stroke_state(ctx, stroke); } fz_catch(ctx) { @@ -375,15 +367,14 @@ fz_list_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, cons } static void -fz_list_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) +fz_list_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_CLIP_TEXT, ctm, NULL, NULL, 0); fz_try(ctx) { - fz_bound_text(dev->ctx, text, NULL, ctm, &node->rect); - node->item.text = fz_keep_text(dev->ctx, text); + fz_bound_text(ctx, text, NULL, ctm, &node->rect); + node->item.text = fz_keep_text(ctx, text); node->flag = accumulate; /* when accumulating, be conservative about culling */ if (accumulate) @@ -398,16 +389,15 @@ fz_list_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accum } static void -fz_list_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_list_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_CLIP_STROKE_TEXT, ctm, NULL, NULL, 0); fz_try(ctx) { - fz_bound_text(dev->ctx, text, stroke, ctm, &node->rect); - node->item.text = fz_keep_text(dev->ctx, text); - node->stroke = fz_keep_stroke_state(dev->ctx, stroke); + fz_bound_text(ctx, text, stroke, ctm, &node->rect); + node->item.text = fz_keep_text(ctx, text); + node->stroke = fz_keep_stroke_state(ctx, stroke); } fz_catch(ctx) { @@ -418,15 +408,14 @@ fz_list_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, } static void -fz_list_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_list_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_IGNORE_TEXT, ctm, NULL, NULL, 0); fz_try(ctx) { - fz_bound_text(dev->ctx, text, NULL, ctm, &node->rect); - node->item.text = fz_keep_text(dev->ctx, text); + fz_bound_text(ctx, text, NULL, ctm, &node->rect); + node->item.text = fz_keep_text(ctx, text); } fz_catch(ctx) { @@ -437,18 +426,17 @@ fz_list_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) } static void -fz_list_pop_clip(fz_device *dev) +fz_list_pop_clip(fz_context *ctx, fz_device *dev) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_POP_CLIP, &fz_identity, NULL, NULL, 0); + node = fz_new_display_node(ctx, FZ_CMD_POP_CLIP, &fz_identity, NULL, NULL, 0); fz_append_display_node(dev->user, node); } static void -fz_list_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +fz_list_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { fz_display_node *node; - fz_context *ctx = dev->ctx; node = fz_new_display_node(ctx, FZ_CMD_FILL_SHADE, ctm, NULL, NULL, alpha); fz_bound_shade(ctx, shade, ctm, &node->rect); node->item.shade = fz_keep_shade(ctx, shade); @@ -456,64 +444,64 @@ fz_list_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float } static void -fz_list_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +fz_list_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_IMAGE, ctm, NULL, NULL, alpha); + node = fz_new_display_node(ctx, FZ_CMD_FILL_IMAGE, ctm, NULL, NULL, alpha); node->rect = fz_unit_rect; fz_transform_rect(&node->rect, ctm); - node->item.image = fz_keep_image(dev->ctx, image); + node->item.image = fz_keep_image(ctx, image); fz_append_display_node(dev->user, node); } static void -fz_list_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, +fz_list_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_IMAGE_MASK, ctm, colorspace, color, alpha); + node = fz_new_display_node(ctx, FZ_CMD_FILL_IMAGE_MASK, ctm, colorspace, color, alpha); node->rect = fz_unit_rect; fz_transform_rect(&node->rect, ctm); - node->item.image = fz_keep_image(dev->ctx, image); + node->item.image = fz_keep_image(ctx, image); fz_append_display_node(dev->user, node); } static void -fz_list_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) +fz_list_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_CLIP_IMAGE_MASK, ctm, NULL, NULL, 0); + node = fz_new_display_node(ctx, FZ_CMD_CLIP_IMAGE_MASK, ctm, NULL, NULL, 0); node->rect = fz_unit_rect; fz_transform_rect(&node->rect, ctm); if (rect) fz_intersect_rect(&node->rect, rect); - node->item.image = fz_keep_image(dev->ctx, image); + node->item.image = fz_keep_image(ctx, image); fz_append_display_node(dev->user, node); } static void -fz_list_begin_mask(fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *color) +fz_list_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *rect, int luminosity, fz_colorspace *colorspace, float *color) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_BEGIN_MASK, &fz_identity, colorspace, color, 0); + node = fz_new_display_node(ctx, FZ_CMD_BEGIN_MASK, &fz_identity, colorspace, color, 0); node->rect = *rect; node->flag = luminosity; fz_append_display_node(dev->user, node); } static void -fz_list_end_mask(fz_device *dev) +fz_list_end_mask(fz_context *ctx, fz_device *dev) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_END_MASK, &fz_identity, NULL, NULL, 0); + node = fz_new_display_node(ctx, FZ_CMD_END_MASK, &fz_identity, NULL, NULL, 0); fz_append_display_node(dev->user, node); } static void -fz_list_begin_group(fz_device *dev, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha) +fz_list_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *rect, int isolated, int knockout, int blendmode, float alpha) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_BEGIN_GROUP, &fz_identity, NULL, NULL, alpha); + node = fz_new_display_node(ctx, FZ_CMD_BEGIN_GROUP, &fz_identity, NULL, NULL, alpha); node->rect = *rect; node->item.blendmode = blendmode; node->flag |= isolated ? ISOLATED : 0; @@ -522,19 +510,19 @@ fz_list_begin_group(fz_device *dev, const fz_rect *rect, int isolated, int knock } static void -fz_list_end_group(fz_device *dev) +fz_list_end_group(fz_context *ctx, fz_device *dev) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_END_GROUP, &fz_identity, NULL, NULL, 0); + node = fz_new_display_node(ctx, FZ_CMD_END_GROUP, &fz_identity, NULL, NULL, 0); fz_append_display_node(dev->user, node); } static int -fz_list_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) +fz_list_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { /* We ignore id here, as we will pass on our own id */ fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_BEGIN_TILE, ctm, NULL, NULL, 0); + node = fz_new_display_node(ctx, FZ_CMD_BEGIN_TILE, ctm, NULL, NULL, 0); node->rect = *area; node->color[0] = xstep; node->color[1] = ystep; @@ -547,10 +535,10 @@ fz_list_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, flo } static void -fz_list_end_tile(fz_device *dev) +fz_list_end_tile(fz_context *ctx, fz_device *dev) { fz_display_node *node; - node = fz_new_display_node(dev->ctx, FZ_CMD_END_TILE, &fz_identity, NULL, NULL, 0); + node = fz_new_display_node(ctx, FZ_CMD_END_TILE, &fz_identity, NULL, NULL, 0); fz_append_display_node(dev->user, node); } @@ -665,14 +653,13 @@ skip_to_end_tile(fz_display_node *node, int *progress) } void -fz_run_display_list(fz_display_list *list, fz_device *dev, const fz_matrix *top_ctm, const fz_rect *scissor, fz_cookie *cookie) +fz_run_display_list(fz_context *ctx, fz_display_list *list, fz_device *dev, const fz_matrix *top_ctm, const fz_rect *scissor, fz_cookie *cookie) { fz_display_node *node; fz_matrix ctm; int clipped = 0; int tiled = 0; int progress = 0; - fz_context *ctx = dev->ctx; if (!scissor) scissor = &fz_infinite_rect; @@ -753,75 +740,75 @@ visible: switch (node->cmd) { case FZ_CMD_BEGIN_PAGE: - fz_begin_page(dev, &node_rect, &ctm); + fz_begin_page(ctx, dev, &node_rect, &ctm); break; case FZ_CMD_END_PAGE: - fz_end_page(dev); + fz_end_page(ctx, dev); break; case FZ_CMD_FILL_PATH: - fz_fill_path(dev, node->item.path, node->flag, &ctm, + fz_fill_path(ctx, dev, node->item.path, node->flag, &ctm, node->colorspace, node->color, node->alpha); break; case FZ_CMD_STROKE_PATH: - fz_stroke_path(dev, node->item.path, node->stroke, &ctm, + fz_stroke_path(ctx, dev, node->item.path, node->stroke, &ctm, node->colorspace, node->color, node->alpha); break; case FZ_CMD_CLIP_PATH: - fz_clip_path(dev, node->item.path, &node_rect, node->flag, &ctm); + fz_clip_path(ctx, dev, node->item.path, &node_rect, node->flag, &ctm); break; case FZ_CMD_CLIP_STROKE_PATH: - fz_clip_stroke_path(dev, node->item.path, &node_rect, node->stroke, &ctm); + fz_clip_stroke_path(ctx, dev, node->item.path, &node_rect, node->stroke, &ctm); break; case FZ_CMD_FILL_TEXT: - fz_fill_text(dev, node->item.text, &ctm, + fz_fill_text(ctx, dev, node->item.text, &ctm, node->colorspace, node->color, node->alpha); break; case FZ_CMD_STROKE_TEXT: - fz_stroke_text(dev, node->item.text, node->stroke, &ctm, + fz_stroke_text(ctx, dev, node->item.text, node->stroke, &ctm, node->colorspace, node->color, node->alpha); break; case FZ_CMD_CLIP_TEXT: - fz_clip_text(dev, node->item.text, &ctm, node->flag); + fz_clip_text(ctx, dev, node->item.text, &ctm, node->flag); break; case FZ_CMD_CLIP_STROKE_TEXT: - fz_clip_stroke_text(dev, node->item.text, node->stroke, &ctm); + fz_clip_stroke_text(ctx, dev, node->item.text, node->stroke, &ctm); break; case FZ_CMD_IGNORE_TEXT: - fz_ignore_text(dev, node->item.text, &ctm); + fz_ignore_text(ctx, dev, node->item.text, &ctm); break; case FZ_CMD_FILL_SHADE: if ((dev->hints & FZ_IGNORE_SHADE) == 0) - fz_fill_shade(dev, node->item.shade, &ctm, node->alpha); + fz_fill_shade(ctx, dev, node->item.shade, &ctm, node->alpha); break; case FZ_CMD_FILL_IMAGE: if ((dev->hints & FZ_IGNORE_IMAGE) == 0) - fz_fill_image(dev, node->item.image, &ctm, node->alpha); + fz_fill_image(ctx, dev, node->item.image, &ctm, node->alpha); break; case FZ_CMD_FILL_IMAGE_MASK: if ((dev->hints & FZ_IGNORE_IMAGE) == 0) - fz_fill_image_mask(dev, node->item.image, &ctm, + fz_fill_image_mask(ctx, dev, node->item.image, &ctm, node->colorspace, node->color, node->alpha); break; case FZ_CMD_CLIP_IMAGE_MASK: if ((dev->hints & FZ_IGNORE_IMAGE) == 0) - fz_clip_image_mask(dev, node->item.image, &node_rect, &ctm); + fz_clip_image_mask(ctx, dev, node->item.image, &node_rect, &ctm); break; case FZ_CMD_POP_CLIP: - fz_pop_clip(dev); + fz_pop_clip(ctx, dev); break; case FZ_CMD_BEGIN_MASK: - fz_begin_mask(dev, &node_rect, node->flag, node->colorspace, node->color); + fz_begin_mask(ctx, dev, &node_rect, node->flag, node->colorspace, node->color); break; case FZ_CMD_END_MASK: - fz_end_mask(dev); + fz_end_mask(ctx, dev); break; case FZ_CMD_BEGIN_GROUP: - fz_begin_group(dev, &node_rect, + fz_begin_group(ctx, dev, &node_rect, (node->flag & ISOLATED) != 0, (node->flag & KNOCKOUT) != 0, node->item.blendmode, node->alpha); break; case FZ_CMD_END_GROUP: - fz_end_group(dev); + fz_end_group(ctx, dev); break; case FZ_CMD_BEGIN_TILE: { @@ -832,14 +819,14 @@ visible: tile_rect.y0 = node->color[3]; tile_rect.x1 = node->color[4]; tile_rect.y1 = node->color[5]; - cached = fz_begin_tile_id(dev, &node->rect, &tile_rect, node->color[0], node->color[1], &ctm, node->flag); + cached = fz_begin_tile_id(ctx, dev, &node->rect, &tile_rect, node->color[0], node->color[1], &ctm, node->flag); if (cached) node = skip_to_end_tile(node, &progress); break; } case FZ_CMD_END_TILE: tiled--; - fz_end_tile(dev); + fz_end_tile(ctx, dev); break; } } diff --git a/source/fitz/load-png.c b/source/fitz/load-png.c index d897b5be..1cca89c0 100644 --- a/source/fitz/load-png.c +++ b/source/fitz/load-png.c @@ -4,7 +4,6 @@ struct info { - fz_context *ctx; unsigned int width, height, depth, n; int interlace, indexed; unsigned int size; @@ -162,7 +161,7 @@ static const unsigned int adam7_iy[7] = { 0, 0, 4, 0, 2, 0, 1 }; static const unsigned int adam7_dy[7] = { 8, 8, 8, 4, 4, 2, 2 }; static void -png_deinterlace_passes(struct info *info, unsigned int *w, unsigned int *h, unsigned int *ofs) +png_deinterlace_passes(fz_context *ctx, struct info *info, unsigned int *w, unsigned int *h, unsigned int *ofs) { int p, bpp = info->depth * info->n; ofs[0] = 0; @@ -180,7 +179,7 @@ png_deinterlace_passes(struct info *info, unsigned int *w, unsigned int *h, unsi } static void -png_deinterlace(struct info *info, unsigned int *passw, unsigned int *passh, unsigned int *passofs) +png_deinterlace(fz_context *ctx, struct info *info, unsigned int *passw, unsigned int *passh, unsigned int *passofs) { unsigned int n = info->n; unsigned int depth = info->depth; @@ -188,7 +187,7 @@ png_deinterlace(struct info *info, unsigned int *passw, unsigned int *passh, uns unsigned char *output; unsigned int p, x, y, k; - output = fz_malloc_array(info->ctx, info->height, stride); + output = fz_malloc_array(ctx, info->height, stride); for (p = 0; p < 7; p++) { @@ -214,17 +213,17 @@ png_deinterlace(struct info *info, unsigned int *passw, unsigned int *passh, uns } } - fz_free(info->ctx, info->samples); + fz_free(ctx, info->samples); info->samples = output; } static void -png_read_ihdr(struct info *info, unsigned char *p, unsigned int size) +png_read_ihdr(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size) { int color, compression, filter; if (size != 13) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "IHDR chunk is the wrong size"); + fz_throw(ctx, FZ_ERROR_GENERIC, "IHDR chunk is the wrong size"); info->width = getuint(p + 0); info->height = getuint(p + 4); @@ -236,21 +235,21 @@ png_read_ihdr(struct info *info, unsigned char *p, unsigned int size) info->interlace = p[12]; if (info->width <= 0) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "image width must be > 0"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image width must be > 0"); if (info->height <= 0) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "image height must be > 0"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image height must be > 0"); if (info->depth != 1 && info->depth != 2 && info->depth != 4 && info->depth != 8 && info->depth != 16) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "image bit depth must be one of 1, 2, 4, 8, 16"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image bit depth must be one of 1, 2, 4, 8, 16"); if (color == 2 && info->depth < 8) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for truecolor"); + fz_throw(ctx, FZ_ERROR_GENERIC, "illegal bit depth for truecolor"); if (color == 3 && info->depth > 8) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for indexed"); + fz_throw(ctx, FZ_ERROR_GENERIC, "illegal bit depth for indexed"); if (color == 4 && info->depth < 8) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for grayscale with alpha"); + fz_throw(ctx, FZ_ERROR_GENERIC, "illegal bit depth for grayscale with alpha"); if (color == 6 && info->depth < 8) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for truecolor with alpha"); + fz_throw(ctx, FZ_ERROR_GENERIC, "illegal bit depth for truecolor with alpha"); info->indexed = 0; if (color == 0) /* gray */ @@ -267,25 +266,25 @@ png_read_ihdr(struct info *info, unsigned char *p, unsigned int size) info->n = 1; } else - fz_throw(info->ctx, FZ_ERROR_GENERIC, "unknown color type"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown color type"); if (compression != 0) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "unknown compression method"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown compression method"); if (filter != 0) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "unknown filter method"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown filter method"); if (info->interlace != 0 && info->interlace != 1) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "interlace method not supported"); + fz_throw(ctx, FZ_ERROR_GENERIC, "interlace method not supported"); } static void -png_read_plte(struct info *info, unsigned char *p, unsigned int size) +png_read_plte(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size) { int n = size / 3; int i; if (n > 256) { - fz_warn(info->ctx, "too many samples in palette"); + fz_warn(ctx, "too many samples in palette"); n = 256; } @@ -306,7 +305,7 @@ png_read_plte(struct info *info, unsigned char *p, unsigned int size) } static void -png_read_trns(struct info *info, unsigned char *p, unsigned int size) +png_read_trns(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size) { unsigned int i; @@ -316,7 +315,7 @@ png_read_trns(struct info *info, unsigned char *p, unsigned int size) { if (size > 256) { - fz_warn(info->ctx, "too many samples in transparency table"); + fz_warn(ctx, "too many samples in transparency table"); size = 256; } for (i = 0; i < size; i++) @@ -328,14 +327,14 @@ png_read_trns(struct info *info, unsigned char *p, unsigned int size) else { if (size != info->n * 2) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "tRNS chunk is the wrong size"); + fz_throw(ctx, FZ_ERROR_GENERIC, "tRNS chunk is the wrong size"); for (i = 0; i < info->n; i++) info->trns[i] = (p[i * 2] << 8 | p[i * 2 + 1]) & ((1 << info->depth) - 1); } } static void -png_read_idat(struct info *info, unsigned char *p, unsigned int size, z_stream *stm) +png_read_idat(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size, z_stream *stm) { int code; @@ -344,20 +343,20 @@ png_read_idat(struct info *info, unsigned char *p, unsigned int size, z_stream * code = inflate(stm, Z_SYNC_FLUSH); if (code != Z_OK && code != Z_STREAM_END) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "zlib error: %s", stm->msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: %s", stm->msg); if (stm->avail_in != 0) { if (stm->avail_out == 0) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "ran out of output before input"); - fz_throw(info->ctx, FZ_ERROR_GENERIC, "inflate did not consume buffer (%d remaining)", stm->avail_in); + fz_throw(ctx, FZ_ERROR_GENERIC, "ran out of output before input"); + fz_throw(ctx, FZ_ERROR_GENERIC, "inflate did not consume buffer (%d remaining)", stm->avail_in); } } static void -png_read_phys(struct info *info, unsigned char *p, unsigned int size) +png_read_phys(fz_context *ctx, struct info *info, unsigned char *p, unsigned int size) { if (size != 9) - fz_throw(info->ctx, FZ_ERROR_GENERIC, "pHYs chunk is the wrong size"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pHYs chunk is the wrong size"); if (p[8] == 1) { info->xres = (getuint(p) * 254 + 5000) / 10000; @@ -373,7 +372,6 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in z_stream stm; memset(info, 0, sizeof (struct info)); - info->ctx = ctx; memset(info->palette, 255, sizeof(info->palette)); info->xres = 96; info->yres = 96; @@ -393,7 +391,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in png image"); if (!memcmp(p + 4, "IHDR", 4)) - png_read_ihdr(info, p + 8, size); + png_read_ihdr(ctx, info, p + 8, size); else fz_throw(ctx, FZ_ERROR_GENERIC, "png file must start with IHDR chunk"); @@ -408,7 +406,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in } else { - png_deinterlace_passes(info, passw, passh, passofs); + png_deinterlace_passes(ctx, info, passw, passh, passofs); info->size = passofs[7]; } @@ -439,13 +437,13 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in png image"); if (!memcmp(p + 4, "PLTE", 4)) - png_read_plte(info, p + 8, size); + png_read_plte(ctx, info, p + 8, size); if (!memcmp(p + 4, "tRNS", 4)) - png_read_trns(info, p + 8, size); + png_read_trns(ctx, info, p + 8, size); if (!memcmp(p + 4, "pHYs", 4)) - png_read_phys(info, p + 8, size); + png_read_phys(ctx, info, p + 8, size); if (!memcmp(p + 4, "IDAT", 4)) - png_read_idat(info, p + 8, size, &stm); + png_read_idat(ctx, info, p + 8, size, &stm); if (!memcmp(p + 4, "IEND", 4)) break; @@ -480,7 +478,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in if (!info->interlace) png_predict(info->samples, info->width, info->height, info->n, info->depth); else - png_deinterlace(info, passw, passh, passofs); + png_deinterlace(ctx, info, passw, passh, passofs); } fz_catch(ctx) { @@ -513,7 +511,7 @@ png_expand_palette(fz_context *ctx, struct info *info, fz_pixmap *src) } } - fz_drop_pixmap(info->ctx, src); + fz_drop_pixmap(ctx, src); return dst; } @@ -564,14 +562,14 @@ fz_load_png(fz_context *ctx, unsigned char *p, int total) } fz_catch(ctx) { - fz_free(png.ctx, png.samples); + fz_free(ctx, png.samples); fz_rethrow_message(ctx, "out of memory loading png"); } image->xres = png.xres; image->yres = png.yres; - fz_unpack_tile(image, png.samples, png.n, png.depth, stride, png.indexed); + fz_unpack_tile(ctx, image, png.samples, png.n, png.depth, stride, png.indexed); if (png.indexed) image = png_expand_palette(ctx, &png, image); @@ -579,9 +577,9 @@ fz_load_png(fz_context *ctx, unsigned char *p, int total) png_mask_transparency(&png, image); if (png.transparency || png.n == 2 || png.n == 4) - fz_premultiply_pixmap(png.ctx, image); + fz_premultiply_pixmap(ctx, image); - fz_free(png.ctx, png.samples); + fz_free(ctx, png.samples); return image; } @@ -602,5 +600,5 @@ fz_load_png_info(fz_context *ctx, unsigned char *p, int total, int *wp, int *hp, *hp = png.height; *xresp = png.xres; *yresp = png.xres; - fz_free(png.ctx, png.samples); + fz_free(ctx, png.samples); } diff --git a/source/fitz/load-tiff.c b/source/fitz/load-tiff.c index 77fb816d..c783784a 100644 --- a/source/fitz/load-tiff.c +++ b/source/fitz/load-tiff.c @@ -11,8 +11,6 @@ struct tiff { - fz_context *ctx; - /* "file" */ unsigned char *bp, *rp, *ep; @@ -142,63 +140,63 @@ static const unsigned char bitrev[256] = }; static void -fz_decode_tiff_uncompressed(struct tiff *tiff, fz_stream *stm, unsigned char *wp, int wlen) +fz_decode_tiff_uncompressed(fz_context *ctx, struct tiff *tiff, fz_stream *stm, unsigned char *wp, int wlen) { - fz_read(stm, wp, wlen); - fz_drop_stream(stm); + fz_read(ctx, stm, wp, wlen); + fz_drop_stream(ctx, stm); } static void -fz_decode_tiff_packbits(struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) +fz_decode_tiff_packbits(fz_context *ctx, struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) { - fz_stream *stm = fz_open_rld(chain); - fz_read(stm, wp, wlen); - fz_drop_stream(stm); + fz_stream *stm = fz_open_rld(ctx, chain); + fz_read(ctx, stm, wp, wlen); + fz_drop_stream(ctx, stm); } static void -fz_decode_tiff_lzw(struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) +fz_decode_tiff_lzw(fz_context *ctx, struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) { - fz_stream *stm = fz_open_lzwd(chain, 1); - fz_read(stm, wp, wlen); - fz_drop_stream(stm); + fz_stream *stm = fz_open_lzwd(ctx, chain, 1); + fz_read(ctx, stm, wp, wlen); + fz_drop_stream(ctx, stm); } static void -fz_decode_tiff_flate(struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) +fz_decode_tiff_flate(fz_context *ctx, struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) { - fz_stream *stm = fz_open_flated(chain, 15); - fz_read(stm, wp, wlen); - fz_drop_stream(stm); + fz_stream *stm = fz_open_flated(ctx, chain, 15); + fz_read(ctx, stm, wp, wlen); + fz_drop_stream(ctx, stm); } static void -fz_decode_tiff_fax(struct tiff *tiff, int comp, fz_stream *chain, unsigned char *wp, int wlen) +fz_decode_tiff_fax(fz_context *ctx, struct tiff *tiff, int comp, fz_stream *chain, unsigned char *wp, int wlen) { fz_stream *stm; int black_is_1 = tiff->photometric == 0; int k = comp == 4 ? -1 : 0; int encoded_byte_align = comp == 2; - stm = fz_open_faxd(chain, + stm = fz_open_faxd(ctx, chain, k, 0, encoded_byte_align, tiff->imagewidth, tiff->imagelength, 0, black_is_1); - fz_read(stm, wp, wlen); - fz_drop_stream(stm); + fz_read(ctx, stm, wp, wlen); + fz_drop_stream(ctx, stm); } static void -fz_decode_tiff_jpeg(struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) +fz_decode_tiff_jpeg(fz_context *ctx, struct tiff *tiff, fz_stream *chain, unsigned char *wp, int wlen) { fz_stream *stm; fz_stream *jpegtables = NULL; int color_transform = -1; /* unset */ if (tiff->jpegtables && (int)tiff->jpegtableslen > 0) - jpegtables = fz_open_memory(tiff->ctx, tiff->jpegtables, (int)tiff->jpegtableslen); + jpegtables = fz_open_memory(ctx, tiff->jpegtables, (int)tiff->jpegtableslen); if (tiff->photometric == 2 /* RGB */ || tiff->photometric == 3 /* RGBPal */) color_transform = 0; - stm = fz_open_dctd(chain, color_transform, 0, jpegtables); - fz_read(stm, wp, wlen); - fz_drop_stream(stm); + stm = fz_open_dctd(ctx, chain, color_transform, 0, jpegtables); + fz_read(ctx, stm, wp, wlen); + fz_drop_stream(ctx, stm); } static inline int getcomp(unsigned char *line, int x, int bpc) @@ -276,7 +274,7 @@ fz_invert_tiff(unsigned char *line, int width, int comps, int bits, int alpha) } static void -fz_expand_tiff_colormap(struct tiff *tiff) +fz_expand_tiff_colormap(fz_context *ctx, struct tiff *tiff) { int maxval = 1 << tiff->bitspersample; unsigned char *samples; @@ -289,17 +287,17 @@ fz_expand_tiff_colormap(struct tiff *tiff) /* image can be with or without extrasamples: comps is 1 or 2 */ if (tiff->samplesperpixel != 1 && tiff->samplesperpixel != 2) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid number of samples for RGBPal"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid number of samples for RGBPal"); if (tiff->bitspersample != 1 && tiff->bitspersample != 4 && tiff->bitspersample != 8) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid number of bits for RGBPal"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid number of bits for RGBPal"); if (tiff->colormaplen < (unsigned)maxval * 3) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "insufficient colormap data"); + fz_throw(ctx, FZ_ERROR_GENERIC, "insufficient colormap data"); stride = tiff->imagewidth * (tiff->samplesperpixel + 2); - samples = fz_malloc(tiff->ctx, stride * tiff->imagelength); + samples = fz_malloc(ctx, stride * tiff->imagelength); for (y = 0; y < tiff->imagelength; y++) { @@ -330,12 +328,12 @@ fz_expand_tiff_colormap(struct tiff *tiff) tiff->samplesperpixel += 2; tiff->bitspersample = 8; tiff->stride = stride; - fz_free(tiff->ctx, tiff->samples); + fz_free(ctx, tiff->samples); tiff->samples = samples; } static void -fz_decode_tiff_strips(struct tiff *tiff) +fz_decode_tiff_strips(fz_context *ctx, struct tiff *tiff) { fz_stream *stm; @@ -354,40 +352,40 @@ fz_decode_tiff_strips(struct tiff *tiff) unsigned i; if (!tiff->rowsperstrip || !tiff->stripoffsets || !tiff->stripbytecounts) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "no image data in tiff; maybe it is tiled"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no image data in tiff; maybe it is tiled"); if (tiff->stripoffsetslen < (tiff->imagelength - 1) / tiff->rowsperstrip + 1 || tiff->stripbytecountslen < (tiff->imagelength - 1) / tiff->rowsperstrip + 1) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "insufficient strip offset data"); + fz_throw(ctx, FZ_ERROR_GENERIC, "insufficient strip offset data"); if (tiff->planar != 1) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "image data is not in chunky format"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image data is not in chunky format"); tiff->stride = (tiff->imagewidth * tiff->samplesperpixel * tiff->bitspersample + 7) / 8; switch (tiff->photometric) { case 0: /* WhiteIsZero -- inverted */ - tiff->colorspace = fz_device_gray(tiff->ctx); + tiff->colorspace = fz_device_gray(ctx); break; case 1: /* BlackIsZero */ - tiff->colorspace = fz_device_gray(tiff->ctx); + tiff->colorspace = fz_device_gray(ctx); break; case 2: /* RGB */ - tiff->colorspace = fz_device_rgb(tiff->ctx); + tiff->colorspace = fz_device_rgb(ctx); break; case 3: /* RGBPal */ - tiff->colorspace = fz_device_rgb(tiff->ctx); + tiff->colorspace = fz_device_rgb(ctx); break; case 5: /* CMYK */ - tiff->colorspace = fz_device_cmyk(tiff->ctx); + tiff->colorspace = fz_device_cmyk(ctx); break; case 6: /* YCbCr */ /* it's probably a jpeg ... we let jpeg convert to rgb */ - tiff->colorspace = fz_device_rgb(tiff->ctx); + tiff->colorspace = fz_device_rgb(ctx); break; default: - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "unknown photometric: %d", tiff->photometric); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown photometric: %d", tiff->photometric); } switch (tiff->resolutionunit) @@ -412,7 +410,7 @@ fz_decode_tiff_strips(struct tiff *tiff) tiff->yresolution = 96; } - tiff->samples = fz_malloc_array(tiff->ctx, tiff->imagelength, tiff->stride); + tiff->samples = fz_malloc_array(ctx, tiff->imagelength, tiff->stride); memset(tiff->samples, 0x55, tiff->imagelength * tiff->stride); wp = tiff->samples; @@ -428,7 +426,7 @@ fz_decode_tiff_strips(struct tiff *tiff) wlen = tiff->samples + (unsigned int)(tiff->stride * tiff->imagelength) - wp; if (rp + rlen > tiff->ep) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "strip extends beyond the end of the file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "strip extends beyond the end of the file"); /* the bits are in un-natural order */ if (tiff->fillorder == 2) @@ -436,39 +434,39 @@ fz_decode_tiff_strips(struct tiff *tiff) rp[i] = bitrev[rp[i]]; /* the strip decoders will close this */ - stm = fz_open_memory(tiff->ctx, rp, rlen); + stm = fz_open_memory(ctx, rp, rlen); switch (tiff->compression) { case 1: - fz_decode_tiff_uncompressed(tiff, stm, wp, wlen); + fz_decode_tiff_uncompressed(ctx, tiff, stm, wp, wlen); break; case 2: - fz_decode_tiff_fax(tiff, 2, stm, wp, wlen); + fz_decode_tiff_fax(ctx, tiff, 2, stm, wp, wlen); break; case 3: - fz_decode_tiff_fax(tiff, 3, stm, wp, wlen); + fz_decode_tiff_fax(ctx, tiff, 3, stm, wp, wlen); break; case 4: - fz_decode_tiff_fax(tiff, 4, stm, wp, wlen); + fz_decode_tiff_fax(ctx, tiff, 4, stm, wp, wlen); break; case 5: - fz_decode_tiff_lzw(tiff, stm, wp, wlen); + fz_decode_tiff_lzw(ctx, tiff, stm, wp, wlen); break; case 6: - fz_warn(tiff->ctx, "deprecated JPEG in TIFF compression not fully supported"); + fz_warn(ctx, "deprecated JPEG in TIFF compression not fully supported"); /* fall through */ case 7: - fz_decode_tiff_jpeg(tiff, stm, wp, wlen); + fz_decode_tiff_jpeg(ctx, tiff, stm, wp, wlen); break; case 8: - fz_decode_tiff_flate(tiff, stm, wp, wlen); + fz_decode_tiff_flate(ctx, tiff, stm, wp, wlen); break; case 32773: - fz_decode_tiff_packbits(tiff, stm, wp, wlen); + fz_decode_tiff_packbits(ctx, tiff, stm, wp, wlen); break; default: - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "unknown TIFF compression: %d", tiff->compression); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown TIFF compression: %d", tiff->compression); } /* scramble the bits back into original order */ @@ -493,7 +491,7 @@ fz_decode_tiff_strips(struct tiff *tiff) /* RGBPal */ if (tiff->photometric == 3 && tiff->colormap) - fz_expand_tiff_colormap(tiff); + fz_expand_tiff_colormap(ctx, tiff); /* WhiteIsZero .. invert */ if (tiff->photometric == 0) @@ -584,7 +582,7 @@ fz_read_tiff_tag_value(unsigned *p, struct tiff *tiff, unsigned type, unsigned o } static void -fz_read_tiff_tag(struct tiff *tiff, unsigned offset) +fz_read_tiff_tag(fz_context *ctx, struct tiff *tiff, unsigned offset) { unsigned tag; unsigned type; @@ -662,7 +660,7 @@ fz_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case ICCProfile: - tiff->profile = fz_malloc(tiff->ctx, count); + tiff->profile = fz_malloc(ctx, count); /* ICC profile data type is set to UNDEFINED. * TBYTE reading not correct in fz_read_tiff_tag_value */ fz_read_tiff_bytes(tiff->profile, tiff, value, count); @@ -675,19 +673,19 @@ fz_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case StripOffsets: - tiff->stripoffsets = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); + tiff->stripoffsets = fz_malloc_array(ctx, count, sizeof(unsigned)); fz_read_tiff_tag_value(tiff->stripoffsets, tiff, type, value, count); tiff->stripoffsetslen = count; break; case StripByteCounts: - tiff->stripbytecounts = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); + tiff->stripbytecounts = fz_malloc_array(ctx, count, sizeof(unsigned)); fz_read_tiff_tag_value(tiff->stripbytecounts, tiff, type, value, count); tiff->stripbytecountslen = count; break; case ColorMap: - tiff->colormap = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); + tiff->colormap = fz_malloc_array(ctx, count, sizeof(unsigned)); fz_read_tiff_tag_value(tiff->colormap, tiff, type, value, count); tiff->colormaplen = count; break; @@ -696,10 +694,10 @@ fz_read_tiff_tag(struct tiff *tiff, unsigned offset) case TileLength: case TileOffsets: case TileByteCounts: - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "tiled tiffs not supported"); + fz_throw(ctx, FZ_ERROR_GENERIC, "tiled tiffs not supported"); default: - /* fz_warn(tiff->ctx, "unknown tag: %d t=%d n=%d", tag, type, count); */ + /* fz_warn(ctx, "unknown tag: %d t=%d n=%d", tag, type, count); */ break; } } @@ -722,7 +720,6 @@ fz_decode_tiff_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, in unsigned version; memset(tiff, 0, sizeof(struct tiff)); - tiff->ctx = ctx; tiff->bp = buf; tiff->rp = buf; tiff->ep = buf + len; @@ -748,12 +745,12 @@ fz_decode_tiff_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, in tiff->order = TII; tiff->order = readshort(tiff); if (tiff->order != TII && tiff->order != TMM) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "not a TIFF file, wrong magic marker"); + fz_throw(ctx, FZ_ERROR_GENERIC, "not a TIFF file, wrong magic marker"); /* check version */ version = readshort(tiff); if (version != 42) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "not a TIFF file, wrong version marker"); + fz_throw(ctx, FZ_ERROR_GENERIC, "not a TIFF file, wrong version marker"); /* get offset of IFD */ tiff->ifd_offset = readlong(tiff); @@ -767,12 +764,12 @@ fz_next_ifd(fz_context *ctx, struct tiff *tiff, unsigned offset) tiff->rp = tiff->bp + offset; if (tiff->rp <= tiff->bp || tiff->rp > tiff->ep) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid IFD offset %u", offset); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid IFD offset %u", offset); count = readshort(tiff); if (count * 12 > (unsigned)(tiff->ep - tiff->rp)) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "overlarge IFD entry count %u", count); + fz_throw(ctx, FZ_ERROR_GENERIC, "overlarge IFD entry count %u", count); tiff->rp += count * 12; offset = readlong(tiff); @@ -790,13 +787,13 @@ fz_seek_ifd(fz_context *ctx, struct tiff *tiff, int subimage) offset = fz_next_ifd(ctx, tiff, offset); if (offset == 0) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "subimage index %i out of range", subimage); + fz_throw(ctx, FZ_ERROR_GENERIC, "subimage index %i out of range", subimage); } tiff->rp = tiff->bp + offset; if (tiff->rp < tiff->bp || tiff->rp > tiff->ep) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid IFD offset %u", tiff->ifd_offset); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid IFD offset %u", tiff->ifd_offset); } static void @@ -811,12 +808,12 @@ fz_decode_tiff_ifd(fz_context *ctx, struct tiff *tiff) count = readshort(tiff); if (count * 12 > (unsigned)(tiff->ep - tiff->rp)) - fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "overlarge IFD entry count %u", count); + fz_throw(ctx, FZ_ERROR_GENERIC, "overlarge IFD entry count %u", count); offset += 2; for (i = 0; i < count; i++) { - fz_read_tiff_tag(tiff, offset); + fz_read_tiff_tag(ctx, tiff, offset); offset += 12; } } @@ -838,7 +835,7 @@ fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, int len, int subimage if (tiff.rowsperstrip > tiff.imagelength) tiff.rowsperstrip = tiff.imagelength; - fz_decode_tiff_strips(&tiff); + fz_decode_tiff_strips(ctx, &tiff); /* Byte swap 16-bit images to big endian if necessary */ if (tiff.bitspersample == 16) @@ -846,11 +843,11 @@ fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, int len, int subimage fz_swap_tiff_byte_order(tiff.samples, tiff.imagewidth * tiff.imagelength * tiff.samplesperpixel); /* Expand into fz_pixmap struct */ - image = fz_new_pixmap(tiff.ctx, tiff.colorspace, tiff.imagewidth, tiff.imagelength); + image = fz_new_pixmap(ctx, tiff.colorspace, tiff.imagewidth, tiff.imagelength); image->xres = tiff.xresolution; image->yres = tiff.yresolution; - fz_unpack_tile(image, tiff.samples, tiff.samplesperpixel, tiff.bitspersample, tiff.stride, 0); + fz_unpack_tile(ctx, image, tiff.samples, tiff.samplesperpixel, tiff.bitspersample, tiff.stride, 0); /* We should only do this on non-pre-multiplied images, but files in the wild are bad */ if (tiff.extrasamples /* == 2 */) @@ -858,8 +855,8 @@ fz_load_tiff_subimage(fz_context *ctx, unsigned char *buf, int len, int subimage /* CMYK is a subtractive colorspace, we want additive for premul alpha */ if (image->n == 5) { - fz_pixmap *rgb = fz_new_pixmap(tiff.ctx, fz_device_rgb(ctx), image->w, image->h); - fz_convert_pixmap(tiff.ctx, rgb, image); + fz_pixmap *rgb = fz_new_pixmap(ctx, fz_device_rgb(ctx), image->w, image->h); + fz_convert_pixmap(ctx, rgb, image); rgb->xres = image->xres; rgb->yres = image->yres; fz_drop_pixmap(ctx, image); diff --git a/source/fitz/outline.c b/source/fitz/outline.c index 7a019883..07a27001 100644 --- a/source/fitz/outline.c +++ b/source/fitz/outline.c @@ -15,20 +15,20 @@ fz_drop_outline(fz_context *ctx, fz_outline *outline) } static void -do_debug_outline_xml(fz_output *out, fz_outline *outline, int level) +fz_debug_outline_xml_imp(fz_context *ctx, fz_output *out, fz_outline *outline, int level) { while (outline) { - fz_printf(out, "<outline title=\"%s\" page=\"%d\"", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); + fz_printf(ctx, out, "<outline title=\"%s\" page=\"%d\"", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); if (outline->down) { - fz_printf(out, ">\n"); - do_debug_outline_xml(out, outline->down, level + 1); - fz_printf(out, "</outline>\n"); + fz_printf(ctx, out, ">\n"); + fz_debug_outline_xml_imp(ctx, out, outline->down, level + 1); + fz_printf(ctx, out, "</outline>\n"); } else { - fz_printf(out, " />\n"); + fz_printf(ctx, out, " />\n"); } outline = outline->next; } @@ -37,20 +37,20 @@ do_debug_outline_xml(fz_output *out, fz_outline *outline, int level) void fz_print_outline_xml(fz_context *ctx, fz_output *out, fz_outline *outline) { - do_debug_outline_xml(out, outline, 0); + fz_debug_outline_xml_imp(ctx, out, outline, 0); } static void -do_debug_outline(fz_output *out, fz_outline *outline, int level) +fz_print_outline_imp(fz_context *ctx, fz_output *out, fz_outline *outline, int level) { int i; while (outline) { for (i = 0; i < level; i++) - fz_printf(out, "\t"); - fz_printf(out, "%s\t%d\n", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); + fz_printf(ctx, out, "\t"); + fz_printf(ctx, out, "%s\t%d\n", outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0); if (outline->down) - do_debug_outline(out, outline->down, level + 1); + fz_print_outline_imp(ctx, out, outline->down, level + 1); outline = outline->next; } } @@ -58,5 +58,5 @@ do_debug_outline(fz_output *out, fz_outline *outline, int level) void fz_print_outline(fz_context *ctx, fz_output *out, fz_outline *outline) { - do_debug_outline(out, outline, 0); + fz_print_outline_imp(ctx, out, outline, 0); } diff --git a/source/fitz/output-pcl.c b/source/fitz/output-pcl.c index 90695eb7..a6dcc23b 100644 --- a/source/fitz/output-pcl.c +++ b/source/fitz/output-pcl.c @@ -302,7 +302,7 @@ make_init(fz_pcl_options *pcl, char *buf, unsigned long len, const char *str, in } static void -pcl_header(fz_output *out, fz_pcl_options *pcl, int num_copies, int xres) +pcl_header(fz_context *ctx, fz_output *out, fz_pcl_options *pcl, int num_copies, int xres) { char odd_page_init[80]; char even_page_init[80]; @@ -313,12 +313,12 @@ pcl_header(fz_output *out, fz_pcl_options *pcl, int num_copies, int xres) if (pcl->page_count == 0) { if (pcl->features & HACK__IS_A_LJET4PJL) - fz_puts(out, "\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n"); - fz_puts(out, "\033E"); /* reset printer */ + fz_puts(ctx, out, "\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n"); + fz_puts(ctx, out, "\033E"); /* reset printer */ /* If the printer supports it, set the paper size */ /* based on the actual requested size. */ if (pcl->features & PCL_CAN_SET_PAPER_SIZE) - fz_printf(out, "\033&l%dA", pcl->paper_size); + fz_printf(ctx, out, "\033&l%dA", pcl->paper_size); /* If printer can duplex, set duplex mode appropriately. */ if (pcl->features & PCL_HAS_DUPLEX) { @@ -327,17 +327,17 @@ pcl_header(fz_output *out, fz_pcl_options *pcl, int num_copies, int xres) if (pcl->duplex) { if (!pcl->tumble) - fz_puts(out, "\033&l1S"); + fz_puts(ctx, out, "\033&l1S"); else - fz_puts(out, "\033&l2S"); + fz_puts(ctx, out, "\033&l2S"); } else - fz_puts(out, "\033&l0S"); + fz_puts(ctx, out, "\033&l0S"); } else { /* default to duplex for this printer */ - fz_puts(out, "\033&l1S"); + fz_puts(ctx, out, "\033&l1S"); } } } @@ -360,58 +360,55 @@ pcl_header(fz_output *out, fz_pcl_options *pcl, int num_copies, int xres) { if (pcl->page_count != 0 && (pcl->features & PCL_CAN_SET_PAPER_SIZE)) { - fz_printf(out, "\033&l%dA", pcl->paper_size); + fz_printf(ctx, out, "\033&l%dA", pcl->paper_size); } - fz_puts(out, "\033&l0o0l0E"); - fz_puts(out, pcl->odd_page_init); + fz_puts(ctx, out, "\033&l0o0l0E"); + fz_puts(ctx, out, pcl->odd_page_init); } else - fz_puts(out, pcl->even_page_init); + fz_puts(ctx, out, pcl->even_page_init); } else { if (pcl->features & PCL_CAN_SET_PAPER_SIZE) { - fz_printf(out, "\033&l%dA", pcl->paper_size); + fz_printf(ctx, out, "\033&l%dA", pcl->paper_size); } - fz_puts(out, "\033&l0o0l0E"); - fz_puts(out, pcl->odd_page_init); + fz_puts(ctx, out, "\033&l0o0l0E"); + fz_puts(ctx, out, pcl->odd_page_init); } - fz_printf(out, "\033&l%dX", num_copies); /* # of copies */ + fz_printf(ctx, out, "\033&l%dX", num_copies); /* # of copies */ /* End raster graphics, position cursor at top. */ - fz_puts(out, "\033*rB\033*p0x0Y"); + fz_puts(ctx, out, "\033*rB\033*p0x0Y"); /* The DeskJet and DeskJet Plus reset everything upon */ /* receiving \033*rB, so we must reinitialize graphics mode. */ if (pcl->features & PCL_END_GRAPHICS_DOES_RESET) { - fz_puts(out, pcl->odd_page_init); /* Assume this does the right thing */ - fz_printf(out, "\033&l%dX", num_copies); /* # of copies */ + fz_puts(ctx, out, pcl->odd_page_init); /* Assume this does the right thing */ + fz_printf(ctx, out, "\033&l%dX", num_copies); /* # of copies */ } /* Set resolution. */ - fz_printf(out, "\033*t%dR", xres); + fz_printf(ctx, out, "\033*t%dR", xres); pcl->page_count++; } void -fz_output_pcl(fz_output *out, const fz_pixmap *pixmap, fz_pcl_options *pcl) +fz_output_pcl(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, fz_pcl_options *pcl) { //unsigned char *sp; //int y, x, sn, dn, ss; - fz_context *ctx; if (!out || !pixmap) return; - ctx = out->ctx; - if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pcl"); - pcl_header(out, pcl, 1, pixmap->xres); + pcl_header(ctx, out, pcl, 1, pixmap->xres); #if 0 sn = pixmap->n; @@ -464,7 +461,7 @@ fz_output_pcl(fz_output *out, const fz_pixmap *pixmap, fz_pcl_options *pcl) break; } fz_write_byte(out, xrep-1); - fz_write(out, sp, dn); + fz_write(ctx, out, sp, dn); sp += sn*xrep; x += xrep; } @@ -474,7 +471,7 @@ fz_output_pcl(fz_output *out, const fz_pixmap *pixmap, fz_pcl_options *pcl) x += d; while (d > 0) { - fz_write(out, sp, dn); + fz_write(ctx, out, sp, dn); sp += sn; d--; } @@ -593,11 +590,10 @@ void wind(void) {} void -fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pcl) +fz_output_pcl_bitmap(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pcl) { unsigned char *data, *out_data; int y, ss, rmask, line_size; - fz_context *ctx; int num_blank_lines; int compression = -1; unsigned char *prev_row = NULL; @@ -610,15 +606,13 @@ fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pc if (!out || !bitmap) return; - ctx = out->ctx; - if (pcl->features & HACK__IS_A_OCE9050) { /* Enter HPGL/2 mode, begin plot, Initialise (start plot), Enter PCL mode */ - fz_puts(out, "\033%1BBPIN;\033%1A"); + fz_puts(ctx, out, "\033%1BBPIN;\033%1A"); } - pcl_header(out, pcl, 1, bitmap->xres); + pcl_header(ctx, out, pcl, 1, bitmap->xres); fz_var(prev_row); fz_var(out_row_mode_2); @@ -663,23 +657,23 @@ fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pc if (pcl->features & PCL_ANY_SPACING) { if (num_blank_lines > 0) - fz_printf(out, "\033*p+%dY", num_blank_lines * bitmap->yres); + fz_printf(ctx, out, "\033*p+%dY", num_blank_lines * bitmap->yres); /* Start raster graphics. */ - fz_puts(out, "\033*r1A"); + fz_puts(ctx, out, "\033*r1A"); } else if (pcl->features & PCL_MODE_3_COMPRESSION) { /* Start raster graphics. */ - fz_puts(out, "\033*r1A"); + fz_puts(ctx, out, "\033*r1A"); for (; num_blank_lines; num_blank_lines--) - fz_puts(out, "\033*b0W"); + fz_puts(ctx, out, "\033*b0W"); } else { /* Start raster graphics. */ - fz_puts(out, "\033*r1A"); + fz_puts(ctx, out, "\033*r1A"); for (; num_blank_lines; num_blank_lines--) - fz_puts(out, "\033*bW"); + fz_puts(ctx, out, "\033*bW"); } } @@ -701,30 +695,30 @@ fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pc if (mode_3ns && compression != 2) { /* Switch to mode 2 */ - fz_puts(out, from3to2); + fz_puts(ctx, out, from3to2); compression = 2; } if (pcl->features & PCL_MODE_3_COMPRESSION) { /* Must clear the seed row. */ - fz_puts(out, "\033*b1Y"); + fz_puts(ctx, out, "\033*b1Y"); num_blank_lines--; } if (mode_3ns) { for (; num_blank_lines; num_blank_lines--) - fz_puts(out, "\033*b0W"); + fz_puts(ctx, out, "\033*b0W"); } else { for (; num_blank_lines; num_blank_lines--) - fz_puts(out, "\033*bW"); + fz_puts(ctx, out, "\033*bW"); } } else if (pcl->features & PCL3_SPACING) - fz_printf(out, "\033*p+%dY", num_blank_lines * bitmap->yres); + fz_printf(ctx, out, "\033*p+%dY", num_blank_lines * bitmap->yres); else - fz_printf(out, "\033*b%dY", num_blank_lines); + fz_printf(ctx, out, "\033*b%dY", num_blank_lines); /* Clear the seed row (only matters for mode 3 compression). */ memset(prev_row, 0, line_size); } @@ -744,7 +738,7 @@ fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pc if (count3 + penalty3 < count2 + penalty2) { if (compression != 3) - fz_puts(out, from2to3); + fz_puts(ctx, out, from2to3); compression = 3; out_data = (unsigned char *)out_row_mode_3; out_count = count3; @@ -752,7 +746,7 @@ fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pc else { if (compression != 2) - fz_puts(out, from3to2); + fz_puts(ctx, out, from3to2); compression = 2; out_data = (unsigned char *)out_row_mode_2; out_count = count2; @@ -770,17 +764,17 @@ fz_output_pcl_bitmap(fz_output *out, const fz_bitmap *bitmap, fz_pcl_options *pc } /* Transfer the data */ - fz_printf(out, "\033*b%dW", out_count); - fz_write(out, out_data, out_count); + fz_printf(ctx, out, "\033*b%dW", out_count); + fz_write(ctx, out, out_data, out_count); } /* end raster graphics and eject page */ - fz_puts(out, "\033*rB\f"); + fz_puts(ctx, out, "\033*rB\f"); if (pcl->features & HACK__IS_A_OCE9050) { /* Pen up, pen select, advance full page, reset */ - fz_puts(out, "\033%1BPUSP0PG;\033E"); + fz_puts(ctx, out, "\033%1BPUSP0PG;\033E"); } } fz_always(ctx) @@ -811,13 +805,12 @@ fz_write_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, fz_ fz_try(ctx) { - out = fz_new_output_with_file(ctx, fp); - fz_output_pcl(out, pixmap, pcl); + out = fz_new_output_with_file(ctx, fp, 1); + fz_output_pcl(ctx, out, pixmap, pcl); } fz_always(ctx) { - fz_drop_output(out); - fclose(fp); + fz_drop_output(ctx, out); } fz_catch(ctx) { @@ -841,13 +834,12 @@ fz_write_pcl_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe fz_try(ctx) { - out = fz_new_output_with_file(ctx, fp); - fz_output_pcl_bitmap(out, bitmap, pcl); + out = fz_new_output_with_file(ctx, fp, 1); + fz_output_pcl_bitmap(ctx, out, bitmap, pcl); } fz_always(ctx) { - fz_drop_output(out); - fclose(fp); + fz_drop_output(ctx, out); } fz_catch(ctx) { diff --git a/source/fitz/output-pwg.c b/source/fitz/output-pwg.c index a2107db6..4af67c25 100644 --- a/source/fitz/output-pwg.c +++ b/source/fitz/output-pwg.c @@ -1,103 +1,100 @@ #include "mupdf/fitz.h" void -fz_output_pwg_file_header(fz_output *out) +fz_output_pwg_file_header(fz_context *ctx, fz_output *out) { static const unsigned char pwgsig[4] = { 'R', 'a', 'S', '2' }; /* Sync word */ - fz_write(out, pwgsig, 4); + fz_write(ctx, out, pwgsig, 4); } static void -output_header(fz_output *out, const fz_pwg_options *pwg, int xres, int yres, int w, int h, int bpp) +output_header(fz_context *ctx, fz_output *out, const fz_pwg_options *pwg, int xres, int yres, int w, int h, int bpp) { static const char zero[64] = { 0 }; int i; /* Page Header: */ - fz_write(out, pwg ? pwg->media_class : zero, 64); - fz_write(out, pwg ? pwg->media_color : zero, 64); - fz_write(out, pwg ? pwg->media_type : zero, 64); - fz_write(out, pwg ? pwg->output_type : zero, 64); - fz_write_int32be(out, pwg ? pwg->advance_distance : 0); - fz_write_int32be(out, pwg ? pwg->advance_media : 0); - fz_write_int32be(out, pwg ? pwg->collate : 0); - fz_write_int32be(out, pwg ? pwg->cut_media : 0); - fz_write_int32be(out, pwg ? pwg->duplex : 0); - fz_write_int32be(out, xres); - fz_write_int32be(out, yres); + fz_write(ctx, out, pwg ? pwg->media_class : zero, 64); + fz_write(ctx, out, pwg ? pwg->media_color : zero, 64); + fz_write(ctx, out, pwg ? pwg->media_type : zero, 64); + fz_write(ctx, out, pwg ? pwg->output_type : zero, 64); + fz_write_int32be(ctx, out, pwg ? pwg->advance_distance : 0); + fz_write_int32be(ctx, out, pwg ? pwg->advance_media : 0); + fz_write_int32be(ctx, out, pwg ? pwg->collate : 0); + fz_write_int32be(ctx, out, pwg ? pwg->cut_media : 0); + fz_write_int32be(ctx, out, pwg ? pwg->duplex : 0); + fz_write_int32be(ctx, out, xres); + fz_write_int32be(ctx, out, yres); /* CUPS format says that 284->300 are supposed to be the bbox of the * page in points. PWG says 'Reserved'. */ for (i=284; i < 300; i += 4) - fz_write(out, zero, 4); - fz_write_int32be(out, pwg ? pwg->insert_sheet : 0); - fz_write_int32be(out, pwg ? pwg->jog : 0); - fz_write_int32be(out, pwg ? pwg->leading_edge : 0); + fz_write(ctx, out, zero, 4); + fz_write_int32be(ctx, out, pwg ? pwg->insert_sheet : 0); + fz_write_int32be(ctx, out, pwg ? pwg->jog : 0); + fz_write_int32be(ctx, out, pwg ? pwg->leading_edge : 0); /* CUPS format says that 312->320 are supposed to be the margins of * the lower left hand edge of page in points. PWG says 'Reserved'. */ for (i=312; i < 320; i += 4) - fz_write(out, zero, 4); - fz_write_int32be(out, pwg ? pwg->manual_feed : 0); - fz_write_int32be(out, pwg ? pwg->media_position : 0); - fz_write_int32be(out, pwg ? pwg->media_weight : 0); - fz_write_int32be(out, pwg ? pwg->mirror_print : 0); - fz_write_int32be(out, pwg ? pwg->negative_print : 0); - fz_write_int32be(out, pwg ? pwg->num_copies : 0); - fz_write_int32be(out, pwg ? pwg->orientation : 0); - fz_write_int32be(out, pwg ? pwg->output_face_up : 0); - fz_write_int32be(out, w * 72/ xres); /* Page size in points */ - fz_write_int32be(out, h * 72/ yres); - fz_write_int32be(out, pwg ? pwg->separations : 0); - fz_write_int32be(out, pwg ? pwg->tray_switch : 0); - fz_write_int32be(out, pwg ? pwg->tumble : 0); - fz_write_int32be(out, w); /* Page image in pixels */ - fz_write_int32be(out, h); - fz_write_int32be(out, pwg ? pwg->media_type_num : 0); - fz_write_int32be(out, bpp < 8 ? 1 : 8); /* Bits per color */ - fz_write_int32be(out, bpp); /* Bits per pixel */ - fz_write_int32be(out, (w * bpp + 7)/8); /* Bytes per line */ - fz_write_int32be(out, 0); /* Chunky pixels */ + fz_write(ctx, out, zero, 4); + fz_write_int32be(ctx, out, pwg ? pwg->manual_feed : 0); + fz_write_int32be(ctx, out, pwg ? pwg->media_position : 0); + fz_write_int32be(ctx, out, pwg ? pwg->media_weight : 0); + fz_write_int32be(ctx, out, pwg ? pwg->mirror_print : 0); + fz_write_int32be(ctx, out, pwg ? pwg->negative_print : 0); + fz_write_int32be(ctx, out, pwg ? pwg->num_copies : 0); + fz_write_int32be(ctx, out, pwg ? pwg->orientation : 0); + fz_write_int32be(ctx, out, pwg ? pwg->output_face_up : 0); + fz_write_int32be(ctx, out, w * 72/ xres); /* Page size in points */ + fz_write_int32be(ctx, out, h * 72/ yres); + fz_write_int32be(ctx, out, pwg ? pwg->separations : 0); + fz_write_int32be(ctx, out, pwg ? pwg->tray_switch : 0); + fz_write_int32be(ctx, out, pwg ? pwg->tumble : 0); + fz_write_int32be(ctx, out, w); /* Page image in pixels */ + fz_write_int32be(ctx, out, h); + fz_write_int32be(ctx, out, pwg ? pwg->media_type_num : 0); + fz_write_int32be(ctx, out, bpp < 8 ? 1 : 8); /* Bits per color */ + fz_write_int32be(ctx, out, bpp); /* Bits per pixel */ + fz_write_int32be(ctx, out, (w * bpp + 7)/8); /* Bytes per line */ + fz_write_int32be(ctx, out, 0); /* Chunky pixels */ switch (bpp) { - case 1: fz_write_int32be(out, 3); /* Black */ break; - case 8: fz_write_int32be(out, 18); /* Sgray */ break; - case 24: fz_write_int32be(out, 19); /* Srgb */ break; - case 32: fz_write_int32be(out, 6); /* Cmyk */ break; - default: fz_throw(out->ctx, FZ_ERROR_GENERIC, "pixmap bpp must be 1, 8, 24 or 32 to write as pwg"); + case 1: fz_write_int32be(ctx, out, 3); /* Black */ break; + case 8: fz_write_int32be(ctx, out, 18); /* Sgray */ break; + case 24: fz_write_int32be(ctx, out, 19); /* Srgb */ break; + case 32: fz_write_int32be(ctx, out, 6); /* Cmyk */ break; + default: fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap bpp must be 1, 8, 24 or 32 to write as pwg"); } - fz_write_int32be(out, pwg ? pwg->compression : 0); - fz_write_int32be(out, pwg ? pwg->row_count : 0); - fz_write_int32be(out, pwg ? pwg->row_feed : 0); - fz_write_int32be(out, pwg ? pwg->row_step : 0); - fz_write_int32be(out, bpp <= 8 ? 1 : 3); /* Num Colors */ + fz_write_int32be(ctx, out, pwg ? pwg->compression : 0); + fz_write_int32be(ctx, out, pwg ? pwg->row_count : 0); + fz_write_int32be(ctx, out, pwg ? pwg->row_feed : 0); + fz_write_int32be(ctx, out, pwg ? pwg->row_step : 0); + fz_write_int32be(ctx, out, bpp <= 8 ? 1 : 3); /* Num Colors */ for (i=424; i < 452; i += 4) - fz_write(out, zero, 4); - fz_write_int32be(out, 1); /* TotalPageCount */ - fz_write_int32be(out, 1); /* CrossFeedTransform */ - fz_write_int32be(out, 1); /* FeedTransform */ - fz_write_int32be(out, 0); /* ImageBoxLeft */ - fz_write_int32be(out, 0); /* ImageBoxTop */ - fz_write_int32be(out, w); /* ImageBoxRight */ - fz_write_int32be(out, h); /* ImageBoxBottom */ + fz_write(ctx, out, zero, 4); + fz_write_int32be(ctx, out, 1); /* TotalPageCount */ + fz_write_int32be(ctx, out, 1); /* CrossFeedTransform */ + fz_write_int32be(ctx, out, 1); /* FeedTransform */ + fz_write_int32be(ctx, out, 0); /* ImageBoxLeft */ + fz_write_int32be(ctx, out, 0); /* ImageBoxTop */ + fz_write_int32be(ctx, out, w); /* ImageBoxRight */ + fz_write_int32be(ctx, out, h); /* ImageBoxBottom */ for (i=480; i < 1668; i += 4) - fz_write(out, zero, 4); - fz_write(out, pwg ? pwg->rendering_intent : zero, 64); - fz_write(out, pwg ? pwg->page_size_name : zero, 64); + fz_write(ctx, out, zero, 4); + fz_write(ctx, out, pwg ? pwg->rendering_intent : zero, 64); + fz_write(ctx, out, pwg ? pwg->page_size_name : zero, 64); } void -fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg) +fz_output_pwg_page(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg) { unsigned char *sp; int y, x, sn, dn, ss; - fz_context *ctx; if (!out || !pixmap) return; - ctx = out->ctx; - if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4 && pixmap->n != 5) fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale, rgb or cmyk to write as pwg"); @@ -106,7 +103,7 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options if (dn > 1) dn--; - output_header(out, pwg, pixmap->xres, pixmap->yres, pixmap->w, pixmap->h, dn*8); + output_header(ctx, out, pwg, pixmap->xres, pixmap->yres, pixmap->w, pixmap->h, dn*8); /* Now output the actual bitmap, using a packbits like compression */ sp = pixmap->samples; @@ -124,7 +121,7 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options if (memcmp(sp, sp + yrep * ss, ss) != 0) break; } - fz_write_byte(out, yrep-1); + fz_write_byte(ctx, out, yrep-1); /* Encode the line */ x = 0; @@ -152,18 +149,18 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options if (memcmp(sp, sp + xrep*sn, sn) != 0) break; } - fz_write_byte(out, xrep-1); - fz_write(out, sp, dn); + fz_write_byte(ctx, out, xrep-1); + fz_write(ctx, out, sp, dn); sp += sn*xrep; x += xrep; } else { - fz_write_byte(out, 257-d); + fz_write_byte(ctx, out, 257-d); x += d; while (d > 0) { - fz_write(out, sp, dn); + fz_write(ctx, out, sp, dn); sp += sn; d--; } @@ -177,7 +174,7 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options } void -fz_output_pwg_bitmap_page(fz_output *out, const fz_bitmap *bitmap, const fz_pwg_options *pwg) +fz_output_pwg_bitmap_page(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, const fz_pwg_options *pwg) { unsigned char *sp; int y, x, ss; @@ -186,7 +183,7 @@ fz_output_pwg_bitmap_page(fz_output *out, const fz_bitmap *bitmap, const fz_pwg_ if (!out || !bitmap) return; - output_header(out, pwg, bitmap->xres, bitmap->yres, bitmap->w, bitmap->h, 1); + output_header(ctx, out, pwg, bitmap->xres, bitmap->yres, bitmap->w, bitmap->h, 1); /* Now output the actual bitmap, using a packbits like compression */ sp = bitmap->samples; @@ -205,7 +202,7 @@ fz_output_pwg_bitmap_page(fz_output *out, const fz_bitmap *bitmap, const fz_pwg_ if (memcmp(sp, sp + yrep * ss, byte_width) != 0) break; } - fz_write_byte(out, yrep-1); + fz_write_byte(ctx, out, yrep-1); /* Encode the line */ x = 0; @@ -233,15 +230,15 @@ fz_output_pwg_bitmap_page(fz_output *out, const fz_bitmap *bitmap, const fz_pwg_ if (sp[0] != sp[xrep]) break; } - fz_write_byte(out, xrep-1); - fz_write(out, sp, 1); + fz_write_byte(ctx, out, xrep-1); + fz_write(ctx, out, sp, 1); sp += xrep; x += xrep; } else { - fz_write_byte(out, 257-d); - fz_write(out, sp, d); + fz_write_byte(ctx, out, 257-d); + fz_write(ctx, out, sp, d); sp += d; x += d; } @@ -254,10 +251,10 @@ fz_output_pwg_bitmap_page(fz_output *out, const fz_bitmap *bitmap, const fz_pwg_ } void -fz_output_pwg(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg) +fz_output_pwg(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options *pwg) { - fz_output_pwg_file_header(out); - fz_output_pwg_page(out, pixmap, pwg); + fz_output_pwg_file_header(ctx, out); + fz_output_pwg_page(ctx, out, pixmap, pwg); } void @@ -276,15 +273,14 @@ fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, con fz_try(ctx) { - out = fz_new_output_with_file(ctx, fp); + out = fz_new_output_with_file(ctx, fp, 1); if (!append) - fz_output_pwg_file_header(out); - fz_output_pwg_page(out, pixmap, pwg); + fz_output_pwg_file_header(ctx, out); + fz_output_pwg_page(ctx, out, pixmap, pwg); } fz_always(ctx) { - fz_drop_output(out); - fclose(fp); + fz_drop_output(ctx, out); } fz_catch(ctx) { @@ -308,15 +304,14 @@ fz_write_pwg_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe fz_try(ctx) { - out = fz_new_output_with_file(ctx, fp); + out = fz_new_output_with_file(ctx, fp, 1); if (!append) - fz_output_pwg_file_header(out); - fz_output_pwg_bitmap_page(out, bitmap, pwg); + fz_output_pwg_file_header(ctx, out); + fz_output_pwg_bitmap_page(ctx, out, bitmap, pwg); } fz_always(ctx) { - fz_drop_output(out); - fclose(fp); + fz_drop_output(ctx, out); } fz_catch(ctx) { diff --git a/source/fitz/output.c b/source/fitz/output.c index 8f5a4a0f..52381377 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -1,44 +1,42 @@ #include "mupdf/fitz.h" -void fz_rebind_output(fz_output *out, fz_context *ctx) +struct fz_output_s { - if (out != NULL) - out->ctx = ctx; -} + void *opaque; + int (*printf)(fz_context *, void *opaque, const char *, va_list ap); + int (*write)(fz_context *, void *opaque, const void *, int n); + void (*close)(fz_context *, void *opaque); +}; static int -file_printf(fz_output *out, const char *fmt, va_list ap) +file_printf(fz_context *ctx, void *opaque, const char *fmt, va_list ap) { - FILE *file = (FILE *)out->opaque; - - return fz_vfprintf(out->ctx, file, fmt, ap); + FILE *file = opaque; + return fz_vfprintf(ctx, file, fmt, ap); } static int -file_write(fz_output *out, const void *buffer, int count) +file_write(fz_context *ctx, void *opaque, const void *buffer, int count) { - FILE *file = (FILE *)out->opaque; - + FILE *file = opaque; return fwrite(buffer, 1, count, file); } static void -file_close(fz_output *out) +file_close(fz_context *ctx, void *opaque) { - FILE *file = (FILE *)out->opaque; - + FILE *file = opaque; fclose(file); } fz_output * -fz_new_output_with_file(fz_context *ctx, FILE *file) +fz_new_output_with_file(fz_context *ctx, FILE *file, int close) { fz_output *out = fz_malloc_struct(ctx, fz_output); - out->ctx = ctx; out->opaque = file; out->printf = file_printf; out->write = file_write; - out->close = NULL; + out->close = close ? file_close : NULL; return out; } @@ -56,7 +54,6 @@ fz_new_output_to_filename(fz_context *ctx, const char *filename) fz_try(ctx) { out = fz_malloc_struct(ctx, fz_output); - out->ctx = ctx; out->opaque = file; out->printf = file_printf; out->write = file_write; @@ -71,17 +68,17 @@ fz_new_output_to_filename(fz_context *ctx, const char *filename) } void -fz_drop_output(fz_output *out) +fz_drop_output(fz_context *ctx, fz_output *out) { if (!out) return; if (out->close) - out->close(out); - fz_free(out->ctx, out); + out->close(ctx, out->opaque); + fz_free(ctx, out); } int -fz_printf(fz_output *out, const char *fmt, ...) +fz_printf(fz_context *ctx, fz_output *out, const char *fmt, ...) { int ret; va_list ap; @@ -90,60 +87,64 @@ fz_printf(fz_output *out, const char *fmt, ...) return 0; va_start(ap, fmt); - ret = out->printf(out, fmt, ap); + ret = out->printf(ctx, out->opaque, fmt, ap); va_end(ap); return ret; } int -fz_write(fz_output *out, const void *data, int len) +fz_write(fz_context *ctx, fz_output *out, const void *data, int len) { if (!out) return 0; - return out->write(out, data, len); + return out->write(ctx, out->opaque, data, len); } void -fz_putc(fz_output *out, char c) +fz_putc(fz_context *ctx, fz_output *out, char c) { if (out) - (void)out->write(out, &c, 1); + (void)out->write(ctx, out->opaque, &c, 1); } int -fz_puts(fz_output *out, const char *str) +fz_puts(fz_context *ctx, fz_output *out, const char *str) { if (!out) return 0; - return out->write(out, str, strlen(str)); + return out->write(ctx, out->opaque, str, strlen(str)); } static int -buffer_printf(fz_output *out, const char *fmt, va_list list) +buffer_printf(fz_context *ctx, void *opaque, const char *fmt, va_list list) { - fz_buffer *buffer = (fz_buffer *)out->opaque; - - return fz_buffer_vprintf(out->ctx, buffer, fmt, list); + fz_buffer *buffer = opaque; + return fz_buffer_vprintf(ctx, buffer, fmt, list); } static int -buffer_write(fz_output *out, const void *data, int len) +buffer_write(fz_context *ctx, void *opaque, const void *data, int len) { - fz_buffer *buffer = (fz_buffer *)out->opaque; - - fz_write_buffer(out->ctx, buffer, (unsigned char *)data, len); + fz_buffer *buffer = opaque; + fz_write_buffer(ctx, buffer, (unsigned char *)data, len); return len; } +static void +buffer_close(fz_context *ctx, void *opaque) +{ + fz_buffer *buffer = opaque; + fz_drop_buffer(ctx, buffer); +} + fz_output * fz_new_output_with_buffer(fz_context *ctx, fz_buffer *buf) { fz_output *out = fz_malloc_struct(ctx, fz_output); - out->ctx = ctx; - out->opaque = buf; + out->opaque = fz_keep_buffer(ctx, buf); out->printf = buffer_printf; out->write = buffer_write; - out->close = NULL; + out->close = buffer_close; return out; } diff --git a/source/fitz/path.c b/source/fitz/path.c index 6c7991b9..4712ea35 100644 --- a/source/fitz/path.c +++ b/source/fitz/path.c @@ -270,14 +270,14 @@ fz_bound_path(fz_context *ctx, fz_path *path, const fz_stroke_state *stroke, con if (stroke) { - fz_adjust_rect_for_stroke(r, stroke, ctm); + fz_adjust_rect_for_stroke(ctx, r, stroke, ctm); } return r; } fz_rect * -fz_adjust_rect_for_stroke(fz_rect *r, const fz_stroke_state *stroke, const fz_matrix *ctm) +fz_adjust_rect_for_stroke(fz_context *ctx, fz_rect *r, const fz_stroke_state *stroke, const fz_matrix *ctm) { float expand; diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c index d6a74ea1..fa4843bc 100644 --- a/source/fitz/pixmap.c +++ b/source/fitz/pixmap.c @@ -478,7 +478,7 @@ fz_invert_pixmap(fz_context *ctx, fz_pixmap *pix) } } -void fz_invert_pixmap_rect(fz_pixmap *image, const fz_irect *rect) +void fz_invert_pixmap_rect(fz_context *ctx, fz_pixmap *image, const fz_irect *rect) { unsigned char *p; int x, y, n; @@ -526,23 +526,21 @@ fz_gamma_pixmap(fz_context *ctx, fz_pixmap *pix, float gamma) */ void -fz_output_pnm_header(fz_output *out, int w, int h, int n) +fz_output_pnm_header(fz_context *ctx, fz_output *out, int w, int h, int n) { - fz_context *ctx = out->ctx; - if (n != 1 && n != 2 && n != 4) fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pnm"); if (n == 1 || n == 2) - fz_printf(out, "P5\n"); + fz_printf(ctx, out, "P5\n"); if (n == 4) - fz_printf(out, "P6\n"); - fz_printf(out, "%d %d\n", w, h); - fz_printf(out, "255\n"); + fz_printf(ctx, out, "P6\n"); + fz_printf(ctx, out, "%d %d\n", w, h); + fz_printf(ctx, out, "255\n"); } void -fz_output_pnm_band(fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *p) +fz_output_pnm_band(fz_context *ctx, fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *p) { int len; int start = band * bandheight; @@ -557,21 +555,21 @@ fz_output_pnm_band(fz_output *out, int w, int h, int n, int band, int bandheight switch (n) { case 1: - fz_write(out, p, len); + fz_write(ctx, out, p, len); break; case 2: while (len--) { - fz_putc(out, p[0]); + fz_putc(ctx, out, p[0]); p += 2; } break; case 4: while (len--) { - fz_putc(out, p[0]); - fz_putc(out, p[1]); - fz_putc(out, p[2]); + fz_putc(ctx, out, p[0]); + fz_putc(ctx, out, p[1]); + fz_putc(ctx, out, p[2]); p += 4; } } @@ -581,9 +579,9 @@ void fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename) { fz_output *out = fz_new_output_to_filename(ctx, filename); - fz_output_pnm_header(out, pixmap->w, pixmap->h, pixmap->n); - fz_output_pnm_band(out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples); - fz_drop_output(out); + fz_output_pnm_header(ctx, out, pixmap->w, pixmap->h, pixmap->n); + fz_output_pnm_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples); + fz_drop_output(ctx, out); } /* @@ -591,29 +589,29 @@ fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename) */ void -fz_output_pam_header(fz_output *out, int w, int h, int n, int savealpha) +fz_output_pam_header(fz_context *ctx, fz_output *out, int w, int h, int n, int savealpha) { int sn = n; int dn = n; if (!savealpha && dn > 1) dn--; - fz_printf(out, "P7\n"); - fz_printf(out, "WIDTH %d\n", w); - fz_printf(out, "HEIGHT %d\n", h); - fz_printf(out, "DEPTH %d\n", dn); - fz_printf(out, "MAXVAL 255\n"); - if (dn == 1) fz_printf(out, "TUPLTYPE GRAYSCALE\n"); - else if (dn == 2 && sn == 2) fz_printf(out, "TUPLTYPE GRAYSCALE_ALPHA\n"); - else if (dn == 3 && sn == 4) fz_printf(out, "TUPLTYPE RGB\n"); - else if (dn == 4 && sn == 4) fz_printf(out, "TUPLTYPE RGB_ALPHA\n"); - else if (dn == 4 && sn == 5) fz_printf(out, "TUPLTYPE CMYK\n"); - else if (dn == 5 && sn == 5) fz_printf(out, "TUPLTYPE CMYK_ALPHA\n"); - fz_printf(out, "ENDHDR\n"); + fz_printf(ctx, out, "P7\n"); + fz_printf(ctx, out, "WIDTH %d\n", w); + fz_printf(ctx, out, "HEIGHT %d\n", h); + fz_printf(ctx, out, "DEPTH %d\n", dn); + fz_printf(ctx, out, "MAXVAL 255\n"); + if (dn == 1) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE\n"); + else if (dn == 2 && sn == 2) fz_printf(ctx, out, "TUPLTYPE GRAYSCALE_ALPHA\n"); + else if (dn == 3 && sn == 4) fz_printf(ctx, out, "TUPLTYPE RGB\n"); + else if (dn == 4 && sn == 4) fz_printf(ctx, out, "TUPLTYPE RGB_ALPHA\n"); + else if (dn == 4 && sn == 5) fz_printf(ctx, out, "TUPLTYPE CMYK\n"); + else if (dn == 5 && sn == 5) fz_printf(ctx, out, "TUPLTYPE CMYK_ALPHA\n"); + fz_printf(ctx, out, "ENDHDR\n"); } void -fz_output_pam_band(fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *sp, int savealpha) +fz_output_pam_band(fz_context *ctx, fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *sp, int savealpha) { int y, x, k; int start = band * bandheight; @@ -633,7 +631,7 @@ fz_output_pam_band(fz_output *out, int w, int h, int n, int band, int bandheight while (x--) { for (k = 0; k < dn; k++) - fz_putc(out, sp[k]); + fz_putc(ctx, out, sp[k]); sp += sn; } } @@ -643,9 +641,9 @@ void fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) { fz_output *out = fz_new_output_to_filename(ctx, filename); - fz_output_pam_header(out, pixmap->w, pixmap->h, pixmap->n, savealpha); - fz_output_pam_band(out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha); - fz_drop_output(out); + fz_output_pam_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, savealpha); + fz_output_pam_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha); + fz_drop_output(ctx, out); } /* @@ -662,16 +660,16 @@ static inline void big32(unsigned char *buf, unsigned int v) buf[3] = (v) & 0xff; } -static void putchunk(char *tag, unsigned char *data, int size, fz_output *out) +static void putchunk(fz_context *ctx, fz_output *out, char *tag, unsigned char *data, int size) { unsigned int sum; - fz_write_int32be(out, size); - fz_write(out, tag, 4); - fz_write(out, data, size); + fz_write_int32be(ctx, out, size); + fz_write(ctx, out, tag, 4); + fz_write(ctx, out, data, size); sum = crc32(0, NULL, 0); sum = crc32(sum, (unsigned char*)tag, 4); sum = crc32(sum, data, size); - fz_write_int32be(out, sum); + fz_write_int32be(ctx, out, sum); } void @@ -684,13 +682,13 @@ fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) fz_try(ctx) { - poc = fz_output_png_header(out, pixmap->w, pixmap->h, pixmap->n, savealpha); - fz_output_png_band(out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha, poc); + poc = fz_output_png_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, savealpha); + fz_output_png_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha, poc); } fz_always(ctx) { - fz_output_png_trailer(out, poc); - fz_drop_output(out); + fz_output_png_trailer(ctx, out, poc); + fz_drop_output(ctx, out); } fz_catch(ctx) { @@ -699,24 +697,22 @@ fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) } void -fz_output_png(fz_output *out, const fz_pixmap *pixmap, int savealpha) +fz_output_png(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, int savealpha) { fz_png_output_context *poc; - fz_context *ctx; if (!out) return; - ctx = out->ctx; - poc = fz_output_png_header(out, pixmap->w, pixmap->h, pixmap->n, savealpha); + poc = fz_output_png_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, savealpha); fz_try(ctx) { - fz_output_png_band(out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha, poc); + fz_output_png_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, 0, pixmap->h, pixmap->samples, savealpha, poc); } fz_always(ctx) { - fz_output_png_trailer(out, poc); + fz_output_png_trailer(ctx, out, poc); } fz_catch(ctx) { @@ -733,19 +729,16 @@ struct fz_png_output_context_s }; fz_png_output_context * -fz_output_png_header(fz_output *out, int w, int h, int n, int savealpha) +fz_output_png_header(fz_context *ctx, fz_output *out, int w, int h, int n, int savealpha) { static const unsigned char pngsig[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; unsigned char head[13]; - fz_context *ctx; int color; fz_png_output_context *poc; if (!out) return NULL; - ctx = out->ctx; - if (n != 1 && n != 2 && n != 4) fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as png"); @@ -771,24 +764,21 @@ fz_output_png_header(fz_output *out, int w, int h, int n, int savealpha) head[11] = 0; /* filter */ head[12] = 0; /* interlace */ - fz_write(out, pngsig, 8); - putchunk("IHDR", head, 13, out); + fz_write(ctx, out, pngsig, 8); + putchunk(ctx, out, "IHDR", head, 13); return poc; } void -fz_output_png_band(fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *sp, int savealpha, fz_png_output_context *poc) +fz_output_png_band(fz_context *ctx, fz_output *out, int w, int h, int n, int band, int bandheight, unsigned char *sp, int savealpha, fz_png_output_context *poc) { unsigned char *dp; int y, x, k, sn, dn, err, finalband; - fz_context *ctx; if (!out || !sp || !poc) return; - ctx = out->ctx; - if (n != 1 && n != 2 && n != 4) fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as png"); @@ -867,23 +857,20 @@ fz_output_png_band(fz_output *out, int w, int h, int n, int band, int bandheight } if (poc->stream.next_out != poc->cdata) - putchunk("IDAT", poc->cdata, poc->stream.next_out - poc->cdata, out); + putchunk(ctx, out, "IDAT", poc->cdata, poc->stream.next_out - poc->cdata); } while (poc->stream.avail_out == 0); } void -fz_output_png_trailer(fz_output *out, fz_png_output_context *poc) +fz_output_png_trailer(fz_context *ctx, fz_output *out, fz_png_output_context *poc) { unsigned char block[1]; int err; - fz_context *ctx; if (!out || !poc) return; - ctx = out->ctx; - err = deflateEnd(&poc->stream); if (err != Z_OK) fz_throw(ctx, FZ_ERROR_GENERIC, "compression error %d", err); @@ -892,7 +879,7 @@ fz_output_png_trailer(fz_output *out, fz_png_output_context *poc) fz_free(ctx, poc->udata); fz_free(ctx, poc); - putchunk("IEND", block, 0, out); + putchunk(ctx, out, "IEND", block, 0); } /* We use an auxiliary function to do pixmap_as_png, as it can enable us to @@ -924,12 +911,12 @@ png_from_pixmap(fz_context *ctx, fz_pixmap *pix, int drop) } buf = fz_new_buffer(ctx, 1024); out = fz_new_output_with_buffer(ctx, buf); - fz_output_png(out, pix, 1); + fz_output_png(ctx, out, pix, 1); } fz_always(ctx) { fz_drop_pixmap(ctx, drop ? pix : pix2); - fz_drop_output(out); + fz_drop_output(ctx, out); } fz_catch(ctx) { @@ -957,23 +944,23 @@ fz_new_png_from_pixmap(fz_context *ctx, fz_pixmap *pix) * Write pixmap to TGA file (with or without alpha channel) */ -static inline void tga_put_pixel(unsigned char *data, int n, int is_bgr, fz_output *out) +static inline void tga_put_pixel(fz_context *ctx, fz_output *out, unsigned char *data, int n, int is_bgr) { if (n >= 3 && !is_bgr) { - fz_putc(out, data[2]); - fz_putc(out, data[1]); - fz_putc(out, data[0]); + fz_putc(ctx, out, data[2]); + fz_putc(ctx, out, data[1]); + fz_putc(ctx, out, data[0]); if (n == 4) - fz_putc(out, data[3]); + fz_putc(ctx, out, data[3]); return; } if (n == 2) { - fz_putc(out, data[0]); - fz_putc(out, data[0]); + fz_putc(ctx, out, data[0]); + fz_putc(ctx, out, data[0]); } - fz_write(out, data, n); + fz_write(ctx, out, data, n); } void @@ -1003,7 +990,7 @@ fz_write_tga(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int savea if (savealpha && d == 2) head[16] = 32; - fz_write(out, head, sizeof(head)); + fz_write(ctx, out, head, sizeof(head)); for (k = 1; k <= pixmap->h; k++) { int i, j; @@ -1013,23 +1000,23 @@ fz_write_tga(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int savea for (; i + j < pixmap->w && j < 128 && !memcmp(line + i * n, line + (i + j) * n, d); j++); if (j > 1) { - fz_putc(out, j - 1 + 128); - tga_put_pixel(line + i * n, d, is_bgr, out); + fz_putc(ctx, out, j - 1 + 128); + tga_put_pixel(ctx, out, line + i * n, d, is_bgr); } else { for (; i + j < pixmap->w && j <= 128 && memcmp(line + (i + j - 1) * n, line + (i + j) * n, d) != 0; j++); if (i + j < pixmap->w || j > 128) j--; - fz_putc(out, j - 1); + fz_putc(ctx, out, j - 1); for (; j > 0; j--, i++) - tga_put_pixel(line + i * n, d, is_bgr, out); + tga_put_pixel(ctx, out, line + i * n, d, is_bgr); } } } - fz_write(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.\0", 26); + fz_write(ctx, out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.\0", 26); - fz_drop_output(out); + fz_drop_output(ctx, out); } unsigned int @@ -1403,7 +1390,7 @@ fz_pixmap_set_resolution(fz_pixmap *pix, int res) } void -fz_md5_pixmap(fz_pixmap *pix, unsigned char digest[16]) +fz_md5_pixmap(fz_context *ctx, fz_pixmap *pix, unsigned char digest[16]) { fz_md5 md5; diff --git a/source/fitz/shade.c b/source/fitz/shade.c index 01ada9a4..f5e25639 100644 --- a/source/fitz/shade.c +++ b/source/fitz/shade.c @@ -1,18 +1,28 @@ #include "mupdf/fitz.h" +typedef struct fz_mesh_processor_s fz_mesh_processor; + +struct fz_mesh_processor_s { + fz_shade *shade; + fz_mesh_prepare_fn *prepare; + fz_mesh_process_fn *process; + void *process_arg; + int ncomp; +}; + #define SWAP(a,b) {fz_vertex *t = (a); (a) = (b); (b) = t;} static inline void -paint_tri(fz_mesh_processor *painter, fz_vertex *v0, fz_vertex *v1, fz_vertex *v2) +paint_tri(fz_context *ctx, fz_mesh_processor *painter, fz_vertex *v0, fz_vertex *v1, fz_vertex *v2) { if (painter->process) { - painter->process(painter->process_arg, v0, v1, v2); + painter->process(ctx, painter->process_arg, v0, v1, v2); } } static inline void -paint_quad(fz_mesh_processor *painter, fz_vertex *v0, fz_vertex *v1, fz_vertex *v2, fz_vertex *v3) +paint_quad(fz_context *ctx, fz_mesh_processor *painter, fz_vertex *v0, fz_vertex *v1, fz_vertex *v2, fz_vertex *v3) { /* For a quad with corners (in clockwise or anticlockwise order) are * v0, v1, v2, v3. We can choose to split in in various different ways. @@ -35,27 +45,27 @@ paint_quad(fz_mesh_processor *painter, fz_vertex *v0, fz_vertex *v1, fz_vertex * */ if (painter->process) { - painter->process(painter->process_arg, v0, v1, v3); - painter->process(painter->process_arg, v3, v2, v1); + painter->process(ctx, painter->process_arg, v0, v1, v3); + painter->process(ctx, painter->process_arg, v3, v2, v1); } } static inline void -fz_prepare_color(fz_mesh_processor *painter, fz_vertex *v, float *c) +fz_prepare_color(fz_context *ctx, fz_mesh_processor *painter, fz_vertex *v, float *c) { if (painter->prepare) { - painter->prepare(painter->process_arg, v, c); + painter->prepare(ctx, painter->process_arg, v, c); } } static inline void -fz_prepare_vertex(fz_mesh_processor *painter, fz_vertex *v, const fz_matrix *ctm, float x, float y, float *c) +fz_prepare_vertex(fz_context *ctx, fz_mesh_processor *painter, fz_vertex *v, const fz_matrix *ctm, float x, float y, float *c) { fz_transform_point_xy(&v->p, ctm, x, y); if (painter->prepare) { - painter->prepare(painter->process_arg, v, c); + painter->prepare(ctx, painter->process_arg, v, c); } } @@ -86,19 +96,19 @@ fz_process_mesh_type1(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz x = x0; - fz_prepare_vertex(painter, &v[0], &local_ctm, x, y, p); + fz_prepare_vertex(ctx, painter, &v[0], &local_ctm, x, y, p); p += n; - fz_prepare_vertex(painter, &v[1], &local_ctm, x, yn, p + xdivs * n); + fz_prepare_vertex(ctx, painter, &v[1], &local_ctm, x, yn, p + xdivs * n); for (xx = 0; xx < xdivs; xx++) { x = x0 + (x1 - x0) * (xx + 1) / xdivs; - fz_prepare_vertex(painter, &vn[0], &local_ctm, x, y, p); + fz_prepare_vertex(ctx, painter, &vn[0], &local_ctm, x, y, p); p += n; - fz_prepare_vertex(painter, &vn[1], &local_ctm, x, yn, p + xdivs * n); + fz_prepare_vertex(ctx, painter, &vn[1], &local_ctm, x, yn, p + xdivs * n); - paint_quad(painter, &v[0], &vn[0], &vn[1], &v[1]); + paint_quad(ctx, painter, &v[0], &vn[0], &vn[1], &v[1]); SWAP(v,vn); } y = yn; @@ -142,42 +152,42 @@ fz_process_mesh_type2(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz v2.p = fz_point_on_circle(p0, -HUGENUM, theta); v3.p = fz_point_on_circle(p1, -HUGENUM, theta); - fz_prepare_color(painter, &v0, &zero); - fz_prepare_color(painter, &v1, &one); - fz_prepare_color(painter, &v2, &zero); - fz_prepare_color(painter, &v3, &one); + fz_prepare_color(ctx, painter, &v0, &zero); + fz_prepare_color(ctx, painter, &v1, &one); + fz_prepare_color(ctx, painter, &v2, &zero); + fz_prepare_color(ctx, painter, &v3, &one); - paint_quad(painter, &v0, &v2, &v3, &v1); + paint_quad(ctx, painter, &v0, &v2, &v3, &v1); if (shade->u.l_or_r.extend[0]) { e0.p.x = v0.p.x - (p1.x - p0.x) * HUGENUM; e0.p.y = v0.p.y - (p1.y - p0.y) * HUGENUM; - fz_prepare_color(painter, &e0, &zero); + fz_prepare_color(ctx, painter, &e0, &zero); e1.p.x = v2.p.x - (p1.x - p0.x) * HUGENUM; e1.p.y = v2.p.y - (p1.y - p0.y) * HUGENUM; - fz_prepare_color(painter, &e1, &zero); + fz_prepare_color(ctx, painter, &e1, &zero); - paint_quad(painter, &e0, &v0, &v2, &e1); + paint_quad(ctx, painter, &e0, &v0, &v2, &e1); } if (shade->u.l_or_r.extend[1]) { e0.p.x = v1.p.x + (p1.x - p0.x) * HUGENUM; e0.p.y = v1.p.y + (p1.y - p0.y) * HUGENUM; - fz_prepare_color(painter, &e0, &one); + fz_prepare_color(ctx, painter, &e0, &one); e1.p.x = v3.p.x + (p1.x - p0.x) * HUGENUM; e1.p.y = v3.p.y + (p1.y - p0.y) * HUGENUM; - fz_prepare_color(painter, &e1, &one); + fz_prepare_color(ctx, painter, &e1, &one); - paint_quad(painter, &e0, &v1, &v3, &e1); + paint_quad(ctx, painter, &e0, &v1, &v3, &e1); } } static void -fz_paint_annulus(const fz_matrix *ctm, +fz_paint_annulus(fz_context *ctx, const fz_matrix *ctm, fz_point p0, float r0, float c0, fz_point p1, float r1, float c1, int count, @@ -213,17 +223,17 @@ fz_paint_annulus(const fz_matrix *ctm, fz_transform_point(&b2.p, ctm); fz_transform_point(&b3.p, ctm); - fz_prepare_color(painter, &t0, &c0); - fz_prepare_color(painter, &t1, &c0); - fz_prepare_color(painter, &t2, &c1); - fz_prepare_color(painter, &t3, &c1); - fz_prepare_color(painter, &b0, &c0); - fz_prepare_color(painter, &b1, &c0); - fz_prepare_color(painter, &b2, &c1); - fz_prepare_color(painter, &b3, &c1); + fz_prepare_color(ctx, painter, &t0, &c0); + fz_prepare_color(ctx, painter, &t1, &c0); + fz_prepare_color(ctx, painter, &t2, &c1); + fz_prepare_color(ctx, painter, &t3, &c1); + fz_prepare_color(ctx, painter, &b0, &c0); + fz_prepare_color(ctx, painter, &b1, &c0); + fz_prepare_color(ctx, painter, &b2, &c1); + fz_prepare_color(ctx, painter, &b3, &c1); - paint_quad(painter, &t0, &t2, &t3, &t1); - paint_quad(painter, &b0, &b2, &b3, &b1); + paint_quad(ctx, painter, &t0, &t2, &t3, &t1); + paint_quad(ctx, painter, &b0, &b2, &b3, &b1); a = b; } @@ -264,10 +274,10 @@ fz_process_mesh_type3(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz e.y = p0.y + (p1.y - p0.y) * rs; er = r0 + (r1 - r0) * rs; - fz_paint_annulus(ctm, e, er, 0, p0, r0, 0, count, painter); + fz_paint_annulus(ctx, ctm, e, er, 0, p0, r0, 0, count, painter); } - fz_paint_annulus(ctm, p0, r0, 0, p1, r1, 1, count, painter); + fz_paint_annulus(ctx, ctm, p0, r0, 0, p1, r1, 1, count, painter); if (shade->u.l_or_r.extend[1]) { @@ -280,15 +290,15 @@ fz_process_mesh_type3(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz e.y = p1.y + (p0.y - p1.y) * rs; er = r1 + (r0 - r1) * rs; - fz_paint_annulus(ctm, p1, r1, 1, e, er, 1, count, painter); + fz_paint_annulus(ctx, ctm, p1, r1, 1, e, er, 1, count, painter); } } -static inline float read_sample(fz_stream *stream, int bits, float min, float max) +static inline float read_sample(fz_context *ctx, fz_stream *stream, int bits, float min, float max) { /* we use pow(2,x) because (1<<x) would overflow the math on 32-bit samples */ float bitscale = 1 / (powf(2, bits) - 1); - return min + fz_read_bits(stream, bits) * (max - min) * bitscale; + return min + fz_read_bits(ctx, stream, bits) * (max - min) * bitscale; } static void @@ -314,55 +324,55 @@ fz_process_mesh_type4(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz fz_try(ctx) { - while (!fz_is_eof_bits(stream)) + while (!fz_is_eof_bits(ctx, stream)) { - flag = fz_read_bits(stream, bpflag); - x = read_sample(stream, bpcoord, x0, x1); - y = read_sample(stream, bpcoord, y0, y1); + flag = fz_read_bits(ctx, stream, bpflag); + x = read_sample(ctx, stream, bpcoord, x0, x1); + y = read_sample(ctx, stream, bpcoord, y0, y1); for (i = 0; i < ncomp; i++) - c[i] = read_sample(stream, bpcomp, c0[i], c1[i]); - fz_prepare_vertex(painter, vd, ctm, x, y, c); + c[i] = read_sample(ctx, stream, bpcomp, c0[i], c1[i]); + fz_prepare_vertex(ctx, painter, vd, ctm, x, y, c); switch (flag) { case 0: /* start new triangle */ SWAP(va, vd); - fz_read_bits(stream, bpflag); - x = read_sample(stream, bpcoord, x0, x1); - y = read_sample(stream, bpcoord, y0, y1); + fz_read_bits(ctx, stream, bpflag); + x = read_sample(ctx, stream, bpcoord, x0, x1); + y = read_sample(ctx, stream, bpcoord, y0, y1); for (i = 0; i < ncomp; i++) - c[i] = read_sample(stream, bpcomp, c0[i], c1[i]); - fz_prepare_vertex(painter, vb, ctm, x, y, c); + c[i] = read_sample(ctx, stream, bpcomp, c0[i], c1[i]); + fz_prepare_vertex(ctx, painter, vb, ctm, x, y, c); - fz_read_bits(stream, bpflag); - x = read_sample(stream, bpcoord, x0, x1); - y = read_sample(stream, bpcoord, y0, y1); + fz_read_bits(ctx, stream, bpflag); + x = read_sample(ctx, stream, bpcoord, x0, x1); + y = read_sample(ctx, stream, bpcoord, y0, y1); for (i = 0; i < ncomp; i++) - c[i] = read_sample(stream, bpcomp, c0[i], c1[i]); - fz_prepare_vertex(painter, vc, ctm, x, y, c); + c[i] = read_sample(ctx, stream, bpcomp, c0[i], c1[i]); + fz_prepare_vertex(ctx, painter, vc, ctm, x, y, c); - paint_tri(painter, va, vb, vc); + paint_tri(ctx, painter, va, vb, vc); break; case 1: /* Vb, Vc, Vd */ SWAP(va, vb); SWAP(vb, vc); SWAP(vc, vd); - paint_tri(painter, va, vb, vc); + paint_tri(ctx, painter, va, vb, vc); break; case 2: /* Va, Vc, Vd */ SWAP(vb, vc); SWAP(vc, vd); - paint_tri(painter, va, vb, vc); + paint_tri(ctx, painter, va, vb, vc); break; } } } fz_always(ctx) { - fz_drop_stream(stream); + fz_drop_stream(ctx, stream); } fz_catch(ctx) { @@ -399,20 +409,20 @@ fz_process_mesh_type5(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz buf = fz_malloc_array(ctx, vprow, sizeof(fz_vertex)); first = 1; - while (!fz_is_eof_bits(stream)) + while (!fz_is_eof_bits(ctx, stream)) { for (i = 0; i < vprow; i++) { - x = read_sample(stream, bpcoord, x0, x1); - y = read_sample(stream, bpcoord, y0, y1); + x = read_sample(ctx, stream, bpcoord, x0, x1); + y = read_sample(ctx, stream, bpcoord, y0, y1); for (k = 0; k < ncomp; k++) - c[k] = read_sample(stream, bpcomp, c0[k], c1[k]); - fz_prepare_vertex(painter, &buf[i], ctm, x, y, c); + c[k] = read_sample(ctx, stream, bpcomp, c0[k], c1[k]); + fz_prepare_vertex(ctx, painter, &buf[i], ctm, x, y, c); } if (!first) for (i = 0; i < vprow - 1; i++) - paint_quad(painter, &ref[i], &ref[i+1], &buf[i+1], &buf[i]); + paint_quad(ctx, painter, &ref[i], &ref[i+1], &buf[i+1], &buf[i]); SWAP(ref,buf); first = 0; @@ -422,7 +432,7 @@ fz_process_mesh_type5(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz { fz_free(ctx, ref); fz_free(ctx, buf); - fz_drop_stream(stream); + fz_drop_stream(ctx, stream); } fz_catch(ctx) { @@ -441,7 +451,7 @@ struct tensor_patch_s }; static void -triangulate_patch(fz_mesh_processor *painter, tensor_patch p) +triangulate_patch(fz_context *ctx, fz_mesh_processor *painter, tensor_patch p) { fz_vertex v0, v1, v2, v3; @@ -450,12 +460,12 @@ triangulate_patch(fz_mesh_processor *painter, tensor_patch p) v2.p = p.pole[3][3]; v3.p = p.pole[3][0]; - fz_prepare_color(painter, &v0, p.color[0]); - fz_prepare_color(painter, &v1, p.color[1]); - fz_prepare_color(painter, &v2, p.color[2]); - fz_prepare_color(painter, &v3, p.color[3]); + fz_prepare_color(ctx, painter, &v0, p.color[0]); + fz_prepare_color(ctx, painter, &v1, p.color[1]); + fz_prepare_color(ctx, painter, &v2, p.color[2]); + fz_prepare_color(ctx, painter, &v3, p.color[3]); - paint_quad(painter, &v0, &v1, &v2, &v3); + paint_quad(ctx, painter, &v0, &v1, &v2, &v3); } static inline void midcolor(float *c, float *c1, float *c2, int n) @@ -526,7 +536,7 @@ split_stripe(tensor_patch *p, tensor_patch *s0, tensor_patch *s1, int n) } static void -draw_stripe(fz_mesh_processor *painter, tensor_patch *p, int depth) +draw_stripe(fz_context *ctx, fz_mesh_processor *painter, tensor_patch *p, int depth) { tensor_patch s0, s1; @@ -537,14 +547,14 @@ draw_stripe(fz_mesh_processor *painter, tensor_patch *p, int depth) if (depth == 0) { /* if no more subdividing, draw two new patches... */ - triangulate_patch(painter, s1); - triangulate_patch(painter, s0); + triangulate_patch(ctx, painter, s1); + triangulate_patch(ctx, painter, s0); } else { /* ...otherwise, continue subdividing. */ - draw_stripe(painter, &s1, depth); - draw_stripe(painter, &s0, depth); + draw_stripe(ctx, painter, &s1, depth); + draw_stripe(ctx, painter, &s0, depth); } } @@ -573,7 +583,7 @@ split_patch(tensor_patch *p, tensor_patch *s0, tensor_patch *s1, int n) } static void -draw_patch(fz_mesh_processor *painter, tensor_patch *p, int depth, int origdepth) +draw_patch(fz_context *ctx, fz_mesh_processor *painter, tensor_patch *p, int depth, int origdepth) { tensor_patch s0, s1; @@ -584,14 +594,14 @@ draw_patch(fz_mesh_processor *painter, tensor_patch *p, int depth, int origdepth if (depth == 0) { /* if no more subdividing, draw two new patches... */ - draw_stripe(painter, &s0, origdepth); - draw_stripe(painter, &s1, origdepth); + draw_stripe(ctx, painter, &s0, origdepth); + draw_stripe(ctx, painter, &s1, origdepth); } else { /* ...otherwise, continue subdividing. */ - draw_patch(painter, &s0, depth, origdepth); - draw_patch(painter, &s1, depth, origdepth); + draw_patch(ctx, painter, &s0, depth, origdepth); + draw_patch(ctx, painter, &s1, depth, origdepth); } } @@ -708,7 +718,7 @@ fz_process_mesh_type6(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz { float (*prevc)[FZ_MAX_COLORS] = NULL; fz_point *prevp = NULL; - while (!fz_is_eof_bits(stream)) + while (!fz_is_eof_bits(ctx, stream)) { float (*c)[FZ_MAX_COLORS] = color_storage[store]; fz_point *v = point_storage[store]; @@ -717,7 +727,7 @@ fz_process_mesh_type6(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz int flag; tensor_patch patch; - flag = fz_read_bits(stream, bpflag); + flag = fz_read_bits(ctx, stream, bpflag); if (flag == 0) { @@ -732,15 +742,15 @@ fz_process_mesh_type6(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz for (i = startpt; i < 12; i++) { - v[i].x = read_sample(stream, bpcoord, x0, x1); - v[i].y = read_sample(stream, bpcoord, y0, y1); + v[i].x = read_sample(ctx, stream, bpcoord, x0, x1); + v[i].y = read_sample(ctx, stream, bpcoord, y0, y1); fz_transform_point(&v[i], ctm); } for (i = startcolor; i < 4; i++) { for (k = 0; k < ncomp; k++) - c[i][k] = read_sample(stream, bpcomp, c0[k], c1[k]); + c[i][k] = read_sample(ctx, stream, bpcomp, c0[k], c1[k]); } if (flag == 0) @@ -781,7 +791,7 @@ fz_process_mesh_type6(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz for (i = 0; i < 4; i++) memcpy(patch.color[i], c[i], ncomp * sizeof(float)); - draw_patch(painter, &patch, SUBDIV, SUBDIV); + draw_patch(ctx, painter, &patch, SUBDIV, SUBDIV); prevp = v; prevc = c; @@ -790,7 +800,7 @@ fz_process_mesh_type6(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz } fz_always(ctx) { - fz_drop_stream(stream); + fz_drop_stream(ctx, stream); } fz_catch(ctx) { @@ -821,7 +831,7 @@ fz_process_mesh_type7(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz fz_try(ctx) { - while (!fz_is_eof_bits(stream)) + while (!fz_is_eof_bits(ctx, stream)) { float (*c)[FZ_MAX_COLORS] = color_storage[store]; fz_point *v = point_storage[store]; @@ -830,7 +840,7 @@ fz_process_mesh_type7(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz int flag; tensor_patch patch; - flag = fz_read_bits(stream, bpflag); + flag = fz_read_bits(ctx, stream, bpflag); if (flag == 0) { @@ -845,15 +855,15 @@ fz_process_mesh_type7(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz for (i = startpt; i < 16; i++) { - v[i].x = read_sample(stream, bpcoord, x0, x1); - v[i].y = read_sample(stream, bpcoord, y0, y1); + v[i].x = read_sample(ctx, stream, bpcoord, x0, x1); + v[i].y = read_sample(ctx, stream, bpcoord, y0, y1); fz_transform_point(&v[i], ctm); } for (i = startcolor; i < 4; i++) { for (k = 0; k < ncomp; k++) - c[i][k] = read_sample(stream, bpcomp, c0[k], c1[k]); + c[i][k] = read_sample(ctx, stream, bpcomp, c0[k], c1[k]); } if (flag == 0) @@ -894,7 +904,7 @@ fz_process_mesh_type7(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz for (i = 0; i < 4; i++) memcpy(patch.color[i], c[i], ncomp * sizeof(float)); - draw_patch(painter, &patch, SUBDIV, SUBDIV); + draw_patch(ctx, painter, &patch, SUBDIV, SUBDIV); prevp = v; prevc = c; @@ -903,7 +913,7 @@ fz_process_mesh_type7(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz } fz_always(ctx) { - fz_drop_stream(stream); + fz_drop_stream(ctx, stream); } fz_catch(ctx) { @@ -917,7 +927,6 @@ fz_process_mesh(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, { fz_mesh_processor painter; - painter.ctx = ctx; painter.shade = shade; painter.prepare = prepare; painter.process = process; diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c index f963eb19..dd1249c8 100644 --- a/source/fitz/stext-device.c +++ b/source/fitz/stext-device.c @@ -47,7 +47,7 @@ add_point_to_rect(fz_rect *a, const fz_point *p) } fz_rect * -fz_text_char_bbox(fz_rect *bbox, fz_text_span *span, int i) +fz_text_char_bbox(fz_context *ctx, fz_rect *bbox, fz_text_span *span, int i) { fz_point a, d; const fz_point *max; @@ -112,7 +112,6 @@ add_bbox_to_span(fz_text_span *span) struct span_soup_s { - fz_context *ctx; int len, cap; fz_text_span **spans; }; @@ -121,7 +120,6 @@ static span_soup * new_span_soup(fz_context *ctx) { span_soup *soup = fz_malloc_struct(ctx, span_soup); - soup->ctx = ctx; soup->len = 0; soup->cap = 0; soup->spans = NULL; @@ -129,7 +127,7 @@ new_span_soup(fz_context *ctx) } static void -free_span_soup(span_soup *soup) +free_span_soup(fz_context *ctx, span_soup *soup) { int i; @@ -137,21 +135,21 @@ free_span_soup(span_soup *soup) return; for (i = 0; i < soup->len; i++) { - fz_free(soup->ctx, soup->spans[i]); + fz_free(ctx, soup->spans[i]); } - fz_free(soup->ctx, soup->spans); - fz_free(soup->ctx, soup); + fz_free(ctx, soup->spans); + fz_free(ctx, soup); } static void -add_span_to_soup(span_soup *soup, fz_text_span *span) +add_span_to_soup(fz_context *ctx, span_soup *soup, fz_text_span *span) { if (span == NULL) return; if (soup->len == soup->cap) { int newcap = (soup->cap ? soup->cap * 2 : 16); - soup->spans = fz_resize_array(soup->ctx, soup->spans, newcap, sizeof(*soup->spans)); + soup->spans = fz_resize_array(ctx, soup->spans, newcap, sizeof(*soup->spans)); soup->cap = newcap; } add_bbox_to_span(span); @@ -638,7 +636,7 @@ fz_add_text_char_imp(fz_context *ctx, fz_text_device *dev, fz_text_style *style, if (can_append == 0) { /* Start a new span */ - add_span_to_soup(dev->spans, dev->cur_span); + add_span_to_soup(ctx, dev->spans, dev->cur_span); dev->cur_span = NULL; dev->cur_span = fz_new_text_span(ctx, &p, wmode, trm); dev->cur_span->spacing = 0; @@ -787,60 +785,59 @@ fz_text_extract(fz_context *ctx, fz_text_device *dev, fz_text *text, const fz_ma } static void -fz_text_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +fz_text_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_text_device *tdev = dev->user; fz_text_style *style; - style = fz_lookup_text_style(dev->ctx, tdev->sheet, text, ctm, colorspace, color, alpha, NULL); - fz_text_extract(dev->ctx, tdev, text, ctm, style); + style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, colorspace, color, alpha, NULL); + fz_text_extract(ctx, tdev, text, ctm, style); } static void -fz_text_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_text_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { fz_text_device *tdev = dev->user; fz_text_style *style; - style = fz_lookup_text_style(dev->ctx, tdev->sheet, text, ctm, colorspace, color, alpha, stroke); - fz_text_extract(dev->ctx, tdev, text, ctm, style); + style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, colorspace, color, alpha, stroke); + fz_text_extract(ctx, tdev, text, ctm, style); } static void -fz_text_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) +fz_text_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { fz_text_device *tdev = dev->user; fz_text_style *style; - style = fz_lookup_text_style(dev->ctx, tdev->sheet, text, ctm, NULL, NULL, 0, NULL); - fz_text_extract(dev->ctx, tdev, text, ctm, style); + style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, NULL, NULL, 0, NULL); + fz_text_extract(ctx, tdev, text, ctm, style); } static void -fz_text_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_text_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { fz_text_device *tdev = dev->user; fz_text_style *style; - style = fz_lookup_text_style(dev->ctx, tdev->sheet, text, ctm, NULL, NULL, 0, stroke); - fz_text_extract(dev->ctx, tdev, text, ctm, style); + style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, NULL, NULL, 0, stroke); + fz_text_extract(ctx, tdev, text, ctm, style); } static void -fz_text_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_text_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { fz_text_device *tdev = dev->user; fz_text_style *style; - style = fz_lookup_text_style(dev->ctx, tdev->sheet, text, ctm, NULL, NULL, 0, NULL); - fz_text_extract(dev->ctx, tdev, text, ctm, style); + style = fz_lookup_text_style(ctx, tdev->sheet, text, ctm, NULL, NULL, 0, NULL); + fz_text_extract(ctx, tdev, text, ctm, style); } static void -fz_text_fill_image_mask(fz_device *dev, fz_image *img, const fz_matrix *ctm, +fz_text_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *img, const fz_matrix *ctm, fz_colorspace *cspace, float *color, float alpha) { fz_text_device *tdev = dev->user; fz_text_page *page = tdev->page; fz_image_block *block; - fz_context *ctx = dev->ctx; /* If the alpha is less than 50% then it's probably a watermark or * effect or something. Skip it */ @@ -865,9 +862,9 @@ fz_text_fill_image_mask(fz_device *dev, fz_image *img, const fz_matrix *ctm, } static void -fz_text_fill_image(fz_device *dev, fz_image *img, const fz_matrix *ctm, float alpha) +fz_text_fill_image(fz_context *ctx, fz_device *dev, fz_image *img, const fz_matrix *ctm, float alpha) { - fz_text_fill_image_mask(dev, img, ctm, NULL, NULL, alpha); + fz_text_fill_image_mask(ctx, dev, img, ctm, NULL, NULL, alpha); } static int @@ -957,9 +954,8 @@ fz_bidi_reorder_text_page(fz_context *ctx, fz_text_page *page) } static void -fz_text_begin_page(fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm) +fz_text_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm) { - fz_context *ctx = dev->ctx; fz_text_device *tdev = dev->user; if (tdev->page->len) @@ -975,16 +971,15 @@ fz_text_begin_page(fz_device *dev, const fz_rect *mediabox, const fz_matrix *ctm } static void -fz_text_end_page(fz_device *dev) +fz_text_end_page(fz_context *ctx, fz_device *dev) { - fz_context *ctx = dev->ctx; fz_text_device *tdev = dev->user; - add_span_to_soup(tdev->spans, tdev->cur_span); + add_span_to_soup(ctx, tdev->spans, tdev->cur_span); tdev->cur_span = NULL; strain_soup(ctx, tdev); - free_span_soup(tdev->spans); + free_span_soup(ctx, tdev->spans); tdev->spans = NULL; /* TODO: smart sorting of blocks in reading order */ @@ -994,11 +989,11 @@ fz_text_end_page(fz_device *dev) } static void -fz_text_drop_user(fz_device *dev) +fz_text_drop_user(fz_context *ctx, fz_device *dev) { fz_text_device *tdev = dev->user; - free_span_soup(tdev->spans); - fz_free(dev->ctx, tdev); + free_span_soup(ctx, tdev->spans); + fz_free(ctx, tdev); } fz_device * diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index 6ed595fc..f090020d 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -29,39 +29,39 @@ static int font_is_italic(fz_font *font) } static void -fz_print_style_begin(fz_output *out, fz_text_style *style) +fz_print_style_begin(fz_context *ctx, fz_output *out, fz_text_style *style) { int script = style->script; - fz_printf(out, "<span class=\"s%d\">", style->id); + fz_printf(ctx, out, "<span class=\"s%d\">", style->id); while (script-- > 0) - fz_printf(out, "<sup>"); + fz_printf(ctx, out, "<sup>"); while (++script < 0) - fz_printf(out, "<sub>"); + fz_printf(ctx, out, "<sub>"); } static void -fz_print_style_end(fz_output *out, fz_text_style *style) +fz_print_style_end(fz_context *ctx, fz_output *out, fz_text_style *style) { int script = style->script; while (script-- > 0) - fz_printf(out, "</sup>"); + fz_printf(ctx, out, "</sup>"); while (++script < 0) - fz_printf(out, "</sub>"); - fz_printf(out, "</span>"); + fz_printf(ctx, out, "</sub>"); + fz_printf(ctx, out, "</span>"); } static void -fz_print_style(fz_output *out, fz_text_style *style) +fz_print_style(fz_context *ctx, fz_output *out, fz_text_style *style) { char *s = strchr(style->font->name, '+'); s = s ? s + 1 : style->font->name; - fz_printf(out, "span.s%d{font-family:\"%s\";font-size:%gpt;", + fz_printf(ctx, out, "span.s%d{font-family:\"%s\";font-size:%gpt;", style->id, s, style->size); if (font_is_italic(style->font)) - fz_printf(out, "font-style:italic;"); + fz_printf(ctx, out, "font-style:italic;"); if (font_is_bold(style->font)) - fz_printf(out, "font-weight:bold;"); - fz_printf(out, "}\n"); + fz_printf(ctx, out, "font-weight:bold;"); + fz_printf(ctx, out, "}\n"); } void @@ -69,11 +69,11 @@ fz_print_text_sheet(fz_context *ctx, fz_output *out, fz_text_sheet *sheet) { fz_text_style *style; for (style = sheet->style; style; style = style->next) - fz_print_style(out, style); + fz_print_style(ctx, out, style); } static void -send_data_base64(fz_output *out, fz_buffer *buffer) +send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer) { int i, len; static const char set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -85,8 +85,8 @@ send_data_base64(fz_output *out, fz_buffer *buffer) int d = buffer->data[3*i+1]; int e = buffer->data[3*i+2]; if ((i & 15) == 0) - fz_printf(out, "\n"); - fz_printf(out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); + fz_printf(ctx, out, "\n"); + fz_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); } i *= 3; switch (buffer->len-i) @@ -95,13 +95,13 @@ send_data_base64(fz_output *out, fz_buffer *buffer) { int c = buffer->data[i]; int d = buffer->data[i+1]; - fz_printf(out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); + fz_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); break; } case 1: { int c = buffer->data[i]; - fz_printf(out, "%c%c==", set[c>>2], set[(c&3)<<4]); + fz_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); break; } default: @@ -119,7 +119,7 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) fz_text_span *span; void *last_region = NULL; - fz_printf(out, "<div class=\"page\">\n"); + fz_printf(ctx, out, "<div class=\"page\">\n"); for (block_n = 0; block_n < page->len; block_n++) { @@ -128,7 +128,7 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) case FZ_PAGE_BLOCK_TEXT: { fz_text_block * block = page->blocks[block_n].u.text; - fz_printf(out, "<div class=\"block\"><p>\n"); + fz_printf(ctx, out, "<div class=\"block\"><p>\n"); for (line_n = 0; line_n < block->len; line_n++) { int lastcol=-1; @@ -138,16 +138,16 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) if (line->region != last_region) { if (last_region) - fz_printf(out, "</div>"); - fz_printf(out, "<div class=\"metaline\">"); + fz_printf(ctx, out, "</div>"); + fz_printf(ctx, out, "<div class=\"metaline\">"); last_region = line->region; } - fz_printf(out, "<div class=\"line\""); + fz_printf(ctx, out, "<div class=\"line\""); #ifdef DEBUG_INTERNALS if (line->region) - fz_printf(out, " region=\"%x\"", line->region); + fz_printf(ctx, out, " region=\"%x\"", line->region); #endif - fz_printf(out, ">"); + fz_printf(ctx, out, ">"); for (span = line->first_span; span; span = span->next) { float size = fz_matrix_expansion(&span->transform); @@ -157,17 +157,17 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) { if (lastcol >= 0) { - fz_printf(out, "</div>"); + fz_printf(ctx, out, "</div>"); } /* If we skipped any columns then output some spacer spans */ while (lastcol < span->column-1) { - fz_printf(out, "<div class=\"cell\"></div>"); + fz_printf(ctx, out, "<div class=\"cell\"></div>"); lastcol++; } lastcol++; /* Now output the span to contain this entire column */ - fz_printf(out, "<div class=\"cell\" style=\""); + fz_printf(ctx, out, "<div class=\"cell\" style=\""); { fz_text_span *sn; for (sn = span->next; sn; sn = sn->next) @@ -175,103 +175,103 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) if (sn->column != lastcol) break; } - fz_printf(out, "width:%g%%;align:%s", span->column_width, (span->align == 0 ? "left" : (span->align == 1 ? "center" : "right"))); + fz_printf(ctx, out, "width:%g%%;align:%s", span->column_width, (span->align == 0 ? "left" : (span->align == 1 ? "center" : "right"))); } if (span->indent > 1) - fz_printf(out, ";padding-left:1em;text-indent:-1em"); + fz_printf(ctx, out, ";padding-left:1em;text-indent:-1em"); if (span->indent < -1) - fz_printf(out, ";text-indent:1em"); - fz_printf(out, "\">"); + fz_printf(ctx, out, ";text-indent:1em"); + fz_printf(ctx, out, "\">"); } #ifdef DEBUG_INTERNALS - fz_printf(out, "<span class=\"internal_span\""); + fz_printf(ctx, out, "<span class=\"internal_span\""); if (span->column) - fz_printf(out, " col=\"%x\"", span->column); - fz_printf(out, ">"); + fz_printf(ctx, out, " col=\"%x\"", span->column); + fz_printf(ctx, out, ">"); #endif if (span->spacing >= 1) - fz_printf(out, " "); + fz_printf(ctx, out, " "); if (base_offset > SUBSCRIPT_OFFSET) - fz_printf(out, "<sub>"); + fz_printf(ctx, out, "<sub>"); else if (base_offset < SUPERSCRIPT_OFFSET) - fz_printf(out, "<sup>"); + fz_printf(ctx, out, "<sup>"); for (ch_n = 0; ch_n < span->len; ch_n++) { fz_text_char *ch = &span->text[ch_n]; if (style != ch->style) { if (style) - fz_print_style_end(out, style); - fz_print_style_begin(out, ch->style); + fz_print_style_end(ctx, out, style); + fz_print_style_begin(ctx, out, ch->style); style = ch->style; } if (ch->c == '<') - fz_printf(out, "<"); + fz_printf(ctx, out, "<"); else if (ch->c == '>') - fz_printf(out, ">"); + fz_printf(ctx, out, ">"); else if (ch->c == '&') - fz_printf(out, "&"); + fz_printf(ctx, out, "&"); else if (ch->c >= 32 && ch->c <= 127) - fz_printf(out, "%c", ch->c); + fz_printf(ctx, out, "%c", ch->c); else - fz_printf(out, "&#x%x;", ch->c); + fz_printf(ctx, out, "&#x%x;", ch->c); } if (style) { - fz_print_style_end(out, style); + fz_print_style_end(ctx, out, style); style = NULL; } if (base_offset > SUBSCRIPT_OFFSET) - fz_printf(out, "</sub>"); + fz_printf(ctx, out, "</sub>"); else if (base_offset < SUPERSCRIPT_OFFSET) - fz_printf(out, "</sup>"); + fz_printf(ctx, out, "</sup>"); #ifdef DEBUG_INTERNALS - fz_printf(out, "</span>"); + fz_printf(ctx, out, "</span>"); #endif } /* Close our floating span */ - fz_printf(out, "</div>"); + fz_printf(ctx, out, "</div>"); /* Close the line */ - fz_printf(out, "</div>"); - fz_printf(out, "\n"); + fz_printf(ctx, out, "</div>"); + fz_printf(ctx, out, "\n"); } /* Close the metaline */ - fz_printf(out, "</div>"); + fz_printf(ctx, out, "</div>"); last_region = NULL; - fz_printf(out, "</p></div>\n"); + fz_printf(ctx, out, "</p></div>\n"); break; } case FZ_PAGE_BLOCK_IMAGE: { fz_image_block *image = page->blocks[block_n].u.image; - fz_printf(out, "<img width=%d height=%d src=\"data:", image->image->w, image->image->h); + fz_printf(ctx, out, "<img width=%d height=%d src=\"data:", image->image->w, image->image->h); switch (image->image->buffer == NULL ? FZ_IMAGE_JPX : image->image->buffer->params.type) { case FZ_IMAGE_JPEG: - fz_printf(out, "image/jpeg;base64,"); - send_data_base64(out, image->image->buffer->buffer); + fz_printf(ctx, out, "image/jpeg;base64,"); + send_data_base64(ctx, out, image->image->buffer->buffer); break; case FZ_IMAGE_PNG: - fz_printf(out, "image/png;base64,"); - send_data_base64(out, image->image->buffer->buffer); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, image->image->buffer->buffer); break; default: { fz_buffer *buf = fz_new_png_from_image(ctx, image->image, image->image->w, image->image->h); - fz_printf(out, "image/png;base64,"); - send_data_base64(out, buf); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(out, "\">\n"); + fz_printf(ctx, out, "\">\n"); break; } } } - fz_printf(out, "</div>\n"); + fz_printf(ctx, out, "</div>\n"); } void @@ -279,7 +279,7 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) { int block_n; - fz_printf(out, "<page width=\"%g\" height=\"%g\">\n", + fz_printf(ctx, out, "<page width=\"%g\" height=\"%g\">\n", page->mediabox.x1 - page->mediabox.x0, page->mediabox.y1 - page->mediabox.y0); @@ -293,12 +293,12 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) fz_text_line *line; char *s; - fz_printf(out, "<block bbox=\"%g %g %g %g\">\n", + fz_printf(ctx, out, "<block bbox=\"%g %g %g %g\">\n", block->bbox.x0, block->bbox.y0, block->bbox.x1, block->bbox.y1); for (line = block->lines; line < block->lines + block->len; line++) { fz_text_span *span; - fz_printf(out, "<line bbox=\"%g %g %g %g\">\n", + fz_printf(ctx, out, "<line bbox=\"%g %g %g %g\">\n", line->bbox.x0, line->bbox.y0, line->bbox.x1, line->bbox.y1); for (span = line->first_span; span; span = span->next) { @@ -311,43 +311,43 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) { if (style) { - fz_printf(out, "</span>\n"); + fz_printf(ctx, out, "</span>\n"); } style = ch->style; s = strchr(style->font->name, '+'); s = s ? s + 1 : style->font->name; - fz_printf(out, "<span bbox=\"%g %g %g %g\" font=\"%s\" size=\"%g\">\n", + fz_printf(ctx, out, "<span bbox=\"%g %g %g %g\" font=\"%s\" size=\"%g\">\n", span->bbox.x0, span->bbox.y0, span->bbox.x1, span->bbox.y1, s, style->size); } { fz_rect rect; - fz_text_char_bbox(&rect, span, char_num); - fz_printf(out, "<char bbox=\"%g %g %g %g\" x=\"%g\" y=\"%g\" c=\"", + fz_text_char_bbox(ctx, &rect, span, char_num); + fz_printf(ctx, out, "<char bbox=\"%g %g %g %g\" x=\"%g\" y=\"%g\" c=\"", rect.x0, rect.y0, rect.x1, rect.y1, ch->p.x, ch->p.y); } switch (ch->c) { - case '<': fz_printf(out, "<"); break; - case '>': fz_printf(out, ">"); break; - case '&': fz_printf(out, "&"); break; - case '"': fz_printf(out, """); break; - case '\'': fz_printf(out, "'"); break; + case '<': fz_printf(ctx, out, "<"); break; + case '>': fz_printf(ctx, out, ">"); break; + case '&': fz_printf(ctx, out, "&"); break; + case '"': fz_printf(ctx, out, """); break; + case '\'': fz_printf(ctx, out, "'"); break; default: if (ch->c >= 32 && ch->c <= 127) - fz_printf(out, "%c", ch->c); + fz_printf(ctx, out, "%c", ch->c); else - fz_printf(out, "&#x%x;", ch->c); + fz_printf(ctx, out, "&#x%x;", ch->c); break; } - fz_printf(out, "\"/>\n"); + fz_printf(ctx, out, "\"/>\n"); } if (style) - fz_printf(out, "</span>\n"); + fz_printf(ctx, out, "</span>\n"); } - fz_printf(out, "</line>\n"); + fz_printf(ctx, out, "</line>\n"); } - fz_printf(out, "</block>\n"); + fz_printf(ctx, out, "</block>\n"); break; } case FZ_PAGE_BLOCK_IMAGE: @@ -356,7 +356,7 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) } } } - fz_printf(out, "</page>\n"); + fz_printf(ctx, out, "</page>\n"); } void @@ -385,12 +385,12 @@ fz_print_text_page(fz_context *ctx, fz_output *out, fz_text_page *page) { n = fz_runetochar(utf, ch->c); for (i = 0; i < n; i++) - fz_printf(out, "%c", utf[i]); + fz_printf(ctx, out, "%c", utf[i]); } } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); break; } case FZ_PAGE_BLOCK_IMAGE: diff --git a/source/fitz/stext-search.c b/source/fitz/stext-search.c index 29f51e64..475c0c8a 100644 --- a/source/fitz/stext-search.c +++ b/source/fitz/stext-search.c @@ -14,7 +14,7 @@ static inline int iswhite(int c) return c == ' ' || c == '\r' || c == '\n' || c == '\t' || c == 0xA0 || c == 0x2028 || c == 0x2029; } -fz_char_and_box *fz_text_char_at(fz_char_and_box *cab, fz_text_page *page, int idx) +fz_char_and_box *fz_text_char_at(fz_context *ctx, fz_char_and_box *cab, fz_text_page *page, int idx) { int block_num; int ofs = 0; @@ -35,7 +35,7 @@ fz_char_and_box *fz_text_char_at(fz_char_and_box *cab, fz_text_page *page, int i if (idx < ofs + span->len) { cab->c = span->text[idx - ofs].c; - fz_text_char_bbox(&cab->bbox, span, idx - ofs); + fz_text_char_bbox(ctx, &cab->bbox, span, idx - ofs); return cab; } ofs += span->len; @@ -55,21 +55,21 @@ fz_char_and_box *fz_text_char_at(fz_char_and_box *cab, fz_text_page *page, int i return cab; } -static int charat(fz_text_page *page, int idx) +static int charat(fz_context *ctx, fz_text_page *page, int idx) { fz_char_and_box cab; - return fz_text_char_at(&cab, page, idx)->c; + return fz_text_char_at(ctx, &cab, page, idx)->c; } -static fz_rect *bboxat(fz_text_page *page, int idx, fz_rect *bbox) +static fz_rect *bboxat(fz_context *ctx, fz_text_page *page, int idx, fz_rect *bbox) { fz_char_and_box cab; /* FIXME: Nasty extra copy */ - *bbox = fz_text_char_at(&cab, page, idx)->bbox; + *bbox = fz_text_char_at(ctx, &cab, page, idx)->bbox; return bbox; } -static int textlen(fz_text_page *page) +static int textlen(fz_context *ctx, fz_text_page *page) { int len = 0; int block_num; @@ -95,21 +95,21 @@ static int textlen(fz_text_page *page) return len; } -static int match(fz_text_page *page, const char *s, int n) +static int match(fz_context *ctx, fz_text_page *page, const char *s, int n) { int orig = n; int c; while (*s) { s += fz_chartorune(&c, (char *)s); - if (iswhite(c) && iswhite(charat(page, n))) + if (iswhite(c) && iswhite(charat(ctx, page, n))) { const char *s_next; /* Skip over whitespace in the document */ do n++; - while (iswhite(charat(page, n))); + while (iswhite(charat(ctx, page, n))); /* Skip over multiple whitespace in the search string */ while (s_next = s + fz_chartorune(&c, (char *)s), iswhite(c)) @@ -117,7 +117,7 @@ static int match(fz_text_page *page, const char *s, int n) } else { - if (fz_tolower(c) != fz_tolower(charat(page, n))) + if (fz_tolower(c) != fz_tolower(charat(ctx, page, n))) return 0; n++; } @@ -134,17 +134,17 @@ fz_search_text_page(fz_context *ctx, fz_text_page *text, const char *needle, fz_ return 0; hit_count = 0; - len = textlen(text); + len = textlen(ctx, text); for (pos = 0; pos < len; pos++) { - n = match(text, needle, pos); + n = match(ctx, text, needle, pos); if (n) { fz_rect linebox = fz_empty_rect; for (i = 0; i < n; i++) { fz_rect charbox; - bboxat(text, pos + i, &charbox); + bboxat(ctx, text, pos + i, &charbox); if (!fz_is_empty_rect(&charbox)) { if (charbox.y0 != linebox.y0 || fz_abs(charbox.x0 - linebox.x1) > 5) @@ -195,7 +195,7 @@ fz_highlight_selection(fz_context *ctx, fz_text_page *page, fz_rect rect, fz_rec { for (i = 0; i < span->len; i++) { - fz_text_char_bbox(&charbox, span, i); + fz_text_char_bbox(ctx, &charbox, span, i); if (charbox.x1 >= x0 && charbox.x0 <= x1 && charbox.y1 >= y0 && charbox.y0 <= y1) { if (charbox.y0 != linebox.y0 || fz_abs(charbox.x0 - linebox.x1) > 5) @@ -256,7 +256,7 @@ fz_copy_selection(fz_context *ctx, fz_text_page *page, fz_rect rect) for (i = 0; i < span->len; i++) { - fz_text_char_bbox(&hitbox, span, i); + fz_text_char_bbox(ctx, &hitbox, span, i); c = span->text[i].c; if (c < 32) c = '?'; diff --git a/source/fitz/store.c b/source/fitz/store.c index 315f8e81..d4cafe15 100644 --- a/source/fitz/store.c +++ b/source/fitz/store.c @@ -114,7 +114,7 @@ evict(fz_context *ctx, fz_item *item) { fz_store_hash hash = { NULL }; hash.drop = item->val->drop; - if (item->type->make_hash_key(&hash, item->key)) + if (item->type->make_hash_key(ctx, &hash, item->key)) fz_hash_remove(ctx, store->hash, &hash); } fz_unlock(ctx, FZ_LOCK_ALLOC); @@ -251,7 +251,7 @@ fz_store_item(fz_context *ctx, void *key, void *val_, unsigned int itemsize, fz_ if (type->make_hash_key) { hash.drop = val->drop; - use_hash = type->make_hash_key(&hash, key); + use_hash = type->make_hash_key(ctx, &hash, key); } type->keep_key(ctx, key); @@ -363,7 +363,7 @@ fz_find_item(fz_context *ctx, fz_store_drop_fn *drop, void *key, fz_store_type * if (type->make_hash_key) { hash.drop = drop; - use_hash = type->make_hash_key(&hash, key); + use_hash = type->make_hash_key(ctx, &hash, key); } fz_lock(ctx, FZ_LOCK_ALLOC); @@ -377,7 +377,7 @@ fz_find_item(fz_context *ctx, fz_store_drop_fn *drop, void *key, fz_store_type * /* Others we have to hunt for slowly */ for (item = store->head; item; item = item->next) { - if (item->val->drop == drop && !type->cmp_key(item->key, key)) + if (item->val->drop == drop && !type->cmp_key(ctx, item->key, key)) break; } } @@ -411,7 +411,7 @@ fz_remove_item(fz_context *ctx, fz_store_drop_fn *drop, void *key, fz_store_type if (type->make_hash_key) { hash.drop = drop; - use_hash = type->make_hash_key(&hash, key); + use_hash = type->make_hash_key(ctx, &hash, key); } fz_lock(ctx, FZ_LOCK_ALLOC); @@ -426,7 +426,7 @@ fz_remove_item(fz_context *ctx, fz_store_drop_fn *drop, void *key, fz_store_type { /* Others we have to hunt for slowly */ for (item = store->head; item; item = item->next) - if (item->val->drop == drop && !type->cmp_key(item->key, key)) + if (item->val->drop == drop && !type->cmp_key(ctx, item->key, key)) break; } if (item) @@ -527,7 +527,7 @@ fz_print_store_locked(fz_context *ctx, FILE *out) next->val->refs++; fprintf(out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size); fz_unlock(ctx, FZ_LOCK_ALLOC); - item->type->debug(out, item->key); + item->type->debug(ctx, out, item->key); fprintf(out, " = %p\n", item->val); fflush(out); fz_lock(ctx, FZ_LOCK_ALLOC); diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c index c5808a73..fe8fc443 100644 --- a/source/fitz/stream-open.c +++ b/source/fitz/stream-open.c @@ -1,20 +1,7 @@ #include "mupdf/fitz.h" -void fz_rebind_stream(fz_stream *stm, fz_context *ctx) -{ - if (stm == NULL || stm->ctx == ctx) - return; - do { - stm->ctx = ctx; - stm = (stm->rebind == NULL ? NULL : stm->rebind(stm)); - } while (stm != NULL); -} - fz_stream * -fz_new_stream(fz_context *ctx, void *state, - fz_stream_next_fn *next, - fz_stream_close_fn *close, - fz_stream_rebind_fn *rebind) +fz_new_stream(fz_context *ctx, void *state, fz_stream_next_fn *next, fz_stream_close_fn *close) { fz_stream *stm; @@ -43,14 +30,12 @@ fz_new_stream(fz_context *ctx, void *state, stm->next = next; stm->close = close; stm->seek = NULL; - stm->rebind = rebind; - stm->ctx = ctx; return stm; } fz_stream * -fz_keep_stream(fz_stream *stm) +fz_keep_stream(fz_context *ctx, fz_stream *stm) { if (stm) stm->refs ++; @@ -58,7 +43,7 @@ fz_keep_stream(fz_stream *stm) } void -fz_drop_stream(fz_stream *stm) +fz_drop_stream(fz_context *ctx, fz_stream *stm) { if (!stm) return; @@ -66,8 +51,8 @@ fz_drop_stream(fz_stream *stm) if (stm->refs == 0) { if (stm->close) - stm->close(stm->ctx, stm->state); - fz_free(stm->ctx, stm); + stm->close(ctx, stm->state); + fz_free(ctx, stm); } } @@ -79,14 +64,14 @@ typedef struct fz_file_stream_s unsigned char buffer[4096]; } fz_file_stream; -static int next_file(fz_stream *stm, int n) +static int next_file(fz_context *ctx, fz_stream *stm, int n) { fz_file_stream *state = stm->state; /* n is only a hint, that we can safely ignore */ n = read(state->file, state->buffer, sizeof(state->buffer)); if (n < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); stm->rp = state->buffer; stm->wp = state->buffer + n; stm->pos += n; @@ -96,12 +81,12 @@ static int next_file(fz_stream *stm, int n) return *stm->rp++; } -static void seek_file(fz_stream *stm, int offset, int whence) +static void seek_file(fz_context *ctx, fz_stream *stm, int offset, int whence) { fz_file_stream *state = stm->state; int n = lseek(state->file, offset, whence); if (n < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "cannot lseek: %s", strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot lseek: %s", strerror(errno)); stm->pos = n; stm->rp = state->buffer; stm->wp = state->buffer; @@ -125,7 +110,7 @@ fz_open_fd(fz_context *ctx, int fd) fz_try(ctx) { - stm = fz_new_stream(ctx, state, next_file, close_file, NULL); + stm = fz_new_stream(ctx, state, next_file, close_file); } fz_catch(ctx) { @@ -173,12 +158,12 @@ fz_open_file_w(fz_context *ctx, const wchar_t *name) /* Memory stream */ -static int next_buffer(fz_stream *stm, int max) +static int next_buffer(fz_context *ctx, fz_stream *stm, int max) { return EOF; } -static void seek_buffer(fz_stream *stm, int offset, int whence) +static void seek_buffer(fz_context *ctx, fz_stream *stm, int offset, int whence) { int pos = stm->pos - (stm->wp - stm->rp); /* Convert to absolute pos */ @@ -211,7 +196,7 @@ fz_open_buffer(fz_context *ctx, fz_buffer *buf) fz_stream *stm; fz_keep_buffer(ctx, buf); - stm = fz_new_stream(ctx, buf, next_buffer, close_buffer, NULL); + stm = fz_new_stream(ctx, buf, next_buffer, close_buffer); stm->seek = seek_buffer; stm->rp = buf->data; @@ -227,7 +212,7 @@ fz_open_memory(fz_context *ctx, unsigned char *data, int len) { fz_stream *stm; - stm = fz_new_stream(ctx, NULL, next_buffer, close_buffer, NULL); + stm = fz_new_stream(ctx, NULL, next_buffer, close_buffer); stm->seek = seek_buffer; stm->rp = data; diff --git a/source/fitz/stream-prog.c b/source/fitz/stream-prog.c index 01f3e5ef..fbf42666 100644 --- a/source/fitz/stream-prog.c +++ b/source/fitz/stream-prog.c @@ -27,7 +27,7 @@ typedef struct prog_state unsigned char buffer[4096]; } prog_state; -static int next_prog(fz_stream *stm, int len) +static int next_prog(fz_context *ctx, fz_stream *stm, int len) { prog_state *ps = (prog_state *)stm->state; int n; @@ -50,14 +50,14 @@ static int next_prog(fz_stream *stm, int len) if (len <= 0) { show_progress(av, stm->pos); - fz_throw(stm->ctx, FZ_ERROR_TRYLATER, "Not enough data yet"); + fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data yet"); } } } n = (len > 0 ? read(ps->fd, buf, len) : 0); if (n < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); stm->rp = ps->buffer + stm->pos; stm->wp = ps->buffer + stm->pos + n; stm->pos += n; @@ -66,7 +66,7 @@ static int next_prog(fz_stream *stm, int len) return *stm->rp++; } -static void seek_prog(fz_stream *stm, int offset, int whence) +static void seek_prog(fz_context *ctx, fz_stream *stm, int offset, int whence) { prog_state *ps = (prog_state *)stm->state; int n; @@ -84,7 +84,7 @@ static void seek_prog(fz_stream *stm, int offset, int whence) if (whence == SEEK_END) { show_progress(ps->available, ps->length); - fz_throw(stm->ctx, FZ_ERROR_TRYLATER, "Not enough data to seek to end yet"); + fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data to seek to end yet"); } } if (whence == SEEK_CUR) @@ -94,7 +94,7 @@ static void seek_prog(fz_stream *stm, int offset, int whence) if (offset > ps->available) { show_progress(ps->available, offset); - fz_throw(stm->ctx, FZ_ERROR_TRYLATER, "Not enough data to seek (relatively) to offset yet"); + fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data to seek (relatively) to offset yet"); } } if (whence == SEEK_SET) @@ -102,13 +102,13 @@ static void seek_prog(fz_stream *stm, int offset, int whence) if (offset > ps->available) { show_progress(ps->available, offset); - fz_throw(stm->ctx, FZ_ERROR_TRYLATER, "Not enough data to seek to offset yet"); + fz_throw(ctx, FZ_ERROR_TRYLATER, "Not enough data to seek to offset yet"); } } n = lseek(ps->fd, offset, whence); if (n < 0) - fz_throw(stm->ctx, FZ_ERROR_GENERIC, "cannot lseek: %s", strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot lseek: %s", strerror(errno)); stm->pos = n; stm->wp = stm->rp; } @@ -122,7 +122,7 @@ static void close_prog(fz_context *ctx, void *state) fz_free(ctx, state); } -static int meta_prog(fz_stream *stm, int key, int size, void *ptr) +static int meta_prog(fz_context *ctx, fz_stream *stm, int key, int size, void *ptr) { prog_state *ps = (prog_state *)stm->state; switch(key) @@ -153,7 +153,7 @@ fz_open_fd_progressive(fz_context *ctx, int fd, int bps) fz_try(ctx) { - stm = fz_new_stream(ctx, state, next_prog, close_prog, NULL); + stm = fz_new_stream(ctx, state, next_prog, close_prog); } fz_catch(ctx) { diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index 49e1c1a3..75261ea5 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -3,14 +3,14 @@ #define MIN_BOMB (100 << 20) int -fz_read(fz_stream *stm, unsigned char *buf, int len) +fz_read(fz_context *ctx, fz_stream *stm, unsigned char *buf, int len) { int count, n; count = 0; do { - n = fz_available(stm, len); + n = fz_available(ctx, stm, len); if (n > len) n = len; if (n == 0) @@ -28,17 +28,16 @@ fz_read(fz_stream *stm, unsigned char *buf, int len) } fz_buffer * -fz_read_all(fz_stream *stm, int initial) +fz_read_all(fz_context *ctx, fz_stream *stm, int initial) { - return fz_read_best(stm, initial, NULL); + return fz_read_best(ctx, stm, initial, NULL); } fz_buffer * -fz_read_best(fz_stream *stm, int initial, int *truncated) +fz_read_best(fz_context *ctx, fz_stream *stm, int initial, int *truncated) { fz_buffer *buf = NULL; int n; - fz_context *ctx = stm->ctx; fz_var(buf); @@ -62,7 +61,7 @@ fz_read_best(fz_stream *stm, int initial, int *truncated) fz_throw(ctx, FZ_ERROR_GENERIC, "compression bomb detected"); } - n = fz_read(stm, buf->data + buf->len, buf->cap - buf->len); + n = fz_read(ctx, stm, buf->data + buf->len, buf->cap - buf->len); if (n == 0) break; @@ -91,19 +90,19 @@ fz_read_best(fz_stream *stm, int initial, int *truncated) } void -fz_read_line(fz_stream *stm, char *mem, int n) +fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, int n) { char *s = mem; int c = EOF; while (n > 1) { - c = fz_read_byte(stm); + c = fz_read_byte(ctx, stm); if (c == EOF) break; if (c == '\r') { - c = fz_peek_byte(stm); + c = fz_peek_byte(ctx, stm); if (c == '\n') - fz_read_byte(stm); + fz_read_byte(ctx, stm); break; } if (c == '\n') @@ -116,50 +115,50 @@ fz_read_line(fz_stream *stm, char *mem, int n) } int -fz_tell(fz_stream *stm) +fz_tell(fz_context *ctx, fz_stream *stm) { return stm->pos - (stm->wp - stm->rp); } void -fz_seek(fz_stream *stm, int offset, int whence) +fz_seek(fz_context *ctx, fz_stream *stm, int offset, int whence) { stm->avail = 0; /* Reset bit reading */ if (stm->seek) { if (whence == 1) { - offset = fz_tell(stm) + offset; + offset = fz_tell(ctx, stm) + offset; whence = 0; } - stm->seek(stm, offset, whence); + stm->seek(ctx, stm, offset, whence); stm->eof = 0; } else if (whence != 2) { if (whence == 0) - offset -= fz_tell(stm); + offset -= fz_tell(ctx, stm); if (offset < 0) - fz_warn(stm->ctx, "cannot seek backwards"); + fz_warn(ctx, "cannot seek backwards"); /* dog slow, but rare enough */ while (offset-- > 0) { - if (fz_read_byte(stm) == EOF) + if (fz_read_byte(ctx, stm) == EOF) { - fz_warn(stm->ctx, "seek failed"); + fz_warn(ctx, "seek failed"); break; } } } else - fz_warn(stm->ctx, "cannot seek"); + fz_warn(ctx, "cannot seek"); } -int fz_stream_meta(fz_stream *stm, int key, int size, void *ptr) +int fz_stream_meta(fz_context *ctx, fz_stream *stm, int key, int size, void *ptr) { if (!stm || !stm->meta) return -1; - return stm->meta(stm, key, size, ptr); + return stm->meta(ctx, stm, key, size, ptr); } fz_buffer * @@ -173,11 +172,11 @@ fz_read_file(fz_context *ctx, const char *filename) stm = fz_open_file(ctx, filename); fz_try(ctx) { - buf = fz_read_all(stm, 0); + buf = fz_read_all(ctx, stm, 0); } fz_always(ctx) { - fz_drop_stream(stm); + fz_drop_stream(ctx, stm); } fz_catch(ctx) { diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index b4e10fe4..29acc530 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -31,7 +31,6 @@ struct font_s struct svg_device_s { - fz_context *ctx; fz_output *out; fz_output *out_store; fz_output *defs; @@ -53,7 +52,7 @@ struct svg_device_s * so we have to delay definitions until after the symbol definition ends. */ static fz_output * -start_def(svg_device *sdev) +start_def(fz_context *ctx, svg_device *sdev) { sdev->def_count++; if (sdev->def_count == 2) @@ -61,8 +60,8 @@ start_def(svg_device *sdev) if (sdev->defs == NULL) { if (sdev->defs_buffer == NULL) - sdev->defs_buffer = fz_new_buffer(sdev->ctx, 1024); - sdev->defs = fz_new_output_with_buffer(sdev->ctx, sdev->defs_buffer); + sdev->defs_buffer = fz_new_buffer(ctx, 1024); + sdev->defs = fz_new_output_with_buffer(ctx, sdev->defs_buffer); } sdev->out = sdev->defs; } @@ -70,7 +69,7 @@ start_def(svg_device *sdev) } static fz_output * -end_def(svg_device *sdev) +end_def(fz_context *ctx, svg_device *sdev) { if (sdev->def_count > 0) sdev->def_count--; @@ -78,7 +77,7 @@ end_def(svg_device *sdev) sdev->out = sdev->out_store; if (sdev->def_count == 0 && sdev->defs_buffer != NULL) { - fz_write(sdev->out, sdev->defs_buffer->data, sdev->defs_buffer->len); + fz_write(ctx, sdev->out, sdev->defs_buffer->data, sdev->defs_buffer->len); sdev->defs_buffer->len = 0; } return sdev->out; @@ -87,12 +86,12 @@ end_def(svg_device *sdev) /* Helper functions */ static void -svg_dev_path(svg_device *sdev, fz_path *path) +svg_dev_path(fz_context *ctx, svg_device *sdev, fz_path *path) { fz_output *out = sdev->out; float x, y; int i, k; - fz_printf(out, " d=\""); + fz_printf(ctx, out, " d=\""); for (i = 0, k = 0; i < path->cmd_len; i++) { switch (path->cmds[i]) @@ -100,46 +99,46 @@ svg_dev_path(svg_device *sdev, fz_path *path) case FZ_MOVETO: x = path->coords[k++]; y = path->coords[k++]; - fz_printf(out, "M %g %g ", x, y); + fz_printf(ctx, out, "M %g %g ", x, y); break; case FZ_LINETO: x = path->coords[k++]; y = path->coords[k++]; - fz_printf(out, "L %g %g ", x, y); + fz_printf(ctx, out, "L %g %g ", x, y); break; case FZ_CURVETO: x = path->coords[k++]; y = path->coords[k++]; - fz_printf(out, "C %g %g ", x, y); + fz_printf(ctx, out, "C %g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fz_printf(out, "%g %g ", x, y); + fz_printf(ctx, out, "%g %g ", x, y); x = path->coords[k++]; y = path->coords[k++]; - fz_printf(out, "%g %g ", x, y); + fz_printf(ctx, out, "%g %g ", x, y); break; case FZ_CLOSE_PATH: - fz_printf(out, "Z "); + fz_printf(ctx, out, "Z "); break; } } - fz_printf(out, "\""); + fz_printf(ctx, out, "\""); } static void -svg_dev_ctm(svg_device *sdev, const fz_matrix *ctm) +svg_dev_ctm(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm) { fz_output *out = sdev->out; if (ctm->a != 1.0 || ctm->b != 0 || ctm->c != 0 || ctm->d != 1.0 || ctm->e != 0 || ctm->f != 0) { - fz_printf(out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", + fz_printf(ctx, out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", ctm->a, ctm->b, ctm->c, ctm->d, ctm->e, ctm->f); } } static void -svg_dev_stroke_state(svg_device *sdev, fz_stroke_state *stroke_state, const fz_matrix *ctm) +svg_dev_stroke_state(fz_context *ctx, svg_device *sdev, fz_stroke_state *stroke_state, const fz_matrix *ctm) { fz_output *out = sdev->out; float exp; @@ -148,31 +147,30 @@ svg_dev_stroke_state(svg_device *sdev, fz_stroke_state *stroke_state, const fz_m if (exp == 0) exp = 1; - fz_printf(out, " stroke-width=\"%g\"", stroke_state->linewidth/exp); - fz_printf(out, " stroke-linecap=\"%s\"", + fz_printf(ctx, out, " stroke-width=\"%g\"", stroke_state->linewidth/exp); + fz_printf(ctx, out, " stroke-linecap=\"%s\"", (stroke_state->start_cap == FZ_LINECAP_SQUARE ? "square" : (stroke_state->start_cap == FZ_LINECAP_ROUND ? "round" : "butt"))); if (stroke_state->dash_len != 0) { int i; - fz_printf(out, " stroke-dasharray="); + fz_printf(ctx, out, " stroke-dasharray="); for (i = 0; i < stroke_state->dash_len; i++) - fz_printf(out, "%c%g", (i == 0 ? '\"' : ','), stroke_state->dash_list[i]); - fz_printf(out, "\""); + fz_printf(ctx, out, "%c%g", (i == 0 ? '\"' : ','), stroke_state->dash_list[i]); + fz_printf(ctx, out, "\""); if (stroke_state->dash_phase != 0) - fz_printf(out, " stroke-dashoffset=\"%g\"", stroke_state->dash_phase); + fz_printf(ctx, out, " stroke-dashoffset=\"%g\"", stroke_state->dash_phase); } if (stroke_state->linejoin == FZ_LINEJOIN_MITER || stroke_state->linejoin == FZ_LINEJOIN_MITER_XPS) - fz_printf(out, " stroke-miterlimit=\"%g\"", stroke_state->miterlimit); - fz_printf(out, " stroke-linejoin=\"%s\"", + fz_printf(ctx, out, " stroke-miterlimit=\"%g\"", stroke_state->miterlimit); + fz_printf(ctx, out, " stroke-linejoin=\"%s\"", (stroke_state->linejoin == FZ_LINEJOIN_BEVEL ? "bevel" : (stroke_state->linejoin == FZ_LINEJOIN_ROUND ? "round" : "miter"))); } static void -svg_dev_fill_color(svg_device *sdev, fz_colorspace *colorspace, float *color, float alpha) +svg_dev_fill_color(fz_context *ctx, svg_device *sdev, fz_colorspace *colorspace, float *color, float alpha) { - fz_context *ctx = sdev->ctx; fz_output *out = sdev->out; float rgb[FZ_MAX_COLORS]; @@ -188,15 +186,14 @@ svg_dev_fill_color(svg_device *sdev, fz_colorspace *colorspace, float *color, fl /* don't send a fill, as it will be assumed to be black */ } else - fz_printf(out, " fill=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); + fz_printf(ctx, out, " fill=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); if (alpha != 1) - fz_printf(out, " fill-opacity=\"%g\"", alpha); + fz_printf(ctx, out, " fill-opacity=\"%g\"", alpha); } static void -svg_dev_stroke_color(svg_device *sdev, fz_colorspace *colorspace, float *color, float alpha) +svg_dev_stroke_color(fz_context *ctx, svg_device *sdev, fz_colorspace *colorspace, float *color, float alpha) { - fz_context *ctx = sdev->ctx; fz_output *out = sdev->out; float rgb[FZ_MAX_COLORS]; @@ -207,9 +204,9 @@ svg_dev_stroke_color(svg_device *sdev, fz_colorspace *colorspace, float *color, color = rgb; } - fz_printf(out, " fill=\"none\" stroke=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); + fz_printf(ctx, out, " fill=\"none\" stroke=\"rgb(%d,%d,%d)\"", (int)(255*color[0] + 0.5), (int)(255*color[1] + 0.5), (int)(255*color[2]+0.5)); if (alpha != 1) - fz_printf(out, " stroke-opacity=\"%g\"", alpha); + fz_printf(ctx, out, " stroke-opacity=\"%g\"", alpha); } static inline int @@ -222,9 +219,10 @@ is_xml_wspace(int c) } static void -svg_dev_text(svg_device *sdev, const fz_matrix *ctm, fz_text *text) +svg_dev_text(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, fz_text *text) { fz_output *out = sdev->out; + int i; fz_matrix inverse; fz_matrix local_trm; @@ -242,10 +240,10 @@ svg_dev_text(svg_device *sdev, const fz_matrix *ctm, fz_text *text) fz_invert_matrix(&inverse, &local_trm); fz_concat(&local_trm, &local_trm, ctm); - fz_printf(out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", + fz_printf(ctx, out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", local_trm.a, local_trm.b, local_trm.c, local_trm.d, local_trm.e, local_trm.f); - fz_printf(out, " font-size=\"%g\"", size); - fz_printf(out, " font-family=\"%s\"", text->font->name); + fz_printf(ctx, out, " font-size=\"%g\"", size); + fz_printf(ctx, out, " font-family=\"%s\"", text->font->name); /* Leading (and repeated) whitespace presents a problem for SVG * text, so elide it here. */ @@ -256,7 +254,7 @@ svg_dev_text(svg_device *sdev, const fz_matrix *ctm, fz_text *text) break; } - fz_printf(out, " x="); + fz_printf(ctx, out, " x="); was_wspace = 0; for (i=start; i < text->len; i++) { @@ -269,9 +267,9 @@ svg_dev_text(svg_device *sdev, const fz_matrix *ctm, fz_text *text) p.x = it->x; p.y = it->y; fz_transform_point(&p, &inverse); - fz_printf(out, "%c%g", i == start ? '\"' : ' ', p.x); + fz_printf(ctx, out, "%c%g", i == start ? '\"' : ' ', p.x); } - fz_printf(out, "\" y="); + fz_printf(ctx, out, "\" y="); was_wspace = 0; for (i=start; i < text->len; i++) { @@ -284,9 +282,9 @@ svg_dev_text(svg_device *sdev, const fz_matrix *ctm, fz_text *text) p.x = it->x; p.y = it->y; fz_transform_point(&p, &inverse); - fz_printf(out, "%c%g", i == start ? '\"' : ' ', p.y); + fz_printf(ctx, out, "%c%g", i == start ? '\"' : ' ', p.y); } - fz_printf(out, "\">\n"); + fz_printf(ctx, out, "\">\n"); was_wspace = 0; for (i=start; i < text->len; i++) { @@ -297,18 +295,17 @@ svg_dev_text(svg_device *sdev, const fz_matrix *ctm, fz_text *text) continue; was_wspace = is_wspace; if (c >= 32 && c <= 127 && c != '<' && c != '&') - fz_printf(out, "%c", c); + fz_printf(ctx, out, "%c", c); else - fz_printf(out, "&#x%04x;", c); + fz_printf(ctx, out, "&#x%04x;", c); } - fz_printf(out, "\n</text>\n"); + fz_printf(ctx, out, "\n</text>\n"); } static font * -svg_dev_text_as_paths_defs(fz_device *dev, fz_text *text, const fz_matrix *ctm) +svg_dev_text_as_paths_defs(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { svg_device *sdev = dev->user; - fz_context *ctx = sdev->ctx; fz_output *out = sdev->out; int i, font_idx; font *fnt; @@ -360,30 +357,30 @@ svg_dev_text_as_paths_defs(fz_device *dev, fz_text *text, const fz_matrix *ctm) /* Need to send this one */ fz_rect rect; fz_path *path; - path = fz_outline_glyph(sdev->ctx, text->font, gid, &fz_identity); + path = fz_outline_glyph(ctx, text->font, gid, &fz_identity); if (path) { fz_bound_path(ctx, path, NULL, &fz_identity, &rect); shift.e = -rect.x0; shift.f = -rect.y0; fz_transform_path(ctx, path, &shift); - out = start_def(sdev); - fz_printf(out, "<symbol id=\"font_%x_%x\">", fnt->id, gid); - fz_printf(out, "<path"); - svg_dev_path(sdev, path); - fz_printf(out, "/>\n"); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<symbol id=\"font_%x_%x\">", fnt->id, gid); + fz_printf(ctx, out, "<path"); + svg_dev_path(ctx, sdev, path); + fz_printf(ctx, out, "/>\n"); } else { fz_bound_glyph(ctx, text->font, gid, &fz_identity, &rect); shift.e = -rect.x0; shift.f = -rect.y0; - out = start_def(sdev); - fz_printf(out, "<symbol id=\"font_%x_%x\">", fnt->id, gid); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<symbol id=\"font_%x_%x\">", fnt->id, gid); fz_run_t3_glyph(ctx, text->font, gid, &shift, dev); } - fz_printf(out, "</symbol>"); - out = end_def(sdev); + fz_printf(ctx, out, "</symbol>"); + out = end_def(ctx, sdev); fnt->sentlist[gid].x_off = rect.x0; fnt->sentlist[gid].y_off = rect.y0; } @@ -392,11 +389,12 @@ svg_dev_text_as_paths_defs(fz_device *dev, fz_text *text, const fz_matrix *ctm) } static void -svg_dev_text_as_paths_fill(fz_device *dev, fz_text *text, const fz_matrix *ctm, +svg_dev_text_as_paths_fill(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha, font *fnt) { svg_device *sdev = dev->user; fz_output *out = sdev->out; + fz_matrix local_trm, local_trm2; int i; fz_matrix shift = { 1, 0, 0, 1, 0, 0}; @@ -423,20 +421,21 @@ svg_dev_text_as_paths_fill(fz_device *dev, fz_text *text, const fz_matrix *ctm, local_trm.f = it->y; fz_concat(&local_trm2, &local_trm, ctm); fz_concat(&local_trm2, &shift, &local_trm2); - fz_printf(out, "<use xlink:href=\"#font_%x_%x\"", fnt->id, gid); - svg_dev_ctm(sdev, &local_trm2); - svg_dev_fill_color(sdev, colorspace, color, alpha); - fz_printf(out, "/>\n"); + fz_printf(ctx, out, "<use xlink:href=\"#font_%x_%x\"", fnt->id, gid); + svg_dev_ctm(ctx, sdev, &local_trm2); + svg_dev_fill_color(ctx, sdev, colorspace, color, alpha); + fz_printf(ctx, out, "/>\n"); } } static void -svg_dev_text_as_paths_stroke(fz_device *dev, fz_text *text, +svg_dev_text_as_paths_stroke(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha, font *fnt) { svg_device *sdev = dev->user; fz_output *out = sdev->out; + fz_matrix local_trm, local_trm2; int i; fz_matrix shift = { 1, 0, 0, 1, 0, 0}; @@ -463,127 +462,130 @@ svg_dev_text_as_paths_stroke(fz_device *dev, fz_text *text, local_trm.f = it->y; fz_concat(&local_trm2, &local_trm, ctm); fz_concat(&local_trm2, &shift, &local_trm2); - fz_printf(out, "<use xlink:href=\"#font_%x_%x\"", fnt->id, gid); - svg_dev_stroke_state(sdev, stroke, &local_trm2); - svg_dev_ctm(sdev, &local_trm2); - svg_dev_stroke_color(sdev, colorspace, color, alpha); - fz_printf(out, "/>\n"); + fz_printf(ctx, out, "<use xlink:href=\"#font_%x_%x\"", fnt->id, gid); + svg_dev_stroke_state(ctx, sdev, stroke, &local_trm2); + svg_dev_ctm(ctx, sdev, &local_trm2); + svg_dev_stroke_color(ctx, sdev, colorspace, color, alpha); + fz_printf(ctx, out, "/>\n"); } } /* Entry points */ static void -svg_dev_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, +svg_dev_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { svg_device *sdev = dev->user; fz_output *out = sdev->out; - fz_printf(out, "<path"); - svg_dev_ctm(sdev, ctm); - svg_dev_path(sdev, path); - svg_dev_fill_color(sdev, colorspace, color, alpha); + fz_printf(ctx, out, "<path"); + svg_dev_ctm(ctx, sdev, ctm); + svg_dev_path(ctx, sdev, path); + svg_dev_fill_color(ctx, sdev, colorspace, color, alpha); if (even_odd) - fz_printf(out, " fill-rule=\"evenodd\""); - fz_printf(out, "/>\n"); + fz_printf(ctx, out, " fill-rule=\"evenodd\""); + fz_printf(ctx, out, "/>\n"); } static void -svg_dev_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, +svg_dev_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { svg_device *sdev = dev->user; fz_output *out = sdev->out; - fz_printf(out, "<path"); - svg_dev_ctm(sdev, ctm); - svg_dev_stroke_state(sdev, stroke, &fz_identity); - svg_dev_stroke_color(sdev, colorspace, color, alpha); - svg_dev_path(sdev, path); - fz_printf(out, "/>\n"); + fz_printf(ctx, out, "<path"); + svg_dev_ctm(ctx, sdev, ctm); + svg_dev_stroke_state(ctx, sdev, stroke, &fz_identity); + svg_dev_stroke_color(ctx, sdev, colorspace, color, alpha); + svg_dev_path(ctx, sdev, path); + fz_printf(ctx, out, "/>\n"); } static void -svg_dev_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +svg_dev_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { svg_device *sdev = dev->user; fz_output *out; + int num = sdev->id++; - out = start_def(sdev); - fz_printf(out, "<clipPath id=\"cp%d\">\n", num); - fz_printf(out, "<path"); - svg_dev_ctm(sdev, ctm); - svg_dev_path(sdev, path); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<clipPath id=\"cp%d\">\n", num); + fz_printf(ctx, out, "<path"); + svg_dev_ctm(ctx, sdev, ctm); + svg_dev_path(ctx, sdev, path); if (even_odd) - fz_printf(out, " fill-rule=\"evenodd\""); - fz_printf(out, "/>\n</clipPath>\n"); - out = end_def(sdev); - fz_printf(out, "<g clip-path=\"url(#cp%d)\">\n", num); + fz_printf(ctx, out, " fill-rule=\"evenodd\""); + fz_printf(ctx, out, "/>\n</clipPath>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<g clip-path=\"url(#cp%d)\">\n", num); } static void -svg_dev_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) +svg_dev_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { svg_device *sdev = dev->user; + fz_output *out; - fz_context *ctx = dev->ctx; fz_rect bounds; int num = sdev->id++; float white[3] = { 1, 1, 1 }; fz_bound_path(ctx, path, stroke, ctm, &bounds); - out = start_def(sdev); - fz_printf(out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n", + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n", num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); - fz_printf(out, "<path"); - svg_dev_ctm(sdev, ctm); - svg_dev_stroke_state(sdev, stroke, &fz_identity); - svg_dev_stroke_color(sdev, fz_device_rgb(ctx), white, 1); - svg_dev_path(sdev, path); - fz_printf(out, "/>\n</mask>\n"); - out = end_def(sdev); - fz_printf(out, "<g mask=\"url(#ma%d)\">\n", num); + fz_printf(ctx, out, "<path"); + svg_dev_ctm(ctx, sdev, ctm); + svg_dev_stroke_state(ctx, sdev, stroke, &fz_identity); + svg_dev_stroke_color(ctx, sdev, fz_device_rgb(ctx), white, 1); + svg_dev_path(ctx, sdev, path); + fz_printf(ctx, out, "/>\n</mask>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", num); } static void -svg_dev_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +svg_dev_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { svg_device *sdev = dev->user; fz_output *out = sdev->out; + font *fnt; - fz_printf(out, "<text"); - svg_dev_fill_color(sdev, colorspace, color, 0.0f); - svg_dev_text(sdev, ctm, text); - fnt = svg_dev_text_as_paths_defs(dev, text, ctm); - svg_dev_text_as_paths_fill(dev, text, ctm, colorspace, color, alpha, fnt); + fz_printf(ctx, out, "<text"); + svg_dev_fill_color(ctx, sdev, colorspace, color, 0.0f); + svg_dev_text(ctx, sdev, ctm, text); + fnt = svg_dev_text_as_paths_defs(ctx, dev, text, ctm); + svg_dev_text_as_paths_fill(ctx, dev, text, ctm, colorspace, color, alpha, fnt); } static void -svg_dev_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, +svg_dev_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { svg_device *sdev = dev->user; fz_output *out = sdev->out; + font *fnt; - fz_printf(out, "<text"); - svg_dev_fill_color(sdev, colorspace, color, 0.0f); - svg_dev_text(sdev, ctm, text); - fnt = svg_dev_text_as_paths_defs(dev, text, ctm); - svg_dev_text_as_paths_stroke(dev, text, stroke, ctm, colorspace, color, alpha, fnt); + fz_printf(ctx, out, "<text"); + svg_dev_fill_color(ctx, sdev, colorspace, color, 0.0f); + svg_dev_text(ctx, sdev, ctm, text); + fnt = svg_dev_text_as_paths_defs(ctx, dev, text, ctm); + svg_dev_text_as_paths_stroke(ctx, dev, text, stroke, ctm, colorspace, color, alpha, fnt); } static void -svg_dev_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) +svg_dev_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { svg_device *sdev = dev->user; fz_output *out = sdev->out; - fz_context *ctx = dev->ctx; + fz_rect bounds; int num = sdev->id++; float white[3] = { 1, 1, 1 }; @@ -591,25 +593,25 @@ svg_dev_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accum fz_bound_text(ctx, text, NULL, ctm, &bounds); - out = start_def(sdev); - fz_printf(out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n", + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n", num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); - fz_printf(out, "<text"); - svg_dev_fill_color(sdev, fz_device_rgb(ctx), white, 0.0f); - svg_dev_text(sdev, ctm, text); - fnt = svg_dev_text_as_paths_defs(dev, text, ctm); - svg_dev_text_as_paths_fill(dev, text, ctm, fz_device_rgb(ctx), white, 1.0f, fnt); - fz_printf(out, "</mask>\n"); - out = end_def(sdev); - fz_printf(out, "<g mask=\"url(#ma%d)\">\n", num); + fz_printf(ctx, out, "<text"); + svg_dev_fill_color(ctx, sdev, fz_device_rgb(ctx), white, 0.0f); + svg_dev_text(ctx, sdev, ctm, text); + fnt = svg_dev_text_as_paths_defs(ctx, dev, text, ctm); + svg_dev_text_as_paths_fill(ctx, dev, text, ctm, fz_device_rgb(ctx), white, 1.0f, fnt); + fz_printf(ctx, out, "</mask>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", num); } static void -svg_dev_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +svg_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { svg_device *sdev = dev->user; + fz_output *out; - fz_context *ctx = dev->ctx; fz_rect bounds; int num = sdev->id++; float white[3] = { 255, 255, 255 }; @@ -617,34 +619,35 @@ svg_dev_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_bound_text(ctx, text, NULL, ctm, &bounds); - out = start_def(sdev); - fz_printf(out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n", + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n", num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); - fz_printf(out, "<text"); - svg_dev_stroke_state(sdev, stroke, &fz_identity); - svg_dev_stroke_color(sdev, fz_device_rgb(ctx), white, 0.0f); - svg_dev_text(sdev, ctm, text); - fnt = svg_dev_text_as_paths_defs(dev, text, ctm); - svg_dev_text_as_paths_stroke(dev, text, stroke, ctm, fz_device_rgb(ctx), white, 1.0f, fnt); - fz_printf(out, "</mask>\n"); - out = end_def(sdev); - fz_printf(out, "<g mask=\"url(#ma%d)\">\n", num); + fz_printf(ctx, out, "<text"); + svg_dev_stroke_state(ctx, sdev, stroke, &fz_identity); + svg_dev_stroke_color(ctx, sdev, fz_device_rgb(ctx), white, 0.0f); + svg_dev_text(ctx, sdev, ctm, text); + fnt = svg_dev_text_as_paths_defs(ctx, dev, text, ctm); + svg_dev_text_as_paths_stroke(ctx, dev, text, stroke, ctm, fz_device_rgb(ctx), white, 1.0f, fnt); + fz_printf(ctx, out, "</mask>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", num); } static void -svg_dev_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) +svg_dev_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { svg_device *sdev = dev->user; fz_output *out = sdev->out; + float black[3] = { 0, 0, 0}; - fz_printf(out, "<text"); - svg_dev_fill_color(sdev, fz_device_rgb(sdev->ctx), black, 0.0f); - svg_dev_text(sdev, ctm, text); + fz_printf(ctx, out, "<text"); + svg_dev_fill_color(ctx, sdev, fz_device_rgb(ctx), black, 0.0f); + svg_dev_text(ctx, sdev, ctm, text); } static void -send_data_base64(fz_output *out, fz_buffer *buffer) +send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer) { int i, len; static const char set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -656,8 +659,8 @@ send_data_base64(fz_output *out, fz_buffer *buffer) int d = buffer->data[3*i+1]; int e = buffer->data[3*i+2]; if ((i & 15) == 0) - fz_printf(out, "\n"); - fz_printf(out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); + fz_printf(ctx, out, "\n"); + fz_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); } i *= 3; switch (buffer->len-i) @@ -666,13 +669,13 @@ send_data_base64(fz_output *out, fz_buffer *buffer) { int c = buffer->data[i]; int d = buffer->data[i+1]; - fz_printf(out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); + fz_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); break; } case 1: { int c = buffer->data[i]; - fz_printf(out, "%c%c==", set[c>>2], set[(c&3)<<4]); + fz_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); break; } default: @@ -682,11 +685,11 @@ send_data_base64(fz_output *out, fz_buffer *buffer) } static void -svg_dev_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +svg_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { - svg_device *sdev = (svg_device *)dev->user; - fz_context *ctx = dev->ctx; + svg_device *sdev = dev->user; fz_output *out = sdev->out; + fz_matrix local_ctm = *ctm; fz_matrix scale = { 0 }; @@ -695,40 +698,40 @@ svg_dev_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float fz_concat(&local_ctm, &scale, ctm); if (alpha != 1.0f) - fz_printf(out, "<g opacity=\"%g\">", alpha); - fz_printf(out, "<image"); - svg_dev_ctm(sdev, &local_ctm); - fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); + fz_printf(ctx, out, "<g opacity=\"%g\">", alpha); + fz_printf(ctx, out, "<image"); + svg_dev_ctm(ctx, sdev, &local_ctm); + fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type) { case FZ_IMAGE_JPEG: - fz_printf(out, "image/jpeg;base64,"); - send_data_base64(out, image->buffer->buffer); + fz_printf(ctx, out, "image/jpeg;base64,"); + send_data_base64(ctx, out, image->buffer->buffer); break; case FZ_IMAGE_PNG: - fz_printf(out, "image/png;base64,"); - send_data_base64(out, image->buffer->buffer); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, image->buffer->buffer); break; default: { fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h); - fz_printf(out, "image/png;base64,"); - send_data_base64(out, buf); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(out, "\"/>\n"); + fz_printf(ctx, out, "\"/>\n"); if (alpha != 1.0f) - fz_printf(out, "</g>"); + fz_printf(ctx, out, "</g>"); } static void -svg_dev_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +svg_dev_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { - svg_device *sdev = (svg_device *)dev->user; - fz_context *ctx = dev->ctx; + svg_device *sdev = dev->user; fz_output *out = sdev->out; + fz_rect rect; fz_irect bbox; fz_pixmap *pix; @@ -750,12 +753,12 @@ svg_dev_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float fz_paint_shade(ctx, shade, ctm, pix, &bbox); buf = fz_new_png_from_pixmap(ctx, pix); if (alpha != 1.0f) - fz_printf(out, "<g opacity=\"%g\">", alpha); - fz_printf(out, "<image x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:image/png;base64,", pix->x, pix->y, pix->w, pix->h); - send_data_base64(out, buf); - fz_printf(out, "\"/>\n"); + fz_printf(ctx, out, "<g opacity=\"%g\">", alpha); + fz_printf(ctx, out, "<image x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:image/png;base64,", pix->x, pix->y, pix->w, pix->h); + send_data_base64(ctx, out, buf); + fz_printf(ctx, out, "\"/>\n"); if (alpha != 1.0f) - fz_printf(out, "</g>"); + fz_printf(ctx, out, "</g>"); } fz_always(ctx) { @@ -769,11 +772,11 @@ svg_dev_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float } static void -svg_dev_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, +svg_dev_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { - svg_device *sdev = (svg_device *)dev->user; - fz_context *ctx = dev->ctx; + svg_device *sdev = dev->user; + fz_output *out; fz_matrix local_ctm = *ctm; fz_matrix scale = { 0 }; @@ -783,41 +786,40 @@ fz_colorspace *colorspace, float *color, float alpha) scale.d = 1.0f / image->h; fz_concat(&local_ctm, &scale, ctm); - out = start_def(sdev); - fz_printf(out, "<mask id=\"ma%d\"><image", mask); - fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<mask id=\"ma%d\"><image", mask); + fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type) { case FZ_IMAGE_JPEG: - fz_printf(out, "image/jpeg;base64,"); - send_data_base64(out, image->buffer->buffer); + fz_printf(ctx, out, "image/jpeg;base64,"); + send_data_base64(ctx, out, image->buffer->buffer); break; case FZ_IMAGE_PNG: - fz_printf(out, "image/png;base64,"); - send_data_base64(out, image->buffer->buffer); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, image->buffer->buffer); break; default: { fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h); - fz_printf(out, "image/png;base64,"); - send_data_base64(out, buf); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(out, "\"/></mask>\n"); - out = end_def(sdev); - fz_printf(out, "<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", image->w, image->h); - svg_dev_fill_color(sdev, colorspace, color, alpha); - svg_dev_ctm(sdev, &local_ctm); - fz_printf(out, " mask=\"url(#ma%d)\"/>\n", mask); + fz_printf(ctx, out, "\"/></mask>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", image->w, image->h); + svg_dev_fill_color(ctx, sdev, colorspace, color, alpha); + svg_dev_ctm(ctx, sdev, &local_ctm); + fz_printf(ctx, out, " mask=\"url(#ma%d)\"/>\n", mask); } static void -svg_dev_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) +svg_dev_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { - svg_device *sdev = (svg_device *)dev->user; - fz_context *ctx = dev->ctx; + svg_device *sdev = dev->user; fz_output *out; fz_matrix local_ctm = *ctm; fz_matrix scale = { 0 }; @@ -827,99 +829,98 @@ svg_dev_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, co scale.d = 1.0f / image->h; fz_concat(&local_ctm, &scale, ctm); - out = start_def(sdev); - fz_printf(out, "<mask id=\"ma%d\"><image", mask); - svg_dev_ctm(sdev, &local_ctm); - fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<mask id=\"ma%d\"><image", mask); + svg_dev_ctm(ctx, sdev, &local_ctm); + fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type) { case FZ_IMAGE_JPEG: - fz_printf(out, "image/jpeg;base64,"); - send_data_base64(out, image->buffer->buffer); + fz_printf(ctx, out, "image/jpeg;base64,"); + send_data_base64(ctx, out, image->buffer->buffer); break; case FZ_IMAGE_PNG: - fz_printf(out, "image/png;base64,"); - send_data_base64(out, image->buffer->buffer); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, image->buffer->buffer); break; default: { fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h); - fz_printf(out, "image/png;base64,"); - send_data_base64(out, buf); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(out, "\"/></mask>\n"); - out = end_def(sdev); - fz_printf(out, "<g mask=\"url(#ma%d)\">\n", mask); + fz_printf(ctx, out, "\"/></mask>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", mask); } static void -svg_dev_pop_clip(fz_device *dev) +svg_dev_pop_clip(fz_context *ctx, fz_device *dev) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out = sdev->out; /* FIXME */ - fz_printf(out, "</g>\n"); + fz_printf(ctx, out, "</g>\n"); } static void -svg_dev_begin_mask(fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color) +svg_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out; int mask = sdev->id++; - out = start_def(sdev); - fz_printf(out, "<mask id=\"ma%d\">", mask); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<mask id=\"ma%d\">", mask); if (dev->container_len > 0) dev->container[dev->container_len-1].user = mask; } static void -svg_dev_end_mask(fz_device *dev) +svg_dev_end_mask(fz_context *ctx, fz_device *dev) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out = sdev->out; int mask = 0; if (dev->container_len > 0) mask = (int)dev->container[dev->container_len-1].user; - fz_printf(out, "\"/></mask>\n"); - out = end_def(sdev); - fz_printf(out, "<g mask=\"url(#ma%d)\">\n", mask); + fz_printf(ctx, out, "\"/></mask>\n"); + out = end_def(ctx, sdev); + fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", mask); } static void -svg_dev_begin_group(fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha) +svg_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out = sdev->out; /* SVG 1.1 doesn't support adequate blendmodes/knockout etc, so just ignore it for now */ - fz_printf(out, "<g>\n"); + fz_printf(ctx, out, "<g>\n"); } static void -svg_dev_end_group(fz_device *dev) +svg_dev_end_group(fz_context *ctx, fz_device *dev) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out = sdev->out; - fz_printf(out, "</g>\n"); + fz_printf(ctx, out, "</g>\n"); } static int -svg_dev_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) +svg_dev_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out; - fz_context *ctx = dev->ctx; int num; tile *t; @@ -950,16 +951,16 @@ svg_dev_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, flo /* The first thing we do is to capture the contents of the pattern * as a symbol we can reuse. */ - out = start_def(sdev); - fz_printf(out, "<symbol id=\"pac%d\">\n", t->pattern); + out = start_def(ctx, sdev); + fz_printf(ctx, out, "<symbol id=\"pac%d\">\n", t->pattern); return 0; } static void -svg_dev_end_tile(fz_device *dev) +svg_dev_end_tile(fz_context *ctx, fz_device *dev) { - svg_device *sdev = (svg_device *)dev->user; + svg_device *sdev = dev->user; fz_output *out = sdev->out; int num, cp = -1; tile *t; @@ -971,7 +972,7 @@ svg_dev_end_tile(fz_device *dev) num = --sdev->num_tiles; t = &sdev->tiles[num]; - fz_printf(out, "</symbol>\n"); + fz_printf(ctx, out, "</symbol>\n"); /* In svg, the reference tile is taken from (x,y) to (x+width,y+height) * and is repeated at (x+n*width,y+m*height) for all integer n and m. @@ -981,76 +982,66 @@ svg_dev_end_tile(fz_device *dev) * pattern tile, we need to render the pattern contents several times * to ensure that the pattern tile contains everything. */ - fz_printf(out, "<pattern id=\"pa%d\" patternUnits=\"userSpaceOnUse\" patternContentUnits=\"userSpaceOnUse\"", + fz_printf(ctx, out, "<pattern id=\"pa%d\" patternUnits=\"userSpaceOnUse\" patternContentUnits=\"userSpaceOnUse\"", t->pattern); - fz_printf(out, " x=\"0\" y=\"0\" width=\"%g\" height=\"%g\">\n", + fz_printf(ctx, out, " x=\"0\" y=\"0\" width=\"%g\" height=\"%g\">\n", t->step.x, t->step.y); if (t->view.x0 > 0 || t->step.x < t->view.x1 || t->view.y0 > 0 || t->step.y < t->view.y1) { cp = sdev->id++; - fz_printf(out, "<clipPath id=\"cp%d\">\n", cp); - fz_printf(out, "<path d=\"M %g %g L %g %g L %g %g L %g %g Z\"/>", + fz_printf(ctx, out, "<clipPath id=\"cp%d\">\n", cp); + fz_printf(ctx, out, "<path d=\"M %g %g L %g %g L %g %g L %g %g Z\"/>", t->view.x0, t->view.y0, t->view.x1, t->view.y0, t->view.x1, t->view.y1, t->view.x0, t->view.y1); - fz_printf(out, "</clipPath>\n"); - fz_printf(out, "<g clip-path=\"url(#cp%d)\">\n", cp); + fz_printf(ctx, out, "</clipPath>\n"); + fz_printf(ctx, out, "<g clip-path=\"url(#cp%d)\">\n", cp); } /* All the pattern contents will have their own ctm applied. Let's * undo the current one to allow for this */ fz_invert_matrix(&inverse, &t->ctm); - fz_printf(out, "<g"); - svg_dev_ctm(sdev, &inverse); - fz_printf(out, ">\n"); + fz_printf(ctx, out, "<g"); + svg_dev_ctm(ctx, sdev, &inverse); + fz_printf(ctx, out, ">\n"); w = t->view.x1 - t->view.x0; h = t->view.y1 - t->view.y0; for (x = 0; x > -w; x -= t->step.x) for (y = 0; y > -h; y -= t->step.y) - fz_printf(out, "<use x=\"%g\" y=\"%g\" xlink:href=\"#pac%d\"/>", x, y, t->pattern); + fz_printf(ctx, out, "<use x=\"%g\" y=\"%g\" xlink:href=\"#pac%d\"/>", x, y, t->pattern); - fz_printf(out, "</g>\n"); + fz_printf(ctx, out, "</g>\n"); if (cp != -1) - fz_printf(out, "</g>\n"); - fz_printf(out, "</pattern>\n"); - out = end_def(sdev); + fz_printf(ctx, out, "</g>\n"); + fz_printf(ctx, out, "</pattern>\n"); + out = end_def(ctx, sdev); /* Finally, fill a rectangle with the pattern. */ - fz_printf(out, "<rect"); - svg_dev_ctm(sdev, &t->ctm); - fz_printf(out, " fill=\"url(#pa%d)\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n", + fz_printf(ctx, out, "<rect"); + svg_dev_ctm(ctx, sdev, &t->ctm); + fz_printf(ctx, out, " fill=\"url(#pa%d)\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n", t->pattern, t->area.x0, t->area.y0, t->area.x1 - t->area.x0, t->area.y1 - t->area.y0); } static void -svg_dev_drop_user(fz_device *dev) +svg_dev_drop_user(fz_context *ctx, fz_device *dev) { svg_device *sdev = dev->user; - fz_context *ctx = sdev->ctx; fz_output *out = sdev->out; fz_free(ctx, sdev->tiles); fz_drop_buffer(ctx, sdev->defs_buffer); - fz_drop_output(sdev->defs); + fz_drop_output(ctx, sdev->defs); - fz_printf(out, "</svg>\n"); + fz_printf(ctx, out, "</svg>\n"); fz_free(ctx, sdev); } -void svg_rebind(fz_device *dev) -{ - svg_device *sdev = dev->user; - - sdev->ctx = dev->ctx; - fz_rebind_output(sdev->out, sdev->ctx); - fz_rebind_output(sdev->out_store, sdev->ctx); -} - fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, float page_height) { svg_device *sdev = fz_malloc_struct(ctx, svg_device); @@ -1058,7 +1049,6 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, fz_try(ctx) { - sdev->ctx = ctx; sdev->out = out; sdev->out_store = out; sdev->id = 0; @@ -1071,7 +1061,6 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, fz_rethrow(ctx); } - dev->rebind = svg_rebind; dev->drop_user = svg_dev_drop_user; dev->fill_path = svg_dev_fill_path; @@ -1102,9 +1091,9 @@ fz_device *fz_new_svg_device(fz_context *ctx, fz_output *out, float page_width, dev->hints |= FZ_MAINTAIN_CONTAINER_STACK; - fz_printf(out, "<?xml version=\"1.0\" standalone=\"no\"?>\n"); - fz_printf(out, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); - fz_printf(out, "<svg xmlns=\"http://www.w3.org/2000/svg\" " + fz_printf(ctx, out, "<?xml version=\"1.0\" standalone=\"no\"?>\n"); + fz_printf(ctx, out, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); + fz_printf(ctx, out, "<svg xmlns=\"http://www.w3.org/2000/svg\" " "xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" " "width=\"%gcm\" height=\"%gcm\" viewBox=\"0 0 %g %g\">\n", page_width*2.54/72, page_height*2.54/72, page_width, page_height); diff --git a/source/fitz/test-device.c b/source/fitz/test-device.c index 919bda98..16736c80 100644 --- a/source/fitz/test-device.c +++ b/source/fitz/test-device.c @@ -25,9 +25,8 @@ is_rgb_color_u8(int threshold_u8, int r, int g, int b) } static void -fz_test_color(fz_device *dev, fz_colorspace *colorspace, const float *color) +fz_test_color(fz_context *ctx, fz_device *dev, fz_colorspace *colorspace, const float *color) { - fz_context *ctx = dev->ctx; struct test *t = dev->user; if (!*t->is_color && colorspace && colorspace != fz_device_gray(ctx)) @@ -56,35 +55,35 @@ fz_test_color(fz_device *dev, fz_colorspace *colorspace, const float *color) } static void -fz_test_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, +fz_test_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (alpha != 0.0f) - fz_test_color(dev, colorspace, color); + fz_test_color(ctx, dev, colorspace, color); } static void -fz_test_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, +fz_test_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (alpha != 0.0f) - fz_test_color(dev, colorspace, color); + fz_test_color(ctx, dev, colorspace, color); } static void -fz_test_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +fz_test_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (alpha != 0.0f) - fz_test_color(dev, colorspace, color); + fz_test_color(ctx, dev, colorspace, color); } static void -fz_test_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, +fz_test_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { if (alpha != 0.0f) - fz_test_color(dev, colorspace, color); + fz_test_color(ctx, dev, colorspace, color); } struct shadearg @@ -94,25 +93,23 @@ struct shadearg }; static void -prepare_vertex(void *arg0, fz_vertex *v, const float *color) +prepare_vertex(fz_context *ctx, void *arg_, fz_vertex *v, const float *color) { - struct shadearg *arg = arg0; + struct shadearg *arg = arg_; fz_device *dev = arg->dev; fz_shade *shade = arg->shade; if (!shade->use_function) - fz_test_color(dev, shade->colorspace, color); + fz_test_color(ctx, dev, shade->colorspace, color); } static void -fz_test_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +fz_test_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { - fz_context *ctx = dev->ctx; - if (shade->use_function) { int i; for (i = 0; i < 256; i++) - fz_test_color(dev, shade->colorspace, shade->function[i]); + fz_test_color(ctx, dev, shade->colorspace, shade->function[i]); } else { @@ -124,9 +121,8 @@ fz_test_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float } static void -fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +fz_test_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { - fz_context *ctx = dev->ctx; struct test *t = dev->user; fz_pixmap *pix; @@ -145,14 +141,14 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float int threshold_u8 = t->threshold * 255; for (i = 0; i < count; i++) { - int r = fz_read_byte(stream); - int g = fz_read_byte(stream); - int b = fz_read_byte(stream); + int r = fz_read_byte(ctx, stream); + int g = fz_read_byte(ctx, stream); + int b = fz_read_byte(ctx, stream); if (is_rgb_color_u8(threshold_u8, r, g, b)) { *t->is_color = 1; dev->hints |= FZ_IGNORE_IMAGE; - fz_drop_stream(stream); + fz_drop_stream(ctx, stream); fz_throw(ctx, FZ_ERROR_ABORT, "Page found as color; stopping interpretation"); break; } @@ -170,9 +166,9 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float float ds[FZ_MAX_COLORS]; for (k = 0; k < n; k++) - cs[k] = fz_read_byte(stream) / 255.0f; + cs[k] = fz_read_byte(ctx, stream) / 255.0f; - cc.convert(&cc, ds, cs); + cc.convert(ctx, &cc, ds, cs); if (is_rgb_color(t->threshold, ds[0], ds[1], ds[2])) { @@ -181,9 +177,9 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float break; } } - fz_fin_cached_color_converter(&cc); + fz_fin_cached_color_converter(ctx, &cc); } - fz_drop_stream(stream); + fz_drop_stream(ctx, stream); return; } @@ -226,7 +222,7 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float if (*s++ == 0) continue; - cc.convert(&cc, ds, cs); + cc.convert(ctx, &cc, ds, cs); if (is_rgb_color(t->threshold, ds[0], ds[1], ds[2])) { @@ -237,26 +233,26 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float break; } } - fz_fin_cached_color_converter(&cc); + fz_fin_cached_color_converter(ctx, &cc); } fz_drop_pixmap(ctx, pix); } static void -fz_test_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, +fz_test_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { /* We assume that at least some of the image pixels are non-zero */ - fz_test_color(dev, colorspace, color); + fz_test_color(ctx, dev, colorspace, color); } static void -fz_test_free(fz_device *dev) +fz_test_free(fz_context *ctx, fz_device *dev) { if (dev == NULL) return; - fz_free(dev->ctx, dev->user); + fz_free(ctx, dev->user); dev->user = NULL; } diff --git a/source/fitz/text.c b/source/fitz/text.c index f184e11d..4d2b73d9 100644 --- a/source/fitz/text.c +++ b/source/fitz/text.c @@ -76,7 +76,7 @@ fz_bound_text(fz_context *ctx, fz_text *text, const fz_stroke_state *stroke, con } if (stroke) - fz_adjust_rect_for_stroke(bbox, stroke, ctm); + fz_adjust_rect_for_stroke(ctx, bbox, stroke, ctm); /* Compensate for the glyph cache limited positioning precision */ bbox->x0 -= 1; diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c index d6c01323..3a0bba0a 100644 --- a/source/fitz/trace-device.c +++ b/source/fitz/trace-device.c @@ -66,7 +66,7 @@ fz_trace_path(fz_path *path, int indent) } static void -fz_trace_begin_page(fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) +fz_trace_begin_page(fz_context *ctx, fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) { printf("<page mediabox=\"%g %g %g %g\"", rect->x0, rect->y0, rect->x1, rect->y1); fz_trace_matrix(ctm); @@ -74,13 +74,13 @@ fz_trace_begin_page(fz_device *dev, const fz_rect *rect, const fz_matrix *ctm) } static void -fz_trace_end_page(fz_device *dev) +fz_trace_end_page(fz_context *ctx, fz_device *dev) { printf("</page>\n"); } static void -fz_trace_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, +fz_trace_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { printf("<fill_path"); @@ -96,7 +96,7 @@ fz_trace_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix } static void -fz_trace_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_trace_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { int i; @@ -125,7 +125,7 @@ fz_trace_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, con } static void -fz_trace_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) +fz_trace_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm) { printf("<clip_path"); if (even_odd) @@ -142,7 +142,7 @@ fz_trace_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_ } static void -fz_trace_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_trace_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm) { printf("<clip_stroke_path"); fz_trace_matrix(ctm); @@ -152,7 +152,7 @@ fz_trace_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz } static void -fz_trace_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, +fz_trace_fill_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { printf("<fill_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode); @@ -160,12 +160,12 @@ fz_trace_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, fz_trace_matrix(ctm); fz_trace_trm(&text->trm); printf(">\n"); - fz_print_text(dev->ctx, stdout, text); + fz_print_text(ctx, stdout, text); printf("</fill_text>\n"); } static void -fz_trace_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, +fz_trace_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { printf("<stroke_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode); @@ -173,46 +173,46 @@ fz_trace_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, con fz_trace_matrix(ctm); fz_trace_trm(&text->trm); printf(">\n"); - fz_print_text(dev->ctx, stdout, text); + fz_print_text(ctx, stdout, text); printf("</stroke_text>\n"); } static void -fz_trace_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) +fz_trace_clip_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate) { printf("<clip_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode); printf(" accumulate=\"%d\"", accumulate); fz_trace_matrix(ctm); fz_trace_trm(&text->trm); printf(">\n"); - fz_print_text(dev->ctx, stdout, text); + fz_print_text(ctx, stdout, text); printf("</clip_text>\n"); } static void -fz_trace_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) +fz_trace_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm) { printf("<clip_stroke_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode); fz_trace_matrix(ctm); fz_trace_trm(&text->trm); printf(">\n"); - fz_print_text(dev->ctx, stdout, text); + fz_print_text(ctx, stdout, text); printf("</clip_stroke_text>\n"); } static void -fz_trace_ignore_text(fz_device *dev, fz_text *text, const fz_matrix *ctm) +fz_trace_ignore_text(fz_context *ctx, fz_device *dev, fz_text *text, const fz_matrix *ctm) { printf("<ignore_text font=\"%s\" wmode=\"%d\"", text->font->name, text->wmode); fz_trace_matrix(ctm); fz_trace_trm(&text->trm); printf(">\n"); - fz_print_text(dev->ctx, stdout, text); + fz_print_text(ctx, stdout, text); printf("</ignore_text>\n"); } static void -fz_trace_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) +fz_trace_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { printf("<fill_image alpha=\"%g\"", alpha); fz_trace_matrix(ctm); @@ -221,7 +221,7 @@ fz_trace_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float } static void -fz_trace_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) +fz_trace_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { printf("<fill_shade alpha=\"%g\"", alpha); fz_trace_matrix(ctm); @@ -229,7 +229,7 @@ fz_trace_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float } static void -fz_trace_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm, +fz_trace_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha) { printf("<fill_image_mask"); @@ -240,7 +240,7 @@ fz_colorspace *colorspace, float *color, float alpha) } static void -fz_trace_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) +fz_trace_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { printf("<clip_image_mask"); fz_trace_matrix(ctm); @@ -249,13 +249,13 @@ fz_trace_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, c } static void -fz_trace_pop_clip(fz_device *dev) +fz_trace_pop_clip(fz_context *ctx, fz_device *dev) { printf("<pop_clip/>\n"); } static void -fz_trace_begin_mask(fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color) +fz_trace_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int luminosity, fz_colorspace *colorspace, float *color) { printf("<mask bbox=\"%g %g %g %g\" s=\"%s\"", bbox->x0, bbox->y0, bbox->x1, bbox->y1, @@ -264,13 +264,13 @@ fz_trace_begin_mask(fz_device *dev, const fz_rect *bbox, int luminosity, fz_colo } static void -fz_trace_end_mask(fz_device *dev) +fz_trace_end_mask(fz_context *ctx, fz_device *dev) { printf("</mask>\n"); } static void -fz_trace_begin_group(fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha) +fz_trace_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int isolated, int knockout, int blendmode, float alpha) { printf("<group bbox=\"%g %g %g %g\" isolated=\"%d\" knockout=\"%d\" blendmode=\"%s\" alpha=\"%g\">\n", bbox->x0, bbox->y0, bbox->x1, bbox->y1, @@ -278,13 +278,13 @@ fz_trace_begin_group(fz_device *dev, const fz_rect *bbox, int isolated, int knoc } static void -fz_trace_end_group(fz_device *dev) +fz_trace_end_group(fz_context *ctx, fz_device *dev) { printf("</group>\n"); } static int -fz_trace_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) +fz_trace_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id) { printf("<tile"); printf(" area=\"%g %g %g %g\"", area->x0, area->y0, area->x1, area->y1); @@ -296,7 +296,7 @@ fz_trace_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, fl } static void -fz_trace_end_tile(fz_device *dev) +fz_trace_end_tile(fz_context *ctx, fz_device *dev) { printf("</tile>\n"); } diff --git a/source/fitz/transition.c b/source/fitz/transition.c index c71729a9..b4da6192 100644 --- a/source/fitz/transition.c +++ b/source/fitz/transition.c @@ -139,7 +139,7 @@ wipe_lr(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time) return 1; } -int fz_generate_transition(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time, fz_transition *trans) +int fz_generate_transition(fz_context *ctx, fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time, fz_transition *trans) { switch (trans->type) { diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c index bafc4146..8c8a6ba3 100644 --- a/source/fitz/unzip.c +++ b/source/fitz/unzip.c @@ -27,26 +27,26 @@ struct fz_archive_s struct zip_entry *table; }; -static inline int getshort(fz_stream *file) +static inline int getshort(fz_context *ctx, fz_stream *file) { - int a = fz_read_byte(file); - int b = fz_read_byte(file); + int a = fz_read_byte(ctx, file); + int b = fz_read_byte(ctx, file); return a | b << 8; } -static inline int getlong(fz_stream *file) +static inline int getlong(fz_context *ctx, fz_stream *file) { - int a = fz_read_byte(file); - int b = fz_read_byte(file); - int c = fz_read_byte(file); - int d = fz_read_byte(file); + int a = fz_read_byte(ctx, file); + int b = fz_read_byte(ctx, file); + int c = fz_read_byte(ctx, file); + int d = fz_read_byte(ctx, file); return a | b << 8 | c << 16 | d << 24; } -static inline int getlong64(fz_stream *file) +static inline int getlong64(fz_context *ctx, fz_stream *file) { - int a = getlong(file); - int b = getlong(file); + int a = getlong(ctx, file); + int b = getlong(ctx, file); return b != 0 ? -1 : a; } @@ -106,50 +106,50 @@ static void read_zip_dir_imp(fz_context *ctx, fz_archive *zip, int start_offset) int namesize, metasize, commentsize; int i; - fz_seek(file, start_offset, 0); + fz_seek(ctx, file, start_offset, 0); - sig = getlong(file); + sig = getlong(ctx, file); if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip end of central directory signature (0x%x)", sig); - (void) getshort(file); /* this disk */ - (void) getshort(file); /* start disk */ - (void) getshort(file); /* entries in this disk */ - count = getshort(file); /* entries in central directory disk */ - (void) getlong(file); /* size of central directory */ - offset = getlong(file); /* offset to central directory */ + (void) getshort(ctx, file); /* this disk */ + (void) getshort(ctx, file); /* start disk */ + (void) getshort(ctx, file); /* entries in this disk */ + count = getshort(ctx, file); /* entries in central directory disk */ + (void) getlong(ctx, file); /* size of central directory */ + offset = getlong(ctx, file); /* offset to central directory */ /* ZIP64 */ if (count == 0xFFFF || offset == 0xFFFFFFFF) { int offset64, count64; - fz_seek(file, start_offset - 20, 0); + fz_seek(ctx, file, start_offset - 20, 0); - sig = getlong(file); + sig = getlong(ctx, file); if (sig != ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIG) fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip64 end of central directory locator signature (0x%x)", sig); - (void) getlong(file); /* start disk */ - offset64 = getlong64(file); /* offset to end of central directory record */ + (void) getlong(ctx, file); /* start disk */ + offset64 = getlong64(ctx, file); /* offset to end of central directory record */ if (offset64 < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "zip64 files larger than 2 GB aren't supported"); - fz_seek(file, offset64, 0); + fz_seek(ctx, file, offset64, 0); - sig = getlong(file); + sig = getlong(ctx, file); if (sig != ZIP64_END_OF_CENTRAL_DIRECTORY_SIG) fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip64 end of central directory signature (0x%x)", sig); - (void) getlong64(file); /* size of record */ - (void) getshort(file); /* version made by */ - (void) getshort(file); /* version to extract */ - (void) getlong(file); /* disk number */ - (void) getlong(file); /* disk number start */ - count64 = getlong64(file); /* entries in central directory disk */ - (void) getlong64(file); /* entries in central directory */ - (void) getlong64(file); /* size of central directory */ - offset64 = getlong64(file); /* offset to central directory */ + (void) getlong64(ctx, file); /* size of record */ + (void) getshort(ctx, file); /* version made by */ + (void) getshort(ctx, file); /* version to extract */ + (void) getlong(ctx, file); /* disk number */ + (void) getlong(ctx, file); /* disk number start */ + count64 = getlong64(ctx, file); /* entries in central directory disk */ + (void) getlong64(ctx, file); /* entries in central directory */ + (void) getlong64(ctx, file); /* size of central directory */ + offset64 = getlong64(ctx, file); /* offset to central directory */ if (count == 0xFFFF) count = count64; @@ -163,66 +163,66 @@ static void read_zip_dir_imp(fz_context *ctx, fz_archive *zip, int start_offset) zip->table = fz_malloc_array(ctx, count, sizeof *zip->table); memset(zip->table, 0, count * sizeof *zip->table); - fz_seek(file, offset, 0); + fz_seek(ctx, file, offset, 0); for (i = 0; i < count; i++) { - sig = getlong(file); + sig = getlong(ctx, file); if (sig != ZIP_CENTRAL_DIRECTORY_SIG) fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip central directory signature (0x%x)", sig); - (void) getshort(file); /* version made by */ - (void) getshort(file); /* version to extract */ - (void) getshort(file); /* general */ - (void) getshort(file); /* method */ - (void) getshort(file); /* last mod file time */ - (void) getshort(file); /* last mod file date */ - (void) getlong(file); /* crc-32 */ - zip->table[i].csize = getlong(file); - zip->table[i].usize = getlong(file); - namesize = getshort(file); - metasize = getshort(file); - commentsize = getshort(file); - (void) getshort(file); /* disk number start */ - (void) getshort(file); /* int file atts */ - (void) getlong(file); /* ext file atts */ - zip->table[i].offset = getlong(file); + (void) getshort(ctx, file); /* version made by */ + (void) getshort(ctx, file); /* version to extract */ + (void) getshort(ctx, file); /* general */ + (void) getshort(ctx, file); /* method */ + (void) getshort(ctx, file); /* last mod file time */ + (void) getshort(ctx, file); /* last mod file date */ + (void) getlong(ctx, file); /* crc-32 */ + zip->table[i].csize = getlong(ctx, file); + zip->table[i].usize = getlong(ctx, file); + namesize = getshort(ctx, file); + metasize = getshort(ctx, file); + commentsize = getshort(ctx, file); + (void) getshort(ctx, file); /* disk number start */ + (void) getshort(ctx, file); /* int file atts */ + (void) getlong(ctx, file); /* ext file atts */ + zip->table[i].offset = getlong(ctx, file); zip->table[i].name = fz_malloc(ctx, namesize + 1); - fz_read(file, (unsigned char*)zip->table[i].name, namesize); + fz_read(ctx, file, (unsigned char*)zip->table[i].name, namesize); zip->table[i].name[namesize] = 0; while (metasize > 0) { - int type = getshort(file); - int size = getshort(file); + int type = getshort(ctx, file); + int size = getshort(ctx, file); if (type == ZIP64_EXTRA_FIELD_SIG) { int sizeleft = size; if (zip->table[i].usize == 0xFFFFFFFF && sizeleft >= 8) { - zip->table[i].usize = getlong64(file); + zip->table[i].usize = getlong64(ctx, file); sizeleft -= 8; } if (zip->table[i].csize == 0xFFFFFFFF && sizeleft >= 8) { - zip->table[i].csize = getlong64(file); + zip->table[i].csize = getlong64(ctx, file); sizeleft -= 8; } if (zip->table[i].offset == 0xFFFFFFFF && sizeleft >= 8) { - zip->table[i].offset = getlong64(file); + zip->table[i].offset = getlong64(ctx, file); sizeleft -= 8; } - fz_seek(file, sizeleft - size, 1); + fz_seek(ctx, file, sizeleft - size, 1); } - fz_seek(file, size, 1); + fz_seek(ctx, file, size, 1); metasize -= 4 + size; } if (zip->table[i].usize < 0 || zip->table[i].csize < 0 || zip->table[i].offset < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "zip64 files larger than 2 GB are not supported"); - fz_seek(file, commentsize, 1); + fz_seek(ctx, file, commentsize, 1); } qsort(zip->table, count, sizeof *zip->table, case_compare_entries); @@ -235,16 +235,16 @@ static void read_zip_dir(fz_context *ctx, fz_archive *zip) int size, back, maxback; int i, n; - fz_seek(file, 0, SEEK_END); - size = fz_tell(file); + fz_seek(ctx, file, 0, SEEK_END); + size = fz_tell(ctx, file); maxback = fz_mini(size, 0xFFFF + sizeof buf); back = fz_mini(maxback, sizeof buf); while (back < maxback) { - fz_seek(file, size - back, 0); - n = fz_read(file, buf, sizeof buf); + fz_seek(ctx, file, size - back, 0); + n = fz_read(ctx, file, buf, sizeof buf); for (i = n - 4; i > 0; i--) { if (!memcmp(buf + i, "PK\5\6", 4)) @@ -264,27 +264,27 @@ static int read_zip_entry_header(fz_context *ctx, fz_archive *zip, struct zip_en fz_stream *file = zip->file; int sig, general, method, namelength, extralength; - fz_seek(file, ent->offset, 0); + fz_seek(ctx, file, ent->offset, 0); - sig = getlong(file); + sig = getlong(ctx, file); if (sig != ZIP_LOCAL_FILE_SIG) fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip local file signature (0x%x)", sig); - (void) getshort(file); /* version */ - general = getshort(file); /* general */ + (void) getshort(ctx, file); /* version */ + general = getshort(ctx, file); /* general */ if (general & ZIP_ENCRYPTED_FLAG) fz_throw(ctx, FZ_ERROR_GENERIC, "zip content is encrypted"); - method = getshort(file); - (void) getshort(file); /* file time */ - (void) getshort(file); /* file date */ - (void) getlong(file); /* crc-32 */ - (void) getlong(file); /* csize */ - (void) getlong(file); /* usize */ - namelength = getshort(file); - extralength = getshort(file); + method = getshort(ctx, file); + (void) getshort(ctx, file); /* file time */ + (void) getshort(ctx, file); /* file date */ + (void) getlong(ctx, file); /* crc-32 */ + (void) getlong(ctx, file); /* csize */ + (void) getlong(ctx, file); /* usize */ + namelength = getshort(ctx, file); + extralength = getshort(ctx, file); - fz_seek(file, namelength + extralength, 1); + fz_seek(ctx, file, namelength + extralength, 1); return method; } @@ -294,9 +294,9 @@ static fz_stream *open_zip_entry(fz_context *ctx, fz_archive *zip, struct zip_en fz_stream *file = zip->file; int method = read_zip_entry_header(ctx, zip, ent); if (method == 0) - return fz_open_null(file, ent->usize, fz_tell(file)); + return fz_open_null(ctx, file, ent->usize, fz_tell(ctx, file)); if (method == 8) - return fz_open_flated(file, -15); + return fz_open_flated(ctx, file, -15); fz_throw(ctx, FZ_ERROR_GENERIC, "unknown zip method: %d", method); } @@ -318,7 +318,7 @@ static fz_buffer *read_zip_entry(fz_context *ctx, fz_archive *zip, struct zip_en { fz_try(ctx) { - fz_read(file, ubuf->data, ent->usize); + fz_read(ctx, file, ubuf->data, ent->usize); } fz_catch(ctx) { @@ -333,7 +333,7 @@ static fz_buffer *read_zip_entry(fz_context *ctx, fz_archive *zip, struct zip_en cbuf = fz_malloc(ctx, ent->csize); fz_try(ctx) { - fz_read(file, cbuf, ent->csize); + fz_read(ctx, file, cbuf, ent->csize); z.zalloc = (alloc_func) fz_malloc_array; z.zfree = (free_func) fz_free; @@ -458,7 +458,7 @@ fz_drop_archive(fz_context *ctx, fz_archive *zip) if (zip) { fz_free(ctx, zip->directory); - fz_drop_stream(zip->file); + fz_drop_stream(ctx, zip->file); for (i = 0; i < zip->count; ++i) fz_free(ctx, zip->table[i].name); fz_free(ctx, zip->table); @@ -466,13 +466,6 @@ fz_drop_archive(fz_context *ctx, fz_archive *zip) } } -void -fz_rebind_archive(fz_archive *zip, fz_context *ctx) -{ - if (zip->file) - fz_rebind_stream(zip->file, ctx); -} - fz_archive * fz_open_directory(fz_context *ctx, const char *dirname) { @@ -487,7 +480,7 @@ fz_open_archive_with_stream(fz_context *ctx, fz_stream *file) fz_archive *zip; zip = fz_malloc_struct(ctx, fz_archive); - zip->file = fz_keep_stream(file); + zip->file = fz_keep_stream(ctx, file); zip->count = 0; zip->table = NULL; @@ -517,7 +510,7 @@ fz_open_archive(fz_context *ctx, const char *filename) } fz_always(ctx) { - fz_drop_stream(file); + fz_drop_stream(ctx, file); } fz_catch(ctx) { diff --git a/source/fitz/xml.c b/source/fitz/xml.c index 424a6bdf..6051caf5 100644 --- a/source/fitz/xml.c +++ b/source/fitz/xml.c @@ -66,7 +66,6 @@ static const struct { const char *ent; int ucs; } html_entities[] = { struct parser { fz_xml *head; - fz_context *ctx; int preserve_white; int depth; }; @@ -287,7 +286,7 @@ static inline int iswhite(int c) return c == ' ' || c == '\r' || c == '\n' || c == '\t'; } -static void xml_emit_open_tag(struct parser *parser, char *a, char *b) +static void xml_emit_open_tag(fz_context *ctx, struct parser *parser, char *a, char *b) { fz_xml *head, *tail; char *ns; @@ -297,7 +296,7 @@ static void xml_emit_open_tag(struct parser *parser, char *a, char *b) if (*ns == ':') a = ns + 1; - head = fz_malloc_struct(parser->ctx, fz_xml); + head = fz_malloc_struct(ctx, fz_xml); if (b - a > sizeof(head->name) - 1) b = a + sizeof(head->name) - 1; memcpy(head->name, a, b - a); @@ -325,12 +324,12 @@ static void xml_emit_open_tag(struct parser *parser, char *a, char *b) parser->depth++; } -static void xml_emit_att_name(struct parser *parser, char *a, char *b) +static void xml_emit_att_name(fz_context *ctx, struct parser *parser, char *a, char *b) { fz_xml *head = parser->head; struct attribute *att; - att = fz_malloc_struct(parser->ctx, struct attribute); + att = fz_malloc_struct(ctx, struct attribute); if (b - a > sizeof(att->name) - 1) b = a + sizeof(att->name) - 1; memcpy(att->name, a, b - a); @@ -340,7 +339,7 @@ static void xml_emit_att_name(struct parser *parser, char *a, char *b) head->atts = att; } -static void xml_emit_att_value(struct parser *parser, char *a, char *b) +static void xml_emit_att_value(fz_context *ctx, struct parser *parser, char *a, char *b) { fz_xml *head = parser->head; struct attribute *att = head->atts; @@ -348,7 +347,7 @@ static void xml_emit_att_value(struct parser *parser, char *a, char *b) int c; /* entities are all longer than UTFmax so runetochar is safe */ - s = att->value = fz_malloc(parser->ctx, b - a + 1); + s = att->value = fz_malloc(ctx, b - a + 1); while (a < b) { if (*a == '&') { a += xml_parse_entity(&c, a); @@ -361,14 +360,14 @@ static void xml_emit_att_value(struct parser *parser, char *a, char *b) *s = 0; } -static void xml_emit_close_tag(struct parser *parser) +static void xml_emit_close_tag(fz_context *ctx, struct parser *parser) { parser->depth--; if (parser->head->up) parser->head = parser->head->up; } -static void xml_emit_text(struct parser *parser, char *a, char *b) +static void xml_emit_text(fz_context *ctx, struct parser *parser, char *a, char *b) { static char *empty = ""; fz_xml *head; @@ -389,11 +388,11 @@ static void xml_emit_text(struct parser *parser, char *a, char *b) return; } - xml_emit_open_tag(parser, empty, empty); + xml_emit_open_tag(ctx, parser, empty, empty); head = parser->head; /* entities are all longer than UTFmax so runetochar is safe */ - s = head->text = fz_malloc(parser->ctx, b - a + 1); + s = head->text = fz_malloc(ctx, b - a + 1); while (a < b) { if (*a == '&') { a += xml_parse_entity(&c, a); @@ -405,27 +404,27 @@ static void xml_emit_text(struct parser *parser, char *a, char *b) } *s = 0; - xml_emit_close_tag(parser); + xml_emit_close_tag(ctx, parser); } -static void xml_emit_cdata(struct parser *parser, char *a, char *b) +static void xml_emit_cdata(fz_context *ctx, struct parser *parser, char *a, char *b) { static char *empty = ""; fz_xml *head; char *s; - xml_emit_open_tag(parser, empty, empty); + xml_emit_open_tag(ctx, parser, empty, empty); head = parser->head; - s = head->text = fz_malloc(parser->ctx, b - a + 1); + s = head->text = fz_malloc(ctx, b - a + 1); while (a < b) *s++ = *a++; *s = 0; - xml_emit_close_tag(parser); + xml_emit_close_tag(ctx, parser); } -static char *xml_parse_document_imp(struct parser *x, char *p) +static char *xml_parse_document_imp(fz_context *ctx, struct parser *parser, char *p) { char *mark; int quote; @@ -433,7 +432,7 @@ static char *xml_parse_document_imp(struct parser *x, char *p) parse_text: mark = p; while (*p && *p != '<') ++p; - if (mark != p) xml_emit_text(x, mark, p); + if (mark != p) xml_emit_text(ctx, parser, mark, p); if (*p == '<') { ++p; goto parse_element; } return NULL; @@ -471,7 +470,7 @@ parse_cdata: mark = p; while (*p) { if (p[0] == ']' && p[1] == ']' && p[2] == '>') { - xml_emit_cdata(x, mark, p); + xml_emit_cdata(ctx, parser, mark, p); p += 3; goto parse_text; } @@ -495,17 +494,17 @@ parse_closing_element: while (iswhite(*p)) ++p; if (*p != '>') return "syntax error in closing element"; - xml_emit_close_tag(x); + xml_emit_close_tag(ctx, parser); ++p; goto parse_text; parse_element_name: mark = p; while (isname(*p)) ++p; - xml_emit_open_tag(x, mark, p); + xml_emit_open_tag(ctx, parser, mark, p); if (*p == '>') { ++p; goto parse_text; } if (p[0] == '/' && p[1] == '>') { - xml_emit_close_tag(x); + xml_emit_close_tag(ctx, parser); p += 2; goto parse_text; } @@ -519,7 +518,7 @@ parse_attributes: goto parse_attribute_name; if (*p == '>') { ++p; goto parse_text; } if (p[0] == '/' && p[1] == '>') { - xml_emit_close_tag(x); + xml_emit_close_tag(ctx, parser); p += 2; goto parse_text; } @@ -528,7 +527,7 @@ parse_attributes: parse_attribute_name: mark = p; while (isname(*p)) ++p; - xml_emit_att_name(x, mark, p); + xml_emit_att_name(ctx, parser, mark, p); while (iswhite(*p)) ++p; if (*p == '=') { ++p; goto parse_attribute_value; } return "syntax error after attribute name"; @@ -541,7 +540,7 @@ parse_attribute_value: mark = p; while (*p && *p != quote) ++p; if (*p == quote) { - xml_emit_att_value(x, mark, p++); + xml_emit_att_value(ctx, parser, mark, p++); goto parse_attributes; } return "end of data in attribute value"; @@ -599,7 +598,6 @@ fz_parse_xml(fz_context *ctx, unsigned char *s, int n, int preserve_white) memset(&root, 0, sizeof(root)); parser.head = &root; - parser.ctx = ctx; parser.preserve_white = preserve_white; parser.depth = 0; @@ -607,7 +605,7 @@ fz_parse_xml(fz_context *ctx, unsigned char *s, int n, int preserve_white) fz_try(ctx) { - error = xml_parse_document_imp(&parser, p); + error = xml_parse_document_imp(ctx, &parser, p); if (error) fz_throw(ctx, FZ_ERROR_GENERIC, "%s", error); } |