x = $x; $this->y = $y; $this->width = $width; $this->height = $height; } /** * Call to let the rectangle keep the ratio */ public function keepRatio() { $this->keepRatio = true; } /** * Create the SVG representation from this Drawable * * @param RenderContext $ctx The context to use for rendering * * @return DOMElement The SVG Element */ public function toSvg(RenderContext $ctx) { $doc = $ctx->getDocument(); $rect = $doc->createElement('rect'); list($x, $y) = $ctx->toAbsolute($this->x, $this->y); if ($this->keepRatio) { $ctx->keepRatio(); } list($width, $height) = $ctx->toAbsolute($this->width, $this->height); if ($this->keepRatio) { $ctx->ignoreRatio(); } $rect->setAttribute('x', Format::formatSVGNumber($x)); $rect->setAttribute('y', Format::formatSVGNumber($y)); $rect->setAttribute('width', Format::formatSVGNumber($width)); $rect->setAttribute('height', Format::formatSVGNumber($height)); $id = $this->id ?? uniqid('rect-'); $rect->setAttribute('id', $id); $this->setId($id); $this->applyAttributes($rect); $this->appendAnimation($rect, $ctx); $style = new DOMDocument(); $style->loadHTML($this->getStyle()); $rect->appendChild( $rect->ownerDocument->importNode( $style->getElementsByTagName('style')->item(0), true ) ); return $rect; } }