[cairo-commit] cairo-demo/cairo_snippets/snippets arc.cairo, NONE, 1.1 arc_negative.cairo, NONE, 1.1 clip.cairo, NONE, 1.1 clip_image.cairo, NONE, 1.1 curve_rectangle.cairo, NONE, 1.1 curve_to.cairo, NONE, 1.1 fill_and_stroke.cairo, NONE, 1.1 fill_and_stroke2.cairo, NONE, 1.1 gradient.cairo, NONE, 1.1 image.cairo, NONE, 1.1 imagepattern.cairo, NONE, 1.1 libsvg.cairo, NONE, 1.1 operator_add.cairo, NONE, 1.1 operator_atop.cairo, NONE, 1.1 operator_atop_reverse.cairo, NONE, 1.1 operator_in.cairo, NONE, 1.1 operator_in_reverse.cairo, NONE, 1.1 operator_out.cairo, NONE, 1.1 operator_out_reverse.cairo, NONE, 1.1 operator_over.cairo, NONE, 1.1 operator_over_reverse.cairo, NONE, 1.1 operator_saturate.cairo, NONE, 1.1 operator_xor.cairo, NONE, 1.1 path.cairo, NONE, 1.1 pattern_fill.cairo, NONE, 1.1 set_line_cap.cairo, NONE, 1.1 set_line_join.cairo, NONE, 1.1 text.cairo, NONE, 1.1 text_align_center.cairo, NONE, 1.1 text_extents.cairo, NONE, 1.1 xxx_clip_rectangle.cairo, NONE, 1.1 xxx_dash.cairo, NONE, 1.1 xxx_long_lines.cairo, NONE, 1.1 xxx_multi_segment_caps.cairo, NONE, 1.1 xxx_self_intersect.cairo, NONE, 1.1

Kristian Hogsberg commit at pdx.freedesktop.org
Tue Feb 1 14:58:11 PST 2005


Committed by: krh

Update of /cvs/cairo/cairo-demo/cairo_snippets/snippets
In directory gabe:/tmp/cvs-serv9689/snippets

Added Files:
	arc.cairo arc_negative.cairo clip.cairo clip_image.cairo 
	curve_rectangle.cairo curve_to.cairo fill_and_stroke.cairo 
	fill_and_stroke2.cairo gradient.cairo image.cairo 
	imagepattern.cairo libsvg.cairo operator_add.cairo 
	operator_atop.cairo operator_atop_reverse.cairo 
	operator_in.cairo operator_in_reverse.cairo operator_out.cairo 
	operator_out_reverse.cairo operator_over.cairo 
	operator_over_reverse.cairo operator_saturate.cairo 
	operator_xor.cairo path.cairo pattern_fill.cairo 
	set_line_cap.cairo set_line_join.cairo text.cairo 
	text_align_center.cairo text_extents.cairo 
	xxx_clip_rectangle.cairo xxx_dash.cairo xxx_long_lines.cairo 
	xxx_multi_segment_caps.cairo xxx_self_intersect.cairo 
Log Message:
2005-02-01  Kristian Høgsberg  <krh at redhat.com>

        * autotool this thing, move *.cairo into snippets/ and webpage
        related files into html/.



--- NEW FILE: arc.cairo ---
double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0  * (M_PI/180.0);  /* angles are specified */
double angle2 = 180.0 * (M_PI/180.0);  /* in radians           */

snippet_normalize (cr, width, height);

cairo_arc (cr, xc, yc, radius, angle1, angle2);
cairo_stroke (cr);

/* draw helping lines */
cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_alpha (cr, 0.6);
cairo_arc (cr, xc, yc, 0.05, 0, 2*M_PI);
cairo_fill (cr);
cairo_set_line_width (cr, 0.03);
cairo_arc (cr, xc, yc, radius, angle1, angle1);
cairo_line_to (cr, xc, yc);
cairo_arc (cr, xc, yc, radius, angle2, angle2);
cairo_line_to (cr, xc, yc);
cairo_stroke (cr);

--- NEW FILE: arc_negative.cairo ---
double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0  * (M_PI/180.0);  /* angles are specified */
double angle2 = 180.0 * (M_PI/180.0);  /* in radians           */

snippet_normalize (cr, width, height);

cairo_arc_negative (cr, xc, yc, radius, angle1, angle2);
cairo_stroke (cr);

