function draw_pattern($surface_size) { global $s; $con = new CairoContext($s); $con->setSourceRgb(1, 1, 1); $con->rectangle(0, 0, $surface_size / 2, $surface_size / 2); $con->fill(); $con->setSourceRgb(1, 0, 0); $con->rectangle($surface_size / 2, 0, $surface_size / 2, $surface_size / 2); $con->fill(); $con->setSourceRgb(0, 1, 0); $con->rectangle(0, $surface_size / 2, $surface_size / 2, $surface_size / 2); $con->fill(); $con->setSourceRgb(0, 0, 1); $con->rectangle($surface_size / 2, $surface_size / 2, $surface_size / 2, $surface_size / 2); $con->fill(); // $s->writeToPng(dirname(__FILE__) . "temp1.png"); }
function draw_mask($x, $y) { global $con, $width, $height, $sur; $wi = floor(0.9 * $width); $he = floor(0.9 * $height); $x += 0.05 * $width; $y += 0.05 * $height; //$s = new CairoImageSurface(FORMATARGB32, 1, 1); $s = $sur->createSimilar(CairoContent::ALPHA, $wi, $he); $con2 = new CairoContext($s); $con2->setSourceRgb(1, 1, 1); /* white */ $con2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI); $con2->fill(); $con->maskSurface($s, $x, $y); }
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 120, 100); $con = new CairoContext($sur); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->setSourceRgb(0, 0, 0); $con->setMiterLimit(100000); for ($xscale = 1; $xscale <= 1000; $xscale += 999) { for ($yscale = 1; $yscale <= 1000; $yscale += 999) { //$max_scale = ($xscale > $yscale) ? $xscale : $yscale; $max_scale = max($xscale, $yscale); $con->save(); if ($xscale > 1) { $con->translate(50, 0); } if ($yscale > 1) { $con->translate(0, 50); } $con->scale($xscale, $yscale); $con->setLineWidth(10.0 / $max_scale); $con->moveTo(10.0 / $xscale, 10.0 / $yscale); $con->lineTo(40.0 / $xscale, 10.0 / $yscale); $con->lineTo(10.0 / $xscale, 30.0 / $yscale); $con->stroke(); $con->restore(); } } $sur->writeToPng(dirname(__FILE__) . "/miter-precision-php.png");
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 53, 53); $con = new CairoContext($sur); $con->setSourceRgb(1, 0, 0); $con->translate(1, 1); $con->moveTo(0, 0); $con->lineTo(25, 50); $con->lineTo(25, 0); $con->lineTo(50, 25); $con->lineTo(0, 25); $con->closePath(); $con->fill(); $sur->writeToPng(dirname(__FILE__) . "/fill-missed-stop-php.png"); ?>
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 36, 36); $con = new CairoContext($sur); $s = new CairoImageSurface(CairoFormat::ARGB32, 2, 2); $con2 = new CairoContext($s); $con2->setSourceRgb(1, 0, 0); $con2->paint(); $con2->setSourceRgb(0, 0, 1); $con2->rectangle(0, 1, 1, 1); $con2->rectangle(1, 0, 1, 1); $con2->fill(); $con->setSourceRgb(0, 0, 0); $con->paint(); $con->save(); $con->translate(3, 3); $con->scale(10, 10); $con->translate(0.5, 0.5); $con->setSourceSurface($s, 0, 0); $con->paint(); $con->restore(); $sur->writeToPng(dirname(__FILE__) . "/filter-bilinear-extents-php.png"); ?>
$con = new CairoContext($sur); //$s = new CairoImageSurface(FORMATARGB32, $width, $height); $con->translate($pad, $pad); $pat_surface = $sur->createSimilar(CairoContent::COLOR_ALPHA, $patwidth, $patheight); $cr2 = new CairoContext($pat_surface); $cr2->setSourceRgba(1, 0, 1, 0.5); $cr2->rectangle($patwidth / 6.0, $patheight / 6.0, $patwidth / 4.0, $patheight / 4.0); $cr2->fill(); $cr2->setSourceRgba(0, 1, 1, 0.5); $cr2->rectangle($patwidth / 2.0, $patheight / 2.0, $patwidth / 4.0, $patheight / 4.0); $cr2->fill(); $cr2->setLineWidth(1); $cr2->moveTo($patwidth / 6.0, 0); $cr2->lineTo(0, 0); $cr2->lineTo(0, $patheight / 6.0); $cr2->setSourceRgb(1, 0, 0); $cr2->stroke(); $cr2->moveTo($patwidth / 6.0, $patheight); $cr2->lineTo(0, $patheight); $cr2->lineTo(0, 5 * $patheight / 6.0); $cr2->setSourceRgb(0, 1, 0); $cr2->stroke(); $cr2->moveTo(5 * $patwidth / 6.0, 0); $cr2->lineTo($patwidth, 0); $cr2->lineTo($patwidth, $patheight / 6.0); $cr2->setSourceRgb(0, 0, 1); $cr2->stroke(); $cr2->moveTo(5 * $patwidth / 6.0, $patheight); $cr2->lineTo($patwidth, $patheight); $cr2->lineTo($patwidth, 5 * $patheight / 6.0); $cr2->setSourceRgb(1, 1, 0);
<?php $size = 10; $pad = 2; $sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size); $con = new CairoContext($sur); $con->setSourceRgb(0, 0, 1); $con->rectangle($pad, $pad, $size - 2 * $pad, $size - 2 * $pad); $con->fill(); $s = $con->getGroupTarget(); $c = $s->getContent(); $s1 = $s->createSimilar($c, $size / 2, $size / 2); $c = new CairoContext($s1); $c->setSourceRgb(1, 0, 0); $c->rectangle($pad, $pad, $size - 2 * $pad, $size - 2 * $pad); $c->fill(); $s1->setDeviceOffset($size / 2, $size / 2); $con->setSourceSurface($s1, $size / 2, $size / 2); $con->paint(); $sur->writeToPng(dirname(__FILE__) . "/device-offset-positive-php.png");
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 300, 16); $con = new CairoContext($sur); $con->save(); $con->setSourceRgb(1.0, 1.0, 1.0); /* white */ $con->paint(); $con->restore(); $con->selectFontFace('Bitstream Vera Sans', CairoFontSlant::NORMAL, CairoFontWeight::NORMAL); $con->setFontSize(12); $con->setSourceRgb(0, 0, 0); /* black */ $con->moveTo(0, 12); $con->showText('Hello from the '); $con->showText('show-text-current-point-php'); $con->showText(' test.'); $sur->writeToPng(dirname(__FILE__) . '/show-text-current-point.png');
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 32, 16); $con = new CairoContext($sur); $con->save(); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->restore(); $con->arc(8, 8, 4, 0, M_PI); $con->closePath(); $con->arc(8, 8, 4, M_PI, 2 * M_PI); $con->fill(); $con->translate(16, 0); $con->moveTo(8, 4); $con->arcNegative(8, 8, 4, 3 * M_PI / 2, M_PI / 2); $con->closePath(); $con->curveTo(12, 4, 12, 12, 8, 12); $path = $con->copyPathFlat(); $con->newPath(); $con->appendPath($path); $con->fill(); $sur->writeToPng(dirname(__FILE__) . "/close-path-php.png"); ?>
<?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 = 60; $height = 60; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $con = new CairoContext($sur); $dash = array(4.0, 2.0); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->setSourceRgb(0.0, 0.0, 0); $con->translate(0.5, 0.5); $con->setLineWidth(1); /* This is vital to reproduce the bug. */ /* First check simple rectangles */ $con->setSourceRgb(0.0, 0.0, 0); $con->rectangle(-$width / 4, -$height / 4, $width, $height); $con->stroke(); $con->rectangle($width + $width / 4, -$height / 4, -$width, $height); $con->stroke(); $con->rectangle(-$width / 4, $height + $height / 4, $width, -$height); $con->stroke(); $con->rectangle($width + $width / 4, $height + $height / 4, -$width, -$height); $con->stroke(); $con->setDash($dash, 0); /* And now dashed. */ $con->setSourceRgb(1.0, 0.0, 0); $con->rectangle(-$width / 4, -$height / 4, $width, $height); $con->stroke(); $con->setSourceRgb(0.0, 1.0, 0); $con->rectangle($width + $width / 4, -$height / 4, -$width, $height); $con->stroke();
<?php $width = 50; $height = 50; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $con = new CairoContext($sur); $con->setSourceRgb(0.5, 0.5, 0.5); $con->paint(); $con->save(); $pattern = new CairoLinearGradient(0, 0, 10.0, 0); $pattern->addColorStopRgb(0.0, 0.0, 0.0, 1.0); $pattern->addColorStopRgb(1.0, 1.0, 0.0, 0.0); $pattern->setExtend(CairoExtend::REFLECT); $con->setSource($pattern); $con->rectangle(0.0, 0.0, $width, $height); $con->fill(); $con->restore(); $sur->writeToPng(dirname(__FILE__) . "/linear-gradient-reflect-php.png"); ?>
<?php $width = 10; $height = 8; $sur = new CairoImageSurface(CairoFormat::ARGB32, 70, 70); $con = new CairoContext($sur); $line[0] = array('len' => 100.0, 'r' => 1, 'g' => 0, 'b' => 0); $line[1] = array('len' => 10000.0, 'r' => 0, 'g' => 1, 'b' => 0); $line[2] = array('len' => 10000.0, 'r' => 0, 'g' => 0, 'b' => 1); $line[3] = array('len' => 10000.0, 'r' => 1, 'g' => 1, 'b' => 0); $line[4] = array('len' => 10000.0, 'r' => 0, 'g' => 1, 'b' => 1); $line[5] = array('len' => 10000.0, 'r' => 1, 'g' => 0, 'b' => 1); $con->save(); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->restore(); $con->save(); $con->setLineWidth(1); $pos = 10.5; for ($i = 0; $i < 6; $i++) { $con->moveTo($pos, -$line[$i]['len']); $con->lineTo($pos, $line[$i]['len']); $con->setSourceRgb($line[$i]['r'], $line[$i]['g'], $line[$i]['b']); $con->stroke(); $pos += 10; } $con->restore(); $con->moveTo(35, -10000); $con->lineTo(35, 10000); $con->setLineWidth(1); $con->stroke();
$sur = new CairoImageSurface(CairoFormat::ARGB32, 5, 5); $con = new CairoContext($sur); $color = ''; $color .= chr(0x4c); $color .= chr(0x33); $color .= chr(0x19); $color .= chr(0x80); $s = new CairoImageSurface(CairoFormat::ARGB32, 1, 1); $s->createForData($color, CairoFormat::ARGB32, 1, 1, 4); $pat = new CairoSurfacePattern($s); $pat->setExtend(CairoExtend::REPEAT); for ($i = 0; $i < 5; $i++) { switch ($i) { case 0: $con->setSourceRgb(0.6, 0.7, 0.8); break; case 1: $con->setSourceRgba(0.2, 0.4, 0.6, 0.5); break; case 2: $con->setSourceRgba(0.2, 0.4, 0.6, 0.5); break; case 3: default: $con->setSource($pat); } $con->rectangle($i, 0, 1, 5); $con->fill(); } $sur->writeToPng(dirname(__FILE__) . '/set-source.png');
<?php $points = 10; $step = 1.0 / $points; $pad = 1; $width = $pad + $points * 2 + $pad; $height = $width; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $s = new CairoImageSurface(CairoFormat::ARGB32, 1, 1); $con = new CairoContext($sur); $c = new CairoContext($s); $c->setSourceRgb(0, 0, 0); $c->paint(); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->setSourceRgb(0, 0, 0); $con->translate($pad, $pad); $con->setAntialias(CairoAntialias::MODE_NONE); for ($i = 0; $i < $points; $i++) { for ($j = 0; $j < $points; $j++) { $t1 = 2 * $i + ($i + 1) * $step; $t2 = 2 * $j + ($j + 1) * $step; $con->setSourceSurface($s, $t1, $t2); $pat = $con->getSource(); $pat->setFilter(CairoFilter::NEAREST); $con->paint(); } } $sur->writeToPng(dirname(__FILE__) . '/a1-image-sample-php.png'); ?>
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 10, 10); $con = new CairoContext($sur); $con->pushGroup(); $con->setSourceRgb(0, 0, 1); $con->paint(); $con->popGroupToSource(); $con->setOperator(CairoOperator::SOURCE); $con->paint(); $sur->writeToPng(dirname(__FILE__) . "/group-paint-php.png"); ?>