示例#1
0
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);
}
示例#2
0
 /**
  * Draw circle 
  * 
  * @param ezcGraphCoordinate $center Center of ellipse
  * @param mixed $width Width of ellipse
  * @param mixed $height height of ellipse
  * @param ezcGraphColor $color Color
  * @param mixed $filled Filled
  * @return void
  */
 public function drawCircle(ezcGraphCoordinate $center, $width, $height, ezcGraphColor $color, $filled = true)
 {
     $this->initiliazeSurface();
     $this->context->save();
     // Draw circular arc path
     $this->context->newPath();
     $this->context->translate($center->x, $center->y);
     $this->context->scale(1, $height / $width);
     $this->context->arc(0.0, 0.0, $width / 2, 0, 2 * M_PI);
     $this->context->restore();
     $this->getStyle($color, $filled);
     $this->context->stroke();
     // Create polygon array to return
     $polygonArray = array();
     for ($angle = 0; $angle < 2 * M_PI; $angle += deg2rad($this->options->imageMapResolution)) {
         $polygonArray[] = new ezcGraphCoordinate($center->x + cos($angle) * $width / 2, $center->y + sin($angle) * $height / 2);
     }
     return $polygonArray;
 }
示例#3
0
文件: sphere.php 项目: jamesan/cairo
<?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');
示例#4
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();
示例#5
0
<?php

$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
$c->setLineWidth(1);
$c->setSourceRgb(1, 1, 1);
for ($r = 50; $r > 0; $r -= 10) {
    $c->arc(50, 50, $r, 0, 2 * M_PI);
    $c->stroke();
    $c->fill();
}
$s->writeToPng(dirname(__FILE__) . '/CairoContext__arc.png');
示例#6
0
<?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");
?>

示例#7
0
 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();
         $c2->restore();
         $c2->setSourceRgb(1, 1, 1);
         $c2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI);
         $c2->fill();
         //unset($c2);
         $con->maskSurface($msur, $x, $y);
         //unset($msur);
         //unset($stemp);
         break;
     case 1:
         $con->setFontSize(0.9 * $height);
         $ext = $con->textExtents("FG");
         $con->moveTo($x + floor(($width - $ext["width"]) / 2 + 0.5) - $ext["x_bearing"], $y + floor(($height - $ext["height"]) / 2 + 0.5) - $ext["y_bearing"]);
         $con->showText("FG");
         break;
     case 2:
         $wi = floor($width * 9 / 10);
         $he = floor($height * 9 / 10);
示例#8
0
<?php

$size = 10;
$pad = 2;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 0, 0);
$con->paint();
$con->arc($size / 2, $size / 2, $size / 2 - $pad, 0, 2 * M_PI);
$con->clip();
$con->pushGroup();
$con->setSourceRgb(0, 0, 1);
$con->paint();
$con->popGroupToSource();
$con->paint();
$sur->writeToPng(dirname(__FILE__) . "/clip-push-group-php.png");
示例#9
0
<?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');
示例#10
0
<?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");
?>

示例#11
0
<?php

$size = 40;
$pad = 2;
$width = $pad + $size + $pad;
$height = $width;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
$con->translate($pad, $pad);
$con->moveTo($size / 2, $size / 2);
$con->relLineTo($size / 2, 0);
$con->relLineTo($size / -2, $size / 2);
$con->closePath();
$con->setOperator(CairoOperator::SOURCE);
$con->setSourceRgba(1, 0, 0, 0.5);
$con->fill();
$con->arc($size / 2, $size / 2, $size / 4, 0, 2 * M_PI);
$con->setOperator(CairoOperator::OVER);
$con->setSourceRgba(0, 1, 0, 0.5);
$con->fill();
$sur->writeToPng(dirname(__FILE__) . "/over-above-source-php.png");
?>

示例#12
0
<?php

$char = 'Cairo';
$sur = new CairoImageSurface(0, 500, 500);
$con = new CairoContext($sur);
$con->selectFontFace('Sans');
$con->setFontSize(100);
$ext = $con->textExtents($char);
$x = 25.0;
$y = 150.0;
$con->moveTo($x, $y);
$con->showText($char);
$con->setSourceRgba(1, 0.2, 0.2, 0.6);
$con->setLineWidth(6.0);
$con->arc($x, $y, 10, 0, 2 * 3.14);
$con->fill();
$con->moveTo($x, $y);
$con->relLineTo(0, -1 * $ext['height']);
$con->relLineTo($ext['width'], 0);
$con->relLineTo($ext['x_bearing'], -1 * $ext['y_bearing']);
$con->stroke();
$sur->writeToPng(dirname(__FILE__) . '/text-extents.png');