@@ -138,14 +138,19 @@ extension SFSymbolRenderer {
138138 return bounds
139139 }
140140
141- static func getPaths( for svg: DOM . SVG ) -> [ LayerTree . Path ] ? {
141+ static func getPaths( for svg: DOM . SVG ) -> [ SymbolPath ] ? {
142142 let layer = LayerTree . Builder ( svg: svg) . makeLayer ( )
143- let paths = getPaths ( for: layer)
143+ let paths = getSymbolPaths ( for: layer)
144144 return paths. isEmpty ? nil : paths
145145 }
146146
147- static func getPaths( for layer: LayerTree . Layer ,
148- ctm: LayerTree . Transform . Matrix = . identity) -> [ LayerTree . Path ] {
147+ struct SymbolPath {
148+ var `class` : String ?
149+ var path : LayerTree . Path
150+ }
151+
152+ static func getSymbolPaths( for layer: LayerTree . Layer ,
153+ ctm: LayerTree . Transform . Matrix = . identity) -> [ SymbolPath ] {
149154
150155 guard layer. opacity > 0 else { return [ ] }
151156 guard layer. clip. isEmpty else {
@@ -158,24 +163,24 @@ extension SFSymbolRenderer {
158163 }
159164
160165 let ctm = ctm. concatenated ( layer. transform. toMatrix ( ) )
161- var paths = [ LayerTree . Path ] ( )
166+ var paths = [ SymbolPath ] ( )
162167
163168 for c in layer. contents {
164169 switch c {
165170 case let . shape( shape, stroke, fill) :
166171 if let path = makePath ( for: shape, stoke: stroke, fill: fill) ? . applying ( matrix: ctm) {
167172 if fill. rule == . evenodd {
168- paths. append ( path. makeNonZero ( ) )
173+ paths. append ( SymbolPath ( class : layer . class , path: path . makeNonZero ( ) ) )
169174 } else {
170- paths. append ( path)
175+ paths. append ( SymbolPath ( class : layer . class , path: path ) )
171176 }
172177 }
173178 case let . text( text, point, attributes) :
174179 if let path = makePath ( for: text, at: point, with: attributes) {
175- paths. append ( path. applying ( matrix: ctm) )
180+ paths. append ( SymbolPath ( class : layer . class , path: path . applying ( matrix: ctm) ) )
176181 }
177182 case . layer( let l) :
178- paths. append ( contentsOf: getPaths ( for: l, ctm: ctm) )
183+ paths. append ( contentsOf: getSymbolPaths ( for: l, ctm: ctm) )
179184 default :
180185 ( )
181186 }
@@ -216,11 +221,11 @@ extension SFSymbolRenderer {
216221#endif
217222 }
218223
219- static func makeBounds( for paths: [ LayerTree . Path ] ) -> LayerTree . Rect {
224+ static func makeBounds( for paths: [ SymbolPath ] ) -> LayerTree . Rect {
220225 var min = LayerTree . Point. maximum
221226 var max = LayerTree . Point. minimum
222227 for p in paths {
223- let bounds = p. bounds
228+ let bounds = p. path . bounds
224229 min = min. minimum ( combining: . init( bounds. minX, bounds. minY) )
225230 max = max. maximum ( combining: . init( bounds. maxX, bounds. maxY) )
226231 }
@@ -471,11 +476,15 @@ private extension ContainerElement {
471476
472477private extension SFSymbolTemplate . Variant {
473478
474- mutating func appendPaths( _ paths: [ LayerTree . Path ] , from source: LayerTree . Rect ) {
479+ mutating func appendPaths( _ paths: [ SFSymbolRenderer . SymbolPath ] , from source: LayerTree . Rect ) {
475480 let matrix = SFSymbolRenderer . makeTransformation ( from: source, to: bounds)
476481 contents. paths = paths
477- . map { $0. applying ( matrix: matrix) }
478- . map ( SFSymbolRenderer . makeDOMPath)
482+ . map {
483+ let transformed = $0. path. applying ( matrix: matrix)
484+ let dom = SFSymbolRenderer . makeDOMPath ( for: transformed)
485+ dom. class = $0. class
486+ return dom
487+ }
479488
480489 let midX = bounds. midX
481490 let newWidth = ( ( source. width * matrix. a) / 2 ) + 10
0 commit comments