/** * @param ZendPage $page * @param Graphic $graphic * @param float $x * @param float $y * @param float $width * @param float $height * @param bool $keepRatio * * @throws \Exception */ public function drawGraphic(ZendPage $page, Graphic $graphic, $x, $y, $width, $height, $keepRatio = true) { $page->saveGS(); $this->translateAndClipToViewport($page, $graphic->getViewport(), $x, $y, $width, $height, $keepRatio); foreach ($graphic->getElements() as $element) { if (!$element->isVisible()) { continue; } if ($element instanceof Text) { $this->drawText($page, $element); } elseif ($element instanceof PathText) { $this->drawPathText($page, $element); } elseif ($element instanceof AbstractShape) { $this->drawShape($page, $element); } else { throw new InvalidArgumentException('unsupported graphic element: ' . get_class($element)); } } $page->restoreGS(); }
$pos = 1; while ($pos < count($radians)) { list($nextX, $nextY) = ArcUtils::getPolarPoint($r1, $radians[$pos++]); list($c1X, $c1Y) = ArcUtils::getBezierControl($curX, $curY, -$scale); list($c2X, $c2Y) = ArcUtils::getBezierControl($nextX, $nextY, $scale); $path->curveTo($c1X, $c1Y, $c2X, $c2Y, $nextX, $nextY); $curX = $nextX; $curY = $nextY; } list($eX, $eY) = ArcUtils::getPolarPoint($r2, end($radians)); if ($r1 !== $r2) { $path->lineTo($eX, $eY); } return $path; } $graphic = new Graphic(); $graphic->setViewportCorners(-300, -300, 300, 300); $graphic->getDefaultTextFontStyle()->setName(FontStyle::FONT_HELVETICA)->setHAlign(FontStyle::HORIZONTAL_ALIGN_MIDDLE); // draw group labels $graphic->getDefaultShapeStrokeStyle()->setColor('gray'); $graphic->addPath(getGroupPath(275, 280, 1, 118)); $graphic->addPathText('Meine Gruppe', getGroupPath(280, 280, 1, 118)); $graphic->addPath(getGroupPath(275, 280, 121, 118)); $graphic->addPathText('Meine andere Gruppe', getGroupPath(280, 280, 121, 118)); $graphic->addPath(getGroupPath(275, 280, 241, 118)); $graphic->addPathText('Meine dritte Gruppe', getGroupPath(280, 280, 241, 118)); // draw inner arcs $graphic->getDefaultTextFontStyle()->setVAlign(FontStyle::VERTICAL_ALIGN_CENTRAL); $graphic->getDefaultTextFillStyle()->setColor('white'); $graphic->getDefaultShapeFillStyle()->setColor(HtmlColor::rgb(236, 88, 85)); $graphic->getDefaultShapeStrokeStyle()->setColor('white');
/** * @param Graphic $graphic * @param float $width in cm * @param float $height in cm * @param bool $keepRatio * * @return mixed */ public function toSVG(Graphic $graphic, $width = 10.0, $height = 10.0, $keepRatio = true) { $viewport = $graphic->getViewport(); return $this->addElements($this->createSVG($width, $height, $viewport, $keepRatio), $graphic->getElements(), $viewport->getYBase())->asXml(); }
<?php use VectorGraphics\Model\Graphic; use VectorGraphics\Model\Path; use VectorGraphics\Model\Style\FontStyle; $graphic = new Graphic(); $graphic->setViewportCorners(-100, -100, 100, 100); $graphic->addCircle(-40, 40, 40)->setStrokeColor('yellow'); $text = $graphic->addText('A', -40, 40); $text->setFont(80); $text->align(FontStyle::HORIZONTAL_ALIGN_RIGHT, FontStyle::VERTICAL_ALIGN_BASE); $text->setStrokeColor('red'); $text->setStrokeWidth(1); $text->setFillOpacity(0.4); $graphic->addCircle(40, 40, 40)->setStrokeColor('yellow'); $text = $graphic->addText('B', 40, 40); $text->setFont(80, FontStyle::FONT_COURIER); $text->align(FontStyle::HORIZONTAL_ALIGN_LEFT, FontStyle::VERTICAL_ALIGN_BOTTOM); $text->setFillColor('blue'); $text->setStrokeColor('red', 0.4); $text->setStrokeWidth(1); $graphic->addCircle(-40, -40, 40)->setStrokeColor('yellow'); $graphic->addText("C\nh\nj i", -40, -40); $graphic->addCircle(40, -40, 40)->setStrokeColor('yellow'); $text = $graphic->addText('DaDa', 40, -40); $text->setRotation(45); $text->setFont(60, FontStyle::FONT_HELVETICA); $text->align(FontStyle::HORIZONTAL_ALIGN_MIDDLE, FontStyle::VERTICAL_ALIGN_CENTRAL); $text->setStrokeColor('red'); $text->setStrokeWidth(1); $text->setOpacity(0.4);
h<?php use VectorGraphics\Model\Graphic; use VectorGraphics\Model\Path; $graphic = new Graphic(); $graphic->setViewportCorners(-50, -50, 50, 50); $graphic->addRectangle(-49, -49, 98, 98)->setStrokeWidth(2); $graphic->addCircle(0, 0, 45)->setFillColor('red', 0.5); $radius = 40; $path = new Path($radius * sin(0.0 / 5.0 * pi()), $radius * cos(0.0 / 5.0 * pi())); $path->lineTo($radius * sin(4.0 / 5.0 * pi()), $radius * cos(4.0 / 5.0 * pi())); $path->lineTo($radius * sin(8.0 / 5.0 * pi()), $radius * cos(8.0 / 5.0 * pi())); $path->lineTo($radius * sin(2.0 / 5.0 * pi()), $radius * cos(2.0 / 5.0 * pi())); $path->lineTo($radius * sin(6.0 / 5.0 * pi()), $radius * cos(6.0 / 5.0 * pi())); $path->close(); $graphic->addPath($path); return $graphic;