diff options
author | Carl Worth <cworth@cworth.org> | 2005-04-14 14:42:26 +0000 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2005-04-14 14:42:26 +0000 |
commit | 828094aef860c8087564c93408846a4e81eec20d (patch) | |
tree | a184e27200c9abb643b9e345983eddc1af8b1ebb | |
parent | c0d9c13d0403673a7fe994664a4f616c71301474 (diff) |
and delete:
cairo_set_pattern -> cairo_set_source cairo_get_pattern -> cairo_get_source cairo_set_rgb_color -> cairo_set_source_rgb
-> cairo_set_source_rgba cairo_set_alpha -> cairo_get_alpha ->
Note that we'll likely want to add cairo_set_source_surface.
Add _cairo_stock_color helper function. Improve some interfaces:
_cairo_color_init _cairo_color_init_rgb _cairo_color_set_rgb -> _cairo_color_init_rgba _cairo_color_set_alpha _cairo_color_multiply_alpha
_cairo_color_get_rgb -> _cairo_color_get_rbga _cairo_color_get_rgba_premultiplied
Add cairo_stock_t and some helper macros:
CAIRO_COLOR_WHITE CAIRO_COLOR_BLACK CAIRO_COLOR_TRANSPARENT
Fix cairo_pattern_t by eliminating pattern->alpha. Fix cairo_solid_pattern_t to use cairo_color_t rather than three doubles.
Track removal of pattern->alpha, simplifying the code considerably
Track _cairo_color interface changes. Remove gstate->alpha. Propagate down set_source renamings.
cairo_pattern_add_color_stop -> cairo_pattern_add_color_stop_rgba
and add:
cairo_pattern_add_color_stop_rgb
Remove pattern->alpha, simplifying the code considerably.
Track pattern and color interface changes.
Add const where appropriate on cairo_color_t*.
Add private type inspection predicate. (cairo_xlib_surface_set_size): Add check for surface type mismatch, (no useful error reporting yet, though).
Note coverage as en expected failure.
Improve line wrap on expected failure messages.
Port all tests to new cairo_set_source interfaces.
-rw-r--r-- | ChangeLog | 84 | ||||
-rw-r--r-- | src/cairo-color.c | 120 | ||||
-rw-r--r-- | src/cairo-glitz-surface.c | 94 | ||||
-rw-r--r-- | src/cairo-gstate-private.h | 3 | ||||
-rw-r--r-- | src/cairo-gstate.c | 147 | ||||
-rw-r--r-- | src/cairo-pattern.c | 318 | ||||
-rw-r--r-- | src/cairo-pdf-surface.c | 8 | ||||
-rw-r--r-- | src/cairo-ps-surface.c | 9 | ||||
-rw-r--r-- | src/cairo-surface.c | 35 | ||||
-rw-r--r-- | src/cairo-xlib-surface.c | 18 | ||||
-rw-r--r-- | src/cairo.c | 146 | ||||
-rw-r--r-- | src/cairo.h | 55 | ||||
-rw-r--r-- | src/cairoint.h | 92 | ||||
-rw-r--r-- | test/Makefile.am | 1 | ||||
-rw-r--r-- | test/cairo-test.c | 2 | ||||
-rw-r--r-- | test/clip-twice.c | 3 | ||||
-rw-r--r-- | test/coverage.c | 23 | ||||
-rw-r--r-- | test/fill-rule.c | 2 | ||||
-rw-r--r-- | test/line-width.c | 2 | ||||
-rw-r--r-- | test/linear-gradient.c | 31 | ||||
-rw-r--r-- | test/pixman-rotate.c | 13 | ||||
-rw-r--r-- | test/set-source.c | 16 | ||||
-rw-r--r-- | test/text-rotate.c | 9 | ||||
-rw-r--r-- | test/trap-clip.c | 11 |
24 files changed, 628 insertions, 614 deletions
@@ -1,5 +1,89 @@ 2005-04-14 Carl Worth <cworth@cworth.org> + * src/cairo.h: + * src/cairo.c: Rename, add, and delete: + + cairo_set_pattern -> cairo_set_source + cairo_get_pattern -> cairo_get_source + cairo_set_rgb_color -> cairo_set_source_rgb + -> cairo_set_source_rgba + cairo_set_alpha -> + cairo_get_alpha -> + + Note that we'll likely want to add cairo_set_source_surface. + + * src/cairo-color.c: Add _cairo_stock_color helper function. + Improve some interfaces: + + _cairo_color_init _cairo_color_init_rgb + _cairo_color_set_rgb -> _cairo_color_init_rgba + _cairo_color_set_alpha _cairo_color_multiply_alpha + + _cairo_color_get_rgb -> _cairo_color_get_rbga + _cairo_color_get_rgba_premultiplied + + * src/cairoint.h: Add cairo_stock_t and some helper macros: + + CAIRO_COLOR_WHITE + CAIRO_COLOR_BLACK + CAIRO_COLOR_TRANSPARENT + + Fix cairo_pattern_t by eliminating pattern->alpha. + Fix cairo_solid_pattern_t to use cairo_color_t rather than three + doubles. + + * src/cairo-glitz-surface.c: + (_cairo_glitz_pattern_acquire_surface), + (_cairo_glitz_pattern_acquire_surfaces), + (_cairo_glitz_surface_composite_trapezoids): Track removal of + pattern->alpha, simplifying the code considerably + + * src/cairo-gstate-private.h: + + * src/cairo-gstate.c: Track _cairo_color interface changes. Remove + gstate->alpha. Propagate down set_source renamings. + + * src/cairo.h: + * src/cairo-pattern.c: Rename: + + cairo_pattern_add_color_stop -> cairo_pattern_add_color_stop_rgba + + and add: + + cairo_pattern_add_color_stop_rgb + + Remove pattern->alpha, simplifying the code considerably. + + * src/cairo-pdf-surface.c: + * src/cairo-ps-surface.c: Track pattern and color interface + changes. + + * src/cairo-surface.c: Add const where appropriate on + cairo_color_t*. + + * src/cairo-xlib-surface.c: (_cairo_surface_is_xlib): Add private + type inspection predicate. + (cairo_xlib_surface_set_size): Add check for surface type + mismatch, (no useful error reporting yet, though). + + * test/Makefile.am: Note coverage as en expected failure. + + * test/cairo-test.c: (cairo_test_expect_failure): Improve line + wrap on expected failure messages. + + * test/clip-twice.c: + * test/coverage.c: + * test/fill-rule.c: + * test/line-width.c: + * test/linear-gradient.c: + * test/pixman-rotate.c: + * test/set-source.c: + * test/text-rotate.c: + * test/trap-clip.c: Port all tests to new cairo_set_source + interfaces. + +2005-04-14 Carl Worth <cworth@cworth.org> + * test/gradient-alpha-ref.png: * test/gradient-alpha.c: (draw): Make gradient change color in addition to just changing alpha in order to highlight distinction diff --git a/src/cairo-color.c b/src/cairo-color.c index f203d96cc..beb4a3474 100644 --- a/src/cairo-color.c +++ b/src/cairo-color.c @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -36,62 +37,127 @@ #include "cairoint.h" -static cairo_color_t const CAIRO_COLOR_WHITE = { - 1.0, 1.0, 1.0, 1.0, +static cairo_color_t const cairo_color_white = { + 1.0, 1.0, 1.0, 1.0, 0xffff, 0xffff, 0xffff, 0xffff }; -static void -_cairo_color_compute_shorts (cairo_color_t *color); +static cairo_color_t const cairo_color_black = { + 0.0, 0.0, 0.0, 1.0, + 0x0, 0x0, 0x0, 0xffff +}; + +static cairo_color_t const cairo_color_transparent = { + 0.0, 0.0, 0.0, 0.0, + 0x0, 0x0, 0x0, 0x0 +}; + +static cairo_color_t const cairo_color_magenta = { + 1.0, 0.0, 1.0, 1.0, + 0xffff, 0x0, 0xffff, 0xffff +}; + +const cairo_color_t * +_cairo_stock_color (cairo_stock_t stock) +{ + switch (stock) { + case CAIRO_STOCK_WHITE: + return &cairo_color_white; + case CAIRO_STOCK_BLACK: + return &cairo_color_black; + case CAIRO_STOCK_TRANSPARENT: + return &cairo_color_transparent; + } + + ASSERT_NOT_REACHED; + + /* If the user can get here somehow, give a color that indicates a + * problem. */ + return &cairo_color_magenta; +} void _cairo_color_init (cairo_color_t *color) { - *color = CAIRO_COLOR_WHITE; + *color = cairo_color_white; } void -_cairo_color_fini (cairo_color_t *color) +_cairo_color_init_rgb (cairo_color_t *color, + double red, double green, double blue) { - /* Nothing to do here */ + _cairo_color_init_rgba (color, red, green, blue, 1.0); +} + + +/* XXX: The calculation of: + + channel * 0xffff + + isn't really what we want since: + + (1.0 - epsilon) * 0xffff = 0xfffe + + In other words, given an input range of [0.0, 1.0], we have an + infinitely small range tha maps to the output value 0xffff, + (while having large, uniformly sized input ranges for all + other output values). This is undesirable, particularly when + we want to do optimizations for "opaque" colors specfied as + floating-point. +*/ +static void +_cairo_color_compute_shorts (cairo_color_t *color) +{ + color->red_short = color->red * color->alpha * 0xffff; + color->green_short = color->green * color->alpha * 0xffff; + color->blue_short = color->blue * color->alpha * 0xffff; + color->alpha_short = color->alpha * 0xffff; } void -_cairo_color_set_rgb (cairo_color_t *color, double red, double green, double blue) +_cairo_color_init_rgba (cairo_color_t *color, + double red, double green, double blue, + double alpha) { color->red = red; color->green = green; color->blue = blue; + color->alpha = alpha; _cairo_color_compute_shorts (color); } void -_cairo_color_get_rgb (const cairo_color_t *color, - double *red, double *green, double *blue) +_cairo_color_multiply_alpha (cairo_color_t *color, + double alpha) { - if (red) - *red = color->red; - if (green) - *green = color->green; - if (blue) - *blue = color->blue; + color->alpha *= alpha; + + _cairo_color_compute_shorts (color); } void -_cairo_color_set_alpha (cairo_color_t *color, double alpha) +_cairo_color_get_rgba (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha) { - color->alpha = alpha; - - _cairo_color_compute_shorts (color); + *red = color->red; + *green = color->green; + *blue = color->blue; + *alpha = color->alpha; } -static void -_cairo_color_compute_shorts (cairo_color_t *color) +void +_cairo_color_get_rgba_premultiplied (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha) { - color->red_short = (color->red * color->alpha) * 0xffff; - color->green_short = (color->green * color->alpha) * 0xffff; - color->blue_short = (color->blue * color->alpha) * 0xffff; - color->alpha_short = color->alpha * 0xffff; + *red = color->red * color->alpha; + *green = color->green * color->alpha; + *blue = color->blue * color->alpha; + *alpha = color->alpha; } - diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c index a55e775cb..6309b115f 100644 --- a/src/cairo-glitz-surface.c +++ b/src/cairo-glitz-surface.c @@ -562,12 +562,12 @@ _cairo_glitz_pattern_acquire_surface (cairo_pattern_t *pattern, pattern->filter != CAIRO_FILTER_BEST) break; - alpha = (gradient->stops[0].color.alpha * pattern->alpha) * 0xffff; + alpha = (gradient->stops[0].color.alpha) * 0xffff; for (i = 1; i < gradient->n_stops; i++) { unsigned short a; - a = (gradient->stops[i].color.alpha * pattern->alpha) * 0xffff; + a = (gradient->stops[i].color.alpha) * 0xffff; if (a != alpha) break; } @@ -729,50 +729,30 @@ _cairo_glitz_pattern_acquire_surfaces (cairo_pattern_t *src, { cairo_int_status_t status; cairo_pattern_union_t tmp; - cairo_bool_t src_opaque, mask_opaque; - double src_alpha, mask_alpha; - src_opaque = _cairo_pattern_is_opaque (src); - mask_opaque = !mask || _cairo_pattern_is_opaque (mask); - - /* For surface patterns, we move any translucency from src->alpha - * to mask->alpha so we can use the source unchanged. Otherwise we - * move the translucency from mask->alpha to src->alpha so that - * we can drop the mask if possible. - */ - if (src->type == CAIRO_PATTERN_SURFACE) - { - if (mask) { - mask_opaque = mask_opaque && src_opaque; - mask_alpha = mask->alpha * src->alpha; - } else { - mask_opaque = src_opaque; - mask_alpha = src->alpha; - } - - src_alpha = 1.0; - src_opaque = TRUE; - } - else + /* If src and mask are both solid, then the mask alpha can be + * combined into src and mask can be ignored. */ + + /* XXX: This optimization assumes that there is no color + * information in mask, so this will need to change when we + * support RENDER-style 4-channel masks. */ + + if (src->type == CAIRO_PATTERN_SOLID && + mask->type == CAIRO_PATTERN_SOLID) { - if (mask) - { - src_opaque = mask_opaque && src_opaque; - src_alpha = mask->alpha * src->alpha; - /* FIXME: This needs changing when we support RENDER - * style 4-channel masks. - */ - if (mask->type == CAIRO_PATTERN_SOLID) - mask = NULL; - } else - src_alpha = src->alpha; - - mask_alpha = 1.0; - mask_opaque = TRUE; - } + cairo_color_t combined; + cairo_solid_pattern_t *src_solid = (cairo_solid_pattern_t *) src; + cairo_solid_pattern_t *mask_solid = (cairo_solid_pattern_t *) mask; + + combined = src_solid->color; + _cairo_color_multiply_alpha (&combined, mask_solid->color.alpha); + + _cairo_pattern_init_solid (&tmp.solid, &combined); - _cairo_pattern_init_copy (&tmp.base, src); - _cairo_pattern_set_alpha (&tmp.base, src_alpha); + mask = NULL; + } else { + _cairo_pattern_init_copy (&tmp.base, src); + } status = _cairo_glitz_pattern_acquire_surface (&tmp.base, dst, src_x, src_y, @@ -784,14 +764,9 @@ _cairo_glitz_pattern_acquire_surfaces (cairo_pattern_t *src, if (status) return status; - if (mask || !mask_opaque) + if (mask) { - if (mask) - _cairo_pattern_init_copy (&tmp.base, mask); - else - _cairo_pattern_init_solid (&tmp.solid, 0.0, 0.0, 0.0); - - _cairo_pattern_set_alpha (&tmp.base, mask_alpha); + _cairo_pattern_init_copy (&tmp.base, mask); status = _cairo_glitz_pattern_acquire_surface (&tmp.base, dst, mask_x, mask_y, @@ -1001,7 +976,6 @@ _cairo_glitz_surface_composite_trapezoids (cairo_operator_t op, cairo_pattern_union_t tmp; _cairo_pattern_init_copy (&tmp.base, pattern); - _cairo_pattern_set_alpha (&tmp.base, 1.0); status = _cairo_glitz_pattern_acquire_surface (&tmp.base, dst, src_x, src_y, @@ -1009,8 +983,6 @@ _cairo_glitz_surface_composite_trapezoids (cairo_operator_t op, &src, &attributes); _cairo_pattern_fini (&tmp.base); - - alpha = pattern->alpha * 0xffff; } else { @@ -1018,8 +990,8 @@ _cairo_glitz_surface_composite_trapezoids (cairo_operator_t op, src_x, src_y, width, height, &src, &attributes); - alpha = 0xffff; } + alpha = 0xffff; if (status) return status; @@ -1052,7 +1024,7 @@ _cairo_glitz_surface_composite_trapezoids (cairo_operator_t op, return CAIRO_INT_STATUS_UNSUPPORTED; } - color.red = color.green = color.blue = color.alpha = alpha; + color.red = color.green = color.blue = color.alpha = 0xffff; glitz_set_rectangle (mask->surface, &clear_black, 0, 0, 1, 1); glitz_set_rectangle (mask->surface, &color, 1, 0, 1, 1); @@ -1142,18 +1114,6 @@ _cairo_glitz_surface_composite_trapezoids (cairo_operator_t op, pixman_add_trapezoids (image->pixman_image, -dst_x, -dst_y, (pixman_trapezoid_t *) traps, n_traps); - if (alpha != 0xffff) - { - pixman_color_t color; - - color.red = color.green = color.blue = color.alpha = alpha; - - pixman_fill_rectangle (PIXMAN_OPERATOR_IN, - image->pixman_image, - &color, - 0, 0, width, height); - } - mask = (cairo_glitz_surface_t *) _cairo_surface_create_similar_scratch (&dst->base, CAIRO_FORMAT_A8, 0, diff --git a/src/cairo-gstate-private.h b/src/cairo-gstate-private.h index 4ec5291a6..f266bbf4f 100644 --- a/src/cairo-gstate-private.h +++ b/src/cairo-gstate-private.h @@ -64,8 +64,7 @@ struct _cairo_gstate { cairo_surface_t *surface; - cairo_pattern_t *pattern; - double alpha; + cairo_pattern_t *source; cairo_clip_rec_t clip; diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index a9d72bb77..98b2888ba 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -105,12 +106,10 @@ _cairo_gstate_init (cairo_gstate_t *gstate) gstate->clip.region = NULL; gstate->clip.surface = NULL; - - gstate->pattern = _cairo_pattern_create_solid (0.0, 0.0, 0.0); - if (!gstate->pattern) - return CAIRO_STATUS_NO_MEMORY; - gstate->alpha = 1.0; + gstate->source = _cairo_pattern_create_solid (CAIRO_COLOR_BLACK); + if (!gstate->source) + return CAIRO_STATUS_NO_MEMORY; _cairo_gstate_identity_matrix (gstate); @@ -157,7 +156,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other) cairo_surface_reference (gstate->surface); cairo_surface_reference (gstate->clip.surface); - cairo_pattern_reference (gstate->pattern); + cairo_pattern_reference (gstate->source); status = _cairo_path_fixed_init_copy (&gstate->path, &other->path); if (status) @@ -203,7 +202,7 @@ _cairo_gstate_fini (cairo_gstate_t *gstate) pixman_region_destroy (gstate->clip.region); gstate->clip.region = NULL; - cairo_pattern_destroy (gstate->pattern); + cairo_pattern_destroy (gstate->source); _cairo_path_fixed_fini (&gstate->path); @@ -262,7 +261,6 @@ cairo_status_t _cairo_gstate_begin_group (cairo_gstate_t *gstate) { Pixmap pix; - cairo_color_t clear; unsigned int width, height; gstate->parent_surface = gstate->surface; @@ -283,12 +281,9 @@ _cairo_gstate_begin_group (cairo_gstate_t *gstate) _cairo_surface_set_drawableWH (gstate->surface, pix, width, height); - _cairo_color_init (&clear); - _cairo_color_set_alpha (&clear, 0); - status = _cairo_surface_fill_rectangle (gstate->surface, CAIRO_OPERATOR_SRC, - &clear, + &CAIRO_COLOR_TRANSPARENT, 0, 0, _cairo_surface_get_width (gstate->surface), _cairo_surface_get_height (gstate->surface)); @@ -313,7 +308,6 @@ _cairo_gstate_end_group (cairo_gstate_t *gstate) _cairo_surface_init (&mask, gstate->dpy); _cairo_color_init (&mask_color); - _cairo_color_set_alpha (&mask_color, gstate->alpha); _cairo_surface_set_solid_color (&mask, &mask_color); @@ -383,29 +377,44 @@ _cairo_gstate_get_target_surface (cairo_gstate_t *gstate) } cairo_status_t -_cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t *pattern) +_cairo_gstate_set_source (cairo_gstate_t *gstate, + cairo_pattern_t *source) { - if (pattern == NULL) + if (source == NULL) return CAIRO_STATUS_NULL_POINTER; - cairo_pattern_reference (pattern); - cairo_pattern_destroy (gstate->pattern); - gstate->pattern = pattern; + cairo_pattern_reference (source); + cairo_pattern_destroy (gstate->source); + gstate->source = source; + + return CAIRO_STATUS_SUCCESS; +} + +cairo_status_t +_cairo_gstate_set_source_solid (cairo_gstate_t *gstate, + const cairo_color_t *color) +{ + cairo_status_t status; + cairo_pattern_t *source; + + source = _cairo_pattern_create_solid (color); + if (!source) + return CAIRO_STATUS_NO_MEMORY; + + status = _cairo_gstate_set_source (gstate, source); + + cairo_pattern_destroy (source); return CAIRO_STATUS_SUCCESS; } cairo_pattern_t * -_cairo_gstate_get_pattern (cairo_gstate_t *gstate) +_cairo_gstate_get_source (cairo_gstate_t *gstate) { if (gstate == NULL) return NULL; -/* XXX: Do we want this? - cairo_pattern_reference (gstate->pattern); -*/ - - return gstate->pattern; + return gstate->source; } cairo_status_t @@ -423,21 +432,9 @@ _cairo_gstate_get_operator (cairo_gstate_t *gstate) } cairo_status_t -_cairo_gstate_set_rgb_color (cairo_gstate_t *gstate, double red, double green, double blue) -{ - cairo_pattern_destroy (gstate->pattern); - - gstate->pattern = _cairo_pattern_create_solid (red, green, blue); - if (!gstate->pattern) - return CAIRO_STATUS_NO_MEMORY; - - return CAIRO_STATUS_SUCCESS; -} - -cairo_status_t _cairo_gstate_get_rgb_color (cairo_gstate_t *gstate, double *red, double *green, double *blue) { - return _cairo_pattern_get_rgb (gstate->pattern, red, green, blue); + return _cairo_pattern_get_rgb (gstate->source, red, green, blue); } cairo_status_t @@ -455,20 +452,6 @@ _cairo_gstate_get_tolerance (cairo_gstate_t *gstate) } cairo_status_t -_cairo_gstate_set_alpha (cairo_gstate_t *gstate, double alpha) -{ - gstate->alpha = alpha; - - return CAIRO_STATUS_SUCCESS; -} - -double -_cairo_gstate_get_alpha (cairo_gstate_t *gstate) -{ - return gstate->alpha; -} - -cairo_status_t _cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule) { gstate->fill_rule = fill_rule; @@ -1314,19 +1297,6 @@ _cairo_gstate_pattern_transform (cairo_gstate_t *gstate, _cairo_pattern_transform (pattern, &tmp_matrix); } -/* XXX: gstate->alpha will be going away before too long, and when it - * does, it may make sense for this function to just disappear. - */ -static void -_cairo_gstate_pattern_init_copy (cairo_gstate_t *gstate, - cairo_pattern_union_t *pattern, - cairo_pattern_t *src) -{ - _cairo_pattern_init_copy (&pattern->base, src); - _cairo_gstate_pattern_transform (gstate, &pattern->base); - _cairo_pattern_set_alpha (&pattern->base, gstate->alpha); -} - cairo_status_t _cairo_gstate_stroke (cairo_gstate_t *gstate) { @@ -1347,7 +1317,7 @@ _cairo_gstate_stroke (cairo_gstate_t *gstate) } _cairo_gstate_clip_and_composite_trapezoids (gstate, - gstate->pattern, + gstate->source, gstate->operator, gstate->surface, &traps); @@ -1570,7 +1540,9 @@ _composite_trap_region (cairo_gstate_t *gstate, return status; } - _cairo_gstate_pattern_init_copy (gstate, &pattern, src); + _cairo_pattern_init_copy (&pattern.base, src); + _cairo_gstate_pattern_transform (gstate, &pattern.base); + if (gstate->clip.surface) _cairo_pattern_init_for_surface (&mask.surface, gstate->clip.surface); @@ -1642,22 +1614,19 @@ _composite_traps_intermediate_surface (cairo_gstate_t *gstate, cairo_surface_t *intermediate; cairo_pattern_union_t pattern; cairo_surface_pattern_t intermediate_pattern; - cairo_color_t empty_color; cairo_status_t status; translate_traps (traps, -extents->x, -extents->y); - _cairo_color_init (&empty_color); - _cairo_color_set_alpha (&empty_color, 0.); intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface, CAIRO_FORMAT_A8, extents->width, extents->height, - &empty_color); + CAIRO_COLOR_TRANSPARENT); if (intermediate == NULL) return CAIRO_STATUS_NO_MEMORY; - _cairo_pattern_init_solid (&pattern.solid, 1.0, 1.0, 1.0); + _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE); status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_ADD, &pattern.base, @@ -1691,7 +1660,8 @@ _composite_traps_intermediate_surface (cairo_gstate_t *gstate, goto out; _cairo_pattern_init_for_surface (&intermediate_pattern, intermediate); - _cairo_gstate_pattern_init_copy (gstate, &pattern, src); + _cairo_pattern_init_copy (&pattern.base, src); + _cairo_gstate_pattern_transform (gstate, &pattern.base); status = _cairo_surface_composite (operator, &pattern.base, @@ -1722,7 +1692,6 @@ _composite_trap_region_solid (cairo_gstate_t *gstate, cairo_surface_t *dst, pixman_region16_t *region) { - cairo_color_t color; int num_rects = pixman_region_num_rects (region); pixman_box16_t *boxes = pixman_region_rects (region); cairo_rectangle_t *rects; @@ -1743,12 +1712,8 @@ _composite_trap_region_solid (cairo_gstate_t *gstate, rects[i].height = boxes[i].y2 - boxes[i].y1; } - _cairo_color_init (&color); - _cairo_color_set_rgb (&color, src->red, src->green, src->blue); - _cairo_color_set_alpha (&color, gstate->alpha); - status = _cairo_surface_fill_rectangles (dst, operator, - &color, rects, num_rects); + &src->color, rects, num_rects); free (rects); @@ -1769,7 +1734,8 @@ _composite_traps (cairo_gstate_t *gstate, cairo_pattern_union_t pattern; cairo_status_t status; - _cairo_gstate_pattern_init_copy (gstate, &pattern, src); + _cairo_pattern_init_copy (&pattern.base, src); + _cairo_gstate_pattern_transform (gstate, &pattern.base); status = _cairo_surface_composite_trapezoids (gstate->operator, &pattern.base, dst, @@ -1876,7 +1842,7 @@ _cairo_gstate_fill (cairo_gstate_t *gstate) } _cairo_gstate_clip_and_composite_trapezoids (gstate, - gstate->pattern, + gstate->source, gstate->operator, gstate->surface, &traps); @@ -2040,7 +2006,6 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) cairo_status_t status; cairo_pattern_union_t pattern; cairo_traps_t traps; - cairo_color_t white_color; cairo_box_t extents; pixman_region16_t *region; @@ -2096,8 +2061,6 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) /* Otherwise represent the clip as a mask surface. */ - _cairo_color_init (&white_color); - if (gstate->clip.surface == NULL) { _cairo_traps_extents (&traps, &extents); _cairo_box_round_to_rectangle (&extents, &gstate->clip.rect); @@ -2106,13 +2069,13 @@ _cairo_gstate_clip (cairo_gstate_t *gstate) CAIRO_FORMAT_A8, gstate->clip.rect.width, gstate->clip.rect.height, - &white_color); + CAIRO_COLOR_WHITE); if (gstate->clip.surface == NULL) return CAIRO_STATUS_NO_MEMORY; } translate_traps (&traps, -gstate->clip.rect.x, -gstate->clip.rect.y); - _cairo_pattern_init_solid (&pattern.solid, 1.0, 1.0, 1.0); + _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE); status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_IN, &pattern.base, @@ -2248,7 +2211,6 @@ _cairo_gstate_show_surface (cairo_gstate_t *gstate, pattern.base.extend = CAIRO_EXTEND_NONE; _cairo_gstate_pattern_transform (gstate, &pattern.base); - _cairo_pattern_set_alpha (&pattern.base, gstate->alpha); pattern_extents.p1.x = _cairo_fixed_from_double (backend_x); pattern_extents.p1.y = _cairo_fixed_from_double (backend_y); @@ -2632,7 +2594,6 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate, { cairo_surface_t *intermediate; cairo_surface_pattern_t intermediate_pattern; - cairo_color_t empty_color; _cairo_rectangle_intersect (&extents, &gstate->clip.rect); @@ -2642,13 +2603,11 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate, goto BAIL1; } - _cairo_color_init (&empty_color); - _cairo_color_set_alpha (&empty_color, .0); intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface, CAIRO_FORMAT_A8, extents.width, extents.height, - &empty_color); + CAIRO_COLOR_TRANSPARENT); if (intermediate == NULL) { status = CAIRO_STATUS_NO_MEMORY; goto BAIL1; @@ -2661,7 +2620,7 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate, transformed_glyphs[i].y -= extents.y; } - _cairo_pattern_init_solid (&pattern.solid, 1.0, 1.0, 1.0); + _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE); status = _cairo_scaled_font_show_glyphs (gstate->scaled_font, CAIRO_OPERATOR_ADD, @@ -2695,7 +2654,8 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate, goto BAIL2; _cairo_pattern_init_for_surface (&intermediate_pattern, intermediate); - _cairo_gstate_pattern_init_copy (gstate, &pattern, gstate->pattern); + _cairo_pattern_init_copy (&pattern.base, gstate->source); + _cairo_gstate_pattern_transform (gstate, &pattern.base); status = _cairo_surface_composite (gstate->operator, &pattern.base, @@ -2715,7 +2675,8 @@ _cairo_gstate_show_glyphs (cairo_gstate_t *gstate, } else { - _cairo_gstate_pattern_init_copy (gstate, &pattern, gstate->pattern); + _cairo_pattern_init_copy (&pattern.base, gstate->source); + _cairo_gstate_pattern_transform (gstate, &pattern.base); status = _cairo_scaled_font_show_glyphs (gstate->scaled_font, gstate->operator, &pattern.base, diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index c0aa6fff8..8fd8f0d9a 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2004 David Reveman + * Copyright © 2005 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without @@ -56,7 +57,6 @@ _cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type) pattern->ref_count = 1; pattern->extend = CAIRO_EXTEND_DEFAULT; pattern->filter = CAIRO_FILTER_DEFAULT; - pattern->alpha = 1.0; cairo_matrix_init_identity (&pattern->matrix); } @@ -150,15 +150,10 @@ _cairo_pattern_fini (cairo_pattern_t *pattern) void _cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, - double red, - double green, - double blue) + const cairo_color_t *color) { _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_SOLID); - - pattern->red = red; - pattern->green = green; - pattern->blue = blue; + pattern->color = *color; } void @@ -209,7 +204,7 @@ _cairo_pattern_init_radial (cairo_radial_pattern_t *pattern, } cairo_pattern_t * -_cairo_pattern_create_solid (double red, double green, double blue) +_cairo_pattern_create_solid (const cairo_color_t *color) { cairo_solid_pattern_t *pattern; @@ -217,7 +212,7 @@ _cairo_pattern_create_solid (double red, double green, double blue) if (pattern == NULL) return NULL; - _cairo_pattern_init_solid (pattern, red, green, blue); + _cairo_pattern_init_solid (pattern, color); return &pattern->base; } @@ -296,11 +291,8 @@ cairo_pattern_destroy (cairo_pattern_t *pattern) static cairo_status_t _cairo_pattern_add_color_stop (cairo_gradient_pattern_t *pattern, - double offset, - double red, - double green, - double blue, - double alpha) + double offset, + cairo_color_t *color) { cairo_color_stop_t *stop; @@ -316,22 +308,48 @@ _cairo_pattern_add_color_stop (cairo_gradient_pattern_t *pattern, stop = &pattern->stops[pattern->n_stops - 1]; stop->offset = _cairo_fixed_from_double (offset); - - _cairo_color_init (&stop->color); - _cairo_color_set_rgb (&stop->color, red, green, blue); - _cairo_color_set_alpha (&stop->color, alpha); + stop->color = *color; return CAIRO_STATUS_SUCCESS; } cairo_status_t -cairo_pattern_add_color_stop (cairo_pattern_t *pattern, - double offset, - double red, - double green, - double blue, - double alpha) +cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, + double offset, + double red, + double green, + double blue) +{ + cairo_color_t color; + + if (pattern->type != CAIRO_PATTERN_LINEAR && + pattern->type != CAIRO_PATTERN_RADIAL) + { + /* XXX: CAIRO_STATUS_INVALID_PATTERN? */ + return CAIRO_STATUS_SUCCESS; + } + + _cairo_restrict_value (&offset, 0.0, 1.0); + _cairo_restrict_value (&red, 0.0, 1.0); + _cairo_restrict_value (&green, 0.0, 1.0); + _cairo_restrict_value (&blue, 0.0, 1.0); + + _cairo_color_init_rgb (&color, red, green, blue); + return _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern, + offset, + &color); +} + +cairo_status_t +cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, + double offset, + double red, + double green, + double blue, + double alpha) { + cairo_color_t color; + if (pattern->type != CAIRO_PATTERN_LINEAR && pattern->type != CAIRO_PATTERN_RADIAL) { @@ -345,11 +363,12 @@ cairo_pattern_add_color_stop (cairo_pattern_t *pattern, _cairo_restrict_value (&blue, 0.0, 1.0); _cairo_restrict_value (&alpha, 0.0, 1.0); + _cairo_color_init_rgba (&color, red, green, blue, alpha); return _cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern, offset, - red, green, blue, - alpha); + &color); } +DEPRECATE (cairo_pattern_add_color_stop, cairo_pattern_add_color_stop_rgba); cairo_status_t cairo_pattern_set_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix) @@ -401,27 +420,20 @@ _cairo_pattern_get_rgb (cairo_pattern_t *pattern, double *green, double *blue) { - if (pattern->type == CAIRO_PATTERN_SOLID) { + double alpha_unused; cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern; - - *red = solid->red; - *green = solid->green; - *blue = solid->blue; - } else + + _cairo_color_get_rgba (&solid->color, red, green, blue, &alpha_unused); + } else { *red = *green = *blue = 1.0; + } return CAIRO_STATUS_SUCCESS; } void -_cairo_pattern_set_alpha (cairo_pattern_t *pattern, double alpha) -{ - pattern->alpha = alpha; -} - -void _cairo_pattern_transform (cairo_pattern_t *pattern, cairo_matrix_t *ctm_inverse) { @@ -510,8 +522,7 @@ _cairo_pattern_shader_init (cairo_gradient_pattern_t *pattern, op->stops[i].color_char[0] = pattern->stops[i].color.red * 0xff; op->stops[i].color_char[1] = pattern->stops[i].color.green * 0xff; op->stops[i].color_char[2] = pattern->stops[i].color.blue * 0xff; - op->stops[i].color_char[3] = pattern->stops[i].color.alpha * - pattern->base.alpha * 0xff; + op->stops[i].color_char[3] = pattern->stops[i].color.alpha * 0xff; op->stops[i].offset = pattern->stops[i].offset; op->stops[i].id = i; } @@ -975,16 +986,10 @@ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern, cairo_surface_t **out, cairo_surface_attributes_t *attribs) { - cairo_color_t color; - - _cairo_color_init (&color); - _cairo_color_set_rgb (&color, pattern->red, pattern->green, pattern->blue); - _cairo_color_set_alpha (&color, pattern->base.alpha); - *out = _cairo_surface_create_similar_solid (dst, CAIRO_FORMAT_ARGB32, 1, 1, - &color); + &pattern->color); if (*out == NULL) return CAIRO_STATUS_NO_MEMORY; @@ -1000,28 +1005,27 @@ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern, /** - * _cairo_pattern_is_opaque + * _cairo_pattern_is_opaque_solid * - * Convenience function to determine whether a pattern has an opaque - * alpha value. This is done by testing whether the pattern's alpha - * value when converted to a byte is 255, so if a backend actually - * supported deep alpha channels this function might not do the right - * thing. + * Convenience function to determine whether a pattern is an opaque + * (alpha==1.0) solid color pattern. This is done by testing whether + * the pattern's alpha value when converted to a byte is 255, so if a + * backend actually supported deep alpha channels this function might + * not do the right thing. * - * Note that for a gradient or surface pattern, the overall resulting - * alpha for the pattern can be non-opaque even this function returns - * %TRUE, since the resulting alpha is the multiplication of the - * alpha of the gradient or surface with the pattern's alpha. In - * the future, alpha will be moved from the base pattern to the - * solid pattern subtype, at which point this function should - * probably be renamed to _cairo_pattern_is_opaque_solid() - * - * Return value: %TRUE if the pattern is opaque + * Return value: %TRUE if the pattern is an opaque, solid color. **/ cairo_bool_t -_cairo_pattern_is_opaque (cairo_pattern_t *pattern) +_cairo_pattern_is_opaque_solid (cairo_pattern_t *pattern) { - return (pattern->alpha >= ((double)0xff00 / (double)0xffff)); + cairo_solid_pattern_t *solid; + + if (pattern->type != CAIRO_PATTERN_SOLID) + return FALSE; + + solid = (cairo_solid_pattern_t *) pattern; + + return (solid->color.alpha >= ((double)0xff00 / (double)0xffff)); } static cairo_int_status_t @@ -1035,85 +1039,39 @@ _cairo_pattern_acquire_surface_for_surface (cairo_surface_pattern_t *pattern, cairo_surface_attributes_t *attr) { cairo_int_status_t status; + int tx, ty; attr->acquired = FALSE; - - /* handle pattern opacity */ - if (!_cairo_pattern_is_opaque (&pattern->base)) + + if (_cairo_surface_is_image (dst)) { - cairo_surface_pattern_t tmp; - cairo_color_t color; - - _cairo_color_init (&color); - _cairo_color_set_alpha (&color, pattern->base.alpha); - - *out = _cairo_surface_create_similar_solid (dst, - CAIRO_FORMAT_ARGB32, - width, height, - &color); - if (*out == NULL) - return CAIRO_STATUS_NO_MEMORY; - - status = _cairo_pattern_init_copy (&tmp.base, &pattern->base); - if (CAIRO_OK (status)) - { - tmp.base.alpha = 1.0; - status = _cairo_surface_composite (CAIRO_OPERATOR_IN, - &tmp.base, - NULL, - *out, - x, y, 0, 0, 0, 0, - width, height); - - _cairo_pattern_fini (&tmp.base); - } - - if (status) { - cairo_surface_destroy (*out); - return status; - } + cairo_image_surface_t *image; - attr->x_offset = -x; - attr->y_offset = -y; - attr->extend = CAIRO_EXTEND_NONE; - attr->filter = CAIRO_FILTER_GOOD; + status = _cairo_surface_acquire_source_image (pattern->surface, + &image, + &attr->extra); + if (CAIRO_OK (status)) + *out = &image->base; + attr->acquired = TRUE; + } + else + status = _cairo_surface_clone_similar (dst, pattern->surface, out); + + attr->extend = pattern->base.extend; + attr->filter = pattern->base.filter; + if (_cairo_matrix_is_integer_translation (&pattern->base.matrix, + &tx, &ty)) + { cairo_matrix_init_identity (&attr->matrix); + attr->x_offset = tx; + attr->y_offset = ty; + attr->filter = CAIRO_FILTER_NEAREST; } else { - int tx, ty; - - if (_cairo_surface_is_image (dst)) - { - cairo_image_surface_t *image; - - status = _cairo_surface_acquire_source_image (pattern->surface, - &image, - &attr->extra); - if (CAIRO_OK (status)) - *out = &image->base; - - attr->acquired = TRUE; - } - else - status = _cairo_surface_clone_similar (dst, pattern->surface, out); - - attr->extend = pattern->base.extend; - attr->filter = pattern->base.filter; - if (_cairo_matrix_is_integer_translation (&pattern->base.matrix, - &tx, &ty)) - { - cairo_matrix_init_identity (&attr->matrix); - attr->x_offset = tx; - attr->y_offset = ty; - attr->filter = CAIRO_FILTER_NEAREST; - } - else - { - attr->matrix = pattern->base.matrix; - attr->x_offset = attr->y_offset = 0; - } + attr->matrix = pattern->base.matrix; + attr->x_offset = attr->y_offset = 0; } return status; @@ -1162,22 +1120,15 @@ _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, /* fast path for gradients with less than 2 color stops */ if (src->n_stops < 2) { + const cairo_color_t *color; cairo_solid_pattern_t solid; if (src->n_stops) - { - _cairo_pattern_init_solid (&solid, - src->stops->color.red, - src->stops->color.green, - src->stops->color.blue); - _cairo_pattern_set_alpha (&solid.base, - src->stops->color.alpha); - } + color = &src->stops->color; else - { - _cairo_pattern_init_solid (&solid, 0.0, 0.0, 0.0); - _cairo_pattern_set_alpha (&solid.base, 0.0); - } + color = CAIRO_COLOR_TRANSPARENT; + + _cairo_pattern_init_solid (&solid, color); return _cairo_pattern_acquire_surface_for_solid (&solid, dst, x, y, @@ -1242,71 +1193,44 @@ _cairo_pattern_acquire_surfaces (cairo_pattern_t *src, cairo_surface_attributes_t *mask_attributes) { cairo_int_status_t status; - cairo_pattern_union_t tmp; - cairo_bool_t src_opaque, mask_opaque; - double src_alpha, mask_alpha; - src_opaque = _cairo_pattern_is_opaque (src); - mask_opaque = !mask || _cairo_pattern_is_opaque (mask); - - /* For surface patterns, we move any translucency from src->alpha - * to mask->alpha so we can use the source unchanged. Otherwise we - * move the translucency from mask->alpha to src->alpha so that - * we can drop the mask if possible. - */ - if (src->type == CAIRO_PATTERN_SURFACE) - { - if (mask) { - mask_opaque = mask_opaque && src_opaque; - mask_alpha = mask->alpha * src->alpha; - } else { - mask_opaque = src_opaque; - mask_alpha = src->alpha; - } - - src_alpha = 1.0; - src_opaque = TRUE; - } - else + /* If src and mask are both solid, then the mask alpha can be + * combined into src and mask can be ignored. */ + + /* XXX: This optimization assumes that there is no color + * information in mask, so this will need to change when we + * support RENDER-style 4-channel masks. */ + if (src->type == CAIRO_PATTERN_SOLID && + mask->type == CAIRO_PATTERN_SOLID) { - if (mask) - { - src_opaque = mask_opaque && src_opaque; - src_alpha = mask->alpha * src->alpha; - /* FIXME: This needs changing when we support RENDER - * style 4-channel masks. - */ - if (mask->type == CAIRO_PATTERN_SOLID) - mask = NULL; - } else - src_alpha = src->alpha; - - mask_alpha = 1.0; - mask_opaque = TRUE; + cairo_color_t combined; + cairo_solid_pattern_t *src_solid = (cairo_solid_pattern_t *) src; + cairo_solid_pattern_t *mask_solid = (cairo_solid_pattern_t *) mask; + + combined = src_solid->color; + _cairo_color_multiply_alpha (&combined, mask_solid->color.alpha); + + _cairo_pattern_init_solid (&tmp.solid, &combined); + + mask = NULL; + } else { + _cairo_pattern_init_copy (&tmp.base, src); } - _cairo_pattern_init_copy (&tmp.base, src); - _cairo_pattern_set_alpha (&tmp.base, src_alpha); - status = _cairo_pattern_acquire_surface (&tmp.base, dst, src_x, src_y, width, height, src_out, src_attributes); - + _cairo_pattern_fini (&tmp.base); if (status) return status; - if (mask || !mask_opaque) + if (mask) { - if (mask) - _cairo_pattern_init_copy (&tmp.base, mask); - else - _cairo_pattern_init_solid (&tmp.solid, 0.0, 0.0, 0.0); - - _cairo_pattern_set_alpha (&tmp.base, mask_alpha); + _cairo_pattern_init_copy (&tmp.base, mask); status = _cairo_pattern_acquire_surface (&tmp.base, dst, mask_x, mask_y, diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index 7b016ad20..bfbecf9de 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -1378,13 +1378,13 @@ emit_solid_pattern (cairo_pdf_surface_t *surface, cairo_output_stream_t *output = document->output_stream; unsigned int alpha; - alpha = _cairo_pdf_surface_add_alpha (surface, pattern->base.alpha); + alpha = _cairo_pdf_surface_add_alpha (surface, pattern->color.alpha); _cairo_pdf_surface_ensure_stream (surface); _cairo_output_stream_printf (output, "%f %f %f rg /a%d gs\r\n", - pattern->red, - pattern->green, - pattern->blue, + pattern->color.red, + pattern->color.green, + pattern->color.blue, alpha); } diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 032e8bf23..c01755c9f 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -146,14 +146,9 @@ _cairo_ps_surface_finish (void *abstract_surface) static void _cairo_ps_surface_erase (cairo_ps_surface_t *surface) { - cairo_color_t transparent; - - _cairo_color_init (&transparent); - _cairo_color_set_rgb (&transparent, 0., 0., 0.); - _cairo_color_set_alpha (&transparent, 0.); _cairo_surface_fill_rectangle (&surface->image->base, CAIRO_OPERATOR_SRC, - &transparent, + CAIRO_COLOR_TRANSPARENT, 0, 0, surface->image->width, surface->image->height); @@ -222,7 +217,7 @@ _cairo_ps_surface_copy_page (void *abstract_surface) /* PostScript can not represent the alpha channel, so we blend the current image over a white RGB surface to eliminate it. */ - _cairo_pattern_init_solid (&white_pattern, 1.0, 1.0, 1.0); + _cairo_pattern_init_solid (&white_pattern, CAIRO_COLOR_WHITE); _cairo_surface_composite (CAIRO_OPERATOR_OVER_REVERSE, &white_pattern.base, diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 59580ff57..ad13883ef 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -77,24 +78,20 @@ cairo_surface_create_similar (cairo_surface_t *other, int width, int height) { - cairo_color_t empty; - if (other == NULL) return NULL; - _cairo_color_init (&empty); - _cairo_color_set_rgb (&empty, 0., 0., 0.); - _cairo_color_set_alpha (&empty, 0.); - - return _cairo_surface_create_similar_solid (other, format, width, height, &empty); + return _cairo_surface_create_similar_solid (other, format, + width, height, + CAIRO_COLOR_TRANSPARENT); } cairo_surface_t * -_cairo_surface_create_similar_solid (cairo_surface_t *other, - cairo_format_t format, - int width, - int height, - cairo_color_t *color) +_cairo_surface_create_similar_solid (cairo_surface_t *other, + cairo_format_t format, + int width, + int height, + const cairo_color_t *color) { cairo_status_t status; cairo_surface_t *surface; @@ -604,13 +601,13 @@ _cairo_surface_composite (cairo_operator_t operator, } cairo_status_t -_cairo_surface_fill_rectangle (cairo_surface_t *surface, - cairo_operator_t operator, - cairo_color_t *color, - int x, - int y, - int width, - int height) +_cairo_surface_fill_rectangle (cairo_surface_t *surface, + cairo_operator_t operator, + const cairo_color_t *color, + int x, + int y, + int width, + int height) { cairo_rectangle_t rect; diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 857226cfb..6e357f9cb 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -866,6 +866,20 @@ static const cairo_surface_backend_t cairo_xlib_surface_backend = { _cairo_xlib_surface_show_glyphs }; +/** + * _cairo_surface_is_xlib: + * @surface: a #cairo_surface_t + * + * Checks if a surface is a #cairo_xlib_surface_t + * + * Return value: True if the surface is an xlib surface + **/ +static cairo_bool_t +_cairo_surface_is_xlib (cairo_surface_t *surface) +{ + return surface->backend == &cairo_xlib_surface_backend; +} + static cairo_surface_t * _cairo_xlib_surface_create_internal (Display *dpy, Drawable drawable, @@ -1089,6 +1103,10 @@ cairo_xlib_surface_set_size (cairo_surface_t *surface, { cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *)surface; + /* XXX: How do we want to handle this error case? */ + if (! _cairo_surface_is_xlib (surface)) + return; + xlib_surface->width = width; xlib_surface->height = height; } diff --git a/src/cairo.c b/src/cairo.c index a5fed1447..ca2b15346 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -661,20 +662,25 @@ cairo_set_operator (cairo_t *cr, cairo_operator_t op) } /** - * cairo_set_rgb_color: - * @cr: a #cairo_t + * cairo_set_source_rgb + * @cr: a cairo context * @red: red component of color * @green: green component of color * @blue: blue component of color * - * Sets a constant color for filling and stroking. This replaces any - * pattern set with cairo_set_pattern(). The color components are - * floating point numbers in the range 0 to 1. If the values passed in - * are outside that range, they will be clamped. + * Sets the source pattern within @cr to an opaque color. This opaque + * color will then be used for any subsequent drawing operation until + * a new source pattern is set. + * + * The color components are floating point numbers in the range 0 to + * 1. If the values passed in are outside that range, they will be + * clamped. **/ void -cairo_set_rgb_color (cairo_t *cr, double red, double green, double blue) +cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue) { + cairo_color_t color; + CAIRO_CHECK_SANITY (cr); if (cr->status) return; @@ -683,52 +689,101 @@ cairo_set_rgb_color (cairo_t *cr, double red, double green, double blue) _cairo_restrict_value (&green, 0.0, 1.0); _cairo_restrict_value (&blue, 0.0, 1.0); - cr->status = _cairo_gstate_set_rgb_color (cr->gstate, red, green, blue); + _cairo_color_init_rgb (&color, red, green, blue); + + cr->status = _cairo_gstate_set_source_solid (cr->gstate, &color); + CAIRO_CHECK_SANITY (cr); } /** - * cairo_set_pattern: - * @cr: a #cairo_t - * @pattern: a #cairo_pattern_t to be used as the source for + * cairo_set_source_rgba: + * @cr: a cairo context + * @red: red component of color + * @green: green component of color + * @blue: blue component of color + * @alpha: alpha component of color + * + * Sets the source pattern within @cr to a translucent color. This + * color will then be used for any subsequent drawing operation until + * a new source pattern is set. + * + * The color and alpha components are floating point numbers in the + * range 0 to 1. If the values passed in are outside that range, they + * will be clamped. + **/ +void +cairo_set_source_rgba (cairo_t *cr, + double red, double green, double blue, + double alpha) +{ + cairo_color_t color; + + CAIRO_CHECK_SANITY (cr); + if (cr->status) + return; + + _cairo_restrict_value (&red, 0.0, 1.0); + _cairo_restrict_value (&green, 0.0, 1.0); + _cairo_restrict_value (&blue, 0.0, 1.0); + _cairo_restrict_value (&alpha, 0.0, 1.0); + + _cairo_color_init_rgba (&color, red, green, blue, alpha); + + cr->status = _cairo_gstate_set_source_solid (cr->gstate, &color); + + CAIRO_CHECK_SANITY (cr); +} +DEPRECATE(cairo_set_rgb_color, cairo_set_source_rgb); + +/** + * cairo_set_source + * @cr: a cairo context + * @source: a #cairo_pattern_t to be used as the source for * subsequent drawing operations. * - * Sets the source pattern within @cr to @pattern. This pattern will - * then be used for any subsequent drawing operation until a new - * pattern is set. + * Sets the source pattern within @cr to @source. This pattern + * will then be used for any subsequent drawing operation until a new + * source pattern is set. * * XXX: I'd also like to direct the reader's attention to some * (not-yet-written) section on cairo's imaging model. How would I do * that if such a section existed? (cworth). **/ void -cairo_set_pattern (cairo_t *cr, cairo_pattern_t *pattern) +cairo_set_source (cairo_t *cr, cairo_pattern_t *source) { CAIRO_CHECK_SANITY (cr); if (cr->status) return; - cr->status = _cairo_gstate_set_pattern (cr->gstate, pattern); + cr->status = _cairo_gstate_set_source (cr->gstate, source); CAIRO_CHECK_SANITY (cr); } +DEPRECATE(cairo_set_pattern, cairo_set_source); /** - * cairo_get_pattern: - * @cr: a #cairo_t + * cairo_get_source: + * @cr: a cairo context * - * Gets the current source pattern for a #cairo_t. + * Gets the current source pattern for @cr. * * Return value: the current source pattern. This object is owned by * cairo. To keep a reference to it, you must call * cairo_pattern_reference(). **/ cairo_pattern_t * -cairo_get_pattern (cairo_t *cr) +cairo_get_source (cairo_t *cr) { CAIRO_CHECK_SANITY (cr); - return _cairo_gstate_get_pattern (cr->gstate); + /* XXX: We'll want to do something like this: + if (cr->status) + return cairo_pattern_nil; + */ + + return _cairo_gstate_get_source (cr->gstate); } -DEPRECATE(cairo_current_pattern, cairo_get_pattern); +DEPRECATE(cairo_current_pattern, cairo_get_source); /** * cairo_set_tolerance: @@ -757,30 +812,6 @@ cairo_set_tolerance (cairo_t *cr, double tolerance) } /** - * cairo_set_alpha: - * @cr: a #cairo_t - * @alpha: the alpha value. 0 is transparent, 1 fully opaque. - * if the value is outside the range 0 to 1, it will be - * clamped to that range. - * - * Sets an overall alpha value used for stroking and filling. This - * value is multiplied with any alpha value coming from a gradient or - * image pattern. - **/ -void -cairo_set_alpha (cairo_t *cr, double alpha) -{ - CAIRO_CHECK_SANITY (cr); - if (cr->status) - return; - - _cairo_restrict_value (&alpha, 0.0, 1.0); - - cr->status = _cairo_gstate_set_alpha (cr->gstate, alpha); - CAIRO_CHECK_SANITY (cr); -} - -/** * cairo_set_fill_rule: * @cr: a #cairo_t * @fill_rule: a fill rule, specified as a #cairo_fill_rule_t @@ -1891,8 +1922,8 @@ DEPRECATE (cairo_current_operator, cairo_get_operator); * operations, (in the case of an alternate source pattern being set * by cairo_set_pattern()). * - * WARNING: This function is scheduled to be removed as part of the - * upcoming API Shakeup. + * WARNING: This function is deprecated and scheduled to be removed as + * part of the upcoming API Shakeup. **/ void cairo_get_rgb_color (cairo_t *cr, double *red, double *green, double *blue) @@ -1904,25 +1935,6 @@ cairo_get_rgb_color (cairo_t *cr, double *red, double *green, double *blue) DEPRECATE (cairo_current_rgb_color, cairo_get_rgb_color); /** - * cairo_get_alpha: - * @cr: a cairo context - * - * Gets the current alpha value, as set by cairo_set_alpha(). - * - * Return value: the current alpha value. - * - * WARNING: This function is scheduled to be removed as part of the - * upcoming API Shakeup. - **/ -double -cairo_get_alpha (cairo_t *cr) -{ - CAIRO_CHECK_SANITY (cr); - return _cairo_gstate_get_alpha (cr->gstate); -} -DEPRECATE (cairo_current_alpha, cairo_get_alpha); - -/** * cairo_get_tolerance: * @cr: a cairo context * diff --git a/src/cairo.h b/src/cairo.h index 761782fba..711038e3a 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -237,31 +238,21 @@ typedef enum cairo_operator { void cairo_set_operator (cairo_t *cr, cairo_operator_t op); -/* XXX: Probably want to bite the bullet and expose a cairo_color_t object */ - -/* XXX: I've been trying to come up with a sane way to specify: - - cairo_set_color (cairo_t *cr, cairo_color_t *color); - - Keith wants to be able to support super-luminescent colors, - (premultiplied colors with R/G/B greater than alpha). The current - API does not allow that. Adding a premulitplied RGBA cairo_color_t - would do the trick. - - One problem though is that alpha is currently orthogonal to - color. For example, show_surface uses gstate->alpha but ignores the - color. So, it doesn't seem be right to have cairo_set_color modify - the behavior of cairo_show_surface. -*/ +void +cairo_set_source (cairo_t *cr, cairo_pattern_t *pattern); +/* XXX: NYI: void -cairo_set_rgb_color (cairo_t *cr, double red, double green, double blue); +cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface); +*/ void -cairo_set_pattern (cairo_t *cr, cairo_pattern_t *pattern); +cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue); void -cairo_set_alpha (cairo_t *cr, double alpha); +cairo_set_source_rgba (cairo_t *cr, + double red, double green, double blue, + double alpha); /* XXX: Currently, the tolerance value is specified by the user in terms of device-space units. If I'm not mistaken, this is the only @@ -698,8 +689,9 @@ cairo_get_operator (cairo_t *cr); void cairo_get_rgb_color (cairo_t *cr, double *red, double *green, double *blue); + cairo_pattern_t * -cairo_get_pattern (cairo_t *cr); +cairo_get_source (cairo_t *cr); double cairo_get_alpha (cairo_t *cr); @@ -977,11 +969,16 @@ void cairo_pattern_destroy (cairo_pattern_t *pattern); cairo_status_t -cairo_pattern_add_color_stop (cairo_pattern_t *pattern, - double offset, - double red, double green, double blue, - double alpha); - +cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, + double offset, + double red, double green, double blue); + +cairo_status_t +cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, + double offset, + double red, double green, double blue, + double alpha); + cairo_status_t cairo_pattern_set_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix); @@ -1127,6 +1124,10 @@ typedef cairo_status_t (*cairo_write_func_t) (void *closure, #define cairo_default_matrix cairo_default_matrix_DEPRECATED_BY_cairo_identity_matrix #define cairo_matrix_set_affine cairo_matrix_set_affine_DEPRECTATED_BY_cairo_matrix_init #define cairo_matrix_set_identity cairo_matrix_set_identity_DEPRECATED_BY_cairo_matrix_init_identity +#define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_DEPRECATED_BY_cairo_pattern_add_color_stop_rgba +#define cairo_set_rgb_color cairo_set_rgb_color_DEPRECATED_BY_cairo_set_source_rgb +#define cairo_set_pattern cairo_set_pattern_DEPRECATED_BY_cairo_set_source +#define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba #else /* CAIRO_API_SHAKEUP_FLAG_DAY */ @@ -1162,6 +1163,10 @@ typedef cairo_status_t (*cairo_write_func_t) (void *closure, #define cairo_default_matrix cairo_identity_matrix #define cairo_matrix_set_affine cairo_matrix_init #define cairo_matrix_set_identity cairo_matrix_init_identity +#define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_rgba +#define cairo_set_rgb_color cairo_set_source_rgb +#define cairo_set_pattern cairo_set_source +#define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba #endif /* CAIRO_API_SHAKEUP_FLAG_DAY */ diff --git a/src/cairoint.h b/src/cairoint.h index 501f49ea3..0089306c2 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -1,6 +1,7 @@ /* cairo - a vector graphics library with display and print output * * Copyright © 2002 University of Southern California + * Copyright © 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -723,6 +724,12 @@ struct _cairo_color { unsigned short alpha_short; }; +typedef enum { + CAIRO_STOCK_WHITE, + CAIRO_STOCK_BLACK, + CAIRO_STOCK_TRANSPARENT +} cairo_stock_t; + #define CAIRO_EXTEND_DEFAULT CAIRO_EXTEND_NONE #define CAIRO_FILTER_DEFAULT CAIRO_FILTER_BEST @@ -744,13 +751,11 @@ struct _cairo_pattern { cairo_matrix_t matrix; cairo_filter_t filter; cairo_extend_t extend; - double alpha; }; typedef struct _cairo_solid_pattern { cairo_pattern_t base; - - double red, green, blue; + cairo_color_t color; } cairo_solid_pattern_t; typedef struct _cairo_surface_pattern { @@ -924,10 +929,14 @@ cairo_private cairo_surface_t * _cairo_gstate_get_target_surface (cairo_gstate_t *gstate); cairo_private cairo_status_t -_cairo_gstate_set_pattern (cairo_gstate_t *gstate, cairo_pattern_t *pattern); +_cairo_gstate_set_source (cairo_gstate_t *gstate, cairo_pattern_t *source); + +cairo_status_t +_cairo_gstate_set_source_solid (cairo_gstate_t *gstate, + const cairo_color_t *color); cairo_private cairo_pattern_t * -_cairo_gstate_get_pattern (cairo_gstate_t *gstate); +_cairo_gstate_get_source (cairo_gstate_t *gstate); cairo_private cairo_status_t _cairo_gstate_set_operator (cairo_gstate_t *gstate, cairo_operator_t operator); @@ -936,9 +945,6 @@ cairo_private cairo_operator_t _cairo_gstate_get_operator (cairo_gstate_t *gstate); cairo_private cairo_status_t -_cairo_gstate_set_rgb_color (cairo_gstate_t *gstate, double red, double green, double blue); - -cairo_private cairo_status_t _cairo_gstate_get_rgb_color (cairo_gstate_t *gstate, double *red, double *green, @@ -951,12 +957,6 @@ cairo_private double _cairo_gstate_get_tolerance (cairo_gstate_t *gstate); cairo_private cairo_status_t -_cairo_gstate_set_alpha (cairo_gstate_t *gstate, double alpha); - -cairo_private double -_cairo_gstate_get_alpha (cairo_gstate_t *gstate); - -cairo_private cairo_status_t _cairo_gstate_set_fill_rule (cairo_gstate_t *gstate, cairo_fill_rule_t fill_rule); cairo_private cairo_fill_rule_t @@ -1184,21 +1184,42 @@ _cairo_gstate_glyph_path (cairo_gstate_t *gstate, /* cairo_color.c */ +cairo_private const cairo_color_t * +_cairo_stock_color (cairo_stock_t stock); + +#define CAIRO_COLOR_WHITE _cairo_stock_color (CAIRO_STOCK_WHITE) +#define CAIRO_COLOR_BLACK _cairo_stock_color (CAIRO_STOCK_BLACK) +#define CAIRO_COLOR_TRANSPARENT _cairo_stock_color (CAIRO_STOCK_TRANSPARENT) + cairo_private void _cairo_color_init (cairo_color_t *color); cairo_private void -_cairo_color_fini (cairo_color_t *color); +_cairo_color_init_rgb (cairo_color_t *color, + double red, double green, double blue); cairo_private void -_cairo_color_set_rgb (cairo_color_t *color, double red, double green, double blue); +_cairo_color_init_rgba (cairo_color_t *color, + double red, double green, double blue, + double alpha); cairo_private void -_cairo_color_get_rgb (const cairo_color_t *color, - double *red, double *green, double *blue); +_cairo_color_multiply_alpha (cairo_color_t *color, + double alpha); cairo_private void -_cairo_color_set_alpha (cairo_color_t *color, double alpha); +_cairo_color_get_rgba (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha); + +cairo_private void +_cairo_color_get_rgba_premultiplied (cairo_color_t *color, + double *red, + double *green, + double *blue, + double *alpha); /* cairo-font.c */ @@ -1375,24 +1396,24 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, int height); cairo_private cairo_surface_t * -_cairo_surface_create_similar_solid (cairo_surface_t *other, - cairo_format_t format, - int width, - int height, - cairo_color_t *color); +_cairo_surface_create_similar_solid (cairo_surface_t *other, + cairo_format_t format, + int width, + int height, + const cairo_color_t *color); cairo_private void _cairo_surface_init (cairo_surface_t *surface, const cairo_surface_backend_t *backend); cairo_private cairo_status_t -_cairo_surface_fill_rectangle (cairo_surface_t *surface, - cairo_operator_t operator, - cairo_color_t *color, - int x, - int y, - int width, - int height); +_cairo_surface_fill_rectangle (cairo_surface_t *surface, + cairo_operator_t operator, + const cairo_color_t *color, + int x, + int y, + int width, + int height); cairo_private cairo_status_t _cairo_surface_composite (cairo_operator_t operator, @@ -1649,7 +1670,7 @@ _cairo_pattern_init_copy (cairo_pattern_t *pattern, cairo_pattern_t *other); cairo_private void _cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, - double red, double green, double blue); + const cairo_color_t *color); cairo_private void _cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, @@ -1668,21 +1689,18 @@ cairo_private void _cairo_pattern_fini (cairo_pattern_t *pattern); cairo_private cairo_pattern_t * -_cairo_pattern_create_solid (double red, double green, double blue); +_cairo_pattern_create_solid (const cairo_color_t *color); cairo_private cairo_status_t _cairo_pattern_get_rgb (cairo_pattern_t *pattern, double *red, double *green, double *blue); cairo_private void -_cairo_pattern_set_alpha (cairo_pattern_t *pattern, double alpha); - -cairo_private void _cairo_pattern_transform (cairo_pattern_t *pattern, cairo_matrix_t *ctm_inverse); cairo_private cairo_bool_t -_cairo_pattern_is_opaque (cairo_pattern_t *pattern); +_cairo_pattern_is_opaque_solid (cairo_pattern_t *pattern); cairo_private cairo_int_status_t _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, diff --git a/test/Makefile.am b/test/Makefile.am index c47789aca..b8e20516a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -57,6 +57,7 @@ trap-clip-ref.png # Also, any test listed here should call cairo_test_expect_failure and # provide an explanation for the expected failure. XFAIL_TESTS = \ +coverage \ pixman-rotate \ text-rotate diff --git a/test/cairo-test.c b/test/cairo-test.c index 487d3dfb6..58339fe55 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -102,7 +102,7 @@ cairo_test_expect_failure (cairo_test_t *test, cairo_test_draw_function_t draw, const char *because) { - printf ("%s is expected to fail %s\n", test->name, because); + printf ("%s is expected to fail:\n\t%s\n", test->name, because); return cairo_test (test, draw); } diff --git a/test/clip-twice.c b/test/clip-twice.c index 8862199e7..eebfec944 100644 --- a/test/clip-twice.c +++ b/test/clip-twice.c @@ -37,7 +37,6 @@ cairo_test_t test = { static cairo_test_status_t draw (cairo_t *cr, int width, int height) { - cairo_set_alpha (cr, 1.0); cairo_new_path (cr); cairo_arc (cr, WIDTH / 2, HEIGHT / 2, WIDTH / 3, 0, 2 * M_PI); cairo_clip (cr); @@ -52,7 +51,7 @@ draw (cairo_t *cr, int width, int height) cairo_close_path (cr); cairo_clip (cr); - cairo_set_rgb_color (cr, 0, 0, 0.6); + cairo_set_source_rgb (cr, 0, 0, 0.6); cairo_new_path (cr); cairo_move_to (cr, 0, 0); diff --git a/test/coverage.c b/test/coverage.c index 1b605af66..1afee3c3c 100644 --- a/test/coverage.c +++ b/test/coverage.c @@ -40,15 +40,13 @@ const char png_filename[] = "romedalen.png"; static void set_solid_pattern (cairo_t *cr, int x, int y) { - cairo_set_rgb_color (cr, 0, 0, 0.6); - cairo_set_alpha (cr, 1.0); + cairo_set_source_rgb (cr, 0, 0, 0.6); } static void set_translucent_pattern (cairo_t *cr, int x, int y) { - cairo_set_rgb_color (cr, 0, 0, 0.6); - cairo_set_alpha (cr, 0.5); + cairo_set_source_rgba (cr, 0, 0, 0.6, 0.5); } static void @@ -58,10 +56,9 @@ set_gradient_pattern (cairo_t *cr, int x, int y) pattern = cairo_pattern_create_linear (x, y, x + WIDTH, y + HEIGHT); - cairo_pattern_add_color_stop (pattern, 0, 1, 1, 1, 1); - cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0.4, 1); - cairo_set_pattern (cr, pattern); - cairo_set_alpha (cr, 1); + cairo_pattern_add_color_stop_rgb (pattern, 0, 1, 1, 1); + cairo_pattern_add_color_stop_rgb (pattern, 1, 0, 0, 0.4); + cairo_set_source (cr, pattern); } static void @@ -70,8 +67,7 @@ set_image_pattern (cairo_t *cr, int x, int y) cairo_pattern_t *pattern; pattern = cairo_test_create_png_pattern (cr, png_filename); - cairo_set_pattern (cr, pattern); - cairo_set_alpha (cr, 1); + cairo_set_source (cr, pattern); } static void @@ -80,8 +76,7 @@ set_translucent_image_pattern (cairo_t *cr, int x, int y) cairo_pattern_t *pattern; pattern = cairo_test_create_png_pattern (cr, png_filename); - cairo_set_pattern (cr, pattern); - cairo_set_alpha (cr, 0.5); + cairo_set_source (cr, pattern); } #if WE_FIX_THE_TEST_SO_THAT_IT_DOES_NOT_DEPEND_ON_HOW_FREETPYE_IS_COMPILED @@ -165,7 +160,6 @@ draw (cairo_t *cr, int width, int height) cairo_save (cr); - cairo_set_alpha (cr, 1.0); cairo_new_path (cr); cairo_arc (cr, x + WIDTH / 2, y + HEIGHT / 2, WIDTH / 3, 0, 2 * M_PI); @@ -186,5 +180,6 @@ draw (cairo_t *cr, int width, int height) int main (void) { - return cairo_test (&test, draw); + return cairo_test_expect_failure (&test, draw, + "missing API to replace cairo_show_surface with alpha"); } diff --git a/test/fill-rule.c b/test/fill-rule.c index 6d5f3b46e..103208cab 100644 --- a/test/fill-rule.c +++ b/test/fill-rule.c @@ -100,7 +100,7 @@ big_star_path (cairo_t *cr) static cairo_test_status_t draw (cairo_t *cr, int width, int height) { - cairo_set_rgb_color (cr, 1, 0, 0); + cairo_set_source_rgb (cr, 1, 0, 0); cairo_translate (cr, 1, 1); little_star_path (cr); diff --git a/test/line-width.c b/test/line-width.c index 285b66b84..ca2d2760b 100644 --- a/test/line-width.c +++ b/test/line-width.c @@ -41,7 +41,7 @@ draw (cairo_t *cr, int width, int height) { int i; - cairo_set_rgb_color (cr, 0, 0, 0); + cairo_set_source_rgb (cr, 0, 0, 0); cairo_translate (cr, 2, 2); for (i=0; i < LINES; i++) { diff --git a/test/linear-gradient.c b/test/linear-gradient.c index 418ddf2fe..c8506c861 100644 --- a/test/linear-gradient.c +++ b/test/linear-gradient.c @@ -72,7 +72,7 @@ draw_unit (cairo_t *cr, cairo_clip (cr); cairo_new_path(cr); - cairo_set_rgb_color (cr, 0.0, 0.0, 0.0); + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); cairo_rectangle (cr, 0, 0, 1, 1); cairo_fill (cr); @@ -84,25 +84,20 @@ draw_unit (cairo_t *cr, 0.5 * cos (gradient_angle), 0.5 * sin (gradient_angle)); if (n_stops == 2) { - cairo_pattern_add_color_stop (pattern, 0., - 0.3, 0.3, 0.3, - 1.0); - cairo_pattern_add_color_stop (pattern, 1., - 1.0, 1.0, 1.0, - 1.0); + cairo_pattern_add_color_stop_rgb (pattern, 0., + 0.3, 0.3, 0.3); + cairo_pattern_add_color_stop_rgb (pattern, 1., + 1.0, 1.0, 1.0); } else { - cairo_pattern_add_color_stop (pattern, 0., - 1.0, 0.0, 0.0, - 1.0); - cairo_pattern_add_color_stop (pattern, 0.5, - 1.0, 1.0, 1.0, - 1.0); - cairo_pattern_add_color_stop (pattern, 1., - 0.0, 0.0, 1.0, - 1.0); + cairo_pattern_add_color_stop_rgb (pattern, 0., + 1.0, 0.0, 0.0); + cairo_pattern_add_color_stop_rgb (pattern, 0.5, + 1.0, 1.0, 1.0); + cairo_pattern_add_color_stop_rgb (pattern, 1., + 0.0, 0.0, 1.0); } - cairo_set_pattern (cr, pattern); + cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_rectangle (cr, -0.5, -0.5, 1, 1); cairo_fill (cr); @@ -113,7 +108,7 @@ draw (cairo_t *cr, int width, int height) { int i, j, k; - cairo_set_rgb_color (cr, 0.5, 0.5, 0.5); + cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); diff --git a/test/pixman-rotate.c b/test/pixman-rotate.c index af3b56103..93f9c866f 100644 --- a/test/pixman-rotate.c +++ b/test/pixman-rotate.c @@ -35,14 +35,12 @@ draw (cairo_t *cr, int width, int height) cairo_set_target_surface (cr, stamp); cairo_new_path (cr); cairo_rectangle (cr, WIDTH / 4, HEIGHT / 4, WIDTH / 2, HEIGHT / 2); - cairo_set_rgb_color (cr, 1, 0, 0); - cairo_set_alpha (cr, 0.8); + cairo_set_source_rgba (cr, 1, 0, 0, 0.8); cairo_fill (cr); cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT); cairo_set_line_width (cr, 2); - cairo_set_rgb_color (cr, 0, 0, 0); - cairo_set_alpha (cr, 1); + cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr); cairo_set_target_surface (cr, target); @@ -51,8 +49,7 @@ draw (cairo_t *cr, int width, int height) * image should be. */ cairo_new_path (cr); cairo_rectangle (cr, WIDTH, HEIGHT, WIDTH, HEIGHT); - cairo_set_rgb_color (cr, 1, 1, 0); - cairo_set_alpha (cr, 0.3); + cairo_set_source_rgba (cr, 1, 1, 0, 0.3); cairo_fill (cr); #if 1 /* Set to 0 to generate reference image */ @@ -62,7 +59,6 @@ draw (cairo_t *cr, int width, int height) cairo_translate (cr, WIDTH, HEIGHT); #endif - cairo_set_alpha (cr, 1); cairo_show_surface (cr, stamp, WIDTH + 2, HEIGHT + 2); cairo_show_page (cr); @@ -77,6 +73,5 @@ int main (void) { return cairo_test_expect_failure (&test, draw, - "because of a known off-by-one bug " - "when rotating a pixman image"); + "known off-by-one bug when rotating a pixman image"); } diff --git a/test/set-source.c b/test/set-source.c index b4d46c8a1..26524917e 100644 --- a/test/set-source.c +++ b/test/set-source.c @@ -52,23 +52,21 @@ draw (cairo_t *cr, int width, int height) for (i=0; i < width; i++) { switch (i) { case 0: - cairo_set_rgb_color (cr, .6, .7, .8); + cairo_set_source_rgb (cr, .6, .7, .8); break; case 1: - cairo_set_rgb_color (cr, .2, .4, .6); - cairo_set_alpha (cr, 0.5); + cairo_set_source_rgba (cr, .2, .4, .6, 0.5); break; case 2: - /* XXX: When ported, this should become: +#if WE_HAD_SUPPORT_FOR_PREMULTIPLIED cairo_set_source_rgba_premultiplied (cr, .1, .2, .3, 0.5); - */ - cairo_set_rgb_color (cr, .2, .4, .6); - cairo_set_alpha (cr, 0.5); +#else + cairo_set_source_rgba (cr, .2, .4, .6, 0.5); +#endif break; case 3: default: - cairo_set_alpha (cr, 1.0); - cairo_set_pattern (cr, pattern); + cairo_set_source (cr, pattern); break; } diff --git a/test/text-rotate.c b/test/text-rotate.c index 3d5f4d3cf..95a602954 100644 --- a/test/text-rotate.c +++ b/test/text-rotate.c @@ -83,7 +83,7 @@ draw (cairo_t *cr, int width, int height) CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, TEXT_SIZE); - cairo_set_rgb_color (cr, 0,0,0); + cairo_set_source_rgb (cr, 0, 0, 0); cairo_translate (cr, WIDTH/2.0, HEIGHT/2.0); @@ -101,10 +101,10 @@ draw (cairo_t *cr, int width, int height) cairo_rotate (cr, 2*M_PI*i/NUM_TEXT); cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, x_off - 0.5, y_off - 0.5, extents.width + 1, extents.height + 1); - cairo_set_rgb_color (cr, 1, 0, 0); + cairo_set_source_rgb (cr, 1, 0, 0); cairo_stroke (cr); cairo_move_to (cr, x_off - extents.x_bearing, y_off - extents.y_bearing); - cairo_set_rgb_color (cr, 0, 0, 0); + cairo_set_source_rgb (cr, 0, 0, 0); cairo_show_text (cr, "cairo"); cairo_restore (cr); } @@ -116,6 +116,5 @@ int main (void) { return cairo_test_expect_failure (&test, draw, - "because of known glyph positioning bugs " - "with rotated text"); + "known bugs in positioning rotated glyphs"); } diff --git a/test/trap-clip.c b/test/trap-clip.c index 4bc6f195a..15549ae1b 100644 --- a/test/trap-clip.c +++ b/test/trap-clip.c @@ -36,15 +36,13 @@ const char png_filename[] = "romedalen.png"; static void set_solid_pattern (cairo_t *cr, int x, int y) { - cairo_set_rgb_color (cr, 0, 0, 0.6); - cairo_set_alpha (cr, 1.0); + cairo_set_source_rgb (cr, 0, 0, 0.6); } static void set_translucent_pattern (cairo_t *cr, int x, int y) { - cairo_set_rgb_color (cr, 0, 0, 0.6); - cairo_set_alpha (cr, 0.5); + cairo_set_source_rgba (cr, 0, 0, 0.6, 0.5); } static void @@ -57,7 +55,6 @@ set_gradient_pattern (cairo_t *cr, int x, int y) cairo_pattern_add_color_stop (pattern, 0, 1, 1, 1, 1); cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0.4, 1); cairo_set_pattern (cr, pattern); - cairo_set_alpha (cr, 1); } static void @@ -67,7 +64,6 @@ set_image_pattern (cairo_t *cr, int x, int y) pattern = cairo_test_create_png_pattern (cr, png_filename); cairo_set_pattern (cr, pattern); - cairo_set_alpha (cr, 1); } static void @@ -113,7 +109,6 @@ clip_none (cairo_t *cr, int x, int y) static void clip_rect (cairo_t *cr, int x, int y) { - cairo_set_alpha (cr, 1.0); cairo_new_path (cr); cairo_rectangle (cr, x + (int)WIDTH / 6, y + (int)HEIGHT / 6, 4 * ((int)WIDTH / 6), 4 * ((int)WIDTH / 6)); @@ -126,7 +121,6 @@ clip_rects (cairo_t *cr, int x, int y) { int height = HEIGHT / 3; - cairo_set_alpha (cr, 1.0); cairo_new_path (cr); cairo_rectangle (cr, x, y, WIDTH, height); cairo_rectangle (cr, x, y + 2 * height, WIDTH, height); @@ -137,7 +131,6 @@ clip_rects (cairo_t *cr, int x, int y) static void clip_circle (cairo_t *cr, int x, int y) { - cairo_set_alpha (cr, 1.0); cairo_new_path (cr); cairo_arc (cr, x + WIDTH / 2, y + HEIGHT / 2, WIDTH / 3, 0, 2 * M_PI); |