Skip to content

Commit d85d47d

Browse files
ssddanbrownbsweeney
authored andcommitted
Changed the attribute merging logic of use tags
This aims to better align the functionality with the spec and behaviour of other SVG renderers by prioritising referenced element attributes instead of use tag attributes. It also prevents width/height/x/y attributes being applied down to avoid mis-positioning.
1 parent 0d3ca5e commit d85d47d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Svg/Tag/UseTag.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,18 @@ public function handle($attributes)
6969
return;
7070
}
7171

72-
$attributes = array_merge($this->reference->attributes, $attributes);
72+
$mergedAttributes = $this->reference->attributes;
73+
$attributesToNotMerge = ['x', 'y', 'width', 'height'];
74+
foreach ($attributes as $attrKey => $attrVal) {
75+
if (!in_array($attrKey, $attributesToNotMerge) && !isset($mergedAttributes[$attrKey])) {
76+
$mergedAttributes[$attrKey] = $attrVal;
77+
}
78+
}
7379

74-
$this->reference->handle($attributes);
80+
$this->reference->handle($mergedAttributes);
7581

7682
foreach ($this->reference->children as $_child) {
77-
$_attributes = array_merge($_child->attributes, $attributes);
83+
$_attributes = array_merge($_child->attributes, $mergedAttributes);
7884
$_child->handle($_attributes);
7985
}
8086
}

0 commit comments

Comments
 (0)