Be more forgiving if webfonts aren't loading
This commit is contained in:
@@ -10,6 +10,7 @@ import lime.graphics.ImageBuffer;
|
||||
import lime.math.Vector2;
|
||||
import lime.net.HTTPRequest;
|
||||
import lime.system.System;
|
||||
import lime.utils.Log;
|
||||
import lime.utils.UInt8Array;
|
||||
|
||||
#if (js && html5)
|
||||
@@ -457,17 +458,21 @@ class Font {
|
||||
#if (js && html5)
|
||||
|
||||
this.name = name;
|
||||
var font = name;
|
||||
|
||||
var ua = Browser.navigator.userAgent.toLowerCase();
|
||||
var isSafari = (ua.indexOf(" safari/") >= 0 && ua.indexOf(" chrome/") < 0);
|
||||
|
||||
if (!isSafari && untyped (Browser.document).fonts && untyped (Browser.document).fonts.load) {
|
||||
|
||||
untyped (Browser.document).fonts.load ("1em '" + font + "'").then (function (_) {
|
||||
untyped (Browser.document).fonts.load ("1em '" + name + "'").then (function (_) {
|
||||
|
||||
promise.complete (this);
|
||||
|
||||
}, function (_) {
|
||||
|
||||
Log.warn ("Could not load web font \"" + name + "\"");
|
||||
promise.complete (this);
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
@@ -482,12 +487,16 @@ class Font {
|
||||
var timeout = 3000;
|
||||
var intervalLength = 50;
|
||||
var intervalCount = 0;
|
||||
var loaded, timeExpired;
|
||||
|
||||
var checkFont = function () {
|
||||
|
||||
intervalCount++;
|
||||
|
||||
if ((node1.offsetWidth != width1 || node2.offsetWidth != width2) || (intervalCount * intervalLength >= timeout)) {
|
||||
loaded = (node1.offsetWidth != width1 || node2.offsetWidth != width2);
|
||||
timeExpired = (intervalCount * intervalLength >= timeout);
|
||||
|
||||
if (loaded || timeExpired) {
|
||||
|
||||
Browser.window.clearInterval (interval);
|
||||
node1.parentNode.removeChild (node1);
|
||||
@@ -495,6 +504,12 @@ class Font {
|
||||
node1 = null;
|
||||
node2 = null;
|
||||
|
||||
if (timeExpired) {
|
||||
|
||||
Log.warn ("Could not load web font \"" + name + "\"");
|
||||
|
||||
}
|
||||
|
||||
promise.complete (this);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user