diff --git a/fonts.js b/fonts.js index 9d8a9e806..4a09931e5 100644 --- a/fonts.js +++ b/fonts.js @@ -137,6 +137,7 @@ var FontLoader = { return true; } + var rules = [ ], names = [ ]; for (var i = 0; i < fonts.length; i++) { var font = fonts[i]; if (!Fonts.lookup(font.name)) { @@ -148,16 +149,86 @@ var FontLoader = { for (var j = 0; j < length; j++) str += String.fromCharCode(data[j]); - worker ? obj.bindWorker(str) : obj.bindDOM(str); + worker ? obj.bindWorker(str) : obj.bindDOM(str, rules, names); } } + if (!worker && rules.length) { + FontLoader.prepareFontLoadEvent(rules, names); + } + if (!checkFontsLoaded()) { document.documentElement.addEventListener( "pdfjsFontLoad", checkFontsLoaded, false); } return; + }, + // 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(rules, names) { + /** 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