webfontloader 1.4.5 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v1.4.6 (May 29, 2013)
2
+ * Merge font watching strategies from core and the Google module
3
+ * Add support for the Samsung Galaxy S4 user agent string
4
+
1
5
  v1.4.5 (May 23, 2013)
2
6
  * Move modules into their own namespace
3
7
  * Add new methods into DomHelper and add specs for all DomHelper methods
data/lib/webfontloader.rb CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  require 'webfontloader/modules'
4
4
 
5
5
  module WebFontLoader
6
- VERSION = '1.4.5'
6
+ VERSION = '1.4.6'
7
7
 
8
8
  ProjectRoot = File.expand_path(File.dirname(__FILE__) + "/..")
9
9
 
@@ -1,5 +1,6 @@
1
1
  describe('FontWatcher', function () {
2
2
  var FontWatcher = webfont.FontWatcher,
3
+ FontWatchRunner = webfont.FontWatchRunner,
3
4
  Font = webfont.Font,
4
5
  UserAgent = webfont.UserAgent,
5
6
  BrowserInfo = webfont.BrowserInfo,
@@ -30,42 +31,34 @@ describe('FontWatcher', function () {
30
31
  eventDispatcher.dispatchFontInactive = jasmine.createSpy('dispatchFontInactive');
31
32
  eventDispatcher.dispatchActive = jasmine.createSpy('dispatchActive');
32
33
  eventDispatcher.dispatchInactive = jasmine.createSpy('dispatchInactive');
33
- });
34
34
 
35
- function FakeFontWatchRunner(activeCallback, inactiveCallback, domHelper,
36
- font, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString) {
37
- this.activeCallback = activeCallback;
38
- this.inactiveCallback = inactiveCallback;
39
- this.font = font;
40
- timeout(opt_timeout);
41
-
42
- if (opt_fontTestString) {
43
- testStrings(opt_fontTestString);
44
- }
45
- }
46
-
47
- FakeFontWatchRunner.prototype.start = function () {
48
- var found = false;
49
-
50
- for (var i = 0; i < activeFonts.length; i += 1) {
51
- if (activeFonts[i].getName() === this.font.getName()) {
52
- found = true;
53
- break;
35
+ spyOn(FontWatchRunner.prototype, 'start').andCallFake(function (font, fontTestString) {
36
+ var found = false;
37
+
38
+ testStrings(this.fontTestString_);
39
+ timeout(this.timeout_);
40
+
41
+ for (var i = 0; i < activeFonts.length; i += 1) {
42
+ if (activeFonts[i].getName() === this.font_.getName()) {
43
+ found = true;
44
+ break;
45
+ }
46
+ }
47
+
48
+ if (found) {
49
+ this.activeCallback_(this.font_);
50
+ } else {
51
+ this.inactiveCallback_(this.font_);
54
52
  }
55
- }
56
- if (found) {
57
- this.activeCallback(this.font);
58
- } else {
59
- this.inactiveCallback(this.font);
60
- }
61
- };
53
+ });
54
+ });
62
55
 
63
56
  describe('watch zero fonts', function () {
64
57
  it('should call inactive when there are no fonts to load', function () {
65
58
  activeFonts = [];
66
59
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
67
60
 
68
- fontWatcher.watchFonts([], {}, FakeFontWatchRunner, true);
61
+ fontWatcher.watchFonts([], {}, null, true);
69
62
  expect(eventDispatcher.dispatchInactive).toHaveBeenCalled();
70
63
  });
71
64
 
@@ -73,7 +66,7 @@ describe('FontWatcher', function () {
73
66
  activeFonts = [];
74
67
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
75
68
 
76
- fontWatcher.watchFonts([], {}, FakeFontWatchRunner, false);
69
+ fontWatcher.watchFonts([], {}, null, false);
77
70
  expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
78
71
  });
79
72
  });
@@ -83,7 +76,7 @@ describe('FontWatcher', function () {
83
76
  activeFonts = [font1];
84
77
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
85
78
 
86
- fontWatcher.watchFonts([font1], {}, FakeFontWatchRunner, false);
79
+ fontWatcher.watchFonts([font1], {}, null, false);
87
80
  expect(eventDispatcher.dispatchFontInactive).not.toHaveBeenCalled();
88
81
  expect(eventDispatcher.dispatchActive).not.toHaveBeenCalled();
89
82
  expect(eventDispatcher.dispatchInactive).not.toHaveBeenCalled();
@@ -95,7 +88,7 @@ describe('FontWatcher', function () {
95
88
  activeFonts = [font1];
96
89
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
97
90
 
98
- fontWatcher.watchFonts([font1], {}, FakeFontWatchRunner, true);
91
+ fontWatcher.watchFonts([font1], {}, null, true);
99
92
  expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
100
93
  expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(font1);
101
94
  expect(eventDispatcher.dispatchFontInactive).not.toHaveBeenCalled();
@@ -109,7 +102,7 @@ describe('FontWatcher', function () {
109
102
  activeFonts = [];
110
103
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
111
104
 
112
- fontWatcher.watchFonts([font1], {}, FakeFontWatchRunner, true);
105
+ fontWatcher.watchFonts([font1], {}, null, true);
113
106
  expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
114
107
  expect(eventDispatcher.dispatchFontActive).not.toHaveBeenCalled();
115
108
  expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font1);
@@ -123,7 +116,7 @@ describe('FontWatcher', function () {
123
116
  activeFonts = [font1, font2, font3];
124
117
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
125
118
 
126
- fontWatcher.watchFonts([font1, font2, font3], {}, FakeFontWatchRunner, true);
119
+ fontWatcher.watchFonts([font1, font2, font3], {}, null, true);
127
120
  expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
128
121
  expect(eventDispatcher.dispatchFontActive).toHaveBeenCalledWith(font1);
129
122
  expect(eventDispatcher.dispatchFontInactive).not.toHaveBeenCalled();
@@ -137,7 +130,7 @@ describe('FontWatcher', function () {
137
130
  activeFonts = [];
138
131
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
139
132
 
140
- fontWatcher.watchFonts([font1, font2, font3], {}, FakeFontWatchRunner, true);
133
+ fontWatcher.watchFonts([font1, font2, font3], {}, null, true);
141
134
  expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font1);
142
135
  expect(eventDispatcher.dispatchFontActive).not.toHaveBeenCalled();
143
136
  expect(eventDispatcher.dispatchFontInactive).toHaveBeenCalledWith(font1);
@@ -151,7 +144,7 @@ describe('FontWatcher', function () {
151
144
  activeFonts = [font1, font3];
152
145
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
153
146
 
154
- fontWatcher.watchFonts([font1, font2, font3], {}, FakeFontWatchRunner, true);
147
+ fontWatcher.watchFonts([font1, font2, font3], {}, null, true);
155
148
  expect(eventDispatcher.dispatchFontLoading.callCount).toEqual(3);
156
149
  expect(eventDispatcher.dispatchFontLoading.calls[0].args[0]).toEqual(font1);
157
150
  expect(eventDispatcher.dispatchFontLoading.calls[1].args[0]).toEqual(font2);
@@ -180,8 +173,7 @@ describe('FontWatcher', function () {
180
173
  activeFonts = [font5, font6];
181
174
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher);
182
175
 
183
- fontWatcher.watchFonts([font5, font6, font7, font8, font9], {}, FakeFontWatchRunner, true);
184
-
176
+ fontWatcher.watchFonts([font5, font6, font7, font8, font9], {}, null, true);
185
177
  expect(eventDispatcher.dispatchFontLoading.callCount).toEqual(5);
186
178
  expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font5);
187
179
  expect(eventDispatcher.dispatchFontLoading).toHaveBeenCalledWith(font6);
@@ -214,18 +206,20 @@ describe('FontWatcher', function () {
214
206
  'font2': null,
215
207
  'font3': 'testString2',
216
208
  'font4': null
217
- }, FakeFontWatchRunner, true);
209
+ }, null, true);
218
210
 
219
- expect(testStrings.callCount).toEqual(2);
220
- expect(testStrings).toHaveBeenCalledWith('testString1');
221
- expect(testStrings).toHaveBeenCalledWith('testString2');
211
+ expect(testStrings.callCount).toEqual(4);
212
+ expect(testStrings.calls[0].args[0]).toEqual('testString1');
213
+ expect(testStrings.calls[1].args[0]).toEqual(FontWatchRunner.DEFAULT_TEST_STRING);
214
+ expect(testStrings.calls[2].args[0]).toEqual('testString2');
215
+ expect(testStrings.calls[3].args[0]).toEqual(FontWatchRunner.DEFAULT_TEST_STRING);
222
216
  });
223
217
  });
224
218
 
225
219
  it('should pass on the timeout to FontWatchRunner', function () {
226
220
  var fontWatcher = new FontWatcher(userAgent, domHelper, eventDispatcher, 4000);
227
221
 
228
- fontWatcher.watchFonts([font1], {}, FakeFontWatchRunner, true);
222
+ fontWatcher.watchFonts([font1], {}, null, true);
229
223
 
230
224
  expect(timeout).toHaveBeenCalledWith(4000);
231
225
  });
@@ -189,8 +189,7 @@ describe('FontWatchRunner', function () {
189
189
  timesToGetTimeBeforeTimeout = 2;
190
190
 
191
191
  var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
192
- domHelper, font, fallbackBugBrowserInfo,
193
- 0, { 'My Other Family': true });
192
+ domHelper, font, fallbackBugBrowserInfo, 0, { 'My Other Family': true });
194
193
 
195
194
  fontWatchRunner.start();
196
195
 
@@ -207,13 +206,12 @@ describe('FontWatchRunner', function () {
207
206
  timesToGetTimeBeforeTimeout = 2;
208
207
 
209
208
  var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
210
- domHelper, font, fallbackBugBrowserInfo,
211
- 0, { 'My Family': true });
209
+ domHelper, new Font('Arimo'), fallbackBugBrowserInfo, 0, { 'Arimo': true });
212
210
 
213
211
  fontWatchRunner.start();
214
212
 
215
213
  jasmine.Clock.tick(1 * 25);
216
- expect(activeCallback).toHaveBeenCalledWith(font);
214
+ expect(activeCallback).toHaveBeenCalledWith(new Font('Arimo'));
217
215
  });
218
216
  });
219
217
 
@@ -243,7 +241,7 @@ describe('FontWatchRunner', function () {
243
241
  ];
244
242
 
245
243
  fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
246
- domHelper, font, browserInfo, 0, {}, 'TestString');
244
+ domHelper, font, browserInfo, 0, null, 'TestString');
247
245
 
