@@ -13,6 +13,23 @@ function getRelativeIconPath (value) {
1313 return relativePathResult ? ( relativePathResult [ 2 ] || relativePathResult [ 3 ] || relativePathResult [ 4 ] ) : undefined ;
1414}
1515
16+ function parseFontIconValue ( value ) {
17+ var valueParts = value . trim ( ) . split ( ' ' ) ;
18+ var result = { } ;
19+ // Just a url
20+ // font-icon: url('./demo.svg');
21+ if ( valueParts . length === 1 ) {
22+ result . url = getRelativeIconPath ( valueParts [ 0 ] ) ;
23+ }
24+ // Font size and url
25+ // font-icon: 20px url('./demo.svg');
26+ if ( valueParts . length === 2 ) {
27+ result . size = valueParts [ 0 ] ;
28+ result . url = getRelativeIconPath ( valueParts [ 1 ] ) ;
29+ }
30+ return result ;
31+ }
32+
1633/**
1734 * Returns a promise with the result of all resolved svg paths of the given file
1835 *
@@ -24,9 +41,9 @@ function getSvgPaths (postCssRoot, compiler, context) {
2441 var relativePaths = [ ] ;
2542 postCssRoot . walkDecls ( ( decl ) => {
2643 if ( decl . prop === 'font-icon' ) {
27- var relativePath = getRelativeIconPath ( decl . value ) ;
28- if ( relativePath ) {
29- relativePaths . push ( relativePath ) ;
44+ var fontIcon = parseFontIconValue ( decl . value ) ;
45+ if ( fontIcon . url ) {
46+ relativePaths . push ( fontIcon . url ) ;
3047 }
3148 }
3249 } ) ;
@@ -44,11 +61,8 @@ function getSvgPaths (postCssRoot, compiler, context) {
4461function replaceIconFontDeclarations ( fontName , postCssRoot , unresolvedSvgPaths ) {
4562 postCssRoot . walkDecls ( ( decl ) => {
4663 if ( decl . prop === 'font-icon' ) {
64+ var fontIcon = parseFontIconValue ( decl . value ) ;
4765 // Add the font name
48- decl . cloneBefore ( {
49- prop : 'font-family' ,
50- value : fontName
51- } ) ;
5266 decl . cloneBefore ( {
5367 prop : 'text-rendering' ,
5468 value : 'auto'
@@ -61,10 +75,24 @@ function replaceIconFontDeclarations (fontName, postCssRoot, unresolvedSvgPaths)
6175 prop : '-moz-osx-font-smoothing' ,
6276 value : 'auto'
6377 } ) ;
64- decl . cloneBefore ( {
65- prop : 'font-weight' ,
66- value : 'normal'
67- } ) ;
78+ // If a font size is set we can use the font shorthand
79+ if ( fontIcon . size ) {
80+ decl . cloneBefore ( {
81+ prop : 'font' ,
82+ value : `normal normal normal ${ fontIcon . size } /1 ${ fontName } `
83+ } ) ;
84+ }
85+ // If no font size is set we use the font attributes
86+ if ( ! fontIcon . size ) {
87+ decl . cloneBefore ( {
88+ prop : 'font-family' ,
89+ value : fontName
90+ } ) ;
91+ decl . cloneBefore ( {
92+ prop : 'font-weight' ,
93+ value : 'normal'
94+ } ) ;
95+ }
6896 // Look up the index of the svg in the array to generate the unicode char position
6997 var iconCharCode = unresolvedSvgPaths . indexOf ( getRelativeIconPath ( decl . value ) ) ;
7098 decl . value = '\'\\e' + _ . padStart ( iconCharCode . toString ( 16 ) , 3 , '0' ) + '\'' ;
0 commit comments