7 function set_solid_pattern ($x, $y)
10 $con->set_source_rgb (1.0, 0, 0.0);
13 function set_translucent_pattern ($x, $y)
16 $con->set_source_rgba (1,0, 0, 0.5);
20 function set_gradient_pattern ($x, $y)
22 global $con,$width,$height;
24 $pat = new CairoLinearGradient ($x, $y, $x +
$width, $y +
$height);
25 $pat->add_color_stop_rgba (0.2, 1, 0, 0, 1);
26 $pat->add_color_stop_rgba ( 0.8, 1, 0, 0, 0.0);
27 $con->set_source ($pat);
31 function set_surface_pattern($x, $y)
33 global $con,$sur,$width,$height;
34 $wi = floor(0.6*$width);
35 $he = floor(0.6*$height);
38 $s = $sur->create_similar(CONTENT_COLOR_ALPHA
, $wi, $he);
39 $con2 = new CairoContext($s);
40 $con2->set_source_rgb(1,0,0);
42 $con2->set_source_rgb(1,1,1);
43 $con2->arc ( 0.5 * $wi, 0.5 * $he, 0.5 * $he, 0, 2 * M_PI
);
45 $s->write_to_png("temp1.png");
46 $con->set_source_surface($s,$x,$y);
52 function draw_mask ($x, $y)
55 global $con,$width,$height,$sur;
56 $wi = floor(0.9 * $width);
57 $he = floor(0.9 * $height);
60 $s = new CairoImageSurface(FORMAT_ARGB32
, 1, 1);
61 $s = $sur->create_similar (
64 $con2 = new CairoContext($s);
66 $con2->set_source_rgb (1, 1, 1); /* white */
68 $con2->arc (0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI
);
72 $con->mask_surface ($s, $x, $y);
77 function draw_glyphs ($x, $y)
80 global $con,$width,$height;
81 $con->set_font_size (0.8 * $height);
83 $extents = $con->text_extents ("FG");
85 $x +
floor (($width - $extents["width"]) / 2 +
0.5) - $extents["x_bearing"],
86 $y +
floor (($height - $extents["height"]) / 2 +
0.5) - $extents["y_bearing"]);
87 $con->show_text ("FG");
90 function draw_polygon ($x, $y)
92 global $con,$width,$height;
94 $wi = floor(0.9 * $width);
95 $he = floor(0.9 * $height);
100 $con->move_to ($x, $y);
101 $con->line_to ($x, $y +
$he);
102 $con->line_to ($x +
$wi / 2, $y +
3 * $he / 4);
103 $con->line_to ($x +
$wi, $y +
$he);
104 $con->line_to ($x +
$wi, $y);
105 $con->line_to ($x +
$wi / 2, $y +
$he / 4);
110 function draw_rects ($x, $y)
112 global $con,$width,$height;
114 $block_width = floor(0.33 * $width +
0.5);
115 $block_height = floor(0.33 * $height +
0.5);
118 for ($i = 0; $i < 3; $i++
)
119 for ($j = 0; $j < 3; $j++
)
120 if (($i +
$j) %
2 == 0)
122 $x +
$block_width * $i, $y +
$block_height * $j,
123 $block_width, $block_height);
128 $imwidth = 4*($width+
$pad) +
$pad;
129 $imheight = 4*($height+
$pad) +
$pad;
131 $sur = new CairoImageSurface(FORMAT_ARGB32
, $imwidth, $imheight);
132 $con = new CairoContext($sur);
134 $con->select_font_face ( "Bitstream Vera Sans",
138 for ($j = 0; $j < 4; $j++
) {
139 for ($i = 0; $i < 4; $i++
) {
140 $x = $i * ($width +
$pad) +
$pad;
141 $y = $j * ($height +
$pad) +
$pad;
145 $pat = new CairoLinearGradient ($x +
$width, $y,
147 $pat->add_color_stop_rgba (0.2,
148 0.0, 0.0, 1.0, 1.0); /* Solid blue */
149 $pat->add_color_stop_rgba ( 0.8,
150 0.0, 0.0, 1.0, 0.0); /* Transparent blue */
151 $con->set_source ($pat);
154 $con->rectangle ($x, $y, $width, $height);
155 $con->fill_preserve ();
158 $con->set_operator (OPERATOR_SOURCE
);
159 //pattern_funcs[i] ($x, $y);
162 set_solid_pattern($x,$y);
165 set_translucent_pattern($x,$y);
168 set_gradient_pattern($x,$y);
171 set_surface_pattern($x,$y);
175 //draw_funcs[j] (cr, x, y);
194 $sur->write_to_png("operator-source-php.png");