Changed the entire file structure to remove the .c includes from cairo.c
[phpCairo.git] / testcases / phpCairo / operator-clear.php
blob32b65ef8da3131cadf16ed31ce695e436cdcd4e6
1 <?
3 $width = 16;
4 $height = 16;
5 $pad = 2;
7 function set_solid_pattern ($x, $y)
9 global $con;
10 $con->setSourceRgb (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->addColorStopRgba (0.2, 1, 0, 0, 1);
19 $pat->addColorStopRgba ( 0.8, 1, 0, 0, 0.0);
20 $con->setSource ($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);
30 $x += 0.05 * $width;
31 $y += 0.05 * $height;
32 //$s = new CairoImageSurface(FORMAT_ARGB32, 1, 1);
33 $s = $sur->createSimilar (
34 CONTENT_ALPHA,
35 $wi, $he);
36 $con2 = new CairoContext($s);
38 $con2->setSourceRgb (1, 1, 1); /* white */
40 $con2->arc (0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI);
41 $con2->fill ();
44 $con->maskSurface ($s, $x, $y);
49 function draw_glyphs ($x, $y)
52 global $con,$width,$height;
53 $con->setFontSize (0.8 * $height);
55 $extents = $con->textExtents ("FG");
56 $con->moveTo (
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->showText ("FG");
62 function draw_polygon ($x, $y)
64 global $con,$width,$height;
66 $wi = floor(0.9 * $width);
67 $he = floor(0.9 * $height);
68 $x += 0.05 * $width;
69 $y += 0.05 * $height;
71 $con->newPath ();
72 $con->moveTo ($x, $y);
73 $con->lineTo ($x, $y + $he);
74 $con->lineTo ($x + $wi / 2, $y + 3 * $he / 4);
75 $con->lineTo ($x + $wi, $y + $he);
76 $con->lineTo ($x + $wi, $y);
77 $con->lineTo ($x + $wi / 2, $y + $he / 4);
78 $con->closePath ();
79 $con->fill ();
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)
93 $con->rectangle (
94 $x + $block_width * $i, $y + $block_height * $j,
95 $block_width, $block_height);
97 $con->fill ();
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->selectFontFace ( "Bitstream Vera Sans",
107 FONT_SLANT_NORMAL,
108 FONT_WEIGHT_NORMAL);
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;
115 $con->save ();
117 $pat = new CairoLinearGradient ($x + $width, $y,
118 $x, $y + $height);
119 $pat->addColorStopRgba (0.2,
120 0.0, 0.0, 1.0, 1.0); /* Solid blue */
121 $pat->addColorStopRgba ( 0.8,
122 0.0, 0.0, 1.0, 0.0); /* Transparent blue */
123 $con->setSource ($pat);
126 $con->rectangle ($x, $y, $width, $height);
127 $con->fillPreserve ();
128 $con->clip ();
130 $con->setOperator (OPERATOR_CLEAR);
131 //pattern_funcs[i] ($x, $y);
132 switch($i) {
133 case 0:
134 set_solid_pattern($x,$y);
135 break;
136 case 1:
137 set_gradient_pattern($x,$y);
138 break;
141 //draw_funcs[j] (cr, x, y);
142 switch($j) {
143 case 0:
144 draw_mask($x,$y);
145 break;
146 case 1:
147 draw_glyphs($x,$y);
148 break;
149 case 2:
150 draw_polygon($x,$y);
151 break;
152 case 3:
153 draw_rects($x,$y);
154 break;
156 $con->restore ();
160 $sur->writeToPng("operator-clear-php.png");