*/
var FontLoader = {
scratchCtx: null,
+ loading: {},
/**
* Create the canvas used for measuring the width of text.
* the font is loaded.
*/
bind: function(objId, fontObj) {
- console.log("load font", objId);
+ this.loading[objId] = true;
var encoding = fontObj.encoding;
- var testStr = "";
- // If the font has a encoding defined. If, use the characters of the
- // encoding, otherwise use some dump string for testing.
- if (Object.keys(encoding).length != 0) {
+
+ // If the font has an encoding, build the test string based on it. If the
+ // font doesn't have an encoding, the font can't been used right now and
+ // we skip here.
+ if (fontObj.supported) {
+ var testStr = "";
for (var enc in encoding) {
testStr += String.fromCharCode(encoding[enc].unicode);
}
} else {
- console.log("empty font.encoding");
- testStr = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+='!";
+ // This font isn't fully supported yet. Resolve the object such that
+ // the execution continues but do nothing else.
+ Objects.resolve(objId);
+ return;
}
var before = this.measure(fontObj, testStr);
for (var i = 0; i < measure.length; i++) {
if (measure[i] !== before[i]) {
console.log("loaded font", objId);
+ delete this.loading[objId];
Objects.resolve(objId);
return;
}
this.$name1 = italic + ' ' + bold + ' ';
this.$name2 = 'px "' + name + '", "';
+
+ this.supported = Object.keys(this.encoding).length != 0;
};
function int16(bytes) {
this.moveText(0, this.current.leading);
},
showText: function(text) {
+ // If the current font isn't supported, we can't display the text and
+ // bail out.
+ if (!this.current.font.supported) {
+ return;
+ }
+
var ctx = this.ctx;
var current = this.current;
var originalText = text;
this.ctx.restore();
},
showSpacedText: function(arr) {
+ // If the current font isn't supported, we can't display the text and
+ // bail out.
+ if (!this.current.font.supported) {
+ return;
+ }
+
for (var i = 0; i < arr.length; ++i) {
var e = arr[i];
if (IsNum(e)) {