/* draw helping lines */
cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_alpha (cr, 0.6);
cairo_arc (cr, xc, yc, 0.05, 0, 2*M_PI);
cairo_fill (cr);
cairo_set_line_width (cr, 0.03);
cairo_arc (cr, xc, yc, radius, angle1, angle1);
cairo_line_to (cr, xc, yc);
cairo_arc (cr, xc, yc, radius, angle2, angle2);
cairo_line_to (cr, xc, yc);
cairo_stroke (cr);

--- NEW FILE: clip.cairo ---
snippet_normalize (cr, width, height);

cairo_arc (cr, 0.5, 0.5, 0.3, 0, 2 * M_PI);
cairo_clip (cr);

cairo_new_path (cr);  /* current path is not
                         consumed by cairo_clip() */
cairo_rectangle (cr, 0, 0, 1, 1);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0, 1, 0);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, 1, 1);
cairo_move_to (cr, 1, 0);
cairo_line_to (cr, 0, 1);
cairo_stroke (cr);

--- NEW FILE: clip_image.cairo ---
int              w,h,stride;
char            *buffer;
cairo_surface_t *image;

snippet_normalize (cr, width, height);

cairo_arc (cr, 0.5, 0.5, 0.3, 0, 2*M_PI);
cairo_clip (cr);
cairo_new_path (cr); /* path not consumed by clip()*/

buffer = read_png_argb32 (
              "data/romedalen.png", &w,&h, &stride);
image  = cairo_surface_create_for_image (
              buffer, CAIRO_FORMAT_ARGB32, w,h, stride);

cairo_scale (cr, 1.0/w, 1.0/h);

cairo_move_to (cr, 0, 0);
cairo_show_surface (cr, image, w, h);

cairo_surface_destroy (image);
free (buffer);

--- NEW FILE: curve_rectangle.cairo ---
/* a custom shape, that could be wrapped in a function */
double x0     = 0.1,   /*< parameters like cairo_rectangle */
       y0     = 0.1,
       width  = 0.8,
       height = 0.8,
       radius = 0.4;   /*< and an approximate curvature radius */

double x1,y1;

snippet_normalize (cr, width, height);

x1=x0+width;
y1=y0+height;
if (!width || !height)
    return;
if (width/2<radius) {
    if (height/2<radius) {
        cairo_move_to  (cr, x0, (y0 + y1)/2);
        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
    } else {
        cairo_move_to  (cr, x0, y0 + radius);
        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
        cairo_line_to (cr, x1 , y1 - radius);
        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
    }
} else {
    if (height/2<radius) {
        cairo_move_to  (cr, x0, (y0 + y1)/2);
        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
        cairo_line_to (cr, x1 - radius, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
        cairo_line_to (cr, x0 + radius, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
    } else {
        cairo_move_to  (cr, x0, y0 + radius);
        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
        cairo_line_to (cr, x1 - radius, y0);
        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
        cairo_line_to (cr, x1 , y1 - radius);
        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
        cairo_line_to (cr, x0 + radius, y1);
        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
    }
}
cairo_close_path (cr);

/* and fill/stroke it */
cairo_save (cr);
    cairo_set_rgb_color (cr, 0.5,0.5,1);
    cairo_fill (cr);
cairo_restore (cr);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 0.5, 0,0);
cairo_stroke (cr);

--- NEW FILE: curve_to.cairo ---
double x=0.1,  y=0.5;
double x1=0.4, y1=0.9,
       x2=0.6, y2=0.1,
       x3=0.9, y3=0.5;

snippet_normalize (cr, width, height);

cairo_move_to (cr,  x, y);
cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);

cairo_stroke (cr);

cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_alpha (cr, 0.6);
cairo_set_line_width (cr, 0.03);
cairo_move_to (cr,x,y);   cairo_line_to (cr,x1,y1);
cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3);
cairo_stroke (cr);

--- NEW FILE: fill_and_stroke.cairo ---
snippet_normalize (cr, width, height);

cairo_move_to (cr, 0.5, 0.1);
cairo_line_to (cr, 0.9, 0.9);
cairo_rel_line_to (cr, -0.4, 0.0);
cairo_curve_to (cr, 0.2, 0.9, 0.2, 0.5, 0.5, 0.5);

