Source of file Text.php
Size: 1,652 Bytes - Last Modified: 2021-12-23T10:11:59+00:00
/var/www/docs.ssmods.com/process/src/ext/phenx/php-svg-lib/src/Svg/Tag/Text.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | <?php /** * @package php-svg-lib * @link http://github.com/PhenX/php-svg-lib * @author Fabien Ménager <fabien.menager@gmail.com> * @license GNU LGPLv3+ http://www.gnu.org/copyleft/lesser.html */ namespace Svg\Tag; class Text extends Shape { protected $x = 0; protected $y = 0; protected $text = ""; public function start($attributes) { $document = $this->document; $height = $this->document->getHeight(); $this->y = $height; if (isset($attributes['x'])) { $this->x = $attributes['x']; } if (isset($attributes['y'])) { $this->y = $height - $attributes['y']; } $document->getSurface()->transform(1, 0, 0, -1, 0, $height); } public function end() { $surface = $this->document->getSurface(); $x = $this->x; $y = $this->y; $style = $surface->getStyle(); $surface->setFont($style->fontFamily, $style->fontStyle, $style->fontWeight); switch ($style->textAnchor) { case "middle": $width = $surface->measureText($this->text); $x -= $width / 2; break; case "end": $width = $surface->measureText($this->text); $x -= $width; break; } $surface->fillText($this->getText(), $x, $y); } protected function after() { $this->document->getSurface()->restore(); } public function appendText($text) { $this->text .= $text; } public function getText() { return trim($this->text); } } |