diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2010-06-30 12:34:55 +0000 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2010-06-30 12:34:55 +0000 |
commit | 0a79c2e01455dfd7b0642fdf4d1a6fe499a41c7e (patch) | |
tree | 2a0cccb6c997eb819596021b4972b1140a5e962d | |
parent | 956f9bfac6f6dc7f13fbfa707d392bc87b2bd33c (diff) |
Use gx_effective_clip_path to get the current visible area instead of manually maintaining the bounds while parsing.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@11466 a1074d23-0009-0410-80fe-cf8c14f379e6
-rw-r--r-- | xps/ghostxps.h | 12 | ||||
-rw-r--r-- | xps/xpsglyphs.c | 10 | ||||
-rw-r--r-- | xps/xpsgradient.c | 5 | ||||
-rw-r--r-- | xps/xpsopacity.c | 18 | ||||
-rw-r--r-- | xps/xpspage.c | 21 | ||||
-rw-r--r-- | xps/xpspath.c | 176 | ||||
-rw-r--r-- | xps/xpstile.c | 18 |
7 files changed, 37 insertions, 223 deletions
diff --git a/xps/ghostxps.h b/xps/ghostxps.h index 89e12ac51..c5a4fae37 100644 --- a/xps/ghostxps.h +++ b/xps/ghostxps.h @@ -63,6 +63,7 @@ #include "gzstate.h" #include "gzpath.h" +#include "gzcpath.h" #include "gsicc_manage.h" #include "gscms.h" @@ -337,9 +338,7 @@ void xps_end_opacity(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, c int xps_parse_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *node); int xps_parse_element(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_item_t *node); -void xps_update_bounds(xps_context_t *ctx, gs_rect *save); -void xps_restore_bounds(xps_context_t *ctx, gs_rect *save); -void xps_clip(xps_context_t *ctx, gs_rect *saved_bounds); +void xps_clip(xps_context_t *ctx); void xps_fill(xps_context_t *ctx); void xps_bounds_in_user_space(xps_context_t *ctx, gs_rect *user); @@ -406,13 +405,6 @@ struct xps_context_s * 1=nonzero, 0=evenodd */ int fill_rule; - - /* We often need the bounding box for the current - * area of the page affected by drawing operations. - * We keep these bounds updated every time we - * clip. The coordinates are in device space. - */ - gs_rect bounds; }; int xps_process_file(xps_context_t *ctx, char *filename); diff --git a/xps/xpsglyphs.c b/xps/xpsglyphs.c index f002abec2..6e03930f6 100644 --- a/xps/xpsglyphs.c +++ b/xps/xpsglyphs.c @@ -468,8 +468,6 @@ xps_parse_glyphs(xps_context_t *ctx, int is_sideways = 0; int bidi_level = 0; - gs_rect saved_bounds; - /* * Extract attributes and extended attributes. */ @@ -590,8 +588,7 @@ xps_parse_glyphs(xps_context_t *ctx, xps_parse_abbreviated_geometry(ctx, clip_att); if (clip_tag) xps_parse_path_geometry(ctx, dict, clip_tag, 0); - - xps_clip(ctx, &saved_bounds); + xps_clip(ctx); } font_size = atof(font_size_att); @@ -673,10 +670,5 @@ xps_parse_glyphs(xps_context_t *ctx, gs_grestore(ctx->pgs); - if (clip_att || clip_tag) - { - xps_restore_bounds(ctx, &saved_bounds); - } - return 0; } diff --git a/xps/xpsgradient.c b/xps/xpsgradient.c index d6f3b0d20..91d381cf7 100644 --- a/xps/xpsgradient.c +++ b/xps/xpsgradient.c @@ -733,7 +733,6 @@ xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dic int spread_method; int code; - gs_rect saved_bounds; gs_rect bbox; gs_function_t *color_func; @@ -794,7 +793,7 @@ xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dic has_opacity = xps_gradient_has_transparent_colors(stop_offsets, stop_colors, stop_count); - xps_clip(ctx, &saved_bounds); + xps_clip(ctx); gs_gsave(ctx->pgs); gs_concat(ctx->pgs, &transform); @@ -861,8 +860,6 @@ xps_parse_gradient_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dic gs_grestore(ctx->pgs); - xps_restore_bounds(ctx, &saved_bounds); - xps_free_gradient_stop_function(ctx, opacity_func); xps_free_gradient_stop_function(ctx, color_func); diff --git a/xps/xpsopacity.c b/xps/xpsopacity.c index 59407492c..cafb87664 100644 --- a/xps/xpsopacity.c +++ b/xps/xpsopacity.c @@ -15,6 +15,24 @@ #include "ghostxps.h" +void +xps_bounds_in_user_space(xps_context_t *ctx, gs_rect *ubox) +{ + gx_clip_path *clip_path; + gs_rect dbox; + int code; + + code = gx_effective_clip_path(ctx->pgs, &clip_path); + if (code < 0) + gs_warn("gx_effective_clip_path failed"); + + dbox.p.x = fixed2float(clip_path->outer_box.p.x); + dbox.p.y = fixed2float(clip_path->outer_box.p.y); + dbox.q.x = fixed2float(clip_path->outer_box.q.x); + dbox.q.y = fixed2float(clip_path->outer_box.q.y); + gs_bbox_transform_inverse(&dbox, &ctm_only(ctx->pgs), ubox); +} + int xps_begin_opacity(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, char *opacity_att, xps_item_t *opacity_mask_tag) diff --git a/xps/xpspage.c b/xps/xpspage.c index 1d98e0d96..5019638e9 100644 --- a/xps/xpspage.c +++ b/xps/xpspage.c @@ -32,8 +32,6 @@ xps_parse_canvas(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_i xps_item_t *clip_tag = NULL; xps_item_t *opacity_mask_tag = NULL; - gs_rect saved_bounds; - gs_matrix transform; transform_att = xps_att(root, "RenderTransform"); @@ -80,7 +78,7 @@ xps_parse_canvas(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_i xps_parse_abbreviated_geometry(ctx, clip_att); if (clip_tag) xps_parse_path_geometry(ctx, dict, clip_tag, 0); - xps_clip(ctx, &saved_bounds); + xps_clip(ctx); } code = xps_begin_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); @@ -101,11 +99,6 @@ xps_parse_canvas(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_i } } - if (clip_att || clip_tag) - { - xps_restore_bounds(ctx, &saved_bounds); - } - xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); gs_grestore(ctx->pgs); @@ -123,12 +116,10 @@ xps_parse_fixed_page(xps_context_t *ctx, xps_part_t *part) xps_resource_t *dict; char *width_att; char *height_att; - int code; - gs_matrix ctm; - gs_rect rc; int has_transparency; char base_uri[1024]; char *s; + int code; if_debug1('|', "doc: parsing page %s\n", part->name); @@ -197,14 +188,6 @@ xps_parse_fixed_page(xps_context_t *ctx, xps_part_t *part) code = gs_erasepage(pgs); if (code < 0) return gs_rethrow(code, "cannot clear page"); - - /* set initial bounds to cover the page */ - gs_currentmatrix(pgs, &ctm); - gs_point_transform(0.0, 0.0, &ctm, &rc.p); - gs_point_transform(atoi(width_att), atoi(height_att), &ctm, &rc.q); - if (rc.p.x > rc.q.x) { float t = rc.p.x; rc.p.x = rc.q.x; rc.q.x = t; } - if (rc.p.y > rc.q.y) { float t = rc.p.y; rc.p.y = rc.q.y; rc.q.y = t; } - ctx->bounds = rc; } /* Pre-parse looking for transparency */ diff --git a/xps/xpspath.c b/xps/xpspath.c index 3b93a0cf2..dec2803ff 100644 --- a/xps/xpspath.c +++ b/xps/xpspath.c @@ -15,153 +15,13 @@ #include "ghostxps.h" -static void -xps_grow_rect(gs_rect *rect, float x, float y) -{ - if (x < rect->p.x) rect->p.x = x; - if (y < rect->p.y) rect->p.y = y; - if (x > rect->q.x) rect->q.x = x; - if (y > rect->q.y) rect->q.y = y; -} - -void -xps_bounds_in_user_space(xps_context_t *ctx, gs_rect *user) -{ - gs_matrix ctm; - gs_matrix inv; - gs_point a, b, c, d; - gs_rect bbox; - - gs_currentmatrix(ctx->pgs, &ctm); - gs_matrix_invert(&ctm, &inv); - - bbox = ctx->bounds; - gs_point_transform(bbox.p.x, bbox.p.y, &inv, &a); - gs_point_transform(bbox.p.x, bbox.q.y, &inv, &b); - gs_point_transform(bbox.q.x, bbox.q.y, &inv, &c); - gs_point_transform(bbox.q.x, bbox.p.y, &inv, &d); - - user->p.x = MIN(MIN(a.x, b.x), MIN(c.x, d.x)); - user->p.y = MIN(MIN(a.y, b.y), MIN(c.y, d.y)); - user->q.x = MAX(MAX(a.x, b.x), MAX(c.x, d.x)); - user->q.y = MAX(MAX(a.y, b.y), MAX(c.y, d.y)); -} - -void -xps_update_bounds(xps_context_t *ctx, gs_rect *save) -{ - segment *seg; - curve_segment *cseg; - gs_rect rc; - - save->p.x = ctx->bounds.p.x; - save->p.y = ctx->bounds.p.y; - save->q.x = ctx->bounds.q.x; - save->q.y = ctx->bounds.q.y; - - /* get bounds of current path (that is about to be clipped) */ - /* the coordinates of the path segments are already in device space (yay!) */ - if (!ctx->pgs->path) - return; - - seg = (segment*)ctx->pgs->path->first_subpath; - if (seg) - { - rc.p.x = rc.q.x = fixed2float(seg->pt.x); - rc.p.y = rc.q.y = fixed2float(seg->pt.y); - } - else - { - rc.p.x = rc.q.x = 0.0; - rc.p.y = rc.q.y = 0.0; - } - - while (seg) - { - switch (seg->type) - { - case s_start: - xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); - break; - case s_line: - xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); - break; - case s_line_close: - break; - case s_curve: - cseg = (curve_segment*)seg; - xps_grow_rect(&rc, fixed2float(cseg->p1.x), fixed2float(cseg->p1.y)); - xps_grow_rect(&rc, fixed2float(cseg->p2.x), fixed2float(cseg->p2.y)); - xps_grow_rect(&rc, fixed2float(seg->pt.x), fixed2float(seg->pt.y)); - break; - } - seg = seg->next; - } - - /* intersect with old bounds, and fix degenerate case */ - - rect_intersect(ctx->bounds, rc); - - if (ctx->bounds.q.x < ctx->bounds.p.x) - ctx->bounds.q.x = ctx->bounds.p.x; - if (ctx->bounds.q.y < ctx->bounds.p.y) - ctx->bounds.q.y = ctx->bounds.p.y; -} - void -xps_restore_bounds(xps_context_t *ctx, gs_rect *save) +xps_clip(xps_context_t *ctx) { - ctx->bounds.p.x = save->p.x; - ctx->bounds.p.y = save->p.y; - ctx->bounds.q.x = save->q.x; - ctx->bounds.q.y = save->q.y; -} - -#if 0 -static void -xps_debug_bounds(xps_context_t *ctx) -{ - gs_matrix mat; - - gs_gsave(ctx->pgs); - - dprintf6("bounds: debug [%g %g %g %g] w=%g h=%g\n", - ctx->bounds.p.x, ctx->bounds.p.y, - ctx->bounds.q.x, ctx->bounds.q.y, - ctx->bounds.q.x - ctx->bounds.p.x, - ctx->bounds.q.y - ctx->bounds.p.y); - - gs_make_identity(&mat); - gs_setmatrix(ctx->pgs, &mat); - - gs_setgray(ctx->pgs, 0.3); - gs_moveto(ctx->pgs, ctx->bounds.p.x, ctx->bounds.p.y); - gs_lineto(ctx->pgs, ctx->bounds.q.x, ctx->bounds.q.y); - gs_moveto(ctx->pgs, ctx->bounds.q.x, ctx->bounds.p.y); - gs_lineto(ctx->pgs, ctx->bounds.p.x, ctx->bounds.q.y); - - gs_moveto(ctx->pgs, ctx->bounds.p.x, ctx->bounds.p.y); - gs_lineto(ctx->pgs, ctx->bounds.p.x, ctx->bounds.q.y); - gs_lineto(ctx->pgs, ctx->bounds.q.x, ctx->bounds.q.y); - gs_lineto(ctx->pgs, ctx->bounds.q.x, ctx->bounds.p.y); - gs_closepath(ctx->pgs); - - gs_stroke(ctx->pgs); - - gs_grestore(ctx->pgs); -} -#endif - -void -xps_clip(xps_context_t *ctx, gs_rect *saved_bounds) -{ - xps_update_bounds(ctx, saved_bounds); - if (ctx->fill_rule == 0) gs_eoclip(ctx->pgs); else gs_clip(ctx->pgs); - gs_newpath(ctx->pgs); } @@ -173,12 +33,12 @@ xps_fill(xps_context_t *ctx) else if (ctx->fill_rule == 0) { if (gs_eofill(ctx->pgs) == gs_error_Remap_Color) xps_high_level_pattern(ctx); - gs_eofill(ctx->pgs); + gs_eofill(ctx->pgs); } else { if (gs_fill(ctx->pgs) == gs_error_Remap_Color) xps_high_level_pattern(ctx); - gs_fill(ctx->pgs); + gs_fill(ctx->pgs); } } @@ -940,9 +800,6 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite float samples[32]; gs_color_space *colorspace; - gs_rect saved_bounds_clip; - gs_rect saved_bounds_opacity; - gs_gsave(ctx->pgs); ctx->fill_rule = 0; @@ -1085,10 +942,10 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite xps_parse_abbreviated_geometry(ctx, clip_att); if (clip_tag) xps_parse_path_geometry(ctx, dict, clip_tag, 0); - - xps_clip(ctx, &saved_bounds_clip); + xps_clip(ctx); } +#if 0 // XXX if (opacity_att || opacity_mask_tag) { /* clip the bounds with the actual path */ @@ -1098,13 +955,14 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite xps_parse_path_geometry(ctx, dict, data_tag, 0); xps_update_bounds(ctx, &saved_bounds_opacity); gs_newpath(ctx->pgs); + } +#endif - code = xps_begin_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); - if (code) - { - gs_grestore(ctx->pgs); - return gs_rethrow(code, "cannot create transparency group"); - } + code = xps_begin_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); + if (code) + { + gs_grestore(ctx->pgs); + return gs_rethrow(code, "cannot create transparency group"); } if (fill_att) @@ -1172,17 +1030,7 @@ xps_parse_path(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, xps_ite } } - if (opacity_att || opacity_mask_tag) - xps_restore_bounds(ctx, &saved_bounds_opacity); - xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); - gs_grestore(ctx->pgs); - - if (clip_att || clip_tag) - { - xps_restore_bounds(ctx, &saved_bounds_clip); - } - return 0; } diff --git a/xps/xpstile.c b/xps/xpstile.c index 866a56cc2..3af66494b 100644 --- a/xps/xpstile.c +++ b/xps/xpstile.c @@ -38,7 +38,6 @@ static int xps_paint_tiling_brush_clipped(struct tile_closure_s *c) { xps_context_t *ctx = c->ctx; - gs_rect saved_bounds; int code; gs_moveto(ctx->pgs, c->viewbox.p.x, c->viewbox.p.y); @@ -49,21 +48,10 @@ xps_paint_tiling_brush_clipped(struct tile_closure_s *c) gs_clip(ctx->pgs); gs_newpath(ctx->pgs); - /* tile paint functions use a different device - * with a different coord space, so we have to - * tweak the bounds. - */ - - saved_bounds = ctx->bounds; - - ctx->bounds = c->viewbox; // transform? - code = c->func(c->ctx, c->base_uri, c->dict, c->tag, c->user); if (code < 0) return gs_rethrow(code, "cannot draw clipped tile"); - ctx->bounds = saved_bounds; - return 0; } @@ -378,9 +366,7 @@ xps_parse_tiling_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, } else { - gs_rect saved_bounds; - - xps_clip(ctx, &saved_bounds); + xps_clip(ctx); gs_concat(ctx->pgs, &transform); @@ -403,8 +389,6 @@ xps_parse_tiling_brush(xps_context_t *ctx, char *base_uri, xps_resource_t *dict, gs_grestore(ctx->pgs); return gs_rethrow(code, "cannot draw tile"); } - - xps_restore_bounds(ctx, &saved_bounds); } xps_end_opacity(ctx, base_uri, dict, opacity_att, NULL); |