fixes #2142 removing sans-serif and monospace from font preloader
diff --git a/player/js/animation/AnimationItem.js b/player/js/animation/AnimationItem.js
index f93c665..863efd6 100644
--- a/player/js/animation/AnimationItem.js
+++ b/player/js/animation/AnimationItem.js
@@ -229,7 +229,7 @@
if(!this.renderer) {
return;
}
- if(this.renderer.globalData.fontManager.loaded()){
+ if(this.renderer.globalData.fontManager.isLoaded){
this.checkLoaded();
}else{
setTimeout(this.waitForFontsLoaded.bind(this),20);
@@ -237,7 +237,10 @@
}
AnimationItem.prototype.checkLoaded = function () {
- if (!this.isLoaded && this.renderer.globalData.fontManager.loaded() && (this.imagePreloader.loaded() || this.renderer.rendererType !== 'canvas')) {
+ if (!this.isLoaded
+ && this.renderer.globalData.fontManager.isLoaded
+ && (this.imagePreloader.loaded() || this.renderer.rendererType !== 'canvas')
+ ) {
this.isLoaded = true;
dataManager.completeData(this.animationData, this.renderer.globalData.fontManager);
if(expressionsPlugin){
diff --git a/player/js/utils/FontManager.js b/player/js/utils/FontManager.js
index 80b0dca..f847ff8 100644
--- a/player/js/utils/FontManager.js
+++ b/player/js/utils/FontManager.js
@@ -12,6 +12,18 @@
, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379
, 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]);
+ function trimFontOptions(font) {
+ var familyArray = font.split(',');
+ var i, len = familyArray.length;
+ var enabledFamilies = [];
+ for (i = 0; i < len; i += 1) {
+ if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') {
+ enabledFamilies.push(familyArray[i]);
+ }
+ }
+ return enabledFamilies.join(',');
+ }
+
function setUpNode(font, family){
var parentNode = createTag('span');
parentNode.style.fontFamily = family;
@@ -34,7 +46,7 @@
// Remember width with no applied web font
var width = node.offsetWidth;
- node.style.fontFamily = font + ', '+family;
+ node.style.fontFamily = trimFontOptions(font) + ', ' + family;
return {node:node, w:width, parent:parentNode};
}
@@ -71,9 +83,9 @@
}
if(loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime){
- setTimeout(this.checkLoadedFonts.bind(this),20);
+ setTimeout(this.checkLoadedFontsBinded, 20);
}else{
- setTimeout(function(){this.isLoaded = true;}.bind(this),0);
+ setTimeout(this.setIsLoadedBinded, 10);
}
}
@@ -269,8 +281,8 @@
return combinedCharacters;
}
- function loaded() {
- return this.isLoaded;
+ function setIsLoaded() {
+ this.isLoaded = true
}
var Font = function(){
@@ -279,17 +291,23 @@
this.typekitLoaded = 0;
this.isLoaded = false;
this.initTime = Date.now();
+ this.setIsLoadedBinded = this.setIsLoaded.bind(this)
+ this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this)
};
//TODO: for now I'm adding these methods to the Class and not the prototype. Think of a better way to implement it.
Font.getCombinedCharacterCodes = getCombinedCharacterCodes;
- Font.prototype.addChars = addChars;
- Font.prototype.addFonts = addFonts;
- Font.prototype.getCharData = getCharData;
- Font.prototype.getFontByName = getFontByName;
- Font.prototype.measureText = measureText;
- Font.prototype.checkLoadedFonts = checkLoadedFonts;
- Font.prototype.loaded = loaded;
+ var fontPrototype = {
+ addChars: addChars,
+ addFonts: addFonts,
+ getCharData: getCharData,
+ getFontByName: getFontByName,
+ measureText: measureText,
+ checkLoadedFonts: checkLoadedFonts,
+ setIsLoaded: setIsLoaded,
+ }
+
+ Font.prototype = fontPrototype;
return Font;