diff --git a/fonts.js b/fonts.js index ff176c264..0de8fd379 100755 --- a/fonts.js +++ b/fonts.js @@ -290,152 +290,69 @@ var FontLoader = { return rule; }, - bind: function(fonts, callback) { + bind: function(fontObj) { // If this isn't Gecko, we assume it's WebKit. See notes in bindWebKit. if (!isGecko) { - var fontObj = fonts[0]; this.bindWebKit(fontObj.loadedName, fontObj); - return; + } else { + var rule = this.bindDOM(fontObj); + FontLoader.prepareFontLoadEvent(fontObj, rule); } - - function checkFontsLoaded() { - for (var i = 0; i < objs.length; i++) { - var fontObj = objs[i]; - if (fontObj.loading) { - return false; - } - } + }, - document.documentElement.removeEventListener( - 'pdfjsFontLoad', checkFontsLoaded, false); + // Set things up so that at least one pdfjsFontLoad event is + // dispatched when all the @font-face |rules| for |names| have been + // loaded in a subdocument. It's expected that the load of |rules| + // has already started in this (outer) document, so that they should + // be ordered before the load in the subdocument. + prepareFontLoadEvent: function(fontObj, rule) { + /** Hack begin */ + // There's no event when a font has finished downloading so the + // following code is a dirty hack to 'guess' when a font is + // ready. This code will be obsoleted by Mozilla bug 471915. + // + // The only reliable way to know if a font is loaded in Gecko + // (at the moment) is document.onload in a document with + // a @font-face rule defined in a "static" stylesheet. We use a + // subdocument in an