webfontloader 1.3.2 → 1.4.0

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.0 (March 28, 2013)
2
+ * Stop exporting the `addModule` API to dynamically add modules (it didn't work anyway.)
3
+ * Stop checking the height when monitoring for font load. This turned out to be inconsistent across platforms.
4
+
1
5
  v1.3.2 (March 27, 2013)
2
6
  * Add support for the Amazon 1 and 2+ browsers.
3
7
 
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.3.2'
6
+ VERSION = '1.4.0'
7
7
 
8
8
  ProjectRoot = File.expand_path(File.dirname(__FILE__) + "/..")
9
9
 
@@ -10,7 +10,7 @@ describe('FontRuler', function () {
10
10
 
11
11
  it('should prevent a long test string from word wrapping', function () {
12
12
  var fontRulerA = new FontRuler(domHelper, 'abc'),
13
- fontRulerB = new FontRuler(domHelper, 'Hello World, this should wrap!');
13
+ fontRulerB = new FontRuler(domHelper, 'abc HelloWorld,thisshouldwrap!!!!');
14
14
 
15
15
  fontRulerA.insert();
16
16
  fontRulerB.insert();
@@ -18,9 +18,9 @@ describe('FontRuler', function () {
18
18
  fontRulerA.setFont('sans-serif');
19
19
  fontRulerB.setFont('sans-serif');
20
20
 
21
- var sizeA = fontRulerA.getSize(),
22
- sizeB = fontRulerB.getSize();
21
+ var widthA = fontRulerA.getWidth(),
22
+ widthB = fontRulerB.getWidth();
23
23
 
24
- expect(sizeA.height).toEqual(sizeB.height);
24
+ expect(widthA).not.toEqual(widthB);
25
25
  });
26
26
  });
@@ -2,7 +2,6 @@ describe('FontWatchRunner', function () {
2
2
  var FontWatchRunner = webfont.FontWatchRunner,
3
3
  BrowserInfo = webfont.BrowserInfo,
4
4
  UserAgentParser = webfont.UserAgentParser,
5
- Size = webfont.Size,
6
5
  DomHelper = webfont.DomHelper,
7
6
  FontRuler = webfont.FontRuler;
8
7
 
@@ -20,40 +19,40 @@ describe('FontWatchRunner', function () {
20
19
  describe('Fake browser', function () {
21
20
  var fontFamily = 'My Family',
22
21
  fontDescription = 'n4',
23
- TARGET_SIZE = new Size(3, 3),
24
- FALLBACK_SIZE_A = new Size(1, 1),
25
- FALLBACK_SIZE_B = new Size(2, 2),
26
- LAST_RESORT_SIZE = new Size(4, 4),
22
+ TARGET_SIZE = 3,
23
+ FALLBACK_SIZE_A = 1,
24
+ FALLBACK_SIZE_B = 2,
25
+ LAST_RESORT_SIZE = 4,
27
26
 
28
27
  browserInfo = new BrowserInfo(true, false, false),
29
28
  fallbackBugBrowserInfo = new BrowserInfo(true, true, false),
30
- setupSizes = [],
31
- actualSizes = [],
29
+ setupWidths = [],
30
+ actualWidths = [],
32
31
  timesToGetTimeBeforeTimeout = 10;
33
32
 
34
33
  beforeEach(function () {
35
34
  jasmine.Clock.useMock();
36
35
 
37
- setupSizes = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE];
36
+ setupWidths = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE];
38
37
 
39
- actualSizes = [];
38
+ actualWidths = [];
40
39
 
41
40
  var setupFinished = false,
42
- fakeGetSizeCount = 0;
41
+ fakeGetWidthCount = 0;
43
42
 
44
- spyOn(FontRuler.prototype, 'getSize').andCallFake(function () {
43
+ spyOn(FontRuler.prototype, 'getWidth').andCallFake(function () {
45
44
  var result = null;
46
45
  if (setupFinished) {
47
46
  // If you are getting an exception here your tests does not specify enough
48
47
  // size data to run properly.
49
- if (fakeGetSizeCount >= actualSizes.length) {
48
+ if (fakeGetWidthCount >= actualWidths.length) {
50
49
  throw 'Invalid test data';
51
50
  }
52
- result = actualSizes[fakeGetSizeCount];
53
- fakeGetSizeCount += 1;
51
+ result = actualWidths[fakeGetWidthCount];
52
+ fakeGetWidthCount += 1;
54
53
  } else {
55
- result = setupSizes[Math.min(fakeGetSizeCount, setupSizes.length - 1)];
56
- fakeGetSizeCount += 1;
54
+ result = setupWidths[Math.min(fakeGetWidthCount, setupWidths.length - 1)];
55
+ fakeGetWidthCount += 1;
57
56
  }
58
57
  return result;
59
58
  });
@@ -73,14 +72,14 @@ describe('FontWatchRunner', function () {
73
72
 
74
73
  spyOn(FontWatchRunner.prototype, 'start').andCallFake(function () {
75
74
  setupFinished = true;
76
- fakeGetSizeCount = 0;
75
+ fakeGetWidthCount = 0;
77
76
 
78
77
  originalStart.apply(this);
79
78
  });
80
79
  });
81
80
 
82
81
  it('should call active if fonts are already loaded', function () {
83
- actualSizes = [
82
+ actualWidths = [
84
83
  TARGET_SIZE, TARGET_SIZE
85
84
  ];
86
85
 
@@ -94,7 +93,7 @@ describe('FontWatchRunner', function () {
94
93
  });
95
94
 
96
95
  it('should wait for font load and call active', function () {
97
- actualSizes = [
96
+ actualWidths = [
98
97
  FALLBACK_SIZE_A, FALLBACK_SIZE_B,
99
98
  FALLBACK_SIZE_A, FALLBACK_SIZE_B,
100
99
  FALLBACK_SIZE_A, FALLBACK_SIZE_B,
@@ -113,7 +112,7 @@ describe('FontWatchRunner', function () {
113
112
  it('should wait for font inactive and call inactive', function () {
114
113
  timesToGetTimeBeforeTimeout = 5;
115
114
 
116
- actualSizes = [
115
+ actualWidths = [
117
116
  FALLBACK_SIZE_A, FALLBACK_SIZE_B,
118
117
  FALLBACK_SIZE_A, FALLBACK_SIZE_B,
119
118
  FALLBACK_SIZE_A, FALLBACK_SIZE_B,
@@ -132,7 +131,7 @@ describe('FontWatchRunner', function () {
132
131
 
133
132
  describe('WebKit fallback bug', function () {
134
133
  it('should ignore fallback size and call active', function () {
135
- actualSizes = [
134
+ actualWidths = [
136
135
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
137
136
  TARGET_SIZE, TARGET_SIZE
138
137
  ];
@@ -147,7 +146,7 @@ describe('FontWatchRunner', function () {
147
146
  });
148
147
 
149
148
  it('should consider last resort font as having identical metrics and call active', function () {
150
- actualSizes = [
149
+ actualWidths = [
151
150
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
152
151
  LAST_RESORT_SIZE, LAST_RESORT_SIZE
153
152
  ];
@@ -164,7 +163,7 @@ describe('FontWatchRunner', function () {
164
163
  });
165
164
 
166
165
  it('should fail to load font and call inactive', function () {
167
- actualSizes = [
166
+ actualWidths = [
168
167
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
169
168
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
170
169
  FALLBACK_SIZE_A, FALLBACK_SIZE_B
@@ -182,7 +181,7 @@ describe('FontWatchRunner', function () {
182
181
  });
183
182
 
184
183
  it('should call inactive when we are loading a metric incompatible font', function () {
185
- actualSizes = [
184
+ actualWidths = [
186
185
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
187
186
  LAST_RESORT_SIZE, LAST_RESORT_SIZE
188
187
  ];
@@ -200,7 +199,7 @@ describe('FontWatchRunner', function () {
200
199
  });
201
200
 
202
201
  it('should call active when we are loading a metric compatible font', function () {
203
- actualSizes = [
202
+ actualWidths = [
204
203
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
205
204
  LAST_RESORT_SIZE, LAST_RESORT_SIZE
206
205
  ];
@@ -218,24 +217,6 @@ describe('FontWatchRunner', function () {
218
217
  });
219
218
  });
220
219
 
221
- describe('webkit metrics bug', function () {
222
- it('should correctly call active even though the height is different', function () {
223
- actualSizes = [
224
- FALLBACK_SIZE_A, FALLBACK_SIZE_B,
225
- new Size(1, 2), new Size(2, 3), // Same as FALLBACK_SIZE_A and FALLBACK_SIZE_B except that the height is different.
226
- TARGET_SIZE, TARGET_SIZE
227
- ];
228
-
229
- var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
230
- domHelper, fontFamily, fontDescription, new BrowserInfo(true, false, true));
231
-
232
- fontWatchRunner.start();
233
-
234
- jasmine.Clock.tick(2 * 25);
235
- expect(activeCallback).toHaveBeenCalledWith('My Family', 'n4');
236
- });
237
- });
238
-
239
220
  describe('test string', function () {
240
221
  var fontWatchRunner = null;
241
222
 
@@ -244,7 +225,7 @@ describe('FontWatchRunner', function () {
244
225
  });
245
226
 
246
227
  it('should be the default', function () {
247
- actualSizes = [
228
+ actualWidths = [
248
229
  TARGET_SIZE, TARGET_SIZE
249
230
  ];
250
231
  fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
@@ -257,7 +238,7 @@ describe('FontWatchRunner', function () {
257
238
  });
258
239
 
259
240
  it('should be a custom string', function () {
260
- actualSizes = [
241
+ actualWidths = [
261
242
  TARGET_SIZE, TARGET_SIZE
262
243
  ];
263
244
 
@@ -302,14 +283,14 @@ describe('FontWatchRunner', function () {
302
283
  var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
303
284
  domHelper, 'SourceSansA', '', userAgent.getBrowserInfo(), 500),
304
285
  ruler = new FontRuler(domHelper, 'abcdef'),
305
- activeSize = null,
306
- originalSize = null,
286
+ activeWidth = null,
287
+ originalWidth = null,
307
288
  finalCheck = false;
308
289
 
309
290
  runs(function () {
310
291
  ruler.insert();
311
292
  ruler.setFont('monospace');
312
- originalSize = ruler.getSize();
293
+ originalWidth = ruler.getWidth();
313
294
  ruler.setFont("'SourceSansA', monospace");
314
295
  fontWatchRunner.start();
315
296
  });
@@ -320,8 +301,8 @@ describe('FontWatchRunner', function () {
320
301
 
321
302
  runs(function () {
322
303
  expect(activeCallback).toHaveBeenCalledWith('SourceSansA', '');
323
- activeSize = ruler.getSize();
324
- expect(activeSize).not.toEqual(originalSize);
304
+ activeWidth = ruler.getWidth();
305
+ expect(activeWidth).not.toEqual(originalWidth);
325
306
 
326
307
  window.setTimeout(function () {
327
308
  finalCheck = true;
@@ -333,8 +314,8 @@ describe('FontWatchRunner', function () {
333
314
  });
334
315
 
335
316
  runs(function () {
336
- expect(ruler.getSize()).not.toEqual(originalSize);
337
- expect(ruler.getSize()).toEqual(activeSize);
317
+ expect(ruler.getWidth()).not.toEqual(originalWidth);
318
+ expect(ruler.getWidth()).toEqual(activeWidth);
338
319
  });
339
320
  });
340
321
 
@@ -359,14 +340,14 @@ describe('FontWatchRunner', function () {
359
340
  var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
360
341
  domHelper, 'SourceSansB', '', userAgent.getBrowserInfo(), 500),
361
342
  ruler = new FontRuler(domHelper, 'abcdef'),
362
- activeSize = null,
363
- originalSize = null,
343
+ activeWidth = null,
344
+ originalWidth = null,
364
345
  finalCheck = false;
365
346
 
366
347
  runs(function () {
367
348
  ruler.insert();
368
349
  ruler.setFont('monospace');
369
- originalSize = ruler.getSize();
350
+ originalWidth = ruler.getWidth();
370
351
  ruler.setFont("'SourceSansB', monospace");
371
352
  fontWatchRunner.start();
372
353
  var link = document.createElement('link');
@@ -383,8 +364,8 @@ describe('FontWatchRunner', function () {
383
364
 
384
365
  runs(function () {
385
366
  expect(activeCallback).toHaveBeenCalledWith('SourceSansB', '');
386
- activeSize = ruler.getSize();
387
- expect(activeSize).not.toEqual(originalSize);
367
+ activeWidth = ruler.getWidth();
368
+ expect(activeWidth).not.toEqual(originalWidth);
388
369
 
389
370
  window.setTimeout(function () {
390
371
  finalCheck = true;
@@ -396,8 +377,8 @@ describe('FontWatchRunner', function () {
396
377
  });
397
378
 
398
379
  runs(function () {
399
- expect(ruler.getSize()).not.toEqual(originalSize);
400
- expect(ruler.getSize()).toEqual(activeSize);
380
+ expect(ruler.getWidth()).not.toEqual(originalWidth);
381
+ expect(ruler.getWidth()).toEqual(activeWidth);
401
382
  });
402
383
  });
403
384
  });
data/spec/deps.js CHANGED
@@ -7,14 +7,13 @@ goog.addDependency("../../src/core/cssclassname.js", ["webfont.CssClassName"], [
7
7
  goog.addDependency("../../src/core/cssfontfamilyname.js", ["webfont.CssFontFamilyName"], []);
8
8
  goog.addDependency("../../src/core/domhelper.js", ["webfont.DomHelper"], []);
9
9
  goog.addDependency("../../src/core/eventdispatcher.js", ["webfont.EventDispatcher"], ["webfont.CssClassName"]);
10
- goog.addDependency("../../src/core/font.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher","webfont.Size"]);
10
+ goog.addDependency("../../src/core/font.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher"]);
11
11
  goog.addDependency("../../src/core/fontmoduleloader.js", ["webfont.FontModuleLoader"], []);
12
- goog.addDependency("../../src/core/fontruler.js", ["webfont.FontRuler"], ["webfont.CssFontFamilyName","webfont.FontVariationDescription","webfont.Size"]);
12
+ goog.addDependency("../../src/core/fontruler.js", ["webfont.FontRuler"], ["webfont.CssFontFamilyName","webfont.FontVariationDescription"]);
13
13
  goog.addDependency("../../src/core/fontvariationdescription.js", ["webfont.FontVariationDescription"], []);
14
14
  goog.addDependency("../../src/core/fontwatcher.js", ["webfont.FontWatcher"], ["webfont.FontWatchRunner"]);
15
15
  goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunner"], ["webfont.FontRuler"]);
16
16
  goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.UserAgentParser","webfont.FontModuleLoader","webfont.WebFont"]);
17
- goog.addDependency("../../src/core/size.js", ["webfont.Size"], []);
18
17
  goog.addDependency("../../src/core/useragent.js", ["webfont.UserAgent"], []);
19
18
  goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent"]);
20
19
  goog.addDependency("../../src/custom/customcss.js", ["webfont.CustomCss"], []);
@@ -1,21 +1,20 @@
1
1
  describe('LastResortWebKitFontWatchRunner', function () {
2
2
  var LastResortWebKitFontWatchRunner = webfont.LastResortWebKitFontWatchRunner,
3
3
  BrowserInfo = webfont.BrowserInfo,
4
- Size = webfont.Size,
5
4
  DomHelper = webfont.DomHelper,
6
5
  FontRuler = webfont.FontRuler,
7
6
  domHelper = new DomHelper(window),
8
7
  fontFamily = 'My Family',
9
8
  fontDescription = 'n4';
10
9
 
11
- var TARGET_SIZE = new Size(3, 3),
12
- FALLBACK_SIZE_A = new Size(1, 1),
13
- FALLBACK_SIZE_B = new Size(2, 2),
14
- LAST_RESORT_SIZE = new Size(4, 4),
10
+ var TARGET_SIZE = 3,
11
+ FALLBACK_SIZE_A = 1,
12
+ FALLBACK_SIZE_B = 2,
13
+ LAST_RESORT_SIZE = 4,
15
14
 
16
15
  browserInfo = new BrowserInfo(true, true, false),
17
- setupSizes = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE],
18
- actualSizes = [],
16
+ setupWidths = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE],
17
+ actualWidths = [],
19
18
  timesToGetTimeBeforeTimeout = 10,
20
19
  activeCallback = null,
21
20
  inactiveCallback = null;
@@ -23,29 +22,29 @@ describe('LastResortWebKitFontWatchRunner', function () {
23
22
  beforeEach(function () {
24
23
  jasmine.Clock.useMock();
25
24
 
26
- actualSizes = [];
25
+ actualWidths = [];
27
26
 
28
27
  activeCallback = jasmine.createSpy('activeCallback');
29
28
  inactiveCallback = jasmine.createSpy('inactiveCallback');
30
29
  timesToGetTimeBeforeTimeout = 10;
31
30
 
32
31
  var setupFinished = false,
33
- fakeGetSizeCount = 0;
32
+ fakeGetWidthCount = 0;
34
33
 
35
- spyOn(FontRuler.prototype, 'getSize').andCallFake(function () {
34
+ spyOn(FontRuler.prototype, 'getWidth').andCallFake(function () {
36
35
  var result = null;
37
36
 
38
37
  if (setupFinished) {
39
38
  // If you are getting an exception here your tests does not specify enough
40
39
  // size data to run properly.
41
- if (fakeGetSizeCount >= actualSizes.length) {
40
+ if (fakeGetWidthCount >= actualWidths.length) {
42
41
  throw 'Invalid test data';
43
42
  }
44
- result = actualSizes[fakeGetSizeCount];
45
- fakeGetSizeCount += 1;
43
+ result = actualWidths[fakeGetWidthCount];
44
+ fakeGetWidthCount += 1;
46
45
  } else {
47
- result = setupSizes[Math.min(fakeGetSizeCount, setupSizes.length - 1)];
48
- fakeGetSizeCount += 1;
46
+ result = setupWidths[Math.min(fakeGetWidthCount, setupWidths.length - 1)];
47
+ fakeGetWidthCount += 1;
49
48
  }
50
49
  return result;
51
50
  });
@@ -63,13 +62,13 @@ describe('LastResortWebKitFontWatchRunner', function () {
63
62
 
64
63
  spyOn(LastResortWebKitFontWatchRunner.prototype, 'start').andCallFake(function () {
65
64
  setupFinished = true;
66
- fakeGetSizeCount = 0;
65
+ fakeGetWidthCount = 0;
67
66
  originalStart.apply(this);
68
67
  });
69
68
  });
70
69
 
71
70
  it('should ignore fallback size and call active', function () {
72
- actualSizes = [
71
+ actualWidths = [
73
72
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
74
73
  TARGET_SIZE, TARGET_SIZE
75
74
  ];
@@ -84,7 +83,7 @@ describe('LastResortWebKitFontWatchRunner', function () {
84
83
  });
85
84
 
86
85
  it('should consider last resort font as having identical metrics and call active', function () {
87
- actualSizes = [
86
+ actualWidths = [
88
87
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
89
88
  LAST_RESORT_SIZE, LAST_RESORT_SIZE
90
89
  ];
@@ -101,7 +100,7 @@ describe('LastResortWebKitFontWatchRunner', function () {
101
100
  });
102
101
 
103
102
  it('should fail to load font and call inactive', function () {
104
- actualSizes = [
103
+ actualWidths = [
105
104
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
106
105
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
107
106
  FALLBACK_SIZE_A, FALLBACK_SIZE_B
@@ -119,7 +118,7 @@ describe('LastResortWebKitFontWatchRunner', function () {
119
118
  });
120
119
 
121
120
  it('should call inactive when we are loading a metric incompatible font', function () {
122
- actualSizes = [
121
+ actualWidths = [
123
122
  LAST_RESORT_SIZE, LAST_RESORT_SIZE,
124
123
  LAST_RESORT_SIZE, LAST_RESORT_SIZE
125
124
  ];
data/spec/index.html CHANGED
@@ -37,7 +37,6 @@
37
37
  <script src="../spec/core/useragentparser_spec.js"></script>
38
38
  <script src="../spec/core/fontmoduleloader_spec.js"></script>
39
39
  <script src="../spec/core/eventdispatcher_spec.js"></script>
40
- <script src="../spec/core/size_spec.js"></script>
41
40
  <script src="../spec/core/fontruler_spec.js"></script>
42
41
  <script src="../spec/core/fontwatchrunner_spec.js"></script>
43
42
  <script src="../spec/core/fontwatcher_spec.js"></script>
@@ -1,7 +1,6 @@
1
1
  goog.provide('webfont.BrowserInfo');
2
2
 
3
3
  /**
4
- * @export
5
4
  * @constructor
6
5
  * @param {boolean} webfontSupport
7
6
  * @param {boolean} webKitFallbackBug
data/src/core/font.js CHANGED
@@ -3,7 +3,6 @@ goog.provide('webfont.WebFont');
3
3
  goog.require('webfont.DomHelper');
4
4
  goog.require('webfont.EventDispatcher');
5
5
  goog.require('webfont.FontWatcher');
6
- goog.require('webfont.Size');
7
6
 
8
7
  /**
9
8
  * @param {Window} mainWindow The main application window containing
@@ -24,8 +23,7 @@ goog.scope(function () {
24
23
  var WebFont = webfont.WebFont,
25
24
  DomHelper = webfont.DomHelper,
26
25
  EventDispatcher = webfont.EventDispatcher,
27
- FontWatcher = webfont.FontWatcher,
28
- Size = webfont.Size;
26
+ FontWatcher = webfont.FontWatcher;
29
27
 
30
28
  /**
31
29
  * @param {string} name
@@ -2,7 +2,6 @@ goog.provide('webfont.FontRuler');
2
2
 
3
3
  goog.require('webfont.CssFontFamilyName');
4
4
  goog.require('webfont.FontVariationDescription');
5
- goog.require('webfont.Size');
6
5
 
7
6
  /**
8
7
  * An element that can be used to measure the metrics
@@ -20,8 +19,7 @@ webfont.FontRuler = function(domHelper, fontTestString) {
20
19
  };
21
20
 
22
21
  goog.scope(function () {
23
- var FontRuler = webfont.FontRuler,
24
- Size = webfont.Size;
22
+ var FontRuler = webfont.FontRuler;
25
23
 
26
24
  /**
27
25
  * @param {string} fontFamily
@@ -55,10 +53,10 @@ goog.scope(function () {
55
53
  };
56
54
 
57
55
  /**
58
- * @return {webfont.Size}
56
+ * @return {number}
59
57
  */
60
- FontRuler.prototype.getSize = function() {
61
- return new Size(this.el_.offsetWidth, this.el_.offsetHeight);
58
+ FontRuler.prototype.getWidth = function() {
59
+ return this.el_.offsetWidth;
62
60
  };
63
61
 
64
62
  /**
@@ -23,7 +23,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
23
23
  this.fontDescription_ = fontDescription;
24
24
  this.fontTestString_ = opt_fontTestString || webfont.FontWatchRunner.DEFAULT_TEST_STRING;
25
25
  this.browserInfo_ = browserInfo;
26
- this.lastResortSizes_ = {};
26
+ this.lastResortWidths_ = {};
27
27
  this.timeout_ = opt_timeout || 5000;
28
28
 
29
29
  this.metricCompatibleFonts_ = opt_metricCompatibleFonts || null;
@@ -31,7 +31,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
31
31
  this.fontRulerA_ = null;
32
32
  this.fontRulerB_ = null;
33
33
 
34
- this.setupLastResortSizes_();
34
+ this.setupLastResortWidths_();
35
35
  };
36
36
 
37
37
  /**
@@ -41,16 +41,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
41
41
  webfont.FontWatchRunner.LastResortFonts = {
42
42
  SERIF: 'serif',
43
43
  SANS_SERIF: 'sans-serif',
44
- MONOSPACE: 'monospace',
45
- // Apple Color Emoji is the last character fallback on iOS. Since
46
- // all iOS installations that support web fonts have this font it
47
- // effectively means that Apple Color Emoji is the last resort
48
- // font on iOS. The caveat is that it only has characters in the
49
- // Emoji code range, and falls back to the real last resort font,
50
- // which is the default sans-serif font. It however affects the
51
- // height of the span we are monitoring, so we'll have to include
52
- // it in our list of last resort fonts.
53
- EMOJI: 'Apple Color Emoji'
44
+ MONOSPACE: 'monospace'
54
45
  };
55
46
 
56
47
  /**
@@ -69,7 +60,7 @@ goog.scope(function () {
69
60
  /**
70
61
  * @private
71
62
  */
72
- FontWatchRunner.prototype.setupLastResortSizes_ = function() {
63
+ FontWatchRunner.prototype.setupLastResortWidths_ = function() {
73
64
  var fontRuler = new FontRuler(this.domHelper_, this.fontTestString_);
74
65
 
75
66
  fontRuler.insert();
@@ -77,7 +68,7 @@ goog.scope(function () {
77
68
  for (var font in FontWatchRunner.LastResortFonts) {
78
69
  if (FontWatchRunner.LastResortFonts.hasOwnProperty(font)) {
79
70
  fontRuler.setFont(FontWatchRunner.LastResortFonts[font], this.fontDescription_);
80
- this.lastResortSizes_[FontWatchRunner.LastResortFonts[font]] = fontRuler.getSize();
71
+ this.lastResortWidths_[FontWatchRunner.LastResortFonts[font]] = fontRuler.getWidth();
81
72
  }
82
73
  }
83
74
  fontRuler.remove();
@@ -98,35 +89,31 @@ goog.scope(function () {
98
89
  };
99
90
 
100
91
  /**
101
- * Returns true if the given size matches the generic font family size.
92
+ * Returns true if the given width matches the generic font family width.
102
93
  *
103
94
  * @private
104
- * @param {?webfont.Size} size
95
+ * @param {number} width
105
96
  * @param {string} lastResortFont
106
97
  * @return {boolean}
107
98
  */
108
- FontWatchRunner.prototype.sizeMatches_ = function(size, lastResortFont) {
109
- if (this.browserInfo_.hasWebKitMetricsBug()) {
110
- return size.equalsWidth(this.lastResortSizes_[lastResortFont]);
111
- } else {
112
- return size.equals(this.lastResortSizes_[lastResortFont]);
113
- }
99
+ FontWatchRunner.prototype.widthMatches_ = function(width, lastResortFont) {
100
+ return width === this.lastResortWidths_[lastResortFont];
114
101
  };
115
102
 
116
103
  /**
117
- * Return true if the given sizes match any of the generic font family
118
- * sizes.
104
+ * Return true if the given widths match any of the generic font family
105
+ * widths.
119
106
  *
120
107
  * @private
121
- * @param {?webfont.Size} a
122
- * @param {?webfont.Size} b
108
+ * @param {number} a
109
+ * @param {number} b
123
110
  * @return {boolean}
124
111
  */
125
- FontWatchRunner.prototype.sizesMatchLastResortSizes_ = function(a, b) {
112
+ FontWatchRunner.prototype.widthsMatchLastResortWidths_ = function(a, b) {
126
113
  for (var font in FontWatchRunner.LastResortFonts) {
127
114
  if (FontWatchRunner.LastResortFonts.hasOwnProperty(font)) {
128
- if (this.sizeMatches_(a, FontWatchRunner.LastResortFonts[font]) &&
129
- this.sizeMatches_(b, FontWatchRunner.LastResortFonts[font])) {
115
+ if (this.widthMatches_(a, FontWatchRunner.LastResortFonts[font]) &&
116
+ this.widthMatches_(b, FontWatchRunner.LastResortFonts[font])) {
130
117
  return true;
131
118
  }
132
119
  }
@@ -147,25 +134,25 @@ goog.scope(function () {
147
134
  * Returns true if both fonts match the normal fallback fonts.
148
135
  *
149
136
  * @private
150
- * @param {webfont.Size} sizeA
151
- * @param {webfont.Size} sizeB
137
+ * @param {number} a
138
+ * @param {number} b
152
139
  * @return {boolean}
153
140
  */
154
- FontWatchRunner.prototype.isFallbackFont_ = function (sizeA, sizeB) {
155
- return this.sizeMatches_(sizeA, FontWatchRunner.LastResortFonts.SERIF) &&
156
- this.sizeMatches_(sizeB, FontWatchRunner.LastResortFonts.SANS_SERIF);
141
+ FontWatchRunner.prototype.isFallbackFont_ = function (a, b) {
142
+ return this.widthMatches_(a, FontWatchRunner.LastResortFonts.SERIF) &&
143
+ this.widthMatches_(b, FontWatchRunner.LastResortFonts.SANS_SERIF);
157
144
  };
158
145
 
159
146
  /**
160
- * Returns true if the WebKit bug is present and both sizes match a last resort font.
147
+ * Returns true if the WebKit bug is present and both widths match a last resort font.
161
148
  *
162
149
  * @private
163
- * @param {webfont.Size} sizeA
164
- * @param {webfont.Size} sizeB
150
+ * @param {number} a
151
+ * @param {number} b
165
152
  * @return {boolean}
166
153
  */
167
- FontWatchRunner.prototype.isLastResortFont_ = function (sizeA, sizeB) {
168
- return this.browserInfo_.hasWebKitFallbackBug() && this.sizesMatchLastResortSizes_(sizeA, sizeB);
154
+ FontWatchRunner.prototype.isLastResortFont_ = function (a, b) {
155
+ return this.browserInfo_.hasWebKitFallbackBug() && this.widthsMatchLastResortWidths_(a, b);
169
156
  };
170
157
 
171
158
  /**
@@ -180,21 +167,21 @@ goog.scope(function () {
180
167
  };
181
168
 
182
169
  /**
183
- * Checks the size of the two spans against their original sizes during each
184
- * async loop. If the size of one of the spans is different than the original
185
- * size, then we know that the font is rendering and finish with the active
170
+ * Checks the width of the two spans against their original widths during each
171
+ * async loop. If the width of one of the spans is different than the original
172
+ * width, then we know that the font is rendering and finish with the active
186
173
  * callback. If we wait more than 5 seconds and nothing has changed, we finish
187
174
  * with the inactive callback.
188
175
  *
189
176
  * @private
190
177
  */
191
178
  FontWatchRunner.prototype.check_ = function() {
192
- var sizeA = this.fontRulerA_.getSize();
193
- var sizeB = this.fontRulerB_.getSize();
179
+ var widthA = this.fontRulerA_.getWidth();
180
+ var widthB = this.fontRulerB_.getWidth();
194
181
 
195
- if (this.isFallbackFont_(sizeA, sizeB) || this.isLastResortFont_(sizeA, sizeB)) {
182
+ if (this.isFallbackFont_(widthA, widthB) || this.isLastResortFont_(widthA, widthB)) {
196
183
  if (this.hasTimedOut_()) {
197
- if (this.isLastResortFont_(sizeA, sizeB) && this.isMetricCompatibleFont_()) {
184
+ if (this.isLastResortFont_(widthA, widthB) && this.isMetricCompatibleFont_()) {
198
185
  this.finish_(this.activeCallback_);
199
186
  } else {
200
187
  this.finish_(this.inactiveCallback_);
@@ -32,4 +32,3 @@ var globalNamespaceObject = window[globalName] = (function() {
32
32
 
33
33
  // Export the public API.
34
34
  globalNamespaceObject['load'] = globalNamespaceObject.load;
35
- globalNamespaceObject['addModule'] = globalNamespaceObject.addModule;
@@ -1,7 +1,6 @@
1
1
  goog.provide('webfont.UserAgent');
2
2
 
3
3
  /**
4
- * @export
5
4
  * @param {string} name
6
5
  * @param {string} version
7
6
  * @param {string} engine
@@ -28,7 +27,6 @@ goog.scope(function () {
28
27
  var UserAgent = webfont.UserAgent;
29
28
 
30
29
  /**
31
- * @export
32
30
  * @return {string}
33
31
  */
34
32
  UserAgent.prototype.getName = function() {
@@ -36,7 +34,6 @@ goog.scope(function () {
36
34
  };
37
35
 
38
36
  /**
39
- * @export
40
37
  * @return {string}
41
38
  */
42
39
  UserAgent.prototype.getVersion = function() {
@@ -44,7 +41,6 @@ goog.scope(function () {
44
41
  };
45
42
 
46
43
  /**
47
- * @export
48
44
  * @return {string}
49
45
  */
50
46
  UserAgent.prototype.getEngine = function() {
@@ -52,7 +48,6 @@ goog.scope(function () {
52
48
  };
53
49
 
54
50
  /**
55
- * @export
56
51
  * @return {string}
57
52
  */
58
53
  UserAgent.prototype.getEngineVersion = function() {
@@ -60,7 +55,6 @@ goog.scope(function () {
60
55
  };
61
56
 
62
57
  /**
63
- * @export
64
58
  * @return {string}
65
59
  */
66
60
  UserAgent.prototype.getPlatform = function() {
@@ -68,7 +62,6 @@ goog.scope(function () {
68
62
  };
69
63
 
70
64
  /**
71
- * @export
72
65
  * @return {string}
73
66
  */
74
67
  UserAgent.prototype.getPlatformVersion = function() {
@@ -76,7 +69,6 @@ goog.scope(function () {
76
69
  };
77
70
 
78
71
  /**
79
- * @export
80
72
  * @return {number|undefined}
81
73
  */
82
74
  UserAgent.prototype.getDocumentMode = function() {
@@ -84,7 +76,6 @@ goog.scope(function () {
84
76
  };
85
77
 
86
78
  /**
87
- * @export
88
79
  * @return {webfont.BrowserInfo}
89
80
  */
90
81
  UserAgent.prototype.getBrowserInfo = function() {
@@ -22,10 +22,10 @@ webfont.LastResortWebKitFontWatchRunner = function(activeCallback,
22
22
  goog.base(this, activeCallback, inactiveCallback, domHelper,
23
23
  fontFamily, fontDescription, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString);
24
24
 
25
- this.webKitLastResortFontSizes_ = this.setUpWebKitLastResortFontSizes_();
26
- this.webKitLastResortSizeChange_ = false;
27
- this.lastObservedSizeA_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SERIF];
28
- this.lastObservedSizeB_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SANS_SERIF];;
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
29
  };
30
30
 
31
31
  goog.inherits(webfont.LastResortWebKitFontWatchRunner, webfont.FontWatchRunner)
@@ -49,57 +49,57 @@ goog.scope(function () {
49
49
  * OS/browsers values.
50
50
  */
51
51
  LastResortWebKitFontWatchRunner.prototype
52
- .setUpWebKitLastResortFontSizes_ = function() {
52
+ .setUpWebKitLastResortFontWidths_ = function() {
53
53
  var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
54
- var lastResortFontSizes = lastResortFonts.length;
55
- var webKitLastResortFontSizes = {};
54
+ var lastResortFontWidths = lastResortFonts.length;
55
+ var webKitLastResortFontWidths = {};
56
56
  var fontRuler = new FontRuler(this.domHelper_, this.fontTestString_);
57
57
 
58
58
  fontRuler.insert();
59
59
  fontRuler.setFont(lastResortFonts[0], this.fontDescription_);
60
60
 
61
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
62
- for (var i = 1; i < lastResortFontSizes; i++) {
61
+ webKitLastResortFontWidths[fontRuler.getWidth()] = true;
62
+ for (var i = 1; i < lastResortFontWidths; i++) {
63
63
  var font = lastResortFonts[i];
64
64
  fontRuler.setFont(font, this.fontDescription_);
65
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
65
+ webKitLastResortFontWidths[fontRuler.getWidth()] = true;
66
66
 
67
67
  // Another WebKit quirk if the normal weight/style is loaded first,
68
68
  // the size of the normal weight is returned when loading another weight.
69
69
  if (this.fontDescription_[1] != '4') {
70
70
  fontRuler.setFont(font, this.fontDescription_[0] + '4');
71
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
71
+ webKitLastResortFontWidths[fontRuler.getWidth()] = true;
72
72
  }
73
73
  }
74
74
  fontRuler.remove();
75
- return webKitLastResortFontSizes;
75
+ return webKitLastResortFontWidths;
76
76
  };
77
77
 
78
78
  /**
79
79
  * @override
80
80
  */
81
81
  LastResortWebKitFontWatchRunner.prototype.check_ = function() {
82
- var sizeA = this.fontRulerA_.getSize();
83
- var sizeB = this.fontRulerB_.getSize();
82
+ var widthA = this.fontRulerA_.getWidth();
83
+ var widthB = this.fontRulerB_.getWidth();
84
84
 
85
- if (!this.webKitLastResortSizeChange_ && sizeA.width == sizeB.width &&
86
- this.webKitLastResortFontSizes_[sizeA.width]) {
87
- this.webKitLastResortFontSizes_ = {};
88
- this.webKitLastResortFontSizes_[sizeA.width] = true;
89
- this.webKitLastResortSizeChange_ = true;
85
+ if (!this.webKitLastResortWidthChange_ && widthA == widthB &&
86
+ this.webKitLastResortFontWidths_[widthA]) {
87
+ this.webKitLastResortFontWidths_ = {};
88
+ this.webKitLastResortFontWidths_[widthA] = true;
89
+ this.webKitLastResortWidthChange_ = true;
90
90
  }
91
- if ((this.lastObservedSizeA_.width != sizeA.width || this.lastObservedSizeB_.width != sizeB.width) &&
92
- (!this.webKitLastResortFontSizes_[sizeA.width] &&
93
- !this.webKitLastResortFontSizes_[sizeB.width])) {
91
+ if ((this.lastObservedWidthA_ != widthA || this.lastObservedWidthB_ != widthB) &&
92
+ (!this.webKitLastResortFontWidths_[widthA] &&
93
+ !this.webKitLastResortFontWidths_[widthB])) {
94
94
  this.finish_(this.activeCallback_);
95
95
  } else if (goog.now() - this.started_ >= 5000) {
96
96
 
97
97
  // In order to handle the fact that a font could be the same size as the
98
98
  // default browser font on a webkit browser, mark the font as active
99
- // after 5 seconds if the latest 2 sizes are in webKitLastResortFontSizes_
99
+ // after 5 seconds if the latest 2 widths are in webKitLastResortFontWidths_
100
100
  // and the font name is known to be metrics compatible.
101
- if (this.webKitLastResortFontSizes_[sizeA.width]
102
- && this.webKitLastResortFontSizes_[sizeB.width] &&
101
+ if (this.webKitLastResortFontWidths_[widthA]
102
+ && this.webKitLastResortFontWidths_[widthB] &&
103
103
  LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS[
104
104
  this.fontFamily_]) {
105
105
  this.finish_(this.activeCallback_);
data/src/modules.yml CHANGED
@@ -9,7 +9,6 @@ core:
9
9
  - core/fontvariationdescription.js
10
10
  - core/eventdispatcher.js
11
11
  - core/fontmoduleloader.js
12
- - core/size.js
13
12
  - core/fontruler.js
14
13
  - core/fontwatchrunner.js
15
14
  - core/fontwatcher.js
@@ -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.3.2'
17
- s.date = '2013-03-27'
16
+ s.version = '1.4.0'
17
+ s.date = '2013-03-28'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -159,7 +159,6 @@ DESC
159
159
  src/core/fontwatchrunner.js
160
160
  src/core/initialize.js
161
161
  src/core/namespace.js
162
- src/core/size.js
163
162
  src/core/useragent.js
164
163
  src/core/useragentparser.js
165
164
  src/custom/customcss.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: 31
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 3
9
- - 2
10
- version: 1.3.2
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
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-03-27 00:00:00 Z
19
+ date: 2013-03-28 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rake
@@ -190,7 +190,6 @@ files:
190
190
  - src/core/fontwatchrunner.js
191
191
  - src/core/initialize.js
192
192
  - src/core/namespace.js
193
- - src/core/size.js
194
193
  - src/core/useragent.js
195
194
  - src/core/useragentparser.js
196
195
  - src/custom/customcss.js
data/src/core/size.js DELETED
@@ -1,43 +0,0 @@
1
- goog.provide('webfont.Size');
2
-
3
- /**
4
- * @constructor
5
- * @param {number} width
6
- * @param {number} height
7
- */
8
- webfont.Size = function (width, height) {
9
- this.width = width;
10
- this.height = height;
11
- };
12
-
13
- goog.scope(function () {
14
- var Size = webfont.Size;
15
-
16
- /**
17
- * Returns true if this size equals other.
18
- *
19
- * @param {webfont.Size} other
20
- * @return {boolean}
21
- */
22
- Size.prototype.equals = function (other) {
23
- return this.equalsWidth(other) && this.equalsHeight(other);
24
- };
25
-
26
- /**
27
- * Returns true if this.width equals other.width
28
- * @param {webfont.Size} other
29
- * @return {boolean}
30
- */
31
- Size.prototype.equalsWidth = function (other) {
32
- return !!other && this.width == other.width;
33
- };
34
-
35
- /**
36
- * Returns true if this.height equals other.height
37
- * @param {webfont.Size} other
38
- * @return {boolean}
39
- */
40
- Size.prototype.equalsHeight = function (other) {
41
- return !!other && this.height == other.height;
42
- };
43
- });