예제 #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
<?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 */
예제 #3
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 / 5, $size / 5);
$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();
$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();
$sur->writeToPng(dirname(__FILE__) . "/over-between-source-php.png");
?>

예제 #4
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");
예제 #5
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");
예제 #6
0
$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();
$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);
예제 #7
0
<?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');
예제 #8
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");
?>

예제 #9
0
<?php

$width = 800;
$height = 800;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 1, 1);
$con->paint();
$con->selectFontFace("Bitstream Vera Sans");
$con->setFontSize(10000);
$con->setSourceRgb(0, 0, 0);
$con->moveTo(-5000, 5000);
$con->showText("xW");
$sur->writeToPng(dirname(__FILE__) . "/large-font-php.png");
예제 #10
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');
예제 #11
0
파일: self-copy.php 프로젝트: jamesan/cairo
<?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');
예제 #12
0
$size = 25;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size);
$con = new CairoContext($sur);
/* Paint background white, then draw in black. */
$con->setSourceRgb(1.0, 1.0, 1.0);
/* white */
$con->paint();
$con->setSourceRgb(0.0, 0.0, 0.0);
/* black */
$con->setLineWidth(1.0);
$con->translate(1, 1);
/* Draw everything first with square caps. */
$con->setLineCap(CairoLineCap::SQUARE);
/* Draw horizontal and vertical segments, each in both
 * directions. */
$con->moveTo(4.5, 0.5);
$con->relLineTo(2.0, 0.0);
$con->moveTo(10.5, 4.5);
$con->relLineTo(0.0, 2.0);
$con->moveTo(6.5, 10.5);
$con->relLineTo(-2.0, 0.0);
$con->moveTo(0.5, 6.5);
$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);
예제 #13
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");
?>

예제 #14
0
<?php

$width = 247;
$height = 26;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
$con->selectFontFace("6x13.pcf");
$con->setFontSize(11.5);
$fo = new CairoFontOptions();
$fo->setHintMetrics(CairoHintMetrics::METRICS_ON);
$con->setFontOptions($fo);
$fe = $con->fontExtents();
$con->moveTo(1, $fe["ascent"] - 1);
$con->setSourceRgb(0, 0, 1);
$fo->setHintStyle(Cairo::HINT_STYLE_NONE);
$con->setFontOptions($fo);
$con->showText("the ");
$fo->setHintStyle(Cairo::HINT_STYLE_SLIGHT);
$con->setFontOptions($fo);
$con->showText("quick ");
$fo->setHintStyle(Cairo::HINT_STYLE_MEDIUM);
$con->setFontOptions($fo);
$con->showText("brown");
$fo->setHintStyle(Cairo::HINT_STYLE_FULL);
$con->setFontOptions($fo);
$con->showText(" fox");
$con->textPath(" jumps over a lazy dog");
$con->fill();
$con->translate($width, $height);
$con->rotate(M_PI);
$con->moveTo(1, $fe["height"] - $fe["descent"] - 1);
예제 #15
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');
예제 #16
0
파일: big-line.php 프로젝트: jamesan/cairo
<?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");
예제 #17
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");
예제 #18
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");
예제 #19
0
<?php

$starsize = 20;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $starsize * 2 + 2, $starsize + 2);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 0, 0);
$con->translate(1, 1);
$con->save();
$con->moveTo(10, 0);
$con->relLineTo(6, 20);
$con->relLineTo(-16, -12);
$con->relLineTo(20, 0);
$con->relLineTo(-16, 12);
$con->setFillRule(CairoFillRule::WINDING);
$con->clip();
$con->paint();
$con->restore();
$con->translate($starsize + 1, 0);
$con->save();
$con->moveTo(10, 0);
$con->relLineTo(6, 20);
$con->relLineTo(-16, -12);
$con->relLineTo(20, 0);
$con->relLineTo(-16, 12);
$con->setFillRule(CairoFillRule::EVEN_ODD);
$con->clip();
$con->paint();
$con->restore();
$sur->writeToPng(dirname(__FILE__) . "/clip-fill-rule-php.png");
?>
예제 #20
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");
?>

예제 #21
0
<?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");
예제 #22
0
<?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");
?>

예제 #23
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();
예제 #24
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);
    $con->closePath();
    $con->moveTo(2 * $linewidth, 0);
예제 #25
0
<?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');
예제 #26
0
<?php

$TEXT_SIZE = 12;
$sur = new CairoImageSurface(CairoFormat::ARGB32, 192, 16);
$con = new CairoContext($sur);
$con->save();
$con->setSourceRgb(1.0, 1.0, 1.0);
/* white */
$con->paint();
$con->restore();
$con->setSourceRgb(0, 0, 0);
/* black */
$con->selectFontFace("Bitstream Vera Serif", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL);
$con->setFontSize($TEXT_SIZE);
$con->moveTo(0, $TEXT_SIZE);
$con->showText("i-am-serif");
$con->selectFontFace("Bitstream Vera Sans", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL);
$con->showText(" i-am-sans");
$con->selectFontFace("Bitstream Vera Sans Mono", CairoFontSlant::NORMAL, CairoFontWeight::NORMAL);
$con->showText(" i-am-mono");
$sur->writeToPng(dirname(__FILE__) . "/select-font-face-php.png");
예제 #27
0
$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);
                $c2 = new CairoContext($msur);
                $c2->save();
                $c2->setSourceRgba(0, 0, 0, 0);
                $c2->setOperator(CairoOperator::SOURCE);
예제 #28
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');