webfontloader 1.5.6 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/Rakefile +5 -1
- data/lib/webfontloader.rb +1 -1
- data/spec/core/font_spec.js +18 -0
- data/spec/core/fontwatcher_spec.js +14 -1
- data/spec/core/nativefontwatchrunner_spec.js +108 -0
- data/spec/core/webfont_spec.js +10 -1
- data/spec/deps.js +2 -1
- data/spec/fixtures/fonts/sourcesansc.css +1 -0
- data/spec/fixtures/fonts/sourcesansd.css +1 -0
- data/spec/index.html +2 -0
- data/spec/modules/monotype_spec.js +1 -1
- data/src/core/browserinfo.js +12 -1
- data/src/core/font.js +26 -3
- data/src/core/fontwatcher.js +17 -3
- data/src/core/fontwatchrunner.js +1 -1
- data/src/core/nativefontwatchrunner.js +46 -0
- data/src/core/useragentparser.js +8 -8
- data/src/modules.yml +1 -0
- data/tools/compiler/base.js +0 -59
- data/tools/compiler/compiler.jar +0 -0
- data/webfontloader.gemspec +6 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9589210eedec7a4bae571f227f5968a0e9b05c7
|
4
|
+
data.tar.gz: d54107d873a216a96075796973fdf8ad091cd46c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0971500a308575e9b2a8b8058c03c56089019bc800bf3efd618051c1a076e465e262de943a6b4451b1cdf02ea14f38e4a65dd398d92dcc63ad0c8d2fc949da56
|
7
|
+
data.tar.gz: 113d98006682af2b0792d58cf08aae4a4fecdcbc1fafcc0f5bf2b7349d87a103ff1e241e0836aedfb5bf17e0be2321875bfe1d1efc4e03174e4a58c1382c9d4d
|
data/README.md
CHANGED
@@ -9,23 +9,23 @@ Web Font Loader gives you added control when using linked fonts via `@font-face`
|
|
9
9
|
* [Get started](#get-started)
|
10
10
|
* [Configuration](#configuration)
|
11
11
|
* [Events](#events)
|
12
|
-
* [Timeout](#
|
12
|
+
* [Timeout](#timeouts)
|
13
13
|
* [Iframes](#iframes)
|
14
14
|
* [Modules](#modules)
|
15
15
|
* [Custom](#custom)
|
16
16
|
* [Fontdeck](#fontdeck)
|
17
|
-
* [Fonts.com](#
|
17
|
+
* [Fonts.com](#fontscom)
|
18
18
|
* [Google](#google)
|
19
19
|
* [Typekit](#typekit)
|
20
20
|
* [Browser support](#browser-support)
|
21
|
-
* [License](#license)
|
21
|
+
* [License](#copyright-and-license)
|
22
22
|
|
23
23
|
## Get Started
|
24
24
|
|
25
25
|
To use the Web Font Loader library, just include it in your page and tell it which fonts to load. For example, you could load fonts from [Google Fonts](http://www.google.com/fonts/) using the Web Font Loader hosted on [Google Hosted Libraries](https://developers.google.com/speed/libraries/) using the following code.
|
26
26
|
|
27
27
|
```html
|
28
|
-
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.
|
28
|
+
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.5.6/webfont.js"></script>
|
29
29
|
<script>
|
30
30
|
WebFont.load({
|
31
31
|
google: {
|
@@ -48,7 +48,7 @@ It is also possible to use the Web Font Loader asynchronously. For example, to l
|
|
48
48
|
(function() {
|
49
49
|
var wf = document.createElement('script');
|
50
50
|
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
|
51
|
-
'://ajax.googleapis.com/ajax/libs/webfont/1.
|
51
|
+
'://ajax.googleapis.com/ajax/libs/webfont/1.5.6/webfont.js';
|
52
52
|
wf.type = 'text/javascript';
|
53
53
|
wf.async = 'true';
|
54
54
|
var s = document.getElementsByTagName('script')[0];
|
@@ -131,7 +131,7 @@ WebFontConfig = {
|
|
131
131
|
};
|
132
132
|
```
|
133
133
|
|
134
|
-
The timeout value should be in milliseconds, and defaults to
|
134
|
+
The timeout value should be in milliseconds, and defaults to 3000 milliseconds (3 seconds) if not supplied.
|
135
135
|
|
136
136
|
### Iframes
|
137
137
|
|
@@ -200,7 +200,7 @@ In this example, the `fonts.css` file might look something like this:
|
|
200
200
|
If your fonts are already included in another stylesheet you can also leave out the `urls` array and just specify font family names to start font loading. As long as the names match those that are declared in the `families` array, the proper loading classes will be applied to the html element.
|
201
201
|
|
202
202
|
```html
|
203
|
-
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.
|
203
|
+
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.5.6/webfont.js"></script>
|
204
204
|
<script>
|
205
205
|
WebFont.load({
|
206
206
|
custom: {
|
@@ -271,7 +271,7 @@ WebFontConfig = {
|
|
271
271
|
};
|
272
272
|
```
|
273
273
|
|
274
|
-
You can also supply the `text` parameter to perform character subsetting:
|
274
|
+
Sometimes the font you requested doesn't come in the default variation (e.g. `n4`) and you need to explicitly request the variation you want for font events to work (e.g. `n3`, `n7`, etc.). You can also supply the `text` parameter to perform character subsetting:
|
275
275
|
|
276
276
|
```javascript
|
277
277
|
WebFontConfig = {
|
data/Rakefile
CHANGED
@@ -83,6 +83,10 @@ directory "tmp"
|
|
83
83
|
desc "Compile the JavaScript into target/webfont.js"
|
84
84
|
task :compile, [:modules] => "target/webfont.js"
|
85
85
|
|
86
|
+
file "webfontloader.js" => "target/webfont.js" do
|
87
|
+
cp "target/webfont.js", "webfontloader.js"
|
88
|
+
end
|
89
|
+
|
86
90
|
file "target/webfont.js", [:modules] => SourceJs + ["target"] do |t, args|
|
87
91
|
args.with_defaults(:modules => 'custom google typekit monotype fontdeck')
|
88
92
|
|
@@ -205,7 +209,7 @@ end
|
|
205
209
|
#
|
206
210
|
#############################################################################
|
207
211
|
|
208
|
-
task :release => :build do
|
212
|
+
task :release => [:build, "webfontloader.js"] do
|
209
213
|
unless `git branch` =~ /^\* master$/
|
210
214
|
puts "You must be on the master branch to release!"
|
211
215
|
exit!
|
data/lib/webfontloader.rb
CHANGED
data/spec/core/font_spec.js
CHANGED
@@ -39,6 +39,24 @@ describe('Font', function () {
|
|
39
39
|
});
|
40
40
|
});
|
41
41
|
|
42
|
+
describe('#toCssString', function () {
|
43
|
+
function toCssString(fvd) {
|
44
|
+
return new Font('My Family', fvd).toCssString();
|
45
|
+
}
|
46
|
+
|
47
|
+
it('should expand font styles correctly', function () {
|
48
|
+
expect(toCssString('n4')).toEqual("normal 400 300px 'My Family'");
|
49
|
+
expect(toCssString('i4')).toEqual("italic 400 300px 'My Family'");
|
50
|
+
expect(toCssString('o4')).toEqual("oblique 400 300px 'My Family'");
|
51
|
+
});
|
52
|
+
|
53
|
+
it('should expand weights correctly', function () {
|
54
|
+
for (var i = 1; i < 10; i += 1) {
|
55
|
+
expect(toCssString('n' + i)).toEqual("normal " + (i * 100) + " 300px 'My Family'");
|
56
|
+
}
|
57
|
+
});
|
58
|
+
});
|
59
|
+
|
42
60
|
describe('#getCssVariation', function () {
|
43
61
|
function toCss(fvd) {
|
44
62
|
return new Font('My Family', fvd).getCssVariation();
|
@@ -5,6 +5,7 @@ describe('FontWatcher', function () {
|
|
5
5
|
UserAgent = webfont.UserAgent,
|
6
6
|
BrowserInfo = webfont.BrowserInfo,
|
7
7
|
DomHelper = webfont.DomHelper,
|
8
|
+
Version = webfont.Version,
|
8
9
|
domHelper = new DomHelper(window),
|
9
10
|
eventDispatcher = {},
|
10
11
|
testStrings = null,
|
@@ -17,7 +18,19 @@ describe('FontWatcher', function () {
|
|
17
18
|
activeFonts = [];
|
18
19
|
|
19
20
|
beforeEach(function () {
|
20
|
-
userAgent = new UserAgent(
|
21
|
+
userAgent = new UserAgent(
|
22
|
+
'Firefox',
|
23
|
+
new Version(3, 6),
|
24
|
+
'3.6',
|
25
|
+
'Gecko',
|
26
|
+
new Version(1, 9, 3),
|
27
|
+
'1.9.3',
|
28
|
+
'Macintosh',
|
29
|
+
new Version(10, 6),
|
30
|
+
'10.6',
|
31
|
+
undefined,
|
32
|
+
new BrowserInfo(true, false, false, false)
|
33
|
+
);
|
21
34
|
font1 = new Font('font1');
|
22
35
|
font2 = new Font('font2');
|
23
36
|
font3 = new Font('font3');
|
@@ -0,0 +1,108 @@
|
|
1
|
+
describe('NativeFontWatchRunner', function () {
|
2
|
+
var NativeFontWatchRunner = webfont.NativeFontWatchRunner,
|
3
|
+
Font = webfont.Font,
|
4
|
+
UserAgentParser = webfont.UserAgentParser,
|
5
|
+
DomHelper = webfont.DomHelper,
|
6
|
+
FontRuler = webfont.FontRuler;
|
7
|
+
|
8
|
+
var domHelper = null,
|
9
|
+
activeCallback = null,
|
10
|
+
inactiveCallback = null,
|
11
|
+
userAgent = null,
|
12
|
+
nullFont = null,
|
13
|
+
sourceSansC = null,
|
14
|
+
elena = null;
|
15
|
+
|
16
|
+
beforeEach(function () {
|
17
|
+
domHelper = new DomHelper(window);
|
18
|
+
|
19
|
+
activeCallback = jasmine.createSpy('activeCallback');
|
20
|
+
inactiveCallback = jasmine.createSpy('inactiveCallback');
|
21
|
+
|
22
|
+
var userAgentParser = new UserAgentParser(window.navigator.userAgent, window.document);
|
23
|
+
|
24
|
+
nullFont = new Font('__webfontloader_test_3__');
|
25
|
+
sourceSansC = new Font('SourceSansC');
|
26
|
+
elena = new Font('Elena');
|
27
|
+
|
28
|
+
userAgent = userAgentParser.parse();
|
29
|
+
});
|
30
|
+
|
31
|
+
if (window['FontFace']) {
|
32
|
+
it('should fail to load a null font', function () {
|
33
|
+
var fontWatchRunner = new NativeFontWatchRunner(activeCallback, inactiveCallback,
|
34
|
+
domHelper, nullFont);
|
35
|
+
|
36
|
+
runs(function () {
|
37
|
+
fontWatchRunner.start();
|
38
|
+
});
|
39
|
+
|
40
|
+
waitsFor(function () {
|
41
|
+
return activeCallback.wasCalled || inactiveCallback.wasCalled;
|
42
|
+
});
|
43
|
+
|
44
|
+
runs(function () {
|
45
|
+
expect(inactiveCallback).toHaveBeenCalledWith(nullFont);
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
it('should load font succesfully', function () {
|
50
|
+
var fontWatchRunner = new NativeFontWatchRunner(activeCallback, inactiveCallback,
|
51
|
+
domHelper, sourceSansC),
|
52
|
+
ruler = new FontRuler(domHelper, 'abcdef'),
|
53
|
+
monospace = new Font('monospace'),
|
54
|
+
sourceSansCFallback = new Font('SourceSansC, monospace'),
|
55
|
+
activeWidth = null,
|
56
|
+
originalWidth = null,
|
57
|
+
finalCheck = false;
|
58
|
+
|
59
|
+
runs(function () {
|
60
|
+
ruler.insert();
|
61
|
+
ruler.setFont(monospace);
|
62
|
+
originalWidth = ruler.getWidth();
|
63
|
+
ruler.setFont(sourceSansCFallback);
|
64
|
+
fontWatchRunner.start();
|
65
|
+
});
|
66
|
+
|
67
|
+
waitsFor(function () {
|
68
|
+
return activeCallback.wasCalled || inactiveCallback.wasCalled;
|
69
|
+
});
|
70
|
+
|
71
|
+
runs(function () {
|
72
|
+
expect(activeCallback).toHaveBeenCalledWith(sourceSansC);
|
73
|
+
activeWidth = ruler.getWidth();
|
74
|
+
expect(activeWidth).not.toEqual(originalWidth);
|
75
|
+
|
76
|
+
window.setTimeout(function () {
|
77
|
+
finalCheck = true;
|
78
|
+
}, 200);
|
79
|
+
});
|
80
|
+
|
81
|
+
waitsFor(function () {
|
82
|
+
return finalCheck;
|
83
|
+
});
|
84
|
+
|
85
|
+
runs(function () {
|
86
|
+
expect(ruler.getWidth()).not.toEqual(originalWidth);
|
87
|
+
expect(ruler.getWidth()).toEqual(activeWidth);
|
88
|
+
});
|
89
|
+
});
|
90
|
+
|
91
|
+
it('should attempt to load a non-existing font', function () {
|
92
|
+
var fontWatchRunner = new NativeFontWatchRunner(activeCallback, inactiveCallback,
|
93
|
+
domHelper, elena);
|
94
|
+
|
95
|
+
runs(function () {
|
96
|
+
fontWatchRunner.start();
|
97
|
+
});
|
98
|
+
|
99
|
+
waitsFor(function () {
|
100
|
+
return activeCallback.wasCalled || inactiveCallback.wasCalled;
|
101
|
+
});
|
102
|
+
|
103
|
+
runs(function () {
|
104
|
+
expect(inactiveCallback).toHaveBeenCalledWith(elena);
|
105
|
+
});
|
106
|
+
});
|
107
|
+
}
|
108
|
+
});
|
data/spec/core/webfont_spec.js
CHANGED
@@ -3,6 +3,7 @@ describe('WebFont', function () {
|
|
3
3
|
Font = webfont.Font;
|
4
4
|
UserAgent = webfont.UserAgent,
|
5
5
|
FontWatchRunner = webfont.FontWatchRunner,
|
6
|
+
NativeFontWatchRunner = webfont.NativeFontWatchRunner,
|
6
7
|
BrowserInfo = webfont.BrowserInfo,
|
7
8
|
Version = webfont.Version,
|
8
9
|
Font = webfont.Font,
|
@@ -22,7 +23,7 @@ describe('WebFont', function () {
|
|
22
23
|
new Version(10, 6),
|
23
24
|
'10.6',
|
24
25
|
undefined,
|
25
|
-
new BrowserInfo(true, false, false)
|
26
|
+
new BrowserInfo(true, false, false, false)
|
26
27
|
);
|
27
28
|
fontModuleLoader = new FontModuleLoader();
|
28
29
|
});
|
@@ -156,6 +157,14 @@ describe('WebFont', function () {
|
|
156
157
|
}
|
157
158
|
});
|
158
159
|
|
160
|
+
spyOn(NativeFontWatchRunner.prototype, 'start').andCallFake(function () {
|
161
|
+
if (conf.id) {
|
162
|
+
active(font);
|
163
|
+
} else {
|
164
|
+
inactive(font);
|
165
|
+
}
|
166
|
+
});
|
167
|
+
|
159
168
|
testModule.supportUserAgent = function (userAgent, support) {
|
160
169
|
if (conf.id) {
|
161
170
|
// The monotype module only initializes font
|
data/spec/deps.js
CHANGED
@@ -8,9 +8,10 @@ goog.addDependency("../../src/core/font.js", ["webfont.Font"], []);
|
|
8
8
|
goog.addDependency("../../src/core/fontmodule.js", ["webfont.FontModule"], []);
|
9
9
|
goog.addDependency("../../src/core/fontmoduleloader.js", ["webfont.FontModuleLoader","webfont.FontModuleFactory"], []);
|
10
10
|
goog.addDependency("../../src/core/fontruler.js", ["webfont.FontRuler"], []);
|
11
|
-
goog.addDependency("../../src/core/fontwatcher.js", ["webfont.FontWatcher"], ["webfont.FontWatchRunner"]);
|
11
|
+
goog.addDependency("../../src/core/fontwatcher.js", ["webfont.FontWatcher"], ["webfont.FontWatchRunner","webfont.NativeFontWatchRunner"]);
|
12
12
|
goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunner"], ["webfont.Font","webfont.FontRuler"]);
|
13
13
|
goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.WebFont","webfont.modules.Typekit","webfont.modules.Fontdeck","webfont.modules.Monotype","webfont.modules.Custom","webfont.modules.google.GoogleFontApi"]);
|
14
|
+
goog.addDependency("../../src/core/nativefontwatchrunner.js", ["webfont.NativeFontWatchRunner"], ["webfont.Font"]);
|
14
15
|
goog.addDependency("../../src/core/useragent.js", ["webfont.UserAgent"], []);
|
15
16
|
goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent","webfont.Version"]);
|
16
17
|
goog.addDependency("../../src/core/version.js", ["webfont.Version"], []);
|
@@ -0,0 +1 @@
|
|
1
|
+
@font-face{font-family:SourceSansC;src:url(sourcesans.eot?#iefix) format('embedded-opentype'),url(sourcesans.woff) format('woff'),url(sourcesans.otf) format('opentype'),url(sourcesans.ttf) format('truetype'),url(sourcesans.svg#source_sans_proregular) format('svg');}
|
@@ -0,0 +1 @@
|
|
1
|
+
@font-face{font-family:SourceSansD;src:url(sourcesans.eot?#iefix) format('embedded-opentype'),url(sourcesans.woff) format('woff'),url(sourcesans.otf) format('opentype'),url(sourcesans.ttf) format('truetype'),url(sourcesans.svg#source_sans_proregular) format('svg');}
|
data/spec/index.html
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
<link rel="stylesheet" href="fixtures/fonts/nullfont2.css">
|
11
11
|
<link rel="stylesheet" href="fixtures/fonts/nullfont3.css">
|
12
12
|
<link rel="stylesheet" href="fixtures/fonts/sourcesansa.css">
|
13
|
+
<link rel="stylesheet" href="fixtures/fonts/sourcesansc.css">
|
13
14
|
</head>
|
14
15
|
<body>
|
15
16
|
<script>
|
@@ -34,6 +35,7 @@
|
|
34
35
|
<script src="../spec/core/font_spec.js"></script>
|
35
36
|
<script src="../spec/core/fontruler_spec.js"></script>
|
36
37
|
<script src="../spec/core/fontwatchrunner_spec.js"></script>
|
38
|
+
<script src="../spec/core/nativefontwatchrunner_spec.js"></script>
|
37
39
|
<script src="../spec/core/fontwatcher_spec.js"></script>
|
38
40
|
<script src="../spec/core/webfont_spec.js"></script>
|
39
41
|
<script src="../spec/core/version_spec.js"></script>
|
data/src/core/browserinfo.js
CHANGED
@@ -7,10 +7,11 @@ goog.provide('webfont.BrowserInfo');
|
|
7
7
|
* @param {boolean} webKitFallbackBug
|
8
8
|
* @param {boolean} webKitMetricsBug
|
9
9
|
*/
|
10
|
-
webfont.BrowserInfo = function (webfontSupport, webKitFallbackBug, webKitMetricsBug) {
|
10
|
+
webfont.BrowserInfo = function (webfontSupport, webKitFallbackBug, webKitMetricsBug, hasNativeFontLoading) {
|
11
11
|
this.webfontSupport_ = webfontSupport;
|
12
12
|
this.webKitFallbackBug_ = webKitFallbackBug;
|
13
13
|
this.webKitMetricsBug_ = webKitMetricsBug;
|
14
|
+
this.hasNativeFontLoading_ = hasNativeFontLoading;
|
14
15
|
};
|
15
16
|
|
16
17
|
goog.scope(function () {
|
@@ -70,4 +71,14 @@ goog.scope(function () {
|
|
70
71
|
BrowserInfo.prototype.hasWebKitMetricsBug = function () {
|
71
72
|
return this.webKitMetricsBug_;
|
72
73
|
};
|
74
|
+
|
75
|
+
/**
|
76
|
+
* @export
|
77
|
+
*
|
78
|
+
* Returns true if this browser has native font loading as
|
79
|
+
* specified in: http://dev.w3.org/csswg/css-font-loading/
|
80
|
+
*/
|
81
|
+
BrowserInfo.prototype.hasNativeFontLoading = function () {
|
82
|
+
return this.hasNativeFontLoading_;
|
83
|
+
};
|
73
84
|
});
|
data/src/core/font.js
CHANGED
@@ -41,6 +41,16 @@ goog.scope(function () {
|
|
41
41
|
return this.quote_(this.name_);
|
42
42
|
};
|
43
43
|
|
44
|
+
/**
|
45
|
+
* Returns a CSS string representation of the font that
|
46
|
+
* can be used as the CSS font property shorthand.
|
47
|
+
*
|
48
|
+
* @return {string}
|
49
|
+
*/
|
50
|
+
Font.prototype.toCssString = function () {
|
51
|
+
return this.getCssStyle() + ' ' + this.getCssWeight() + ' 300px ' + this.getCssName();
|
52
|
+
};
|
53
|
+
|
44
54
|
/**
|
45
55
|
* @private
|
46
56
|
* @param {string} name
|
@@ -71,8 +81,21 @@ goog.scope(function () {
|
|
71
81
|
* @return {string}
|
72
82
|
*/
|
73
83
|
Font.prototype.getCssVariation = function () {
|
74
|
-
|
75
|
-
|
84
|
+
return 'font-style:' + this.getCssStyle() + ';font-weight:' + this.getCssWeight() + ';';
|
85
|
+
};
|
86
|
+
|
87
|
+
/**
|
88
|
+
* @return {string}
|
89
|
+
*/
|
90
|
+
Font.prototype.getCssWeight = function () {
|
91
|
+
return this.weight_ + '00';
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @return {string}
|
96
|
+
*/
|
97
|
+
Font.prototype.getCssStyle = function () {
|
98
|
+
var style = 'normal';
|
76
99
|
|
77
100
|
if (this.style_ === 'o') {
|
78
101
|
style = 'oblique';
|
@@ -80,7 +103,7 @@ goog.scope(function () {
|
|
80
103
|
style = 'italic';
|
81
104
|
}
|
82
105
|
|
83
|
-
return
|
106
|
+
return style;
|
84
107
|
};
|
85
108
|
|
86
109
|
/**
|
data/src/core/fontwatcher.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
goog.provide('webfont.FontWatcher');
|
2
2
|
|
3
3
|
goog.require('webfont.FontWatchRunner');
|
4
|
-
|
4
|
+
goog.require('webfont.NativeFontWatchRunner');
|
5
5
|
/**
|
6
6
|
* @constructor
|
7
7
|
* @param {webfont.UserAgent} userAgent
|
@@ -22,7 +22,8 @@ webfont.FontWatcher = function(userAgent, domHelper, eventDispatcher, opt_timeou
|
|
22
22
|
|
23
23
|
goog.scope(function () {
|
24
24
|
var FontWatcher = webfont.FontWatcher,
|
25
|
-
FontWatchRunner = webfont.FontWatchRunner
|
25
|
+
FontWatchRunner = webfont.FontWatchRunner,
|
26
|
+
NativeFontWatchRunner = webfont.NativeFontWatchRunner;
|
26
27
|
|
27
28
|
/**
|
28
29
|
* Watches a set of font families.
|
@@ -53,7 +54,19 @@ goog.scope(function () {
|
|
53
54
|
|
54
55
|
this.eventDispatcher_.dispatchFontLoading(font);
|
55
56
|
|
56
|
-
var fontWatchRunner =
|
57
|
+
var fontWatchRunner = null;
|
58
|
+
|
59
|
+
if (this.browserInfo_.hasNativeFontLoading()) {
|
60
|
+
fontWatchRunner = new NativeFontWatchRunner(
|
61
|
+
goog.bind(this.fontActive_, this),
|
62
|
+
goog.bind(this.fontInactive_, this),
|
63
|
+
this.domHelper_,
|
64
|
+
font,
|
65
|
+
this.timeout_,
|
66
|
+
fontTestString
|
67
|
+
);
|
68
|
+
} else {
|
69
|
+
fontWatchRunner = new FontWatchRunner(
|
57
70
|
goog.bind(this.fontActive_, this),
|
58
71
|
goog.bind(this.fontInactive_, this),
|
59
72
|
this.domHelper_,
|
@@ -63,6 +76,7 @@ goog.scope(function () {
|
|
63
76
|
metricCompatibleFonts,
|
64
77
|
fontTestString
|
65
78
|
);
|
79
|
+
}
|
66
80
|
|
67
81
|
fontWatchRunner.start();
|
68
82
|
}
|
data/src/core/fontwatchrunner.js
CHANGED
@@ -23,7 +23,7 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
|
|
23
23
|
this.fontTestString_ = opt_fontTestString || webfont.FontWatchRunner.DEFAULT_TEST_STRING;
|
24
24
|
this.browserInfo_ = browserInfo;
|
25
25
|
this.lastResortWidths_ = {};
|
26
|
-
this.timeout_ = opt_timeout ||
|
26
|
+
this.timeout_ = opt_timeout || 3000;
|
27
27
|
|
28
28
|
this.metricCompatibleFonts_ = opt_metricCompatibleFonts || null;
|
29
29
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
goog.provide('webfont.NativeFontWatchRunner');
|
2
|
+
|
3
|
+
goog.require('webfont.Font');
|
4
|
+
|
5
|
+
goog.scope(function () {
|
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 {number=} opt_timeout
|
13
|
+
* @param {string=} opt_fontTestString
|
14
|
+
*/
|
15
|
+
webfont.NativeFontWatchRunner = function(activeCallback, inactiveCallback, domHelper, font, opt_timeout, opt_fontTestString) {
|
16
|
+
this.activeCallback_ = activeCallback;
|
17
|
+
this.inactiveCallback_ = inactiveCallback;
|
18
|
+
this.font_ = font;
|
19
|
+
this.domHelper_ = domHelper;
|
20
|
+
this.timeout_ = opt_timeout || 3000;
|
21
|
+
this.fontTestString_ = opt_fontTestString || undefined;
|
22
|
+
};
|
23
|
+
|
24
|
+
var NativeFontWatchRunner = webfont.NativeFontWatchRunner;
|
25
|
+
|
26
|
+
NativeFontWatchRunner.prototype.start = function () {
|
27
|
+
var doc = this.domHelper_.getLoadWindow().document,
|
28
|
+
that = this;
|
29
|
+
|
30
|
+
// We're using Promises here because the font load API
|
31
|
+
// uses them, so we can be sure they're available.
|
32
|
+
Promise.race([new Promise(function (resolve, reject) {
|
33
|
+
goog.global.setTimeout(function () {
|
34
|
+
reject(that.font_);
|
35
|
+
}, that.timeout_);
|
36
|
+
}), doc.fonts.load(this.font_.toCssString(), this.fontTestString_)]).then(function (fonts) {
|
37
|
+
if (fonts.length === 1) {
|
38
|
+
that.activeCallback_(that.font_);
|
39
|
+
} else {
|
40
|
+
that.inactiveCallback_(that.font_);
|
41
|
+
}
|
42
|
+
}, function () {
|
43
|
+
that.inactiveCallback_(that.font_);
|
44
|
+
});
|
45
|
+
};
|
46
|
+
});
|
data/src/core/useragentparser.js
CHANGED
@@ -44,7 +44,7 @@ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
|
|
44
44
|
new webfont.Version(),
|
45
45
|
webfont.UserAgentParser.UNKNOWN,
|
46
46
|
undefined,
|
47
|
-
new webfont.BrowserInfo(false, false, false));
|
47
|
+
new webfont.BrowserInfo(false, false, false, false));
|
48
48
|
|
49
49
|
|
50
50
|
goog.scope(function () {
|
@@ -191,7 +191,7 @@ goog.scope(function () {
|
|
191
191
|
platformVersion,
|
192
192
|
platformVersionString,
|
193
193
|
documentMode,
|
194
|
-
new BrowserInfo(supportWebFont, false, false)
|
194
|
+
new BrowserInfo(supportWebFont, false, false, !!this.doc_['fonts'])
|
195
195
|
);
|
196
196
|
};
|
197
197
|
|
@@ -246,7 +246,7 @@ goog.scope(function () {
|
|
246
246
|
platformVersion,
|
247
247
|
platformVersionString,
|
248
248
|
documentMode,
|
249
|
-
new BrowserInfo(false, false, false)
|
249
|
+
new BrowserInfo(false, false, false, !!this.doc_['fonts'])
|
250
250
|
);
|
251
251
|
}
|
252
252
|
|
@@ -267,7 +267,7 @@ goog.scope(function () {
|
|
267
267
|
platformVersion,
|
268
268
|
platformVersionString,
|
269
269
|
documentMode,
|
270
|
-
new BrowserInfo(browserVersion.major >= 10, false, false)
|
270
|
+
new BrowserInfo(browserVersion.major >= 10, false, false, !!this.doc_['fonts'])
|
271
271
|
);
|
272
272
|
}
|
273
273
|
}
|
@@ -286,7 +286,7 @@ goog.scope(function () {
|
|
286
286
|
platformVersion,
|
287
287
|
platformVersionString,
|
288
288
|
documentMode,
|
289
|
-
new BrowserInfo(browserVersion.major >= 10, false, false)
|
289
|
+
new BrowserInfo(browserVersion.major >= 10, false, false, !!this.doc_['fonts'])
|
290
290
|
);
|
291
291
|
}
|
292
292
|
return new UserAgent(
|
@@ -300,7 +300,7 @@ goog.scope(function () {
|
|
300
300
|
platformVersion,
|
301
301
|
platformVersionString,
|
302
302
|
documentMode,
|
303
|
-
new BrowserInfo(false, false, false)
|
303
|
+
new BrowserInfo(false, false, false, !!this.doc_['fonts'])
|
304
304
|
);
|
305
305
|
};
|
306
306
|
|
@@ -386,7 +386,7 @@ goog.scope(function () {
|
|
386
386
|
platformVersion,
|
387
387
|
platformVersionString,
|
388
388
|
this.getDocumentMode_(this.doc_),
|
389
|
-
new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug)
|
389
|
+
new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug, !!this.doc_['fonts'])
|
390
390
|
);
|
391
391
|
};
|
392
392
|
|
@@ -438,7 +438,7 @@ goog.scope(function () {
|
|
438
438
|
platformVersion,
|
439
439
|
platformVersionString,
|
440
440
|
this.getDocumentMode_(this.doc_),
|
441
|
-
new BrowserInfo(supportWebFont, false, false)
|
441
|
+
new BrowserInfo(supportWebFont, false, false, !!this.doc_['fonts'])
|
442
442
|
);
|
443
443
|
};
|
444
444
|
|
data/src/modules.yml
CHANGED
data/tools/compiler/base.js
CHANGED
@@ -1473,65 +1473,6 @@ goog.inherits = function(childCtor, parentCtor) {
|
|
1473
1473
|
childCtor.prototype.constructor = childCtor;
|
1474
1474
|
};
|
1475
1475
|
|
1476
|
-
|
1477
|
-
/**
|
1478
|
-
* Call up to the superclass.
|
1479
|
-
*
|
1480
|
-
* If this is called from a constructor, then this calls the superclass
|
1481
|
-
* contructor with arguments 1-N.
|
1482
|
-
*
|
1483
|
-
* If this is called from a prototype method, then you must pass
|
1484
|
-
* the name of the method as the second argument to this function. If
|
1485
|
-
* you do not, you will get a runtime error. This calls the superclass'
|
1486
|
-
* method with arguments 2-N.
|
1487
|
-
*
|
1488
|
-
* This function only works if you use goog.inherits to express
|
1489
|
-
* inheritance relationships between your classes.
|
1490
|
-
*
|
1491
|
-
* This function is a compiler primitive. At compile-time, the
|
1492
|
-
* compiler will do macro expansion to remove a lot of
|
1493
|
-
* the extra overhead that this function introduces. The compiler
|
1494
|
-
* will also enforce a lot of the assumptions that this function
|
1495
|
-
* makes, and treat it as a compiler error if you break them.
|
1496
|
-
*
|
1497
|
-
* @param {!Object} me Should always be "this".
|
1498
|
-
* @param {*=} opt_methodName The method name if calling a super method.
|
1499
|
-
* @param {...*} var_args The rest of the arguments.
|
1500
|
-
* @return {*} The return value of the superclass method.
|
1501
|
-
*/
|
1502
|
-
goog.base = function(me, opt_methodName, var_args) {
|
1503
|
-
var caller = arguments.callee.caller;
|
1504
|
-
if (caller.superClass_) {
|
1505
|
-
// This is a constructor. Call the superclass constructor.
|
1506
|
-
return caller.superClass_.constructor.apply(
|
1507
|
-
me, Array.prototype.slice.call(arguments, 1));
|
1508
|
-
}
|
1509
|
-
|
1510
|
-
var args = Array.prototype.slice.call(arguments, 2);
|
1511
|
-
var foundCaller = false;
|
1512
|
-
for (var ctor = me.constructor;
|
1513
|
-
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
1514
|
-
if (ctor.prototype[opt_methodName] === caller) {
|
1515
|
-
foundCaller = true;
|
1516
|
-
} else if (foundCaller) {
|
1517
|
-
return ctor.prototype[opt_methodName].apply(me, args);
|
1518
|
-
}
|
1519
|
-
}
|
1520
|
-
|
1521
|
-
// If we did not find the caller in the prototype chain,
|
1522
|
-
// then one of two things happened:
|
1523
|
-
// 1) The caller is an instance method.
|
1524
|
-
// 2) This method was not called by the right caller.
|
1525
|
-
if (me[opt_methodName] === caller) {
|
1526
|
-
return me.constructor.prototype[opt_methodName].apply(me, args);
|
1527
|
-
} else {
|
1528
|
-
throw Error(
|
1529
|
-
'goog.base called from a method of one name ' +
|
1530
|
-
'to a method of a different name');
|
1531
|
-
}
|
1532
|
-
};
|
1533
|
-
|
1534
|
-
|
1535
1476
|
/**
|
1536
1477
|
* Allow for aliasing within scope functions. This function exists for
|
1537
1478
|
* uncompiled code - in compiled code the calls will be inlined and the
|
data/tools/compiler/compiler.jar
CHANGED
Binary file
|
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.5.
|
17
|
-
s.date = '2014-
|
16
|
+
s.version = '1.5.7'
|
17
|
+
s.date = '2014-11-17'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -117,6 +117,7 @@ DESC
|
|
117
117
|
spec/core/fontruler_spec.js
|
118
118
|
spec/core/fontwatcher_spec.js
|
119
119
|
spec/core/fontwatchrunner_spec.js
|
120
|
+
spec/core/nativefontwatchrunner_spec.js
|
120
121
|
spec/core/size_spec.js
|
121
122
|
spec/core/useragentparser_spec.js
|
122
123
|
spec/core/version_spec.js
|
@@ -136,6 +137,8 @@ DESC
|
|
136
137
|
spec/fixtures/fonts/sourcesans.woff
|
137
138
|
spec/fixtures/fonts/sourcesansa.css
|
138
139
|
spec/fixtures/fonts/sourcesansb.css
|
140
|
+
spec/fixtures/fonts/sourcesansc.css
|
141
|
+
spec/fixtures/fonts/sourcesansd.css
|
139
142
|
spec/index.html
|
140
143
|
spec/modules/custom_spec.js
|
141
144
|
spec/modules/fontdeck_spec.js
|
@@ -156,6 +159,7 @@ DESC
|
|
156
159
|
src/core/fontwatcher.js
|
157
160
|
src/core/fontwatchrunner.js
|
158
161
|
src/core/initialize.js
|
162
|
+
src/core/nativefontwatchrunner.js
|
159
163
|
src/core/useragent.js
|
160
164
|
src/core/useragentparser.js
|
161
165
|
src/core/version.js
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Carver
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- spec/core/fontruler_spec.js
|
127
127
|
- spec/core/fontwatcher_spec.js
|
128
128
|
- spec/core/fontwatchrunner_spec.js
|
129
|
+
- spec/core/nativefontwatchrunner_spec.js
|
129
130
|
- spec/core/size_spec.js
|
130
131
|
- spec/core/useragentparser_spec.js
|
131
132
|
- spec/core/version_spec.js
|
@@ -145,6 +146,8 @@ files:
|
|
145
146
|
- spec/fixtures/fonts/sourcesans.woff
|
146
147
|
- spec/fixtures/fonts/sourcesansa.css
|
147
148
|
- spec/fixtures/fonts/sourcesansb.css
|
149
|
+
- spec/fixtures/fonts/sourcesansc.css
|
150
|
+
- spec/fixtures/fonts/sourcesansd.css
|
148
151
|
- spec/index.html
|
149
152
|
- spec/modules/custom_spec.js
|
150
153
|
- spec/modules/fontdeck_spec.js
|
@@ -165,6 +168,7 @@ files:
|
|
165
168
|
- src/core/fontwatcher.js
|
166
169
|
- src/core/fontwatchrunner.js
|
167
170
|
- src/core/initialize.js
|
171
|
+
- src/core/nativefontwatchrunner.js
|
168
172
|
- src/core/useragent.js
|
169
173
|
- src/core/useragentparser.js
|
170
174
|
- src/core/version.js
|