示例#1
0
 /**
  * Draws a circular arc consisting of several minor steps on the bounding 
  * lines.
  * 
  * @param ezcGraphCoordinate $center 
  * @param mixed $width 
  * @param mixed $height 
  * @param mixed $size 
  * @param mixed $startAngle 
  * @param mixed $endAngle 
  * @param ezcGraphColor $color 
  * @param bool $filled 
  * @return string Element id
  */
 protected function simulateCircularArc(ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled)
 {
     for ($tmpAngle = min(ceil($startAngle / 180) * 180, $endAngle); $tmpAngle <= $endAngle; $tmpAngle = min(ceil($startAngle / 180 + 1) * 180, $endAngle)) {
         $this->context->newPath();
         $this->context->moveTo($center->x + cos(deg2rad($startAngle)) * $width / 2, $center->y + sin(deg2rad($startAngle)) * $height / 2);
         // @TODO: Use cairo_curve_to()
         for ($angle = $startAngle; $angle <= $tmpAngle; $angle = min($angle + $this->options->circleResolution, $tmpAngle)) {
             $this->context->lineTo($center->x + cos(deg2rad($angle)) * $width / 2, $center->y + sin(deg2rad($angle)) * $height / 2 + $size);
             if ($angle === $tmpAngle) {
                 break;
             }
         }
         for ($angle = $tmpAngle; $angle >= $startAngle; $angle = max($angle - $this->options->circleResolution, $startAngle)) {
             $this->context->lineTo($center->x + cos(deg2rad($angle)) * $width / 2, $center->y + sin(deg2rad($angle)) * $height / 2);
             if ($angle === $startAngle) {
                 break;
             }
         }
         $this->context->closePath();
         $this->getStyle($color, $filled);
         $this->context->stroke();
         $startAngle = $tmpAngle;
         if ($tmpAngle === $endAngle) {
             break;
         }
     }
 }
示例#2
0
文件: dashes.php 项目: jamesan/cairo
<?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");
示例#3
0
<?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");
示例#4
0
<?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");
?>

示例#5
0
<?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();
示例#6
0
<?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");
示例#7
0
$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();
$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);
示例#8
0
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 3 * (3 + 6 + 3), 8 * (6 + 3) + 3);
$con = new CairoContext($sur);
$cap = array(CairoLineCap::ROUND, CairoLineCap::SQUARE, CairoLineCap::BUTT);
$dash = array(2.0, 2.0);
$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 */
示例#9
0
<?php

$width = 100;
$height = 100;
$sur = new CairoPSSurface("temp.ps", $width, $height);
$con = new CairoContext($sur);
$con->setSourceRgb(0, 0, 1);
$con->moveTo(50, 50);
$con->lineTo(50000, 50000);
$con->stroke();
$con->setSourceRgb(0, 1, 0);
$con->moveTo(50, 50);
$con->lineTo(-50000, 50000);
$con->stroke();
$con->setSourceRgb(1, 0, 0);
$con->moveTo(50, 50);
$con->lineTo(50000, -50000);
$con->stroke();
$con->setSourceRgb(1, 1, 0);
$con->moveTo(50, 50);
$con->lineTo(-50000, -50000);
$con->stroke();
$sur->writeToPng(dirname(__FILE__) . "/big-line-php.png");
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 190, 120);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 0, 0);
$con->moveTo(43, 103);
$con->lineTo(91, 101);
$con->lineTo(0, 112);
$con->lineTo(60, 0);
$con->lineTo(91, 101);
$con->lineTo(43, 103);
$con->lineTo(176, 110);
$con->lineTo(116, 100);
$con->lineTo(176, 0);
$con->lineTo(176, 110);
$con->closePath();
$con->fill();
$sur->writeToPng(dirname(__FILE__) . "/fill-degenerate-sort-order-php.png");
?>

示例#11
0
$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);
                $c2 = new CairoContext($msur);
                $c2->save();
                $c2->setSourceRgba(0, 0, 0, 0);
                $c2->setOperator(CairoOperator::SOURCE);
                $c2->paint();
示例#12
0
    $poly = 0x9a795537;
    $n = 32;
    $state = 2 * $state < $state ? 2 * $state ^ $poly : 2 * $state;
    return floor($minval + $state * ($maxval - $minval) / 4294967296.0);
}
$size = 512;
$numseg = 128;
$width = $size + 3;
$height = $size + 3;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $size + 3, $size + 3);
$con = new CairoContext($sur);
$con->setSourceRgb(0, 0, 0);
$con->paint();
$state = 0x123456;
$con->translate(1, 1);
$con->setFillRule(CairoFillRule::EVEN_ODD);
$con->moveTo(0, 0);
for ($i = 0; $i < $numseg; $i++) {
    $x = uniform_random(0, $width);
    $y = uniform_random(0, $height);
    $con->lineTo($x, $y);
    //echo "x = $x";
    //echo "y = $y";
}
$con->closePath();
$con->setSourceRgb(1, 0, 0);
$con->fillPreserve();
$con->setSourceRgb(0, 1, 0);
$con->setLineWidth(0.5);
$con->stroke();
$sur->writeToPng(dirname(__FILE__) . "/random-intersection-php.png");
示例#13
0
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 8, 8);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 1, 1);
$con->paint();
$con->setSourceRgb(0, 0, 0);
$con->setLineJoin(CairoLineJoin::ROUND);
$con->scale(20.0 / 100.0, 20 / 100.0);
$con->scale(1.0 / 20, 1.0 / 20);
$con->setLineWidth(20);
$con->translate(-18300, -13200);
$con->newPath();
$con->moveTo(18928, 13843);
$con->lineTo(18500, 13843);
$con->lineTo(18500, 13400);
$con->lineTo(18928, 13400);
$con->lineTo(18928, 13843);
$con->stroke();
$sur->writeToPng(dirname(__FILE__) . "/infinite-join-php.png");
?>

示例#14
0
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 20, 20);
$con = new CairoContext($sur);
$con->save();
$con->setSourceRgb(1, 1, 1);
$con->paint();
$con->restore();
$con->setLineWidth(4);
$con->setLineCap(CairoLineCap::ROUND);
$con->moveTo(4, 4);
$con->lineTo(4, 16);
$con->moveTo(10, 4);
$con->lineTo(10, 16);
$con->moveTo(16, 4);
$con->lineTo(16, 16);
$con->stroke();
$sur->writeToPng(dirname(__FILE__) . "/caps-sub-paths-php.png");
示例#15
0
$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->writeToPng(dirname(__FILE__) . '/long-lines.png');
示例#16
0
<?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');