-
Notifications
You must be signed in to change notification settings - Fork 648
/
Copy pathgooglefontapi.js
57 lines (49 loc) · 1.77 KB
/
googlefontapi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
goog.provide('webfont.modules.google.GoogleFontApi');
goog.require('webfont.modules.google.FontApiUrlBuilder');
goog.require('webfont.modules.google.FontApiParser');
goog.require('webfont.FontWatchRunner');
goog.require('webfont.StyleSheetWaiter');
/**
* @constructor
* @implements {webfont.FontModule}
*/
webfont.modules.google.GoogleFontApi = function(domHelper, configuration) {
this.domHelper_ = domHelper;
this.configuration_ = configuration;
};
/**
* @const
* @type {string}
*/
webfont.modules.google.GoogleFontApi.NAME = 'google';
goog.scope(function () {
var GoogleFontApi = webfont.modules.google.GoogleFontApi,
FontWatchRunner = webfont.FontWatchRunner,
StyleSheetWaiter = webfont.StyleSheetWaiter,
FontApiUrlBuilder = webfont.modules.google.FontApiUrlBuilder,
FontApiParser = webfont.modules.google.FontApiParser;
GoogleFontApi.METRICS_COMPATIBLE_FONTS = {
"Arimo": true,
"Cousine": true,
"Tinos": true
};
GoogleFontApi.prototype.load = function(onReady) {
var waiter = new StyleSheetWaiter();
var domHelper = this.domHelper_;
var fontApiUrlBuilder = new FontApiUrlBuilder(
this.configuration_['api'],
this.configuration_['text'],
this.configuration_['display'],
this.configuration_['effect'],
this.configuration_['version']
);
var fontFamilies = this.configuration_['families'];
fontApiUrlBuilder.setFontFamilies(fontFamilies);
var fontApiParser = new FontApiParser(fontFamilies);
fontApiParser.parse();
domHelper.loadStylesheet(fontApiUrlBuilder.build(), waiter.startWaitingLoad());
waiter.waitWhileNeededThen(function() {
onReady(fontApiParser.getFonts(), fontApiParser.getFontTestStrings(), GoogleFontApi.METRICS_COMPATIBLE_FONTS);
});
};
});