<?php $size = 100; $border = 10; $linewidth = 20; $sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size); $con = new CairoContext($sur); $s = $con->getGroupTarget(); $c = new CairoContext($s); $c->moveTo($border, $border); $c->lineTo($border + $linewidth, $border); $c->lineTo($size - $border, $size - $border); $c->lineTo($size - $border - $linewidth, $size - $border); $c->clip(); $c->setSourceRgb(0, 0, 1); $c->paint(); $c->setSourceRgb(1, 1, 1); $c->rectangle($size / 2 - $linewidth / 2, $border, $linewidth, $size - 2 * $border); $c->fill(); $c2 = new CairoContext($sur); $c2->setSourceRgb(1, 1, 1); $c2->rectangle($size - $border - $linewidth, $border, $linewidth, $size - 2 * $border); $c2->fill(); $con->setSourceRgb(1, 1, 1); $con->rectangle($border, $border, $linewidth, $size - 2 * $border); $con->fill(); $sur->writeToPng(dirname(__FILE__) . "/clip-nesting-php.png");
<?php $width = 64; $height = 64; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $con = new CairoContext($sur); $con->newPath(); $con->arc($width / 2, $height / 2, $width / 3, 0, 2 * M_PI); $con->clip(); $con->newPath(); $con->moveTo(0, 0); $con->lineTo($width / 4, $height / 2); $con->lineTo(0, $height); $con->lineTo($width, $height); $con->lineTo(3 * $width / 4, $height / 2); $con->lineTo($width, 0); $con->closePath(); $con->clip(); $con->setSourceRgb(0, 0, 0.6); $con->newPath(); $con->moveTo(0, 0); $con->lineTo(0, $height); $con->lineTo($width / 2, 3 * $height / 4); $con->lineTo($width, $height); $con->lineTo($width, 0); $con->lineTo($width / 2, $height / 4); $con->closePath(); $con->fill(); $con->newPath(); $con->arc($width / 2, $height / 2, $width / 5, 0, 2 * M_PI); $con->clip();
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 12, 12); $con = new CairoContext($sur); $source = $sur->createSimilar(CairoContent::COLOR_ALPHA, 12, 12); $con2 = new CairoContext($source); /* Fill the source surface with green */ $con2->setSourceRgb(0, 1, 0); $con2->paint(); /* Draw a blue square in the middle of the source with clipping, * and leave the clip there. */ $con2->rectangle(12 / 4, 12 / 4, 12 / 2, 12 / 2); $con2->clip(); $con2->setSourceRgb(0, 0, 1); $con2->paint(); /* Fill the destination surface with solid red (should not appear * in final result) */ $con->setSourceRgb(1, 0, 0); $con->paint(); /* Now draw the source surface onto the destination surface */ $con->setSourceSurface($source, 0, 0); $con->paint(); $sur->writeToPng(dirname(__FILE__) . '/source-clip.png');