<?php $dashes = array(50.0, 10.0, 10.0, 10.0); $ndash = count($dashes); $offset = -50.0; $sur = new CairoImageSurface(0, 500, 500); $con = new CairoContext($sur); $con->setDash($dashes, $offset); $con->setLineWidth(10.0); $con->moveTo(128.0, 25.6); $con->lineTo(230.4, 230.4); $con->relLineTo(-102.4, 0.0); $con->curveTo(51.2, 230.4, 51.2, 128.0, 128.0, 128.0); $con->stroke(); $sur->writeToPng(dirname(__FILE__) . "/image_dash.png");
<?php $sur = new CairoImageSurface(CairoFormat::ARGB32, 25 * 60, 4 * 60); $con = new CairoContext($sur); $dash = array(20.0, 20.0); $con->setSourceRgb(0, 0, 0); $con->paint(); for ($a = 0; $a < 4; $a++) { for ($b = 0; $b < 5; $b++) { for ($c = 0; $c < 5; $c++) { $con->moveTo(($b * 5 + $c) * 60 + 10, $a * 60 + 10); $con->relCurveTo(0, $b * 10, 0, $b * 10, $c * 10, $b * 10); $con->setSourceRgb(1, 1, 1); $con->setLineWidth(8); $con->setLineCap(CairoLineCap::ROUND); $con->setDash($dash, $a * 10); $con->strokePreserve(); $con->setSourceRgb(0, 0.5, 1); $con->setLineWidth(2); $con->setLineCap(2); $ar = array(8.0, 8.0); $con->setDash($ar, 0); $con->stroke(); } } } $sur->writeToPng(dirname(__FILE__) . '/dash-curve-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');
$dash_long = array(6.0, 6.0); $con->setSourceRgb(1, 0, 0); for ($i = 0; $i < 3; $i++) { $con->save(); $con->setLineCap($cap[$i]); /* simple degenerate paths */ $con->setLineWidth(6); $con->moveTo(6, 6); $con->lineTo(6, 6); $con->stroke(); $con->translate(0, 3 * 3); $con->moveTo(6, 6); $con->closePath(); $con->stroke(); /* degenerate paths starting with dash on */ $con->setDash($dash, 0.0); $con->translate(0, 3 * 3); $con->moveTo(6, 6); $con->lineTo(6, 6); $con->stroke(); $con->translate(0, 3 * 3); $con->moveTo(6, 6); $con->closePath(); $con->stroke(); /* degenerate paths starting with dash off */ /* these should not draw anything */ $con->setDash($dash, 2.0); $con->translate(0, 3 * 3); $con->moveTo(6, 6); $con->lineTo(6, 6); $con->stroke();
$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(); $con->setSourceRgb(0.0, 0.0, 1); $con->rectangle(-$width / 4, $height + $height / 4, $width, -$height); $con->stroke(); $con->setSourceRgb(1.0, 1.0, 0); $con->rectangle($width + $width / 4, $height + $height / 4, -$width, -$height); $con->stroke(); $sur->writeToPng(dirname(__FILE__) . "/leaky-dashed-rectangle-php.png");
$linewidth = 10.0; $size = 5 * $linewidth; $pad = 2 * $linewidth; $sur = new CairoImageSurface(CairoFormat::ARGB32, 3 * ($pad + $size) + $pad, 3 * $pad + 2 * $size); $con = new CairoContext($sur); $dash = array($linewidth, 1.5 * $linewidth); $dashoff = -2 * $linewidth; $con->save(); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->restore(); for ($i = 0; $i < 2; $i++) { $con->save(); $con->setLineWidth($linewidth); $con->setDash($dash, $dashoff); $con->translate($pad, $pad); $con->moveTo(0, 0); $con->relLineTo(0, $size); $con->relLineTo($size, 0); $con->closePath(); $con->moveTo(2 * $linewidth, 0); $con->relLineTo(3 * $linewidth, 0); $con->relLineTo(0, 3 * $linewidth); $con->setLineCap(CairoLineCap::BUTT); $con->setLineJoin(CairoLineJoin::BEVEL); $con->stroke(); $con->translate($size + $pad, 0); $con->moveTo(0, 0); $con->relLineTo(0, $size); $con->relLineTo($size, 0);
<?php $linewidth = 8.0; $size = 5 * $linewidth; $pad = 2 * $linewidth; $imwidth = 3 * ($pad + $size) + $pad; $imheight = $size * 5 + 6 * $pad; $sur = new CairoImageSurface(CairoFormat::ARGB32, $imwidth, $imheight); $con = new CairoContext($sur); $dash = array(1.5 * $linewidth); $con->save(); $con->setSourceRgb(1, 1, 1); $con->paint(); $con->restore(); $con->translate($pad, $pad); $con->setDash($dash, -2 * $linewidth); $con->setLineWidth($linewidth); $con->save(); $con->moveTo(0, 0); $con->relLineTo(0, $size); $con->relLineTo($size, 0); $con->closePath(); $con->moveTo(2 * $linewidth, 0); $con->relLineTo(3 * $linewidth, 0); $con->relLineTo(0, 3 * $linewidth); $con->setLineCap(CairoLineCap::BUTT); $con->setLineJoin(CairoLineJoin::BEVEL); $con->stroke(); $con->translate($size + $pad, 0); $con->moveTo(0, 0); $con->relLineTo(0, $size);