Examples updated to the latest Camel Case .. Was a pain converting them
[phpCairo.git] / testcases / phpCairo / self-copy.php
blobe0d0776842b47f5af009ca4e1a9c0d682634aaad
1 <?
2 $size = 40;
3 $sur = new CairoImageSurface(FORMAT_ARGB32, $size, $size);
4 $con = new CairoContext($sur);
5 $con->setSourceRgb ( 1, 1, 1); /* White */
6 $con->paint ();
8 $con->moveTo ( $size, 0);
9 $con->lineTo ( $size, $size);
10 $con->lineTo ( 0, $size);
12 $con->setSourceRgb ( 0, 0, 0);
13 $con->fill ();
15 /* Create a pattern with the target surface as the source,
16 * offset by $size/2
18 $pattern = new CairoSurfacePattern ($sur);
19 $matrix = new CairoMatrix();
20 $matrix->translate ( - $size / 2, - $size / 2);
21 $pattern->setMatrix ( $matrix);
23 $con->setSource ($pattern);
25 /* Copy two rectangles from the upper-left quarter of the image to
26 * the lower right. It will work if we use $con->fill(), but the
27 * $con->clip() $con->paint() combination fails because the clip
28 * on the surface as a destination affects it as the source as
29 * well.
31 $con->rectangle (
32 2 * $size / 4, 2 * $size / 4,
33 $size / 4, $size / 4);
34 $con->rectangle (
35 3 * $size / 4, 3 * $size / 4,
36 $size / 4, $size / 4);
37 $con->clip ();
38 $con->paint ();
39 $sur->writeToPng("self-copy-php.png");