head 1.3; access; symbols; locks; strict; comment @ * @; 1.3 date 2005.05.17.15.24.39; author cworth; state Exp; branches; next 1.2; commitid 22b4428a0cb74567; 1.2 date 2005.05.17.14.31.43; author cworth; state Exp; branches; next 1.1; commitid 2e0428a004e4567; 1.1 date 2005.03.18.15.26.53; author cworth; state Exp; branches; next ; desc @@ 1.3 log @ * bevels.c: * caps_joins.c: * hering.c: * outline.c: * snapping.c: * spiral.c: * splines_tolerance.c: * star_and_ring.c: * stars.c: * text-rotate.c: * text.c: Remove stale includes of write_png.h. @ text @/* * 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 * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the name of * Red Hat, Inc. not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior * permission. Red Hat, Inc. makes no representations about the * suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: Carl D. Worth */ #include #include #define WIDTH 600 #define HEIGHT 600 #define STRIDE (WIDTH * 4) unsigned char image[STRIDE*HEIGHT]; static void ring_path (cairo_t *cr) { cairo_move_to (cr, 200.86568, 667.80795); cairo_curve_to (cr, 110.32266, 562.62134, 122.22863, 403.77940, 227.41524, 313.23637); cairo_curve_to (cr, 332.60185, 222.69334, 491.42341, 234.57563, 581.96644, 339.76224); cairo_curve_to (cr, 672.50948, 444.94884, 660.64756, 603.79410, 555.46095, 694.33712); cairo_curve_to (cr, 450.27436, 784.88016, 291.40871, 772.99456, 200.86568, 667.80795); cairo_close_path (cr); cairo_move_to (cr, 272.14411, 365.19927); cairo_curve_to (cr, 195.64476, 431.04875, 186.97911, 546.57972, 252.82859, 623.07908); cairo_curve_to (cr, 318.67807, 699.57844, 434.23272, 708.22370, 510.73208, 642.37422); cairo_curve_to (cr, 587.23144, 576.52474, 595.85301, 460.99047, 530.00354, 384.49112); cairo_curve_to (cr, 464.15406, 307.99176, 348.64347, 299.34979, 272.14411, 365.19927); cairo_close_path (cr); } static void star_path (cairo_t *cr) { cairo_matrix_t matrix; cairo_matrix_init (&matrix, 0.647919, -0.761710, 0.761710, 0.647919, -208.7977, 462.0608); cairo_transform (cr, &matrix); cairo_move_to (cr, 505.80857, 746.23606); cairo_line_to (cr, 335.06870, 555.86488); cairo_line_to (cr, 91.840384, 635.31360); cairo_line_to (cr, 282.21157, 464.57374); cairo_line_to (cr, 202.76285, 221.34542); cairo_line_to (cr, 373.50271, 411.71660); cairo_line_to (cr, 616.73103, 332.26788); cairo_line_to (cr, 426.35984, 503.00775); cairo_line_to (cr, 505.80857, 746.23606); cairo_close_path (cr); } static void fill_ring (cairo_t *cr) { cairo_save (cr); cairo_translate (cr, -90, -205); ring_path (cr); cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.75); cairo_fill (cr); cairo_restore (cr); } static void fill_star (cairo_t *cr) { cairo_save (cr); cairo_translate (cr, -90, -205); star_path (cr); cairo_set_source_rgba (cr, 0.0, 0.0, (double) 0xae / 0xff, 0.55135137); cairo_fill (cr); cairo_restore (cr); } static void clip_to_top_and_bottom (cairo_t *cr, int width, int height) { cairo_move_to (cr, 0, 0); cairo_line_to (cr, width, 0); cairo_line_to (cr, 0, height); cairo_line_to (cr, width, height); cairo_close_path (cr); cairo_clip (cr); cairo_new_path (cr); } static void clip_to_left_and_right (cairo_t *cr, int width, int height) { cairo_move_to (cr, 0, 0); cairo_line_to (cr, 0, height); cairo_line_to (cr, width, 0); cairo_line_to (cr, width, height); cairo_close_path (cr); cairo_clip (cr); cairo_new_path (cr); } int main (void) { cairo_t *cr, *cr_ros, *cr_sor; cairo_surface_t *ring_over_star, *star_over_ring, *result; result = cairo_image_surface_create_for_data (image, CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT, STRIDE); ring_over_star = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT); star_over_ring = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT); cr = cairo_create (result); { cr_ros = cairo_create (ring_over_star); clip_to_top_and_bottom (cr_ros, WIDTH, HEIGHT); fill_star (cr_ros); fill_ring (cr_ros); cairo_destroy (cr_ros); } { cr_sor = cairo_create (star_over_ring); clip_to_left_and_right (cr_sor, WIDTH, HEIGHT); fill_ring (cr_sor); fill_star (cr_sor); cairo_destroy (cr_sor); } cairo_set_operator (cr, CAIRO_OPERATOR_ADD); cairo_set_source_surface (cr, ring_over_star, 0, 0); cairo_paint (cr); cairo_set_source_surface (cr, star_over_ring, 0, 0); cairo_paint (cr); cairo_destroy (cr); cairo_surface_write_to_png (result, "star_and_ring.png"); cairo_surface_destroy (result); cairo_surface_destroy (ring_over_star); cairo_surface_destroy (star_over_ring); return 0; } @ 1.2 log @ * Makefile: * bevels.c: (set_hex_color), (main): * caps_joins.c: (main), (stroke_v_twice), (draw_caps_joins): * hering.c: (main), (draw_hering): * outline.c: (main), (create_gradient), (draw_outlines): * snapping.c: (snap_point_for_fill), (snap_point_for_stroke), (snap_line_width), (snap_path_for_fill), (snap_path_for_stroke), (draw_nested), (main): * spiral.c: (main), (draw_spiral): * splines_tolerance.c: (main), (draw_splines): * star_and_ring.c: (star_path), (fill_ring), (fill_star), (main): * stars.c: (main), (draw_stars): * text-rotate.c: (main): * text.c: (box_text), (box_glyphs), (main): Update all programs to match recent cairo API changes. @ text @a28 2 #include "write_png.h" @ 1.1 log @ * star_and_ring.c: Add example showing how to use CAIRO_OPERATOR_ADD to draw to interwoven objects without any seams. @ text @d35 1 a35 1 char image[STRIDE*HEIGHT]; d82 1 a82 1 cairo_matrix_t *matrix; d84 1 a84 2 matrix = cairo_matrix_create (); cairo_matrix_set_affine (matrix, d88 1 a88 2 cairo_concat_matrix (cr, matrix); cairo_matrix_destroy (matrix); d109 1 a109 2 cairo_set_rgb_color (cr, 1.0, 0.0, 0.0); cairo_set_alpha (cr, 0.75); d122 1 a122 2 cairo_set_rgb_color (cr, 0.0, 0.0, (double) 0xae / 0xff); cairo_set_alpha (cr, 0.55135137); d155 1 a155 1 cairo_t *cr; a157 2 cr = cairo_create (); d165 2 a166 1 cairo_save (cr); d168 5 a172 4 cairo_set_target_surface (cr, ring_over_star); clip_to_top_and_bottom (cr, WIDTH, HEIGHT); fill_star (cr); fill_ring (cr); a173 1 cairo_restore (cr); a174 1 cairo_save (cr); d176 5 a180 4 cairo_set_target_surface (cr, star_over_ring); clip_to_left_and_right (cr, WIDTH, HEIGHT); fill_ring (cr); fill_star (cr); a181 1 cairo_restore (cr); a182 1 cairo_set_target_surface (cr, result); d184 6 a189 2 cairo_show_surface (cr, ring_over_star, WIDTH, HEIGHT); cairo_show_surface (cr, star_over_ring, WIDTH, HEIGHT); d191 1 a191 1 write_png_argb32 (image, "star_and_ring.png", WIDTH, HEIGHT, STRIDE); d193 3 a195 1 cairo_destroy (cr); @