248
246
  fontWatchRunner.start();
249
247
 
@@ -277,6 +277,22 @@ describe('UserAgentParser', function () {
277
277
  hasWebKitMetricsBug: false
278
278
  }
279
279
  });
280
+
281
+ expect(parse('Mozilla/5.0 (Linux; Android 4.2.2; SGH-M919 Build/JDQ39) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.169 Mobile Safari/537.22'))
282
+ .toMatchUserAgent({
283
+ name: 'Chrome',
284
+ version: new Version(25, 0, 1364, 169),
285
+ platform: 'Android',
286
+ platformVersion: new Version(4, 2, 2),
287
+ engine: 'AppleWebKit',
288
+ engineVersion: new Version(537, 22),
289
+ documentMode: undefined,
290
+ browserInfo: {
291
+ hasWebFontSupport: true,
292
+ hasWebKitFallbackBug: false,
293
+ hasWebKitMetricsBug: false
294
+ }
295
+ });
280
296
  });
281
297
 
282
298
  it('should detect Chrome on iPad', function () {
@@ -617,6 +633,40 @@ describe('UserAgentParser', function () {
617
633
  });
618
634
  });
619
635
 
636
+ it('should detect Samsung Galaxy S4 builtin browser', function () {
637
+ expect(parse('Mozilla/5.0 (Linux; Android 4.2.2; sl-si; SAMSUNG GT-I9505 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari/535.19'))
638
+ .toMatchUserAgent({
639
+ name: 'Chrome',
640
+ version: new Version(18, 0, 1025, 308),
641
+ platform: 'Android',
642
+ platformVersion: new Version(4, 2, 2),
643
+ engine: 'AppleWebKit',
644
+ engineVersion: new Version(535, 19),
645
+ documentMode: undefined,
646
+ browserInfo: {
647
+ hasWebFontSupport: true,
648
+ hasWebKitFallbackBug: true,
649
+ hasWebKitMetricsBug: false
650
+ }
651
+ });
652
+
653
+ expect(parse('Mozilla/5.0 (Linux; Android 4.2.2; en-us; SAMSUNG SGH-M919 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobile Safari/535.19'))
654
+ .toMatchUserAgent({
655
+ name: 'Chrome',
656
+ version: new Version(18, 0, 1025, 308),
657
+ platform: 'Android',
658
+ platformVersion: new Version(4, 2, 2),
659
+ engine: 'AppleWebKit',
660
+ engineVersion: new Version(535, 19),
661
+ documentMode: undefined,
662
+ browserInfo: {
663
+ hasWebFontSupport: true,
664
+ hasWebKitFallbackBug: true,
665
+ hasWebKitMetricsBug: false
666
+ }
667
+ });
668
+ });
669
+
620
670
  it('should detect Android builtin browser in Desktop mode (Nexus 7)', function () {
621
671
  expect(parse('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24'))
622
672
  .toMatchUserAgent({
@@ -1,6 +1,7 @@
1
1
  describe('WebFont', function () {
2
2
  var WebFont = webfont.WebFont,
3
3
  UserAgent = webfont.UserAgent,
4
+ FontWatchRunner = webfont.FontWatchRunner,
4
5
  BrowserInfo = webfont.BrowserInfo,
5
6
  Version = webfont.Version,
6
7
  Font = webfont.Font,
@@ -141,22 +142,13 @@ describe('WebFont', function () {
141
142
  this.fonts = [];
142
143
  };
143
144
 
144
- testModule.getFontWatchRunnerCtor = function () {
145
- function FakeFontWatchRunner(activeCallback, inactiveCallback) {
146
- this.inactive = inactiveCallback;
147
- this.active = activeCallback;
148
- };
149
-
150
- FakeFontWatchRunner.prototype.start = function () {
151
- if (conf.id) {
152
- this.active(font);
153
- } else {
154
- this.inactive(font);
155
- }
156
- };
157
-
158
- return FakeFontWatchRunner;
159
- };
145
+ spyOn(FontWatchRunner.prototype, 'start').andCallFake(function () {
146
+ if (conf.id) {
147
+ active(font);
148
+ } else {
149
+ inactive(font);
150
+ }
151
+ });
160
152
 
161
153
  testModule.supportUserAgent = function (userAgent, support) {
162
154
  if (conf.id) {
@@ -231,8 +223,8 @@ describe('WebFont', function () {
231
223
  });
232
224
 
233
225
  expect(font.onModuleReady_).toHaveBeenCalled();
234
- expect(font.onModuleReady_.calls[0].args[3]).toEqual([new Font('Elena')]);
235
- expect(font.onModuleReady_.calls[0].args[4]).toEqual({ 'Elena': '1234567' });
226
+ expect(font.onModuleReady_.calls[0].args[2]).toEqual([new Font('Elena')]);
227
+ expect(font.onModuleReady_.calls[0].args[3]).toEqual({ 'Elena': '1234567' });
236
228
  });
237
229
  });
238
230
 
data/spec/deps.js CHANGED
@@ -19,9 +19,8 @@ goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.D
19
19
  goog.addDependency("../../src/modules/ascender.js", ["webfont.modules.Ascender"], ["webfont.Font"]);
20
20
  goog.addDependency("../../src/modules/custom.js", ["webfont.modules.Custom"], ["webfont.Font"]);
21
21
  goog.addDependency("../../src/modules/fontdeck.js", ["webfont.modules.Fontdeck"], ["webfont.Font"]);
22
- goog.addDependency("../../src/modules/google/fontapiparser.js", ["webfont.modules.FontApiParser"], ["webfont.Font"]);
23
- goog.addDependency("../../src/modules/google/fontapiurlbuilder.js", ["webfont.modules.FontApiUrlBuilder"], []);
24
- goog.addDependency("../../src/modules/google/googlefontapi.js", ["webfont.modules.GoogleFontApi"], ["webfont.modules.FontApiUrlBuilder","webfont.modules.FontApiParser","webfont.FontWatchRunner","webfont.modules.LastResortWebKitFontWatchRunner"]);
25
- goog.addDependency("../../src/modules/google/lastresortwebkitfontwatchrunner.js", ["webfont.modules.LastResortWebKitFontWatchRunner"], ["webfont.Font","webfont.FontRuler"]);
22
+ goog.addDependency("../../src/modules/google/fontapiparser.js", ["webfont.modules.google.FontApiParser"], ["webfont.Font"]);
23
+ goog.addDependency("../../src/modules/google/fontapiurlbuilder.js", ["webfont.modules.google.FontApiUrlBuilder"], []);
24
+ goog.addDependency("../../src/modules/google/googlefontapi.js", ["webfont.modules.google.GoogleFontApi"], ["webfont.modules.google.FontApiUrlBuilder","webfont.modules.google.FontApiParser","webfont.FontWatchRunner"]);
26
25
  goog.addDependency("../../src/modules/monotype.js", ["webfont.modules.Monotype"], ["webfont.Font"]);
27
26
  goog.addDependency("../../src/modules/typekit.js", ["webfont.modules.Typekit"], ["webfont.Font"]);
data/spec/index.html CHANGED
@@ -30,7 +30,7 @@
30
30
  goog.require('webfont.modules.Fontdeck');
31
31
  goog.require('webfont.modules.Monotype');
32
32
  goog.require('webfont.modules.Custom');
33
- goog.require('webfont.modules.GoogleFontApi');
33
+ goog.require('webfont.modules.google.GoogleFontApi');
34
34
  </script>
35
35
 
36
36
  <script src="../spec/core/domhelper_spec.js"></script>
@@ -47,7 +47,6 @@
47
47
  <script src="../spec/modules/google/fontapiparser_spec.js"></script>
48
48
  <script src="../spec/modules/google/fontapiurlbuilder_spec.js"></script>
49
49
  <script src="../spec/modules/google/googlefontapi_spec.js"></script>
50
- <script src="../spec/modules/google/lastresortwebkitfontwatchrunner_spec.js"></script>
51
50
  <script src="../spec/modules/custom_spec.js"></script>
52
51
  <script src="../spec/modules/ascender_spec.js"></script>
53
52
  <script src="../spec/modules/fontdeck_spec.js"></script>
@@ -0,0 +1,22 @@
1
+ goog.provide('webfont.FontModule');
2
+
3
+ /**
4
+ * @interface
5
+ */
6
+ webfont.FontModule = function () {};
7
+
8
+ goog.scope(function () {
9
+ var FontModule = webfont.FontModule;
10
+
11
+ /**
12
+ * @param {webfont.UserAgent} userAgent
13
+ * @param {function(boolean)} support
14
+ */
15
+ FontModule.prototype.supportUserAgent = function (userAgent, support) {};
16
+
17
+ /**
18
+ * @param {function(Array.<webfont.Font>, webfont.FontTestStrings=, Object.<string, boolean>=)} onReady
19
+ */
20
+ FontModule.prototype.load = function (onReady) {};
21
+ });
22
+
@@ -1,27 +1,6 @@
1
1
  goog.provide('webfont.FontModuleLoader');
2
- goog.provide('webfont.FontModule');
3
2
  goog.provide('webfont.FontModuleFactory');
4
3
 
5
- /**
6
- * @interface
7
- */
8
- webfont.FontModule = function () {};
9
-
10
- goog.scope(function () {
11
- var FontModule = webfont.FontModule;
12
-
13
- /**
14
- * @param {webfont.UserAgent} userAgent
15
- * @param {function(boolean)} support
16
- */
17
- FontModule.prototype.supportUserAgent = function (userAgent, support) {};
18
-
19
- /**
20
- * @param {function(Array.<webfont.Font>, webfont.FontTestStrings=)} onReady
21
- */
22
- FontModule.prototype.load = function (onReady) {};
23
- });
24
-
25
4
  /** @typedef {function(Object, webfont.DomHelper): webfont.FontModule} */
26
5
  webfont.FontModuleFactory;
27
6
 
@@ -21,26 +21,19 @@ webfont.FontWatcher = function(userAgent, domHelper, eventDispatcher, opt_timeou
21
21
  };
22
22
 
23
23
  goog.scope(function () {
24
- var FontWatcher = webfont.FontWatcher;
24
+ var FontWatcher = webfont.FontWatcher,
25
+ FontWatchRunner = webfont.FontWatchRunner;
25
26
 
26
27
  /**
27
28
  * Watches a set of font families.
28
29
  * @param {Array.<webfont.Font>} fonts The fonts to watch.
29
30
  * @param {Object.<string, string>} fontTestStrings The font test strings for
30
31
  * each family.
31
- * @param {function(new:webfont.FontWatchRunner,
32
- * function(webfont.Font),
33
- * function(webfont.Font),
34
- * webfont.DomHelper,
35
- * webfont.Font,
36
- * webfont.BrowserInfo,
37
- * number=,
38
- * Object.<string, boolean>=,
39
- * string=)} fontWatchRunnerCtor The font watch runner constructor.
32
+ * @param {Object.<String, boolean>} metricCompatibleFonts
40
33
  * @param {boolean} last True if this is the last set of fonts to watch.
41
34
  */
42
35
  FontWatcher.prototype.watchFonts = function(fonts,
43
- fontTestStrings, fontWatchRunnerCtor, last) {
36
+ fontTestStrings, metricCompatibleFonts, last) {
44
37
  var length = fonts.length;
45
38
 
46
39
  if (length === 0 && last) {
@@ -48,23 +41,28 @@ goog.scope(function () {
48
41
  return;
49
42
  }
50
43
 
51
- this.currentlyWatched_ += length;
44
+ this.currentlyWatched_ += fonts.length;
52
45
 
53
46
  if (last) {
54
47
  this.last_ = last;
55
48
  }
56
49
 
57
- for (var i = 0; i < length; i++) {
58
- var font = fonts[i];
59
- var fontTestString = fontTestStrings[font.getName()];
50
+ for (var i = 0; i < fonts.length; i++) {
51
+ var font = fonts[i],
52
+ fontTestString = fontTestStrings[font.getName()];
60
53
 
61
54
  this.eventDispatcher_.dispatchFontLoading(font);
62
55
 
63
- var activeCallback = goog.bind(this.fontActive_, this);
64
- var inactiveCallback = goog.bind(this.fontInactive_, this);
65
- var fontWatchRunner = new fontWatchRunnerCtor(activeCallback,
66
- inactiveCallback, this.domHelper_, font,
67
- this.browserInfo_, this.timeout_, null, fontTestString);
56
+ var fontWatchRunner = new FontWatchRunner(
57
+ goog.bind(this.fontActive_, this),
58
+ goog.bind(this.fontInactive_, this),
59
+ this.domHelper_,
60
+ font,
61
+ this.browserInfo_,
62
+ this.timeout_,
63
+ metricCompatibleFonts,
64
+ fontTestString
65
+ );
68
66
 
69
67
  fontWatchRunner.start();
70
68
  }
@@ -313,10 +313,10 @@ goog.scope(function () {
313
313
  browserVersion = new Version();
314
314
  } else if (browserName == "Silk") {
315
315
  browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Silk\/([\d\._]+)/, 1));
316
- } else if (this.userAgent_.indexOf("Version/") != -1) {
317
- browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.\w]+)/, 1));
318
316
  } else if (browserName == "Chrome") {
319
317
  browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /(Chrome|CrMo|CriOS)\/([\d\.]+)/, 2));
318
+ } else if (this.userAgent_.indexOf("Version/") != -1) {
319
+ browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.\w]+)/, 1));
320
320
  } else if (browserName == "AdobeAIR") {
321
321
  browserVersion = Version.parse(this.getMatchingGroup_(this.userAgent_, /AdobeAIR\/([\d\.]+)/, 1));
322
322
  }
