diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-01-21 16:42:45 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-02-17 18:05:39 +0100 |
commit | f84a189d5f94250e46d2cbd1a75aba00130e2dd6 (patch) | |
tree | 8ee614ab90de1baa8941f91ae4946ed5c2e70721 /source/xps/xps-gradient.c | |
parent | 681039767f2ccc72e236246178893eb0989169c9 (diff) | |
download | mupdf-f84a189d5f94250e46d2cbd1a75aba00130e2dd6.tar.xz |
Add ctx parameter and remove embedded contexts for API regularity.
Purge several embedded contexts:
Remove embedded context in fz_output.
Remove embedded context in fz_stream.
Remove embedded context in fz_device.
Remove fz_rebind_stream (since it is no longer necessary).
Remove embedded context in svg_device.
Remove embedded context in XML parser.
Add ctx argument to fz_document functions.
Remove embedded context in fz_document.
Remove embedded context in pdf_document.
Remove embedded context in pdf_obj.
Make fz_page independent of fz_document in the interface.
We shouldn't need to pass the document to all functions handling a page.
If a page is tied to the source document, it's redundant; otherwise it's
just pointless.
Fix reference counting oddity in fz_new_image_from_pixmap.
Diffstat (limited to 'source/xps/xps-gradient.c')
-rw-r--r-- | source/xps/xps-gradient.c | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/source/xps/xps-gradient.c b/source/xps/xps-gradient.c index d156a406..f3a9f8e8 100644 --- a/source/xps/xps-gradient.c +++ b/source/xps/xps-gradient.c @@ -35,7 +35,7 @@ static inline float lerp(float a, float b, float x) } static int -xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, +xps_parse_gradient_stops(fz_context *ctx, xps_document *doc, char *base_uri, fz_xml *node, struct stop *stops, int maxcount) { fz_colorspace *colorspace; @@ -60,9 +60,9 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, stops[count].offset = fz_atof(offset); stops[count].index = count; - xps_parse_color(doc, base_uri, color, &colorspace, sample); + xps_parse_color(ctx, doc, base_uri, color, &colorspace, sample); - fz_convert_color(doc->ctx, fz_device_rgb(doc->ctx), rgb, colorspace, sample + 1); + fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, sample + 1); stops[count].r = rgb[0]; stops[count].g = rgb[1]; @@ -77,7 +77,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, if (count == 0) { - fz_warn(doc->ctx, "gradient brush has no gradient stops"); + fz_warn(ctx, "gradient brush has no gradient stops"); stops[0].offset = 0; stops[0].r = 0; stops[0].g = 0; @@ -92,7 +92,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, } if (count == maxcount) - fz_warn(doc->ctx, "gradient brush exceeded maximum number of gradient stops"); + fz_warn(ctx, "gradient brush exceeded maximum number of gradient stops"); /* Postprocess to make sure the range of offsets is 0.0 to 1.0 */ @@ -175,7 +175,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node, } static void -xps_sample_gradient_stops(fz_shade *shade, struct stop *stops, int count) +xps_sample_gradient_stops(fz_context *ctx, xps_document *doc, fz_shade *shade, struct stop *stops, int count) { float offset, d; int i, k; @@ -204,18 +204,19 @@ xps_sample_gradient_stops(fz_shade *shade, struct stop *stops, int count) */ static void -xps_draw_one_radial_gradient(xps_document *doc, const fz_matrix *ctm, +xps_draw_one_radial_gradient(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, struct stop *stops, int count, int extend, float x0, float y0, float r0, float x1, float y1, float r1) { + fz_device *dev = doc->dev; fz_shade *shade; /* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */ - shade = fz_malloc_struct(doc->ctx, fz_shade); + shade = fz_malloc_struct(ctx, fz_shade); FZ_INIT_STORABLE(shade, 1, fz_drop_shade_imp); - shade->colorspace = fz_device_rgb(doc->ctx); + shade->colorspace = fz_device_rgb(ctx); shade->bbox = fz_infinite_rect; shade->matrix = fz_identity; shade->use_background = 0; @@ -224,7 +225,7 @@ xps_draw_one_radial_gradient(xps_document *doc, const fz_matrix *ctm, shade->u.l_or_r.extend[0] = extend; shade->u.l_or_r.extend[1] = extend; - xps_sample_gradient_stops(shade, stops, count); + xps_sample_gradient_stops(ctx, doc, shade, stops, count); shade->u.l_or_r.coords[0][0] = x0; shade->u.l_or_r.coords[0][1] = y0; @@ -233,9 +234,9 @@ xps_draw_one_radial_gradient(xps_document *doc, const fz_matrix *ctm, shade->u.l_or_r.coords[1][1] = y1; shade->u.l_or_r.coords[1][2] = r1; - fz_fill_shade(doc->dev, shade, ctm, 1); + fz_fill_shade(ctx, dev, shade, ctm, 1); - fz_drop_shade(doc->ctx, shade); + fz_drop_shade(ctx, shade); } /* @@ -243,17 +244,18 @@ xps_draw_one_radial_gradient(xps_document *doc, const fz_matrix *ctm, */ static void -xps_draw_one_linear_gradient(xps_document *doc, const fz_matrix *ctm, +xps_draw_one_linear_gradient(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, struct stop *stops, int count, int extend, float x0, float y0, float x1, float y1) { + fz_device *dev = doc->dev; fz_shade *shade; /* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */ - shade = fz_malloc_struct(doc->ctx, fz_shade); + shade = fz_malloc_struct(ctx, fz_shade); FZ_INIT_STORABLE(shade, 1, fz_drop_shade_imp); - shade->colorspace = fz_device_rgb(doc->ctx); + shade->colorspace = fz_device_rgb(ctx); shade->bbox = fz_infinite_rect; shade->matrix = fz_identity; shade->use_background = 0; @@ -262,7 +264,7 @@ xps_draw_one_linear_gradient(xps_document *doc, const fz_matrix *ctm, shade->u.l_or_r.extend[0] = extend; shade->u.l_or_r.extend[1] = extend; - xps_sample_gradient_stops(shade, stops, count); + xps_sample_gradient_stops(ctx, doc, shade, stops, count); shade->u.l_or_r.coords[0][0] = x0; shade->u.l_or_r.coords[0][1] = y0; @@ -271,9 +273,9 @@ xps_draw_one_linear_gradient(xps_document *doc, const fz_matrix *ctm, shade->u.l_or_r.coords[1][1] = y1; shade->u.l_or_r.coords[1][2] = 0; - fz_fill_shade(doc->dev, shade, ctm, doc->opacity[doc->opacity_top]); + fz_fill_shade(ctx, dev, shade, ctm, doc->opacity[doc->opacity_top]); - fz_drop_shade(doc->ctx, shade); + fz_drop_shade(ctx, shade); } /* @@ -292,7 +294,7 @@ static inline float point_inside_circle(float px, float py, float x, float y, fl } static void -xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, +xps_draw_radial_gradient(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, struct stop *stops, int count, fz_xml *root, int spread) { @@ -317,9 +319,9 @@ xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect yrad = 1.0; if (origin_att) - xps_parse_point(origin_att, &x0, &y0); + xps_parse_point(ctx, doc, origin_att, &x0, &y0); if (center_att) - xps_parse_point(center_att, &x1, &y1); + xps_parse_point(ctx, doc, center_att, &x1, &y1); if (radius_x_att) xrad = fz_atof(radius_x_att); if (radius_y_att) @@ -353,7 +355,7 @@ xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect if (spread == SPREAD_REPEAT) { for (i = ma - 1; i >= 0; i--) - xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad); + xps_draw_one_radial_gradient(ctx, doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad); } else if (spread == SPREAD_REFLECT) { @@ -361,13 +363,13 @@ xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect ma++; for (i = ma - 2; i >= 0; i -= 2) { - xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad); - xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + (i + 2) * xrad, x1, y1, r1 + i * xrad); + xps_draw_one_radial_gradient(ctx, doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad); + xps_draw_one_radial_gradient(ctx, doc, &local_ctm, stops, count, 0, x0, y0, r0 + (i + 2) * xrad, x1, y1, r1 + i * xrad); } } else { - xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 1, x0, y0, r0, x1, y1, r1); + xps_draw_one_radial_gradient(ctx, doc, &local_ctm, stops, count, 1, x0, y0, r0, x1, y1, r1); } } @@ -377,7 +379,7 @@ xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect */ static void -xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, +xps_draw_linear_gradient(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, struct stop *stops, int count, fz_xml *root, int spread) { @@ -395,9 +397,9 @@ xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect x1 = y1 = 1; if (start_point_att) - xps_parse_point(start_point_att, &x0, &y0); + xps_parse_point(ctx, doc, start_point_att, &x0, &y0); if (end_point_att) - xps_parse_point(end_point_att, &x1, &y1); + xps_parse_point(ctx, doc, end_point_att, &x1, &y1); p1.x = x0; p1.y = y0; p2.x = x1; p2.y = y1; fz_transform_rect(&local_area, fz_invert_matrix(&inv, ctm)); @@ -415,7 +417,7 @@ xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect if (spread == SPREAD_REPEAT) { for (i = mi; i < ma; i++) - xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy); + xps_draw_one_linear_gradient(ctx, doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy); } else if (spread == SPREAD_REFLECT) { @@ -423,13 +425,13 @@ xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect mi--; for (i = mi; i < ma; i += 2) { - xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy); - xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + (i + 2) * dx, y0 + (i + 2) * dy, x1 + i * dx, y1 + i * dy); + xps_draw_one_linear_gradient(ctx, doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy); + xps_draw_one_linear_gradient(ctx, doc, ctm, stops, count, 0, x0 + (i + 2) * dx, y0 + (i + 2) * dy, x1 + i * dx, y1 + i * dy); } } else { - xps_draw_one_linear_gradient(doc, ctm, stops, count, 1, x0, y0, x1, y1); + xps_draw_one_linear_gradient(ctx, doc, ctm, stops, count, 1, x0, y0, x1, y1); } } @@ -439,9 +441,9 @@ xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect */ static void -xps_parse_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, +xps_parse_gradient_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root, - void (*draw)(xps_document *, const fz_matrix*, const fz_rect *, struct stop *, int, fz_xml *, int)) + void (*draw)(fz_context *ctx, xps_document *, const fz_matrix*, const fz_rect *, struct stop *, int, fz_xml *, int)) { fz_xml *node; @@ -473,7 +475,7 @@ xps_parse_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect stop_tag = fz_xml_down(node); } - xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL); + xps_resolve_resource_reference(ctx, doc, dict, &transform_att, &transform_tag, NULL); spread_method = SPREAD_PAD; if (spread_att) @@ -488,40 +490,40 @@ xps_parse_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect transform = fz_identity; if (transform_att) - xps_parse_render_transform(doc, transform_att, &transform); + xps_parse_render_transform(ctx, doc, transform_att, &transform); if (transform_tag) - xps_parse_matrix_transform(doc, transform_tag, &transform); + xps_parse_matrix_transform(ctx, doc, transform_tag, &transform); fz_concat(&transform, &transform, ctm); if (!stop_tag) { - fz_warn(doc->ctx, "missing gradient stops tag"); + fz_warn(ctx, "missing gradient stops tag"); return; } - stop_count = xps_parse_gradient_stops(doc, base_uri, stop_tag, stop_list, MAX_STOPS); + stop_count = xps_parse_gradient_stops(ctx, doc, base_uri, stop_tag, stop_list, MAX_STOPS); if (stop_count == 0) { - fz_warn(doc->ctx, "no gradient stops found"); + fz_warn(ctx, "no gradient stops found"); return; } - xps_begin_opacity(doc, &transform, area, base_uri, dict, opacity_att, NULL); + xps_begin_opacity(ctx, doc, &transform, area, base_uri, dict, opacity_att, NULL); - draw(doc, &transform, area, stop_list, stop_count, root, spread_method); + draw(ctx, doc, &transform, area, stop_list, stop_count, root, spread_method); - xps_end_opacity(doc, base_uri, dict, opacity_att, NULL); + xps_end_opacity(ctx, doc, base_uri, dict, opacity_att, NULL); } void -xps_parse_linear_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, +xps_parse_linear_gradient_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root) { - xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_linear_gradient); + xps_parse_gradient_brush(ctx, doc, ctm, area, base_uri, dict, root, xps_draw_linear_gradient); } void -xps_parse_radial_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, +xps_parse_radial_gradient_brush(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *root) { - xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_radial_gradient); + xps_parse_gradient_brush(ctx, doc, ctm, area, base_uri, dict, root, xps_draw_radial_gradient); } |