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"); }
/** * Draw an image * * The image will be inlined in the SVG document using data URL scheme. For * this the mime type and base64 encoded file content will be merged to * URL. * * @param mixed $file Image file * @param ezcGraphCoordinate $position Top left position * @param mixed $width Width of image in destination image * @param mixed $height Height of image in destination image * @return void */ public function drawImage($file, ezcGraphCoordinate $position, $width, $height) { $this->initiliazeSurface(); // Ensure given bitmap is a PNG image $data = getimagesize($file); if ($data[2] !== IMAGETYPE_PNG) { throw new Exception('Cairo only has support for PNGs.'); } // Create new surface from given bitmap $imageSurface = CairoImageSurface::createFromPng($file); // Create pattern from source image to be able to transform it $pattern = new CairoSurfacePattern($imageSurface); // Scale pattern to defined dimensions and move it to its destination position $matrix = CairoMatrix::multiply($move = CairoMatrix::initTranslate(-$position->x, -$position->y), $scale = CairoMatrix::initScale($data[0] / $width, $data[1] / $height)); $pattern->setMatrix($matrix); // Merge surfaces $this->context->setSource($pattern); $this->context->rectangle($position->x, $position->y, $width, $height); $this->context->fill(); }
$imheight = 4 * ($height + $pad) + $pad; $sur = new CairoImageSurface(CairoFormat::ARGB32, $imwidth, $imheight); $con = new CairoContext($sur); $con->selectFontFace("Bitstream Vera Sans", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL); for ($j = 0; $j < 4; $j++) { for ($i = 0; $i < 2; $i++) { $x = $i * ($width + $pad) + $pad; $y = $j * ($height + $pad) + $pad; $con->save(); $pat = new CairoLinearGradient($x + $width, $y, $x, $y + $height); $pat->addColorStopRgba(0.2, 0.0, 0.0, 1.0, 1.0); /* Solid blue */ $pat->addColorStopRgba(0.8, 0.0, 0.0, 1.0, 0.0); /* Transparent blue */ $con->setSource($pat); $con->rectangle($x, $y, $width, $height); $con->fillPreserve(); $con->clip(); $con->setOperator(CairoOperator::CLEAR); //pattern_funcs[i] ($x, $y); switch ($i) { case 0: set_solid_pattern($x, $y); break; case 1: set_gradient_pattern($x, $y); break; } //draw_funcs[j] (cr, x, y); switch ($j) { case 0:
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 10, 20); $con = new CairoContext($sur); $con->translate(1.0, 1.0); $con->setSourceRgb(1, 0, 0); /* red */ /* First draw the desired shape with a fill */ $con->rectangle(0.5, 0.5, 4.0, 4.0); $con->rectangle(3.5, 3.5, 4.0, 4.0); $con->rectangle(3.5, 1.5, -2.0, 2.0); $con->rectangle(6.5, 4.5, -2.0, 2.0); $con->fill(); /* Then try the same thing with a stroke */ $con->translate(0, 10); $con->moveTo(1.0, 1.0); $con->relLineTo(3.0, 0.0); $con->relLineTo(0.0, 6.0); $con->relLineTo(3.0, 0.0); $con->relLineTo(0.0, -3.0); $con->relLineTo(-6.0, 0.0); $con->closePath(); $con->setLineWidth(1.0); $con->stroke(); $sur->writeToPng(dirname(__FILE__) . '/self-intersecting.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"); ?>
<?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 $width = 71; $height = 28; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $con = new CairoContext($sur); $dash = array(8.0, 2.0); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->setSourceRgb(0.0, 0.0, 0); $con->setLineWidth(2); /* This is vital to reproduce the bug. */ /* First check simple rectangles */ $con->rectangle(2, 2, 67, 24); $con->setDash($dash, 9.0); $con->stroke(); $sur->writeToPng(dirname(__FILE__) . '/leaky-dash.png');
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 8, 8); $con = new CairoContext($sur); $con->save(); $con->setSourceRgb(0, 0, 1); $con->paint(); $con->rectangle(2, 2, 4, 4); $con->clip(); $con->setSourceRgb(1, 0, 0); $con->paint(); $con->restore(); $con->pushGroup(); $s = $con->getGroupTarget(); $con->setSourceRgb(0, 1, 0); $con->fill(); $off = $s->getDeviceOffset(); $te = $off["x"]; echo $te; $con->rectangle(2, 2, 4, 4); $con->fill(); $con->popGroupToSource(); $con->paint(); $sur->writeToPng(dirname(__FILE__) . "/get-group-target-php.png"); ?>
<?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 $sur = new CairoImageSurface(CairoFormat::ARGB32, 28, 14); $con = new CairoContext($sur); $con->rectangle(2, 2, 10, 10); $con->setSourceRgb(0, 0, 1); $con->fillPreserve(); $con->setSourceRgb(1, 0, 0); $con->stroke(); $con->translate(14, 0); $con->arc(7, 7, 5, 0, 2 * M_PI); $con->fillPreserve(); $con->setSourceRgb(0, 0, 1); $con->stroke(); $sur->writeToPng(dirname(__FILE__) . "/fill-and-stroke-php.png"); ?>
$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 $size = 40; $sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size); $con = new CairoContext($sur); $con->setSourceRgb(1, 1, 1); /* White */ $con->paint(); $con->moveTo($size, 0); $con->lineTo($size, $size); $con->lineTo(0, $size); $con->setSourceRgb(0, 0, 0); $con->fill(); /* Create a pattern with the target surface as the source, * offset by $size/2 */ $pattern = new CairoSurfacePattern($sur); $matrix = new CairoMatrix(); $matrix->translate(-$size / 2, -$size / 2); $pattern->setMatrix($matrix); $con->setSource($pattern); /* Copy two rectangles from the upper-left quarter of the image to * the lower right. It will work if we use $con->fill(), but the * $con->clip() $con->paint() combination fails because the clip * on the surface as a destination affects it as the source as * well. */ $con->rectangle(2 * $size / 4, 2 * $size / 4, $size / 4, $size / 4); $con->rectangle(3 * $size / 4, 3 * $size / 4, $size / 4, $size / 4); $con->clip(); $con->paint(); $sur->writeToPng(dirname(__FILE__) . '/self-copy.png');
$con->relLineTo(0.0, -2.0); /* Draw right angle turns in four directions. */ $con->moveTo(0.5, 2.5); $con->relLineTo(0.0, -2.0); $con->relLineTo(2.0, 0.0); $con->moveTo(8.5, 0.5); $con->relLineTo(2.0, 0.0); $con->relLineTo(0.0, 2.0); $con->moveTo(10.5, 8.5); $con->relLineTo(0.0, 2.0); $con->relLineTo(-2.0, 0.0); $con->moveTo(2.5, 10.5); $con->relLineTo(-2.0, 0.0); $con->relLineTo(0.0, -2.0); /* Draw a closed-path rectangle */ $con->rectangle(0.5, 12.5, 10.0, 10.0); $con->stroke(); $con->translate(12, 0); /* Now draw the same results, but with butt caps. */ $con->setLineCap(CairoLineCap::BUTT); /* Draw horizontal and vertical segments, each in both * directions. */ $con->moveTo(4.0, 0.5); $con->relLineTo(3.0, 0.0); $con->moveTo(10.5, 4.0); $con->relLineTo(0.0, 3.0); $con->moveTo(7.0, 10.5); $con->relLineTo(-3.0, 0.0); $con->moveTo(0.5, 7.0); $con->relLineTo(0.0, -3.0); /* Draw right angle turns in four directions. */
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 100, 100); $con = new CairoContext($sur); $s = new CairoImageSurface(CairoFormat::ARGB32, 20, 20); $con2 = new CairoContext($s); $con2->setSourceRgba(1, 0, 0, 1); $con2->rectangle(0, 0, 10, 10); $con2->fill(); $con2->setSourceRgba(0, 1, 0, 1); $con2->rectangle(10, 0, 10, 10); $con2->fill(); $con2->setSourceRgba(0, 0, 1, 1); $con2->rectangle(0, 10, 10, 10); $con2->fill(); $con2->setSourceRgba(1, 1, 0, 1); $con2->rectangle(10, 10, 10, 10); $con2->fill(); $pat = new CairoSurfacePattern($s); $pat->setExtend(CairoExtend::REPEAT); $con->setSourceRgba(0, 0, 0, 1); $con->rectangle(0, 0, 100, 100); $con->fill(); $con->translate(10, 10); $con->setOperator(CairoOperator::OVER); $con->setSource($pat); $con->rectangle(0, 0, 90, 90); $con->fill(); $sur->writeToPng(dirname(__FILE__) . "/composite-integer-translate-over-repeat-php.png"); ?>
<?php $sur = new CairoImageSurface(CairoFormat::RGB24, 165, 30); $con = new CairoContext($sur); $con->moveTo(0, 0); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->setSourceRgb(0, 0, 0); $con->moveTo(0, 0); $con->translate(5, 5); /* First compress the pen to a vertical line. */ $con->rectangle(0, 0, 20, 20); $con->curveTo(20 / 2, 0, 20, 20 / 2, 20, 20); $con->save(); $con->scale(1.0E-5, 1.0); $con->stroke(); $con->restore(); $con->translate(5 + 20, 0); /* Then compress the pen to a horizontal line. */ $con->rectangle(0, 0, 20, 20); $con->curveTo(20 / 2, 0, 20, 20 / 2, 20, 20); $con->save(); $con->scale(1.0, 1.0E-5); $con->stroke(); $con->restore(); $con->translate(5 + 20, 0); /* Finally a line at an angle. */ $con->rectangle(0, 0, 20, 20); $con->curveTo(20 / 2, 0, 20, 20 / 2, 20, 20); $con->save(); $con->rotate(M_PI / 4.0);
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 100, 100); $con = new CairoContext($sur); $s = new CairoImageSurface(CairoFormat::ARGB32, 1, 1); $s->createFromPng(dirname(__FILE__) . "/romedalen.png"); $con->setSourceRgb(0, 0, 0); $con->rectangle(0, 0, 100, 100); $con->fill(); $con->translate(10, 10); $con->setOperator(CairoOperator::OVER); $con->setSourceSurface($s, 0, 0); $con->rectangle(0, 0, 90, 90); $con->fill(); $sur->writeToPng(dirname(__FILE__) . "/composite-integer-translate-over-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 // test_cairo.php $s = new CairoImageSurface(CairoFormat::ARGB32, 400, 400); $c = new CairoContext($s); $c->fill(); $c->setSourceRGB(1, 0, 0); $c->setLineWidth(50); $c->arc(200, 200, 100, 0, 2 * M_PI); $c->stroke(); $c->setSourceRGB(0, 0, 0.6); $c->rectangle(0, 160, 400, 75); $c->fill(); $s->writeToPng(dirname(__FILE__) . '/test.png');
<?php $size = 20; $pad = 2; $surface_size = sqrt(($size - 2 * $pad) * ($size - 2 * $pad) / 2); $sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size); $con = new CairoContext($sur); $s = new CairoImageSurface(CairoFormat::RGB24, $surface_size, $surface_size); $con2 = new CairoContext($s); $con2->setSourceRgb(1, 1, 1); $con2->rectangle(0, 0, $surface_size / 2, $surface_size / 2); $con2->fill(); $con2->setSourceRgb(1, 0, 0); $con2->rectangle($surface_size / 2, 0, $surface_size / 2, $surface_size / 2); $con2->fill(); $con2->setSourceRgb(0, 1, 0); $con2->rectangle(0, $surface_size / 2, $surface_size / 2, $surface_size / 2); $con2->fill(); $con2->setSourceRgb(0, 0, 1); $con2->rectangle($surface_size / 2, $surface_size / 2, $surface_size / 2, $surface_size / 2); $con2->fill(); /* First paint opaque background (black) so we don't need separate * ARGB32 and RGB24 reference images. */ $con->setSourceRgb(0, 0, 0); /* black */ $con->paint(); $con->translate($size / 2, $size / 2); $con->rotate(M_PI / 4.0); $con->translate(-$surface_size / 2, -$surface_size / 2); $con->setSourceSurface($s, 0, 0); $pat = $con->getSource();
<?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');
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 10, 10); $con = new CairoContext($sur); $con->setSourceRgb(0, 0, 1); $con->paint(); $con->resetClip(); $con->clip(); $con->translate(0.5, 0.5); $con->setSourceRgb(0, 1, 0); $con->rectangle(0, 0, 10, 10); $con->fillPreserve(); $con->setSourceRgb(1, 0, 0); $con->stroke(); $con->selectFontFace("Bitstream Vera Sans", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL); $con->moveTo(0, 10); $con->showText("cairo"); $sur->writeToPng(dirname(__FILE__) . "/clip-empty-php.png");
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 10, 10); $con = new CairoContext($sur); $con->rectangle(0, 0, 10, 10); $con->setSourceRgb(0, 0, 1); $con->fill(); $con->resetClip(); $con->rectangle(2, 2, 2, 2); $con->clip(); $con->rectangle(6, 6, 2, 2); $con->clip(); $con->translate(0.5, 0.5); $con->resetClip(); $con->rectangle(2, 2, 2, 2); $con->clip(); $con->rectangle(6, 6, 6, 6); $con->clip(); $con->rectangle(0, 0, 10, 10); $con->setSourceRgb(1, 1, 0); $con->fill(); $con->selectFontFace("Bitstream Vera Sans", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL); $con->moveTo(0, 10); $con->showText("cairo"); $sur->writeToPng(dirname(__FILE__) . "/clip-all-php.png");
<?php $patwidth = 120; $patheight = 120; $size = $patwidth * 2; $pad = 2; $width = $pad + $size + $pad; $height = $width; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $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();
<?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 $Surface = new CairoImageSurface(0, 256, 256); $ctx = new CairoContext($Surface); $ctx->setAntialias(0); $ctx->setFillRule(0); $ctx->scale(256 / 1.0, 256 / 1.0); $pat = new CairoLinearGradient(0.0, 0.0, 0.0, 1.0); $pat->addColorStopRgba(1, 0, 0, 0, 1); $pat->addColorStopRgba(0, 1, 1, 1, 1); $ctx->rectangle(0, 0, 1, 1); $ctx->setSource($pat); $ctx->fill(); $pat = new CairoRadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5); $pat->addColorStopRgba(0, 1, 1, 1, 1); $pat->addColorStopRgba(1, 0, 0, 0, 1); $ctx->setSource($pat); $ctx->arc(0.5, 0.5, 0.3, 0, 2 * 3.14); $ctx->fill(); $check = $ctx->getTarget(); $check->writeToPng(dirname(__FILE__) . '/sphere.png');
$imagewidth = $noperator * ($width + $pad) + $pad; $imageheight = 4 * ($height + $pad) + $pad; $sur = new CairoImageSurface(CairoFormat::ARGB32, $imagewidth, $imageheight); $con = new CairoContext($sur); $con->selectFontFace("Bitstream Vera Sans"); $con->setFontSize(0.9 * $height); for ($i = 0; $i < 4; $i++) { for ($op = CairoOperator::CLEAR; $op < $noperator; $op++) { $x = $op * ($width + $pad) + $pad; $y = $i * ($height + $pad) + $pad; $con->save(); $pat = new CairoLinearGradient($x + $width, $y, $x, $y + $height); $pat->addColorStopRgba(0.2, 0, 0, 1, 1); $pat->addColorStopRgba(0.8, 0, 0, 1, 0); $con->setSource($pat); $con->rectangle($x, $y, $width, $height); $con->fill(); $con->setOperator($op); $con->setSourceRgb(1, 0, 0); $con->moveTo($x, $y); $con->lineTo($x + $width, $y); $con->lineTo($x, $y + $height); $con->clip(); switch ($i) { case 0: $wi = floor($width * 0.9); $he = floor($height * 0.9); $x += 0.05 * $width; $y += 0.05 * $height; //$stemp = $con->get_group_target(); $msur = $sur->createSimilar(CairoContent::ALPHA, $wi, $he);
<?php $points = 10.0; $step = 1.0 / $points; $pad = 1.0; $width = $pad + $points * 2 + $pad; $height = $width; $sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height); $con = new CairoContext($sur); $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 * 1.0 + $i * $step * 2.0; $t2 = 2 * $j * 1.0 + $j * $step * 1.0; $con->rectangle($t1, $t2, 1, 1); $con->fill(); } } $sur->writeToPng(dirname(__FILE__) . '/a1-traps-sample-php.png'); ?>
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 76, 76); $con = new CairoContext($sur); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->setAntialias(CairoAntialias::MODE_NONE); $con->setSourceRgb(0, 0, 0); $con->translate(-300, -300); $con->scale(677.0 / 26, 677.0 / 26); $con->translate(1, 1); $con->rectangle(11, 11, 1, 1); $con->rectangle(11, 12, 1, 1); $con->rectangle(12, 11, 1, 1); $con->rectangle(12, 12, 1, 1); $con->setSourceRgb(0, 0, 0); $con->fill(); $sur->writeToPng(dirname(__FILE__) . "/rectangle-rounding-error-php.png"); ?>