cairo_save (cr);
    cairo_set_rgb_color (cr, 0, 0, 1);
    cairo_fill (cr);
cairo_restore (cr);

cairo_close_path (cr);
cairo_stroke (cr);

--- NEW FILE: fill_and_stroke2.cairo ---
snippet_normalize (cr, width, height);

cairo_move_to (cr, 0.5, 0.1);
cairo_line_to (cr, 0.9, 0.9);
cairo_rel_line_to (cr, -0.4, 0.0);
cairo_curve_to (cr, 0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
cairo_close_path (cr);

cairo_move_to (cr, 0.25, 0.1);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_rel_line_to (cr, -0.2, 0.2);
cairo_rel_line_to (cr, -0.2, -0.2);
cairo_close_path (cr);


cairo_save (cr);
    cairo_set_rgb_color (cr, 0, 0, 1);
    cairo_fill (cr);
cairo_restore (cr);

cairo_stroke (cr);

--- NEW FILE: gradient.cairo ---
cairo_pattern_t *pat;

snippet_normalize (cr, width, height);

pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, 1.0);
cairo_pattern_add_color_stop (pat, 1, 0, 0, 0, 1);
cairo_pattern_add_color_stop (pat, 0, 1, 1, 1, 1);
cairo_rectangle (cr, 0,0,1,1);
cairo_set_pattern (cr, pat);
cairo_fill (cr);

cairo_pattern_destroy (pat);
pat = cairo_pattern_create_radial (0.45, 0.4, 0.1,
                                   0.4,  0.4, 0.5);
cairo_pattern_add_color_stop (pat, 0, 1, 1, 1, 1);
cairo_pattern_add_color_stop (pat, 1, 0, 0, 0, 1);
cairo_set_pattern (cr, pat);
cairo_arc (cr, 0.5, 0.5, 0.3, 0, 2 * M_PI);
cairo_fill (cr);
cairo_pattern_destroy (pat);

--- NEW FILE: image.cairo ---
int              w,h,stride;
char            *buffer;
cairo_surface_t *image;

snippet_normalize (cr, width, height);

buffer = read_png_argb32 (
              "data/romedalen.png", &w,&h, &stride);
image  = cairo_surface_create_for_image (
              buffer, CAIRO_FORMAT_ARGB32, w,h, stride);

cairo_translate (cr, 0.5, 0.5);
cairo_rotate (cr, 45* M_PI/180);
cairo_scale  (cr, 1.0/w, 1.0/h);
cairo_translate (cr, -0.5*w, -0.5*h);

cairo_move_to (cr, 0,0);
cairo_show_surface (cr, image, w, h);
cairo_surface_destroy (image);
free (buffer);

--- NEW FILE: imagepattern.cairo ---
int              w,h,stride;
char            *buffer;
cairo_surface_t *image;
cairo_pattern_t *pattern;
cairo_matrix_t  *matrix;

snippet_normalize (cr, width, height);

buffer = read_png_argb32 (
              "data/romedalen.png", &w,&h, &stride);
image  = cairo_surface_create_for_image (
              buffer, CAIRO_FORMAT_ARGB32, w,h, stride);

cairo_surface_set_repeat (image, 1);
pattern = cairo_pattern_create_for_surface (image);

cairo_translate (cr, 0.5, 0.5);
cairo_rotate (cr, M_PI / 4);
cairo_scale (cr, 1 / sqrt (2), 1 / sqrt (2));
cairo_translate (cr, - 0.5, - 0.5);

matrix = cairo_matrix_create ();
cairo_matrix_scale (matrix, w * 5., h * 5.); 
cairo_pattern_set_matrix (pattern, matrix);
cairo_matrix_destroy (matrix);

cairo_set_pattern (cr, pattern);

cairo_rectangle (cr, 0, 0, 1.0, 1.0);
cairo_fill (cr);

cairo_pattern_destroy (pattern);
cairo_surface_destroy (image);
free (buffer);

--- NEW FILE: libsvg.cairo ---
svg_cairo_t *svgc;
int          w, h;

snippet_normalize (cr, width, height);

svg_cairo_create (&svgc);

svg_cairo_parse (svgc, "data/home.svg");
svg_cairo_get_size (svgc, &w, &h);
cairo_scale (cr, 1.0/w, 1.0/h);
svg_cairo_render (svgc, cr);

