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 +4 -0
- data/lib/webfontloader.rb +1 -1
- data/spec/core/fontruler_spec.js +4 -4
- data/spec/core/fontwatchrunner_spec.js +40 -59
- data/spec/deps.js +2 -3
- data/spec/google/lastresortwebkitfontwatchrunner_spec.js +19 -20
- data/spec/index.html +0 -1
- data/src/core/browserinfo.js +0 -1
- data/src/core/font.js +1 -3
- data/src/core/fontruler.js +4 -6
- data/src/core/fontwatchrunner.js +33 -46
- data/src/core/initialize.js +0 -1
- data/src/core/useragent.js +0 -9
- data/src/google/lastresortwebkitfontwatchrunner.js +25 -25
- data/src/modules.yml +0 -1
- data/webfontloader.gemspec +2 -3
- metadata +5 -6
- data/src/core/size.js +0 -43
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
data/spec/core/fontruler_spec.js
CHANGED
@@ -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, '
|
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
|
22
|
-
|
21
|
+
var widthA = fontRulerA.getWidth(),
|
22
|
+
widthB = fontRulerB.getWidth();
|
23
23
|
|
24
|
-
expect(
|
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 =
|
24
|
-
FALLBACK_SIZE_A =
|
25
|
-
FALLBACK_SIZE_B =
|
26
|
-
LAST_RESORT_SIZE =
|
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
|
-
|
31
|
-
|
29
|
+
setupWidths = [],
|
30
|
+
actualWidths = [],
|
32
31
|
timesToGetTimeBeforeTimeout = 10;
|
33
32
|
|
34
33
|
beforeEach(function () {
|
35
34
|
jasmine.Clock.useMock();
|
36
35
|
|
37
|
-
|
36
|
+
setupWidths = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE];
|
38
37
|
|
39
|
-
|
38
|
+
actualWidths = [];
|
40
39
|
|
41
40
|
var setupFinished = false,
|
42
|
-
|
41
|
+
fakeGetWidthCount = 0;
|
43
42
|
|
44
|
-
spyOn(FontRuler.prototype, '
|
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 (
|
48
|
+
if (fakeGetWidthCount >= actualWidths.length) {
|
50
49
|
throw 'Invalid test data';
|
51
50
|
}
|
52
|
-
result =
|
53
|
-
|
51
|
+
result = actualWidths[fakeGetWidthCount];
|
52
|
+
fakeGetWidthCount += 1;
|
54
53
|
} else {
|
55
|
-
result =
|
56
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
306
|
-
|
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
|
-
|
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
|
-
|
324
|
-
expect(
|
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.
|
337
|
-
expect(ruler.
|
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
|
-
|
363
|
-
|
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
|
-
|
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
|
-
|
387
|
-
expect(
|
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.
|
400
|
-
expect(ruler.
|
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"
|
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"
|
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 =
|
12
|
-
FALLBACK_SIZE_A =
|
13
|
-
FALLBACK_SIZE_B =
|
14
|
-
LAST_RESORT_SIZE =
|
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
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
32
|
+
fakeGetWidthCount = 0;
|
34
33
|
|
35
|
-
spyOn(FontRuler.prototype, '
|
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 (
|
40
|
+
if (fakeGetWidthCount >= actualWidths.length) {
|
42
41
|
throw 'Invalid test data';
|
43
42
|
}
|
44
|
-
result =
|
45
|
-
|
43
|
+
result = actualWidths[fakeGetWidthCount];
|
44
|
+
fakeGetWidthCount += 1;
|
46
45
|
} else {
|
47
|
-
result =
|
48
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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>
|
data/src/core/browserinfo.js
CHANGED
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
|
data/src/core/fontruler.js
CHANGED
@@ -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 {
|
56
|
+
* @return {number}
|
59
57
|
*/
|
60
|
-
FontRuler.prototype.
|
61
|
-
return
|
58
|
+
FontRuler.prototype.getWidth = function() {
|
59
|
+
return this.el_.offsetWidth;
|
62
60
|
};
|
63
61
|
|
64
62
|
/**
|
data/src/core/fontwatchrunner.js
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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
|
92
|
+
* Returns true if the given width matches the generic font family width.
|
102
93
|
*
|
103
94
|
* @private
|
104
|
-
* @param {
|
95
|
+
* @param {number} width
|
105
96
|
* @param {string} lastResortFont
|
106
97
|
* @return {boolean}
|
107
98
|
*/
|
108
|
-
FontWatchRunner.prototype.
|
109
|
-
|
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
|
118
|
-
*
|
104
|
+
* Return true if the given widths match any of the generic font family
|
105
|
+
* widths.
|
119
106
|
*
|
120
107
|
* @private
|
121
|
-
* @param {
|
122
|
-
* @param {
|
108
|
+
* @param {number} a
|
109
|
+
* @param {number} b
|
123
110
|
* @return {boolean}
|
124
111
|
*/
|
125
|
-
FontWatchRunner.prototype.
|
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.
|
129
|
-
this.
|
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 {
|
151
|
-
* @param {
|
137
|
+
* @param {number} a
|
138
|
+
* @param {number} b
|
152
139
|
* @return {boolean}
|
153
140
|
*/
|
154
|
-
FontWatchRunner.prototype.isFallbackFont_ = function (
|
155
|
-
return this.
|
156
|
-
this.
|
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
|
147
|
+
* Returns true if the WebKit bug is present and both widths match a last resort font.
|
161
148
|
*
|
162
149
|
* @private
|
163
|
-
* @param {
|
164
|
-
* @param {
|
150
|
+
* @param {number} a
|
151
|
+
* @param {number} b
|
165
152
|
* @return {boolean}
|
166
153
|
*/
|
167
|
-
FontWatchRunner.prototype.isLastResortFont_ = function (
|
168
|
-
return this.browserInfo_.hasWebKitFallbackBug() && this.
|
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
|
184
|
-
* async loop. If the
|
185
|
-
*
|
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
|
193
|
-
var
|
179
|
+
var widthA = this.fontRulerA_.getWidth();
|
180
|
+
var widthB = this.fontRulerB_.getWidth();
|
194
181
|
|
195
|
-
if (this.isFallbackFont_(
|
182
|
+
if (this.isFallbackFont_(widthA, widthB) || this.isLastResortFont_(widthA, widthB)) {
|
196
183
|
if (this.hasTimedOut_()) {
|
197
|
-
if (this.isLastResortFont_(
|
184
|
+
if (this.isLastResortFont_(widthA, widthB) && this.isMetricCompatibleFont_()) {
|
198
185
|
this.finish_(this.activeCallback_);
|
199
186
|
} else {
|
200
187
|
this.finish_(this.inactiveCallback_);
|
data/src/core/initialize.js
CHANGED
data/src/core/useragent.js
CHANGED
@@ -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.
|
26
|
-
this.
|
27
|
-
this.
|
28
|
-
this.
|
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
|
-
.
|
52
|
+
.setUpWebKitLastResortFontWidths_ = function() {
|
53
53
|
var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
|
54
|
-
var
|
55
|
-
var
|
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
|
-
|
62
|
-
for (var i = 1; 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
|
-
|
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
|
-
|
71
|
+
webKitLastResortFontWidths[fontRuler.getWidth()] = true;
|
72
72
|
}
|
73
73
|
}
|
74
74
|
fontRuler.remove();
|
75
|
-
return
|
75
|
+
return webKitLastResortFontWidths;
|
76
76
|
};
|
77
77
|
|
78
78
|
/**
|
79
79
|
* @override
|
80
80
|
*/
|
81
81
|
LastResortWebKitFontWatchRunner.prototype.check_ = function() {
|
82
|
-
var
|
83
|
-
var
|
82
|
+
var widthA = this.fontRulerA_.getWidth();
|
83
|
+
var widthB = this.fontRulerB_.getWidth();
|
84
84
|
|
85
|
-
if (!this.
|
86
|
-
this.
|
87
|
-
this.
|
88
|
-
this.
|
89
|
-
this.
|
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.
|
92
|
-
(!this.
|
93
|
-
!this.
|
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
|
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.
|
102
|
-
&& this.
|
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
data/webfontloader.gemspec
CHANGED
@@ -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.
|
17
|
-
s.date = '2013-03-
|
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:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
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-
|
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
|
-
});
|