|
31 | 31 | class Document extends AbstractTag |
32 | 32 | { |
33 | 33 | protected $filename; |
| 34 | + protected $_defs_depth = 0; |
34 | 35 | public $inDefs = false; |
35 | 36 |
|
36 | 37 | protected $x; |
@@ -81,6 +82,31 @@ public function __construct() { |
81 | 82 |
|
82 | 83 | } |
83 | 84 |
|
| 85 | + /** |
| 86 | + * Increase the nesting level for defs-like elements |
| 87 | + * |
| 88 | + * @return int |
| 89 | + */ |
| 90 | + public function enterDefs () { |
| 91 | + $this->_defs_depth++; |
| 92 | + $this->inDefs = true; |
| 93 | + return $this->_defs_depth; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Decrease the nesting level for defs-like elements |
| 98 | + * |
| 99 | + * @return int |
| 100 | + */ |
| 101 | + public function exitDefs () { |
| 102 | + $this->_defs_depth--; |
| 103 | + if ($this->_defs_depth < 0) { |
| 104 | + $this->_defs_depth = 0; |
| 105 | + } |
| 106 | + $this->inDefs = ($this->_defs_depth > 0 ? true : false); |
| 107 | + return $this->_defs_depth; |
| 108 | + } |
| 109 | + |
84 | 110 | /** |
85 | 111 | * @return SurfaceInterface |
86 | 112 | */ |
@@ -215,6 +241,7 @@ protected function before($attributes) |
215 | 241 |
|
216 | 242 | public function render(SurfaceInterface $surface) |
217 | 243 | { |
| 244 | + $this->_defs_depth = 0; |
218 | 245 | $this->inDefs = false; |
219 | 246 | $this->surface = $surface; |
220 | 247 |
|
@@ -258,7 +285,7 @@ private function _tagStart($parser, $name, $attributes) |
258 | 285 |
|
259 | 286 | switch (strtolower($name)) { |
260 | 287 | case 'defs': |
261 | | - $this->inDefs = true; |
| 288 | + $this->enterDefs(); |
262 | 289 | return; |
263 | 290 |
|
264 | 291 | case 'svg': |
@@ -328,7 +355,7 @@ private function _tagStart($parser, $name, $attributes) |
328 | 355 | break; |
329 | 356 |
|
330 | 357 | case 'symbol': |
331 | | - $this->inDefs = true; |
| 358 | + $this->enterDefs(); |
332 | 359 | $tag = new Symbol($this, $name); |
333 | 360 | break; |
334 | 361 |
|
@@ -381,11 +408,11 @@ function _tagEnd($parser, $name) |
381 | 408 | $tag = null; |
382 | 409 | switch (strtolower($name)) { |
383 | 410 | case 'defs': |
384 | | - $this->inDefs = false; |
| 411 | + $this->exitDefs(); |
385 | 412 | return; |
386 | 413 |
|
387 | 414 | case 'symbol': |
388 | | - $this->inDefs = false; |
| 415 | + $this->exitDefs(); |
389 | 416 | $tag = array_pop($this->stack); |
390 | 417 | break; |
391 | 418 |
|
|
0 commit comments