@@ -65,6 +65,8 @@ public struct SFSymbolRenderer {
6565 }
6666 var template = try SFSymbolTemplate . make ( )
6767
68+ template. svg. styles = image. styles. map ( makeSymbolStyleSheet)
69+
6870 let boundsRegular = try makeBounds ( svg: image, auto: Self . makeBounds ( for: pathsRegular) , for: . regular)
6971 template. regular. appendPaths ( pathsRegular, from: boundsRegular)
7072
@@ -91,6 +93,29 @@ public struct SFSymbolRenderer {
9193 let result = formatter. encodeRootElement ( element)
9294 return result
9395 }
96+
97+ func makeSymbolStyleSheet( from stylesheet: DOM . StyleSheet ) -> DOM . StyleSheet {
98+ var copy = stylesheet
99+ for selector in stylesheet. attributes. keys {
100+ switch selector {
101+ case . class( let name) :
102+ if SFSymbolRenderer . containsAcceptedName ( name) {
103+ copy. attributes [ selector] = stylesheet. attributes [ selector]
104+ }
105+ case . id, . element:
106+ ( )
107+ }
108+ }
109+ return copy
110+ }
111+
112+ static func containsAcceptedName( _ string: String ? ) -> Bool {
113+ guard let string = string else { return false }
114+ return string. contains ( " hierarchical- " ) ||
115+ string. contains ( " monochrome- " ) ||
116+ string. contains ( " multicolor- " ) ||
117+ string. contains ( " SFSymbolsPreview " )
118+ }
94119}
95120
96121extension SFSymbolRenderer {
@@ -165,19 +190,21 @@ extension SFSymbolRenderer {
165190 let ctm = ctm. concatenated ( layer. transform. toMatrix ( ) )
166191 var paths = [ SymbolPath] ( )
167192
193+ let symbolClass = containsAcceptedName ( layer. class) ? layer. class : nil
194+
168195 for c in layer. contents {
169196 switch c {
170197 case let . shape( shape, stroke, fill) :
171198 if let path = makePath ( for: shape, stoke: stroke, fill: fill) ? . applying ( matrix: ctm) {
172199 if fill. rule == . evenodd {
173- paths. append ( SymbolPath ( class: layer . class , path: path. makeNonZero ( ) ) )
200+ paths. append ( SymbolPath ( class: symbolClass , path: path. makeNonZero ( ) ) )
174201 } else {
175- paths. append ( SymbolPath ( class: layer . class , path: path) )
202+ paths. append ( SymbolPath ( class: symbolClass , path: path) )
176203 }
177204 }
178205 case let . text( text, point, attributes) :
179206 if let path = makePath ( for: text, at: point, with: attributes) {
180- paths. append ( SymbolPath ( class: layer . class , path: path. applying ( matrix: ctm) ) )
207+ paths. append ( SymbolPath ( class: symbolClass , path: path. applying ( matrix: ctm) ) )
181208 }
182209 case . layer( let l) :
183210 paths. append ( contentsOf: getSymbolPaths ( for: l, ctm: ctm) )
0 commit comments