7 function set_solid_pattern ($x, $y)
10 $con->set_source_rgb (1.0, 0, 0.0);
13 function set_gradient_pattern ($x, $y)
15 global $con,$width,$height;
17 $pat = new CairoLinearGradient ($x, $y, $x +
$width, $y +
$height);
18 $pat->add_color_stop_rgba (0.2, 1, 0, 0, 1);
19 $pat->add_color_stop_rgba ( 0.8, 1, 0, 0, 0.0);
20 $con->set_source ($pat);
24 function draw_mask ($x, $y)
27 global $con,$width,$height,$sur;
28 $wi = floor(0.9 * $width);
29 $he = floor(0.9 * $height);
32 //$s = new CairoImageSurface(FORMAT_ARGB32, 1, 1);
33 $s = $sur->create_similar (
36 $con2 = new CairoContext($s);
38 $con2->set_source_rgb (1, 1, 1); /* white */
40 $con2->arc (0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI
);
44 $con->mask_surface ($s, $x, $y);
49 function draw_glyphs ($x, $y)
52 global $con,$width,$height;
53 $con->set_font_size (0.8 * $height);
55 $extents = $con->text_extents ("FG");
57 $x +
floor (($width - $extents["width"]) / 2 +
0.5) - $extents["x_bearing"],
58 $y +
floor (($height - $extents["height"]) / 2 +
0.5) - $extents["y_bearing"]);
59 $con->show_text ("FG");
62 function draw_polygon ($x, $y)
64 global $con,$width,$height;
66 $wi = floor(0.9 * $width);
67 $he = floor(0.9 * $height);
72 $con->move_to ($x, $y);
73 $con->line_to ($x, $y +
$he);
74 $con->line_to ($x +
$wi / 2, $y +
3 * $he / 4);
75 $con->line_to ($x +
$wi, $y +
$he);
76 $con->line_to ($x +
$wi, $y);
77 $con->line_to ($x +
$wi / 2, $y +
$he / 4);
82 function draw_rects ($x, $y)
84 global $con,$width,$height;
86 $block_width = floor(0.33 * $width +
0.5);
87 $block_height = floor(0.33 * $height +
0.5);
90 for ($i = 0; $i < 3; $i++
)
91 for ($j = 0; $j < 3; $j++
)
92 if (($i +
$j) %
2 == 0)
94 $x +
$block_width * $i, $y +
$block_height * $j,
95 $block_width, $block_height);
100 $imwidth = 2*($width+
$pad) +
$pad;
101 $imheight = 4*($height+
$pad) +
$pad;
103 $sur = new CairoImageSurface(FORMAT_ARGB32
, $imwidth, $imheight);
104 $con = new CairoContext($sur);
106 $con->select_font_face ( "Bitstream Vera Sans",
110 for ($j = 0; $j < 4; $j++
) {
111 for ($i = 0; $i < 2; $i++
) {
112 $x = $i * ($width +
$pad) +
$pad;
113 $y = $j * ($height +
$pad) +
$pad;
117 $pat = new CairoLinearGradient ($x +
$width, $y,
119 $pat->add_color_stop_rgba (0.2,
120 0.0, 0.0, 1.0, 1.0); /* Solid blue */
121 $pat->add_color_stop_rgba ( 0.8,
122 0.0, 0.0, 1.0, 0.0); /* Transparent blue */
123 $con->set_source ($pat);
126 $con->rectangle ($x, $y, $width, $height);
127 $con->fill_preserve ();
130 $con->set_operator (OPERATOR_CLEAR
);
131 //pattern_funcs[i] ($x, $y);
134 set_solid_pattern($x,$y);
137 set_gradient_pattern($x,$y);
141 //draw_funcs[j] (cr, x, y);
160 $sur->write_to_png("operator-clear-php.png");