Skip to content

Commit

Permalink
Fix a bug in webfont loading [skip travis] (#10106)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspackman committed Jan 29, 2021
1 parent cf32f52 commit d69dd8c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
18 changes: 9 additions & 9 deletions framework/source/class/qx/bom/webfonts/Manager.js
Expand Up @@ -198,9 +198,9 @@ qx.Class.define("qx.bom.webfonts.Manager", {
if (index !== null) {
qx.lang.Array.removeAt(this.__createdStyles, index);
}
if (familyName in this.__validators) {
this.__validators[familyName].dispose();
delete this.__validators[familyName];
if (fontLookupKey in this.__validators) {
this.__validators[fontLookupKey].dispose();
delete this.__validators[fontLookupKey];
}
},

Expand Down Expand Up @@ -335,18 +335,18 @@ qx.Class.define("qx.bom.webfonts.Manager", {
this.__createdStyles.push(fontLookupKey);
}

if (!this.__validators[familyName]) {
this.__validators[familyName] = new qx.bom.webfonts.Validator(familyName, comparisonString);
this.__validators[familyName].setTimeout(qx.bom.webfonts.Manager.VALIDATION_TIMEOUT);
this.__validators[familyName].addListenerOnce("changeStatus", this.__onFontChangeStatus, this);
if (!this.__validators[fontLookupKey]) {
this.__validators[fontLookupKey] = new qx.bom.webfonts.Validator(familyName, comparisonString, fontWeight, fontStyle);
this.__validators[fontLookupKey].setTimeout(qx.bom.webfonts.Manager.VALIDATION_TIMEOUT);
this.__validators[fontLookupKey].addListenerOnce("changeStatus", this.__onFontChangeStatus, this);
}

if (callback) {
var cbContext = context || window;
this.__validators[familyName].addListenerOnce("changeStatus", callback, cbContext);
this.__validators[fontLookupKey].addListenerOnce("changeStatus", callback, cbContext);
}

this.__validators[familyName].validate();
this.__validators[fontLookupKey].validate();
},


Expand Down
46 changes: 45 additions & 1 deletion framework/source/class/qx/bom/webfonts/Validator.js
Expand Up @@ -34,16 +34,24 @@ qx.Class.define("qx.bom.webfonts.Validator", {
/**
* @param fontFamily {String} The name of the font to be verified
* @param comparisonString {String?} String to be used to detect whether a font was loaded or not
* @param fontWeight {String?} the weight of the font to be verified
* @param fontStyle {String?} the style of the font to be verified
* whether the font has loaded properly
*/
construct : function(fontFamily, comparisonString)
construct : function(fontFamily, comparisonString, fontWeight, fontStyle)
{
this.base(arguments);

if (comparisonString) {
this.setComparisonString(comparisonString);
}

if (fontWeight) {
this.setFontWeight(fontWeight);
}
if (fontStyle) {
this.setFontStyle(fontStyle);
}
if (fontFamily) {
this.setFontFamily(fontFamily);
this.__requestedHelpers = this._getRequestedHelpers();
Expand Down Expand Up @@ -135,6 +143,20 @@ qx.Class.define("qx.bom.webfonts.Validator", {
apply : "_applyFontFamily"
},

/** The font weight to check */
fontWeight: {
nullable: true,
check: "String",
apply: "_applyFontWeight"
},

/** The font style to check */
fontStyle: {
nullable: true,
check: "String",
apply: "_applyFontStyle"
},

/**
* Comparison string used to check whether the font has loaded or not.
*/
Expand Down Expand Up @@ -312,6 +334,12 @@ qx.Class.define("qx.bom.webfonts.Validator", {
styleMap.fontFamily = fontFamily.join(",");
}
}
if (this.getFontWeight()) {
styleMap.fontWeight = this.getFontWeight();
}
if (this.getFontStyle()) {
styleMap.fontStyle = this.getFontStyle();
}

var elem = document.createElement("span");
elem.innerHTML = comparisonString || qx.bom.webfonts.Validator.COMPARISON_STRING;
Expand All @@ -329,6 +357,22 @@ qx.Class.define("qx.bom.webfonts.Validator", {
}
},

// property apply
_applyFontWeight : function(value, old)
{
if (value !== old) {
this._reset();
}
},

// property apply
_applyFontStyle : function(value, old)
{
if (value !== old) {
this._reset();
}
},



/*
Expand Down

0 comments on commit d69dd8c

Please sign in to comment.