예제 #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, 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");