예제 #1
0
 /**
  * Get SVG style definition
  *
  * Returns a string with SVG style definitions created from color, 
  * fillstatus and line thickness.
  * 
  * @param ezcGraphColor $color Color
  * @param mixed $filled Filled
  * @param float $thickness Line thickness.
  * @return string Formatstring
  */
 protected function getStyle(ezcGraphColor $color, $filled = true, $thickness = 1.0)
 {
     switch (true) {
         case $color instanceof ezcGraphLinearGradient:
             $pattern = new CairoLinearGradient($color->startPoint->x, $color->startPoint->y, $color->endPoint->x, $color->endPoint->y);
             $pattern->addColorStopRgba(0, $color->startColor->red / 255, $color->startColor->green / 255, $color->startColor->blue / 255, 1 - $color->startColor->alpha / 255);
             $pattern->addColorStopRgba(1, $color->endColor->red / 255, $color->endColor->green / 255, $color->endColor->blue / 255, 1 - $color->endColor->alpha / 255);
             $this->context->setSource($pattern);
             $this->context->fill();
             break;
         case $color instanceof ezcGraphRadialGradient:
             $pattern = new CairoRadialGradient(0, 0, 0, 0, 0, 1);
             $pattern->addColorStopRgba(0, $color->startColor->red / 255, $color->startColor->green / 255, $color->startColor->blue / 255, 1 - $color->startColor->alpha / 255);
             $pattern->addColorStopRgba(1, $color->endColor->red / 255, $color->endColor->green / 255, $color->endColor->blue / 255, 1 - $color->endColor->alpha / 255);
             // Scale pattern, and move it to the correct position
             $matrix = CairoMatrix::multiply($move = CairoMatrix::initTranslate(-$color->center->x, -$color->center->y), $scale = CairoMatrix::initScale(1 / $color->width, 1 / $color->height));
             $pattern->setMatrix($matrix);
             $this->context->setSource($pattern);
             $this->context->fill();
             break;
         default:
             $this->context->setSourceRgba($color->red / 255, $color->green / 255, $color->blue / 255, 1 - $color->alpha / 255);
             break;
     }
     // Set line width
     $this->context->setLineWidth($thickness);
     // Set requested fill state for context
     if ($filled) {
         $this->context->fillPreserve();
     }
 }
예제 #2
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');
예제 #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
$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();
$cr2->moveTo(5 * $patwidth / 6.0, 0);
$cr2->lineTo($patwidth, 0);
$cr2->lineTo($patwidth, $patheight / 6.0);
$cr2->setSourceRgb(0, 0, 1);
$cr2->stroke();
예제 #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
<?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 */
예제 #7
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');
예제 #8
0
<?php

$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);
예제 #9
0
<?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();
예제 #10
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");
예제 #11
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");
?>

예제 #12
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');
예제 #13
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");
예제 #14
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');