7 function set_solid_pattern ($x, $y)
10 $con->setSourceRgb (1.0, 0, 0.0);
13 function set_translucent_pattern ($x, $y)
16 $con->setSourceRgba (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->addColorStopRgba (0.2, 1, 0, 0, 1);
26 $pat->addColorStopRgba ( 0.8, 1, 0, 0, 0.0);
27 $con->setSource ($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->createSimilar(CONTENT_COLOR_ALPHA
, $wi, $he);
39 $con2 = new CairoContext($s);
40 $con2->setSourceRgb(1,0,0);
42 $con2->setSourceRgb(1,1,1);
43 $con2->arc ( 0.5 * $wi, 0.5 * $he, 0.5 * $he, 0, 2 * M_PI
);
45 $s->writeToPng("temp1.png");
46 $con->setSourceSurface($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->createSimilar (
64 $con2 = new CairoContext($s);
66 $con2->setSourceRgb (1, 1, 1); /* white */
68 $con2->arc (0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI
);
72 $con->maskSurface ($s, $x, $y);
77 function draw_glyphs ($x, $y)
80 global $con,$width,$height;
81 $con->setFontSize (0.8 * $height);
83 $extents = $con->textExtents ("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->showText ("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->moveTo ($x, $y);
101 $con->lineTo ($x, $y +
$he);
102 $con->lineTo ($x +
$wi / 2, $y +
3 * $he / 4);
103 $con->lineTo ($x +
$wi, $y +
$he);
104 $con->lineTo ($x +
$wi, $y);
105 $con->lineTo ($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->selectFontFace ( "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->addColorStopRgba (0.2,
148 0.0, 0.0, 1.0, 1.0); /* Solid blue */
149 $pat->addColorStopRgba ( 0.8,
150 0.0, 0.0, 1.0, 0.0); /* Transparent blue */
151 $con->setSource ($pat);
154 $con->rectangle ($x, $y, $width, $height);
155 $con->fillPreserve ();
158 $con->setOperator (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->writeToPng("operator-source-php.png");