Skip to content

Commit

Permalink
fontLoadPromises -> fontsToLoad
Browse files Browse the repository at this point in the history
fontsToLoad is always an empty array, Promise.all should wait for
fontLoadPromises instead of fontsToLoad.
  • Loading branch information
Rob--W authored and pbrant committed May 8, 2017
1 parent 12ba25f commit 7304b22
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ var FontLoader = {
var rules = [];
var fontsToLoad = [];
var fontLoadPromises = [];
var getNativeFontPromise = function(nativeFontFace) {
// Return a promise that is always fulfilled, even when the font fails to
// load.
return nativeFontFace.loaded.catch(function(e) {
warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
});
};
for (var i = 0, ii = fonts.length; i < ii; i++) {
var font = fonts[i];

Expand All @@ -132,7 +139,7 @@ var FontLoader = {
if (this.isFontLoadingAPISupported) {
var nativeFontFace = font.createNativeFontFace();
if (nativeFontFace) {
fontLoadPromises.push(nativeFontFace.loaded);
fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
}
} else {
var rule = font.bindDOM();
Expand All @@ -145,7 +152,7 @@ var FontLoader = {

var request = FontLoader.queueLoadingCallback(callback);
if (this.isFontLoadingAPISupported) {
Promise.all(fontsToLoad).then(function() {
Promise.all(fontLoadPromises).then(function() {
request.complete();
});
} else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
Expand Down

0 comments on commit 7304b22

Please sign in to comment.