@@ -48,10 +48,6 @@ protected function before($attributes)
48
48
$ link = $ attributes ["href " ] ?? $ attributes ["xlink:href " ];
49
49
$ this ->reference = $ document ->getDef ($ link );
50
50
51
- if ($ this ->reference ) {
52
- $ this ->reference ->before ($ attributes );
53
- }
54
-
55
51
$ surface = $ document ->getSurface ();
56
52
$ surface ->save ();
57
53
@@ -63,11 +59,6 @@ protected function after() {
63
59
return ;
64
60
}
65
61
parent ::after ();
66
-
67
- if ($ this ->reference ) {
68
- $ this ->reference ->after ();
69
- }
70
-
71
62
$ this ->getDocument ()->getSurface ()->restore ();
72
63
}
73
64
@@ -84,19 +75,22 @@ public function handle($attributes)
84
75
return ;
85
76
}
86
77
78
+ $ originalAttributes = array_merge ($ this ->reference ->attributes );
79
+ $ originalStyle = $ this ->reference ->getStyle ();
87
80
$ mergedAttributes = $ this ->reference ->attributes ;
88
- $ attributesToNotMerge = ['x ' , 'y ' , 'width ' , 'height ' , 'href ' , 'xlink:href ' , 'id ' ];
81
+ $ attributesToNotMerge = ['x ' , 'y ' , 'width ' , 'height ' , 'href ' , 'xlink:href ' , 'id ' , ' style ' ];
89
82
foreach ($ attributes as $ attrKey => $ attrVal ) {
90
83
if (!in_array ($ attrKey , $ attributesToNotMerge ) && !isset ($ mergedAttributes [$ attrKey ])) {
91
84
$ mergedAttributes [$ attrKey ] = $ attrVal ;
92
85
}
93
86
}
87
+ $ mergedAttributes ['style ' ] = ($ attributes ['style ' ] ?? '' ) . '; ' . ($ mergedAttributes ['style ' ] ?? '' );
94
88
95
- $ this ->reference -> handle ( $ mergedAttributes );
89
+ $ this ->_handle ( $ this -> reference , $ mergedAttributes );
96
90
97
- foreach ( $ this ->reference ->children as $ _child ) {
98
- $ _attributes = array_merge ( $ _child -> attributes , $ mergedAttributes );
99
- $ _child -> handle ( $ _attributes );
91
+ $ this ->reference ->attributes = $ originalAttributes ;
92
+ if ( $ originalStyle !== null ) {
93
+ $ this -> reference -> setStyle ( $ originalStyle );
100
94
}
101
95
}
102
96
@@ -107,16 +101,32 @@ public function handleEnd()
107
101
return ;
108
102
}
109
103
104
+ if ($ this ->reference ) {
105
+ $ this ->_handleEnd ($ this ->reference );
106
+ }
107
+
110
108
parent ::handleEnd ();
109
+ }
111
110
112
- if (!$ this ->reference ) {
113
- return ;
111
+ private function _handle ($ tag , $ attributes ) {
112
+ $ tag ->handle ($ attributes );
113
+ foreach ($ tag ->children as $ child ) {
114
+ $ originalAttributes = array_merge ($ child ->attributes );
115
+ $ originalStyle = $ child ->getStyle ();
116
+ $ mergedAttributes = $ child ->attributes ;
117
+ $ mergedAttributes ['style ' ] = ($ attributes ['style ' ] ?? '' ) . '; ' . ($ mergedAttributes ['style ' ] ?? '' );
118
+ $ this ->_handle ($ child , $ mergedAttributes );
119
+ $ child ->attributes = $ originalAttributes ;
120
+ if ($ originalStyle !== null ) {
121
+ $ child ->setStyle ($ originalStyle );
122
+ }
114
123
}
124
+ }
115
125
116
- $ this ->reference ->handleEnd ();
117
-
118
- foreach ($ this ->reference ->children as $ _child ) {
119
- $ _child ->handleEnd ();
126
+ private function _handleEnd ($ tag ) {
127
+ foreach ($ tag ->children as $ child ) {
128
+ $ this ->_handleEnd ($ child );
120
129
}
130
+ $ tag ->handleEnd ();
121
131
}
122
132
}
0 commit comments