svg_cairo_destroy (svgc);

--- NEW FILE: operator_add.cairo ---
snippet_normalize (cr, width, height);

snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_atop.cairo ---
snippet_normalize (cr, width, height);

snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_ATOP);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);

--- NEW FILE: operator_atop_reverse.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_ATOP_REVERSE);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_in.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_IN);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_in_reverse.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_IN_REVERSE);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_out.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_OUT);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_out_reverse.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_OUT_REVERSE);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_over.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_over_reverse.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_OVER_REVERSE);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_saturate.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: operator_xor.cairo ---
snippet_normalize (cr, width, height);
snippet_set_bg_svg (cr, "data/freedesktop.svg");
cairo_set_operator (cr, CAIRO_OPERATOR_XOR);
cairo_set_alpha (cr, 0.5);
cairo_set_rgb_color (cr, 1,0,0);
cairo_rectangle (cr, 0.2,0.2, 0.5,0.5);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,1,0);
cairo_rectangle (cr, 0.4,0.4, 0.4,0.4);
cairo_fill (cr);
cairo_set_rgb_color (cr, 0,0,1);
cairo_rectangle (cr, 0.6,0.6, 0.3,0.3);
cairo_fill (cr);


--- NEW FILE: path.cairo ---
snippet_normalize (cr, width, height);
cairo_move_to (cr, 0.5, 0.1);
cairo_line_to (cr, 0.9, 0.9);
cairo_rel_line_to (cr, -0.4, 0.0);
cairo_curve_to (cr, 0.2, 0.9, 0.2, 0.5, 0.5, 0.5);

cairo_stroke (cr);

--- NEW FILE: pattern_fill.cairo ---
/* -*- mode: c -*- */

#define X_FUZZ 0.08
#define Y_FUZZ 0.08

#define X_INNER_RADIUS 0.3
#define Y_INNER_RADIUS 0.2

#define X_OUTER_RADIUS 0.45
#define Y_OUTER_RADIUS 0.35

#define SPIKES 10

int i;
double x;
double y;
char text[] = "KAPOW!";
cairo_text_extents_t extents;

srand (45);
cairo_set_line_width (cr, 0.01);

for (i = 0; i < SPIKES * 2; i++) {

    x = 0.5 + cos (M_PI * i / SPIKES) * X_INNER_RADIUS +
	(double) rand() * X_FUZZ / RAND_MAX;
    y = 0.5 + sin (M_PI * i / SPIKES) * Y_INNER_RADIUS +
	(double) rand() * Y_FUZZ / RAND_MAX;

    if (i == 0)
	cairo_move_to (cr, x, y);
    else
	cairo_line_to (cr, x, y);

    i++;

    x = 0.5 + cos (M_PI * i / SPIKES) * X_OUTER_RADIUS +
	(double) rand() * X_FUZZ / RAND_MAX;
    y = 0.5 + sin (M_PI * i / SPIKES) * Y_OUTER_RADIUS +
	(double) rand() * Y_FUZZ / RAND_MAX;

    cairo_line_to (cr, x, y);
}

cairo_close_path (cr);
cairo_stroke (cr);


cairo_select_font (cr, "Sans",
    CAIRO_FONT_SLANT_NORMAL,
    CAIRO_FONT_WEIGHT_BOLD);

cairo_move_to (cr, x, y);
cairo_text_path (cr, text);

extern void
cairo_current_path_flat (cairo_t			*cr,
			 cairo_move_to_func_t		*move_to,
			 cairo_line_to_func_t		*line_to,
			 cairo_close_path_func_t	*close_path,
			 void				*closure);



cairo_scale_font (cr, 0.2);
cairo_text_extents (cr, text, &extents);
x = 0.5-(extents.width/2 + extents.x_bearing);
y = 0.5-(extents.height/2 + extents.y_bearing);


#if 0
void
cairo_set_pattern (cairo_t *cr, cairo_pattern_t *pattern);
#endif

cairo_set_rgb_color (cr, 1 , 1, 0.5);
cairo_fill (cr);

cairo_move_to (cr, x, y);
cairo_text_path (cr, text);
cairo_set_rgb_color (cr, 0 , 0, 0);
cairo_stroke (cr);


