@@ -29,11 +29,12 @@ public function get_svg($id, $opts=[]) {
29
29
$ doc ->load ($ icon ['filepath ' ]);
30
30
31
31
$ default_opts = [
32
- 'title ' => false ,
33
- 'class ' => false ,
32
+ 'title ' => false ,
33
+ 'class ' => false ,
34
34
'default_class ' => true ,
35
- 'role ' => 'img ' ,
36
- 'fill ' => 'currentColor ' ,
35
+ 'inline_style ' => true ,
36
+ 'role ' => 'img ' ,
37
+ 'fill ' => 'currentColor ' ,
37
38
];
38
39
39
40
$ opts = array_merge ($ default_opts , $ opts );
@@ -90,9 +91,69 @@ public function get_svg($id, $opts=[]) {
90
91
91
92
92
93
94
+
93
95
foreach ($ doc ->getElementsByTagName ('path ' ) as $ item ) {
94
- $ item ->setAttribute ('fill ' , $ opts ['fill ' ]);
96
+ $ fill = $ opts ['fill ' ];
97
+ $ opacity = false ;
98
+
99
+ // duotone
100
+ switch ($ item ->getAttribute ('class ' )) {
101
+ case 'fa-primary ' :
102
+ if (isset ($ opts ['primary ' ]['fill ' ])) $ fill = $ opts ['primary ' ]['fill ' ];
103
+ if (isset ($ opts ['primary ' ]['opacity ' ])) $ opacity = $ opts ['primary ' ]['opacity ' ];
104
+ break ;
105
+
106
+
107
+ case 'fa-secondary ' :
108
+ if (isset ($ opts ['secondary ' ]['fill ' ])) $ fill = $ opts ['secondary ' ]['fill ' ];
109
+ if (isset ($ opts ['secondary ' ]['opacity ' ])) $ opacity = $ opts ['secondary ' ]['opacity ' ];
110
+ break ;
111
+ }
112
+
113
+
114
+ $ item ->setAttribute ('fill ' , $ fill );
115
+ if ($ opacity ) $ item ->setAttribute ('opacity ' , $ opacity );
95
116
}
117
+
118
+
119
+
120
+
121
+
122
+ // duotone styles
123
+ if ($ opts ['inline_style ' ]) {
124
+ $ styles = [];
125
+
126
+ if (isset ($ opts ['primary ' ]['fill ' ])) {
127
+ $ styles [] = '--fa-primary-color: ' . $ opts ['primary ' ]['fill ' ];
128
+ }
129
+
130
+ if (isset ($ opts ['primary ' ]['opacity ' ])) {
131
+ $ styles [] = '--fa-primary-opacity: ' . $ opts ['primary ' ]['opacity ' ];
132
+ }
133
+
134
+
135
+ if (isset ($ opts ['secondary ' ]['fill ' ])) {
136
+ $ styles [] = '--fa-secondary-color: ' . $ opts ['secondary ' ]['fill ' ];
137
+ }
138
+
139
+ if (isset ($ opts ['secondary ' ]['opacity ' ])) {
140
+ $ styles [] = '--fa-secondary-opacity: ' . $ opts ['secondary ' ]['opacity ' ];
141
+ }
142
+
143
+
144
+ if (empty ($ styles ) || !isset ($ opts ['primary ' ]['fill ' ], $ opts ['secondary ' ]['fill ' ]) ) {
145
+ $ styles [] = 'color: ' . $ opts ['fill ' ];
146
+ }
147
+
148
+
149
+
150
+ if ($ styles ) {
151
+ foreach ($ doc ->getElementsByTagName ('svg ' ) as $ svg ) {
152
+ $ svg ->setAttribute ('style ' , implode ('; ' , $ styles ));
153
+ }
154
+ }
155
+ }
156
+
96
157
97
158
return $ doc ->saveHTML ();
98
159
}
@@ -135,10 +196,6 @@ public function get_icon_details($id) {
135
196
*/
136
197
public function get_icon_dir ($ style ) {
137
198
switch ($ style ) {
138
- case 'fas ' :
139
- $ dir = 'solid ' ;
140
- break ;
141
-
142
199
case 'far ' :
143
200
$ dir = 'regular ' ;
144
201
break ;
@@ -151,6 +208,11 @@ public function get_icon_dir($style) {
151
208
$ dir = 'brands ' ;
152
209
break ;
153
210
211
+ case 'fad ' :
212
+ $ dir = 'duotone ' ;
213
+ break ;
214
+
215
+ case 'fas ' :
154
216
default :
155
217
$ dir = 'solid ' ;
156
218
}
0 commit comments