composer package updates
[openemr.git] / vendor / phenx / php-svg-lib / src / Svg / Tag / UseTag.php
blobb88a6cce19e8bbf5ea21b7cca3a47d65cce2f423
1 <?php
2 /**
3 * @package php-svg-lib
4 * @link http://github.com/PhenX/php-svg-lib
5 * @author Fabien M�nager <fabien.menager@gmail.com>
6 * @license GNU LGPLv3+ http://www.gnu.org/copyleft/lesser.html
7 */
9 namespace Svg\Tag;
11 class UseTag extends AbstractTag
13 protected $x = 0;
14 protected $y = 0;
15 protected $width;
16 protected $height;
18 /** @var AbstractTag */
19 protected $reference;
21 protected function before($attributes)
23 if (isset($attributes['x'])) {
24 $this->x = $attributes['x'];
26 if (isset($attributes['y'])) {
27 $this->y = $attributes['y'];
30 if (isset($attributes['width'])) {
31 $this->width = $attributes['width'];
33 if (isset($attributes['height'])) {
34 $this->height = $attributes['height'];
37 parent::before($attributes);
39 $document = $this->getDocument();
41 $link = $attributes["xlink:href"];
42 $this->reference = $document->getDef($link);
44 if ($this->reference) {
45 $this->reference->before($attributes);
48 $surface = $document->getSurface();
49 $surface->save();
51 $surface->translate($this->x, $this->y);
54 protected function after() {
55 parent::after();
57 if ($this->reference) {
58 $this->reference->after();
61 $this->getDocument()->getSurface()->restore();
64 public function handle($attributes)
66 parent::handle($attributes);
68 if (!$this->reference) {
69 return;
72 $attributes = array_merge($this->reference->attributes, $attributes);
74 $this->reference->handle($attributes);
76 foreach ($this->reference->children as $_child) {
77 $_attributes = array_merge($_child->attributes, $attributes);
78 $_child->handle($_attributes);
82 public function handleEnd()
84 parent::handleEnd();
86 if (!$this->reference) {
87 return;
90 $this->reference->handleEnd();
92 foreach ($this->reference->children as $_child) {
93 $_child->handleEnd();