--- NEW FILE: set_line_cap.cairo ---
snippet_normalize (cr, width, height);
cairo_set_line_width (cr, 0.12);
cairo_set_line_cap  (cr, CAIRO_LINE_CAP_BUTT); /* default */
cairo_move_to (cr, 0.25, 0.2); cairo_line_to (cr, 0.25, 0.8);
cairo_stroke (cr);
cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
cairo_move_to (cr, 0.5, 0.2); cairo_line_to (cr, 0.5, 0.8);
cairo_stroke (cr);
cairo_set_line_cap  (cr, CAIRO_LINE_CAP_SQUARE);
cairo_move_to (cr, 0.75, 0.2); cairo_line_to (cr, 0.75, 0.8);
cairo_stroke (cr);

/* draw helping lines */
cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_line_width (cr, 0.01);
cairo_move_to (cr, 0.25, 0.2); cairo_line_to (cr, 0.25, 0.8);
cairo_move_to (cr, 0.5, 0.2);  cairo_line_to (cr, 0.5, 0.8);
cairo_move_to (cr, 0.75, 0.2); cairo_line_to (cr, 0.75, 0.8);
cairo_stroke (cr);

--- NEW FILE: set_line_join.cairo ---
snippet_normalize (cr, width, height);
cairo_set_line_width (cr, 0.16);
cairo_move_to (cr, 0.3, 0.33);
cairo_rel_line_to (cr, 0.2, -0.2);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); /* default */
cairo_stroke (cr);

cairo_move_to (cr, 0.3, 0.63);
cairo_rel_line_to (cr, 0.2, -0.2);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
cairo_stroke (cr);

cairo_move_to (cr, 0.3, 0.93);
cairo_rel_line_to (cr, 0.2, -0.2);
cairo_rel_line_to (cr, 0.2, 0.2);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_stroke (cr);



--- NEW FILE: text.cairo ---
snippet_normalize (cr, width, height);
cairo_select_font (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
                               CAIRO_FONT_WEIGHT_BOLD);
cairo_scale_font (cr, 0.35);

cairo_move_to (cr, 0.04, 0.53);
cairo_show_text (cr, "Hello");

cairo_move_to (cr, 0.27, 0.65);
cairo_text_path (cr, "void");
cairo_save (cr);
    cairo_set_rgb_color (cr, 0.5,0.5,1);
    cairo_fill (cr);
cairo_restore (cr);
cairo_set_line_width (cr, 0.01);
cairo_stroke (cr);

/* draw helping lines */
cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_alpha (cr, 0.6);
cairo_arc (cr, 0.04, 0.53, 0.02, 0, 2*M_PI);
cairo_arc (cr, 0.27, 0.65, 0.02, 0, 2*M_PI);
cairo_fill (cr);


--- NEW FILE: text_align_center.cairo ---
cairo_text_extents_t extents;

const char *utf8 = "cairo";
double x,y;

snippet_normalize (cr, width, height);

cairo_select_font (cr, "Sans",
    CAIRO_FONT_SLANT_NORMAL,
    CAIRO_FONT_WEIGHT_NORMAL);

cairo_scale_font (cr, 0.2);
cairo_text_extents (cr, utf8, &extents);
x = 0.5-(extents.width/2 + extents.x_bearing);
y = 0.5-(extents.height/2 + extents.y_bearing);

cairo_move_to (cr, x, y);
cairo_show_text (cr, utf8);

/* draw helping lines */
cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_alpha (cr, 0.6);
cairo_arc (cr, x, y, 0.05, 0, 2*M_PI);
cairo_fill (cr);
cairo_move_to (cr, 0.5, 0);
cairo_rel_line_to (cr, 0, 1);
cairo_move_to (cr, 0, 0.5);
cairo_rel_line_to (cr, 1, 0);
cairo_stroke (cr);


--- NEW FILE: text_extents.cairo ---
cairo_text_extents_t extents;

const char *utf8 = "cairo";
double x,y;

snippet_normalize (cr, width, height);

cairo_select_font (cr, "Sans",
    CAIRO_FONT_SLANT_NORMAL,
    CAIRO_FONT_WEIGHT_NORMAL);

cairo_scale_font (cr, 0.4);
cairo_text_extents (cr, utf8, &extents);

x=0.1;
y=0.6;

cairo_move_to (cr, x,y);
cairo_show_text (cr, utf8);

