1
1
import { IFontStyles , IRawStyle } from '../interfaces/index' ;
2
2
import { fontFace } from '../glamorExports' ;
3
3
import {
4
- getLanguage
4
+ getLanguage ,
5
+ getWindow
5
6
} from '@uifabric/utilities/lib/index' ;
7
+ import { IFabricConfig } from '../interfaces/IFabricConfig' ;
6
8
7
9
// Default urls.
8
- const DefaultFontUrl = 'https://static2.sharepointonline.com/files/fabric/assets/fonts' ;
9
- const DefaultIconUrl = 'https://static2.sharepointonline.com/files/fabric/assets/icons' ;
10
+ const DefaultBaseUrl = 'https://static2.sharepointonline.com/files/fabric/assets' ;
10
11
11
12
// Fallback fonts, if specified system or web fonts are unavailable.
12
13
const FontFamilyFallbacks = `-apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif` ;
@@ -128,9 +129,9 @@ function _getFontFamily(): string {
128
129
function _createFont ( size : string , weight : number ) : IRawStyle {
129
130
return {
130
131
fontFamily : _getFontFamily ( ) ,
131
- '-moz-osx-font-smoothing' : 'grayscale' ,
132
- '-ms-high-contrast-adjust' : 'none' ,
133
- '-webkit-font-smoothing' : 'antialiased' ,
132
+ MozOsxFontSmoothing : 'grayscale' ,
133
+ MsHighContrastAdjust : 'none' ,
134
+ WebkitFontSmoothing : 'antialiased' ,
134
135
fontSize : size ,
135
136
fontWeight : weight
136
137
} ;
@@ -154,11 +155,12 @@ function _registerFontFace(
154
155
}
155
156
156
157
function _registerFontFaceSet (
158
+ baseUrl : string ,
157
159
fontFamily : string ,
158
160
cdnFolder : string ,
159
161
cdnFontName : string = 'segoeui'
160
162
) : void {
161
- const urlBase = `${ DefaultFontUrl } /${ cdnFolder } /${ cdnFontName } ` ;
163
+ const urlBase = `${ baseUrl } /${ cdnFolder } /${ cdnFontName } ` ;
162
164
163
165
_registerFontFace ( fontFamily , urlBase + '-light' , FontWeights . light ) ;
164
166
_registerFontFace ( fontFamily , urlBase + '-semilight' , FontWeights . semilight ) ;
@@ -167,26 +169,49 @@ function _registerFontFaceSet(
167
169
}
168
170
169
171
function _registerDefaultFontFaces ( ) : void {
170
- // Produce @font -face definitions for all supported web fonts.
171
- _registerFontFaceSet ( FontNameThai , 'leelawadeeui-thai' , 'leelawadeeui' ) ;
172
- _registerFontFaceSet ( FontNameArabic , 'segoeui-arabic' ) ;
173
- _registerFontFaceSet ( FontNameCyrillic , 'segoeui-cyrillic' ) ;
174
- _registerFontFaceSet ( FontNameEastEuropean , 'segoeui-easteuropean' ) ;
175
- _registerFontFaceSet ( FontNameGreek , 'segoeui-greek' ) ;
176
- _registerFontFaceSet ( FontNameHebrew , 'segoeui-hebrew' ) ;
177
- _registerFontFaceSet ( FontNameVietnamese , 'segoeui-vietnamese' ) ;
178
- _registerFontFaceSet ( FontNameWestEuropean , 'segoeui-westeuropean' ) ;
179
- _registerFontFaceSet ( FontFamilySelawik , 'selawik' , 'selawik' ) ;
180
-
181
- // Leelawadee UI (Thai) does not have a 'light' weight, so we override
182
- // the font-face generated above to use the 'semilight' weight instead.
183
- _registerFontFace ( 'Leelawadee UI Web' , `${ DefaultFontUrl } /leelawadeeui-thai/leelawadeeui-semilight` , FontWeights . light ) ;
184
-
185
- // Leelawadee UI (Thai) does not have a 'semibold' weight, so we override
186
- // the font-face generated above to use the 'bold' weight instead.
187
- _registerFontFace ( 'Leelawadee UI Web' , `${ DefaultFontUrl } /leelawadeeui-thai/leelawadeeui-bold` , FontWeights . semibold ) ;
188
-
189
- _registerFontFace ( 'FabricMDL2Icons' , DefaultIconUrl + '/fabricmdl2icons' , FontWeights . regular ) ;
172
+ const baseUrl = _getFontBaseUrl ( ) ;
173
+
174
+ if ( baseUrl ) {
175
+ const fontUrl = `${ baseUrl } /fonts` ;
176
+ const iconUrl = `${ baseUrl } /icons` ;
177
+
178
+ // Produce @font -face definitions for all supported web fonts.
179
+ _registerFontFaceSet ( fontUrl , FontNameThai , 'leelawadeeui-thai' , 'leelawadeeui' ) ;
180
+ _registerFontFaceSet ( fontUrl , FontNameArabic , 'segoeui-arabic' ) ;
181
+ _registerFontFaceSet ( fontUrl , FontNameCyrillic , 'segoeui-cyrillic' ) ;
182
+ _registerFontFaceSet ( fontUrl , FontNameEastEuropean , 'segoeui-easteuropean' ) ;
183
+ _registerFontFaceSet ( fontUrl , FontNameGreek , 'segoeui-greek' ) ;
184
+ _registerFontFaceSet ( fontUrl , FontNameHebrew , 'segoeui-hebrew' ) ;
185
+ _registerFontFaceSet ( fontUrl , FontNameVietnamese , 'segoeui-vietnamese' ) ;
186
+ _registerFontFaceSet ( fontUrl , FontNameWestEuropean , 'segoeui-westeuropean' ) ;
187
+ _registerFontFaceSet ( fontUrl , FontFamilySelawik , 'selawik' , 'selawik' ) ;
188
+
189
+ // Leelawadee UI (Thai) does not have a 'light' weight, so we override
190
+ // the font-face generated above to use the 'semilight' weight instead.
191
+ _registerFontFace ( 'Leelawadee UI Web' , `${ fontUrl } /leelawadeeui-thai/leelawadeeui-semilight` , FontWeights . light ) ;
192
+
193
+ // Leelawadee UI (Thai) does not have a 'semibold' weight, so we override
194
+ // the font-face generated above to use the 'bold' weight instead.
195
+ _registerFontFace ( 'Leelawadee UI Web' , `${ fontUrl } /leelawadeeui-thai/leelawadeeui-bold` , FontWeights . semibold ) ;
196
+
197
+ // Register icon urls.
198
+ _registerFontFace ( 'FabricMDL2Icons' , `${ iconUrl } /fabricmdl2icons` , FontWeights . regular ) ;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Reads the fontBaseUrl from window.FabricConfig.fontBaseUrl or falls back to a default.
204
+ */
205
+ function _getFontBaseUrl ( ) : string {
206
+ let win = getWindow ( ) ;
207
+
208
+ // tslint:disable-next-line:no-string-literal
209
+ let fabricConfig : IFabricConfig = win ? win [ 'FabricConfig' ] : undefined ;
210
+
211
+ return ( fabricConfig && fabricConfig . fontBaseUrl !== undefined ) ? fabricConfig . fontBaseUrl : DefaultBaseUrl ;
190
212
}
191
213
192
- _registerDefaultFontFaces ( ) ;
214
+ /**
215
+ * Register the font faces.
216
+ */
217
+ _registerDefaultFontFaces ( ) ;
0 commit comments