data/src/core/webfont.js CHANGED
@@ -58,9 +58,7 @@ goog.scope(function () {
58
58
  */
59
59
  WebFont.prototype.isModuleSupportingUserAgent_ = function(module, eventDispatcher,
60
60
  fontWatcher, support) {
61
- var fontWatchRunnerCtor = module.getFontWatchRunnerCtor ?
62
- module.getFontWatchRunnerCtor() : webfont.FontWatchRunner,
63
- that = this;
61
+ var that = this;
64
62
 
65
63
  if (!support) {
66
64
  var allModulesLoaded = --this.moduleLoading_ == 0;
@@ -73,32 +71,23 @@ goog.scope(function () {
73
71
  eventDispatcher.dispatchLoading();
74
72
  }
75
73
  }
76
- fontWatcher.watchFonts([], {}, fontWatchRunnerCtor, allModulesLoaded);
74
+ fontWatcher.watchFonts([], {}, null, allModulesLoaded);
77
75
  return;
78
76
  }
79
77
 
80
- module.load(function (fonts, opt_fontTestStrings) {
81
- that.onModuleReady_(eventDispatcher, fontWatcher, fontWatchRunnerCtor, fonts, opt_fontTestStrings);
78
+ module.load(function (fonts, opt_fontTestStrings, opt_metricCompatibleFonts) {
79
+ that.onModuleReady_(eventDispatcher, fontWatcher, fonts, opt_fontTestStrings, opt_metricCompatibleFonts);
82
80
  });
83
81
  };
84
82
 
85
83
  /**
86
84
  * @param {webfont.EventDispatcher} eventDispatcher
87
85
  * @param {webfont.FontWatcher} fontWatcher
88
- * @param {function(new:webfont.FontWatchRunner,
89
- * function(webfont.Font),
90
- * function(webfont.Font),
91
- * webfont.DomHelper,
92
- * webfont.Font,
93
- * webfont.BrowserInfo,
94
- * number=,
95
- * Object.<string, boolean>=,
96
- * string=)} fontWatchRunnerCtor
97
86
  * @param {Array.<webfont.Font>} fonts
98
87
  * @param {webfont.FontTestStrings=} opt_fontTestStrings
88
+ * @param {Object.<string, boolean>=} opt_metricCompatibleFonts
99
89
  */
100
- WebFont.prototype.onModuleReady_ = function(eventDispatcher, fontWatcher,
101
- fontWatchRunnerCtor, fonts, opt_fontTestStrings) {
90
+ WebFont.prototype.onModuleReady_ = function(eventDispatcher, fontWatcher, fonts, opt_fontTestStrings, opt_metricCompatibleFonts) {
102
91
  var allModulesLoaded = --this.moduleLoading_ == 0;
103
92
 
104
93
  if (allModulesLoaded) {
@@ -106,7 +95,7 @@ goog.scope(function () {
106
95
  }
107
96
 
108
97
  setTimeout(function () {
109
- fontWatcher.watchFonts(fonts, opt_fontTestStrings || {}, fontWatchRunnerCtor, allModulesLoaded);
98
+ fontWatcher.watchFonts(fonts, opt_fontTestStrings || {}, opt_metricCompatibleFonts || null, allModulesLoaded);
110
99
  }, 0);
111
100
  };
112
101
 
data/src/modules.yml CHANGED
@@ -8,6 +8,7 @@ core:
8
8
  - core/cssclassname.js
9
9
  - core/font.js
10
10
  - core/eventdispatcher.js
11
+ - core/fontmodule.js
11
12
  - core/fontmoduleloader.js
12
13
  - core/fontruler.js
13
14
  - core/fontwatchrunner.js
@@ -19,7 +20,6 @@ ascender:
19
20
  - modules/ascender.js
20
21
 
21
22
  google:
22
- - modules/google/lastresortwebkitfontwatchrunner.js
23
23
  - modules/google/fontapiurlbuilder.js
24
24
  - modules/google/fontapiparser.js
25
25
  - modules/google/googlefontapi.js
@@ -3,7 +3,6 @@ goog.provide('webfont.modules.google.GoogleFontApi');
3
3
  goog.require('webfont.modules.google.FontApiUrlBuilder');
4
4
  goog.require('webfont.modules.google.FontApiParser');
5
5
  goog.require('webfont.FontWatchRunner');
6
- goog.require('webfont.modules.google.LastResortWebKitFontWatchRunner');
7
6
 
8
7
  /**
9
8
  * @constructor
@@ -20,19 +19,17 @@ webfont.modules.google.GoogleFontApi.NAME = 'google';
20
19
  goog.scope(function () {
21
20
  var GoogleFontApi = webfont.modules.google.GoogleFontApi,
22
21
  FontWatchRunner = webfont.FontWatchRunner,
23
- LastResortWebKitFontWatchRunner = webfont.modules.google.LastResortWebKitFontWatchRunner,
24
22
  FontApiUrlBuilder = webfont.modules.google.FontApiUrlBuilder,
25
23
  FontApiParser = webfont.modules.google.FontApiParser;
26
24
 
27
- GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
28
- support(userAgent.getBrowserInfo().hasWebFontSupport());
25
+ GoogleFontApi.METRICS_COMPATIBLE_FONTS = {
26
+ "Arimo": true,
27
+ "Cousine": true,
28
+ "Tinos": true
29
29
  };
30
30
 
31
- GoogleFontApi.prototype.getFontWatchRunnerCtor = function() {
32
- if (this.userAgent_.getEngine() == "AppleWebKit") {
33
- return LastResortWebKitFontWatchRunner;
34
- }
35
- return FontWatchRunner;
31
+ GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
32
+ support(userAgent.getBrowserInfo().hasWebFontSupport());
36
33
  };
37
34
 
38
35
  GoogleFontApi.prototype.load = function(onReady) {
@@ -59,7 +56,7 @@ goog.scope(function () {
59
56
 
60
57
  domHelper.insertInto('head', domHelper.createCssLink(
61
58
  fontApiUrlBuilder.build()));
62
- onReady(fontApiParser.getFonts(), fontApiParser.getFontTestStrings());
59
+ onReady(fontApiParser.getFonts(), fontApiParser.getFontTestStrings(), GoogleFontApi.METRICS_COMPATIBLE_FONTS);
63
60
  };
64
61
  });
65
62
 
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'webfontloader'
16
- s.version = '1.4.5'
17
- s.date = '2013-05-23'
16
+ s.version = '1.4.6'
17
+ s.date = '2013-05-29'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -142,7 +142,6 @@ DESC
142
142
  spec/modules/google/fontapiparser_spec.js
143
143
  spec/modules/google/fontapiurlbuilder_spec.js
144
144
  spec/modules/google/googlefontapi_spec.js
145
- spec/modules/google/lastresortwebkitfontwatchrunner_spec.js
146
145
  spec/modules/monotype_spec.js
147
146
  spec/modules/typekit_spec.js
148
147
  src/async_load.js
@@ -152,6 +151,7 @@ DESC
152
151
  src/core/domhelper.js
153
152
  src/core/eventdispatcher.js
154
153
  src/core/font.js
154
+ src/core/fontmodule.js
155
155
  src/core/fontmoduleloader.js
156
156
  src/core/fontruler.js
157
157
  src/core/fontwatcher.js
@@ -169,7 +169,6 @@ DESC
169
169
  src/modules/google/fontapiparser.js
170
170
  src/modules/google/fontapiurlbuilder.js
171
171
  src/modules/google/googlefontapi.js
172
- src/modules/google/lastresortwebkitfontwatchrunner.js
173
172
  src/modules/monotype.js
174
173
  src/modules/typekit.js
175
174
  tools/compiler/base.js
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webfontloader
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 5
10
- version: 1.4.5
9
+ - 6
10
+ version: 1.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Carver
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-05-23 00:00:00 Z
19
+ date: 2013-05-29 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rake
@@ -170,7 +170,6 @@ files:
170
170
  - spec/modules/google/fontapiparser_spec.js
171
171
  - spec/modules/google/fontapiurlbuilder_spec.js
172
172
  - spec/modules/google/googlefontapi_spec.js
173
- - spec/modules/google/lastresortwebkitfontwatchrunner_spec.js
174
173
  - spec/modules/monotype_spec.js
175
174
  - spec/modules/typekit_spec.js
176
175
  - src/async_load.js
@@ -180,6 +179,7 @@ files:
180
179
  - src/core/domhelper.js
181
180
  - src/core/eventdispatcher.js
182
181
  - src/core/font.js
182
+ - src/core/fontmodule.js
183
183
  - src/core/fontmoduleloader.js
184
184
  - src/core/fontruler.js
185
185
  - src/core/fontwatcher.js
@@ -197,7 +197,6 @@ files:
197
197
  - src/modules/google/fontapiparser.js
198
198
  - src/modules/google/fontapiurlbuilder.js
199
199
  - src/modules/google/googlefontapi.js
200
- - src/modules/google/lastresortwebkitfontwatchrunner.js
201
200
  - src/modules/monotype.js
202
201
  - src/modules/typekit.js
203
202
  - tools/compiler/base.js
@@ -1,137 +0,0 @@
1
- describe('modules.google.LastResortWebKitFontWatchRunner', function () {
2
- var LastResortWebKitFontWatchRunner = webfont.modules.google.LastResortWebKitFontWatchRunner,
3
- BrowserInfo = webfont.BrowserInfo,
4
- DomHelper = webfont.DomHelper,
5
- FontRuler = webfont.FontRuler,
6
- Font = webfont.Font,
7
- domHelper = new DomHelper(window),
8
- font = new Font('My Family', 'n4');
9
-
10
- var TARGET_SIZE = 3,
11
- FALLBACK_SIZE_A = 1,
12
- FALLBACK_SIZE_B = 2,
13
- LAST_RESORT_SIZE = 4,
14
-
15
- browserInfo = new BrowserInfo(true, true, false),
16
- setupWidths = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE],
17
- actualWidths = [],
18
- timesToGetTimeBeforeTimeout = 10,
19
- activeCallback = null,
20
- inactiveCallback = null;
21
-
22
- beforeEach(function () {
23
- jasmine.Clock.useMock();
24
-
25
- actualWidths = [];
26
-
27
- activeCallback = jasmine.createSpy('activeCallback');
28
- inactiveCallback = jasmine.createSpy('inactiveCallback');
29
- timesToGetTimeBeforeTimeout = 10;
30
-
31
- var setupFinished = false,
32
- fakeGetWidthCount = 0;
33
-
34
- spyOn(FontRuler.prototype, 'getWidth').andCallFake(function () {
35
- var result = null;
36
-
37
- if (setupFinished) {
38
- // If you are getting an exception here your tests does not specify enough
39
- // size data to run properly.
40
- if (fakeGetWidthCount >= actualWidths.length) {
41
- throw 'Invalid test data';
42
- }
43
- result = actualWidths[fakeGetWidthCount];
44
- fakeGetWidthCount += 1;
45
- } else {
46
- result = setupWidths[Math.min(fakeGetWidthCount, setupWidths.length - 1)];
47
- fakeGetWidthCount += 1;
48
- }
49
- return result;
50
- });
51
-
52
- spyOn(goog, 'now').andCallFake(function () {
53
- if (timesToGetTimeBeforeTimeout <= 0) {
54
- return 6000;
55
- } else {
56
- timesToGetTimeBeforeTimeout -= 1;
57
- return 1;
58
- }
59
- });
60
-
61
- var originalStart = LastResortWebKitFontWatchRunner.prototype.start;
62
-
63
- spyOn(LastResortWebKitFontWatchRunner.prototype, 'start').andCallFake(function () {
64
- setupFinished = true;
65
- fakeGetWidthCount = 0;
66
- originalStart.apply(this);
67
- });
68
- });
69
-
70
- it('should ignore fallback size and call active', function () {
71
- actualWidths = [
72
- LAST_RESORT_SIZE, LAST_RESORT_SIZE,
73
- TARGET_SIZE, TARGET_SIZE
74
- ];
75
-
76
- var fontWatchRunner = new LastResortWebKitFontWatchRunner(activeCallback, inactiveCallback,
77
- domHelper, font, browserInfo);
78
-
79
- fontWatchRunner.start();
80
-
81
- jasmine.Clock.tick(1 * 25);
82
- expect(activeCallback).toHaveBeenCalledWith(font);
83
- });
84
-
85
- it('should consider last resort font as having identical metrics and call active', function () {
86
- actualWidths = [
87
- LAST_RESORT_SIZE, LAST_RESORT_SIZE,
88
- LAST_RESORT_SIZE, LAST_RESORT_SIZE
89
- ];
90
-
91
- timesToGetTimeBeforeTimeout = 2;
92
-
93
- var arimo = new Font('Arimo');
94
-
95
- var fontWatchRunner = new LastResortWebKitFontWatchRunner(activeCallback, inactiveCallback,
96
- domHelper, arimo, browserInfo);
97
-
98
- fontWatchRunner.start();
99
-
100
- jasmine.Clock.tick(1 * 25);
101
- expect(activeCallback).toHaveBeenCalledWith(arimo);
102
- });
103
-
104
- it('should fail to load font and call inactive', function () {
105
- actualWidths = [
106
- LAST_RESORT_SIZE, LAST_RESORT_SIZE,
107
- LAST_RESORT_SIZE, LAST_RESORT_SIZE,
108
- FALLBACK_SIZE_A, FALLBACK_SIZE_B
109
- ];
110
-
111
- timesToGetTimeBeforeTimeout = 3;
112
-
113
- var fontWatchRunner = new LastResortWebKitFontWatchRunner(activeCallback, inactiveCallback,
114
- domHelper, font, browserInfo);
115
-
116
- fontWatchRunner.start();
117
-
118
- jasmine.Clock.tick(2 * 25);
119
- expect(inactiveCallback).toHaveBeenCalledWith(font);
120
- });
121
-
122
- it('should call inactive when we are loading a metric incompatible font', function () {
123
- actualWidths = [
124
- LAST_RESORT_SIZE, LAST_RESORT_SIZE,
125
- LAST_RESORT_SIZE, LAST_RESORT_SIZE
126
- ];
127
-
128
- timesToGetTimeBeforeTimeout = 2;
129
-
130
- var fontWatchRunner = new LastResortWebKitFontWatchRunner(activeCallback, inactiveCallback,
131
- domHelper, font, browserInfo);
132
-
133
- fontWatchRunner.start();
134
- jasmine.Clock.tick(1 * 25);
135
- expect(inactiveCallback).toHaveBeenCalledWith(font);
136
- });
137
- });
@@ -1,115 +0,0 @@
1
- goog.provide('webfont.modules.google.LastResortWebKitFontWatchRunner');
2
-
3
- goog.require('webfont.Font');
4
- goog.require('webfont.FontRuler');
5
-
6
- /**
7
- * @constructor
8
- * @param {function(webfont.Font)} activeCallback
9
- * @param {function(webfont.Font)} inactiveCallback
10
- * @param {webfont.DomHelper} domHelper
11
- * @param {webfont.Font} font
12
- * @param {webfont.BrowserInfo} browserInfo
13
- * @param {number=} opt_timeout
14
- * @param {Object.<string, boolean>=} opt_metricCompatibleFonts
15
- * @param {string=} opt_fontTestString
16
- * @extends webfont.FontWatchRunner
17
- */
18
- webfont.modules.google.LastResortWebKitFontWatchRunner = function(activeCallback,
19
- inactiveCallback, domHelper, font,
20
- browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString) {
21
-
22
- goog.base(this, activeCallback, inactiveCallback, domHelper,
23
- font, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString);
24
-
25
- this.webKitLastResortFontWidths_ = this.setUpWebKitLastResortFontWidths_();
26
- this.webKitLastResortWidthChange_ = false;
27
- this.lastObservedWidthA_ = this.lastResortWidths_[webfont.FontWatchRunner.LastResortFonts.SERIF];
28
- this.lastObservedWidthB_ = this.lastResortWidths_[webfont.FontWatchRunner.LastResortFonts.SANS_SERIF];;
29
- };
30
-
31
- goog.inherits(webfont.modules.google.LastResortWebKitFontWatchRunner, webfont.FontWatchRunner)
32
-
33
- webfont.modules.google.LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS = {
34
- "Arimo": true,
35
- "Cousine": true,
36
- "Tinos": true
37
- };
38
-
39
- goog.scope(function () {
40
- var LastResortWebKitFontWatchRunner = webfont.modules.google.LastResortWebKitFontWatchRunner,
41
- Font = webfont.Font,
42
- FontRuler = webfont.FontRuler;
43
-
44
- /**
45
- * While loading a web font webkit applies a last resort fallback font to the
46
- * element on which the web font is applied.
47
- * See file: WebKit/Source/WebCore/css/CSSFontFaceSource.cpp.
48
- * Looking at the different implementation for the different platforms,
49
- * the last resort fallback font is different. This code uses the default
50
- * OS/browsers values.
51
- */
52
- LastResortWebKitFontWatchRunner.prototype
53
- .setUpWebKitLastResortFontWidths_ = function() {
54
- var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
55
- var variation = this.font_.getVariation();
56
- var lastResortFontWidths = lastResortFonts.length;
57
- var webKitLastResortFontWidths = {};
58
- var fontRuler = new FontRuler(this.domHelper_, this.fontTestString_);
59
-
60
- fontRuler.insert();
61
- fontRuler.setFont(new Font(lastResortFonts[0], variation));
62
-
63
- webKitLastResortFontWidths[fontRuler.getWidth()] = true;
64
- for (var i = 1; i < lastResortFontWidths; i++) {
65
- var font = lastResortFonts[i];
66
- fontRuler.setFont(new Font(font, variation));
67
- webKitLastResortFontWidths[fontRuler.getWidth()] = true;
68
-
69
- // Another WebKit quirk if the normal weight/style is loaded first,
70
- // the size of the normal weight is returned when loading another weight.
71
- if (variation.toString().charAt(1) != '4') {
72
- fontRuler.setFont(new Font(font, variation.charAt(0) + '4'));
73
- webKitLastResortFontWidths[fontRuler.getWidth()] = true;
74
- }
75
- }
76
- fontRuler.remove();
77
- return webKitLastResortFontWidths;
78
- };
79
-
80
- /**
81
- * @override
82
- */
83
- LastResortWebKitFontWatchRunner.prototype.check_ = function() {
84
- var widthA = this.fontRulerA_.getWidth();
85
- var widthB = this.fontRulerB_.getWidth();
86
-
87
- if (!this.webKitLastResortWidthChange_ && widthA == widthB &&
88
- this.webKitLastResortFontWidths_[widthA]) {
89
- this.webKitLastResortFontWidths_ = {};
90
- this.webKitLastResortFontWidths_[widthA] = true;
91
- this.webKitLastResortWidthChange_ = true;
92
- }
93
- if ((this.lastObservedWidthA_ != widthA || this.lastObservedWidthB_ != widthB) &&
94
- (!this.webKitLastResortFontWidths_[widthA] &&
95
- !this.webKitLastResortFontWidths_[widthB])) {
96
- this.finish_(this.activeCallback_);
97
- } else if (this.hasTimedOut_()) {
98
-
99
- // In order to handle the fact that a font could be the same size as the
100
- // default browser font on a webkit browser, mark the font as active
101
- // after 5 seconds if the latest 2 widths are in webKitLastResortFontWidths_
102
- // and the font name is known to be metrics compatible.
103
- if (this.webKitLastResortFontWidths_[widthA]
104
- && this.webKitLastResortFontWidths_[widthB] &&
105
- LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS[
106
- this.font_.getName()]) {
107
- this.finish_(this.activeCallback_);
108
- } else {
109
- this.finish_(this.inactiveCallback_);
110
- }
111
- } else {
112
- this.asyncCheck_();
113
- }
114
- };
115
- });