/* draw helping lines */
cairo_set_rgb_color (cr, 1,0.2,0.2);
cairo_set_alpha (cr, 0.6);
cairo_arc (cr, x, y, 0.05, 0, 2*M_PI);
cairo_fill (cr);
cairo_move_to (cr, x,y);
cairo_rel_line_to (cr, 0, -extents.height);
cairo_rel_line_to (cr, extents.width, 0);
cairo_rel_line_to (cr, extents.x_bearing, -extents.y_bearing);
cairo_stroke (cr);


--- NEW FILE: xxx_clip_rectangle.cairo ---
/* This is intended to test the rectangle-based clipping support in
 * cairo.  On 2004-08-03, we noticed a bug in which this clipping
 * wasn't happening at all, so we disabled it in
 * cairo_gstate.c:extract_transformed_rectangle.
 *
 * When that works again, and is re-enabled, this test can be renamed
 * without the xxx_.
 */

snippet_normalize (cr, width, height);

cairo_new_path (cr);
cairo_move_to (cr, .25, .25);
cairo_line_to (cr, .25, .75);
cairo_line_to (cr, .75, .75);
cairo_line_to (cr, .75, .25);
cairo_line_to (cr, .25, .25);
cairo_close_path (cr);

cairo_clip (cr);

cairo_move_to (cr, 0, 0);
cairo_line_to (cr, 1, 1);
cairo_stroke (cr);

--- NEW FILE: xxx_dash.cairo ---
/* BUG: spline is not stroked, is it a bug that
   a negative offset for cairo_set_dash, causes
   no dashing to occur?
*/

double dashes[] = {0.20,  /* ink */
                   0.05,  /* skip */
                   0.05,  /* ink */
                   0.05   /* skip*/ 
                  };
int    ndash  = sizeof (dashes)/sizeof(dashes[0]); 
double offset = -0.2; 

snippet_normalize (cr, width, height);

cairo_set_dash (cr, dashes, ndash, offset);

cairo_move_to (cr, 0.5, 0.1);
cairo_line_to (cr, 0.9, 0.9);
cairo_rel_line_to (cr, -0.4, 0.0);
cairo_curve_to (cr, 0.2, 0.9, 0.2, 0.5, 0.5, 0.5);

cairo_stroke (cr);

--- NEW FILE: xxx_long_lines.cairo ---
snippet_normalize (cr, width, height);

cairo_move_to (cr, 0.1, -50);
cairo_line_to (cr, 0.1,  50);
cairo_set_rgb_color (cr, 1, 0 ,0);
cairo_stroke (cr);

cairo_move_to (cr, 0.2, -60);
cairo_line_to (cr, 0.2,  60);
cairo_set_rgb_color (cr, 1, 1 ,0);
cairo_stroke (cr);

cairo_move_to (cr, 0.3, -70);
cairo_line_to (cr, 0.3,  70);
cairo_set_rgb_color (cr, 0, 1 ,0);
cairo_stroke (cr);

cairo_move_to (cr, 0.4, -80);
cairo_line_to (cr, 0.4,  80);
cairo_set_rgb_color (cr, 0, 0 ,1);
cairo_stroke (cr);

--- NEW FILE: xxx_multi_segment_caps.cairo ---
/* BUG: Caps are added only to the last subpath in a complex path */
snippet_normalize (cr, width, height);

cairo_move_to (cr, 0.2, 0.3);
cairo_line_to (cr, 0.8, 0.3);

cairo_move_to (cr, 0.2, 0.5);
cairo_line_to (cr, 0.8, 0.5);

cairo_move_to (cr, 0.2, 0.7);
cairo_line_to (cr, 0.8, 0.7);

cairo_set_line_width (cr, 0.12);
cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
cairo_stroke (cr);

--- NEW FILE: xxx_self_intersect.cairo ---
/* the minimally different shade of the right part of the bar
   is an artifact of the self intersect bug described in BUGS */

snippet_normalize (cr, width, height);

cairo_move_to (cr, 0.3, 0.3);
cairo_line_to (cr, 0.7, 0.3);

cairo_line_to (cr, 0.5, 0.3);
cairo_line_to (cr, 0.5, 0.7);

cairo_set_line_width (cr, 0.22);
cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join  (cr, CAIRO_LINE_JOIN_ROUND);
cairo_stroke (cr);




More information about the cairo-commit mailing list