just create one dummy element too, and centralize hackery
This commit is contained in:
parent
9bc06a9924
commit
6b72f8e98a
49
fonts.js
49
fonts.js
@ -149,7 +149,11 @@ var FontLoader = {
|
|||||||
for (var j = 0; j < length; j++)
|
for (var j = 0; j < length; j++)
|
||||||
str += String.fromCharCode(data[j]);
|
str += String.fromCharCode(data[j]);
|
||||||
|
|
||||||
worker ? obj.bindWorker(str) : obj.bindDOM(str, rules, names);
|
var rule = worker ? obj.bindWorker(str) : obj.bindDOM(str);
|
||||||
|
if (rule) {
|
||||||
|
rules.push(rule);
|
||||||
|
names.push(font.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,14 +186,25 @@ var FontLoader = {
|
|||||||
// our @font-face rule was loaded. However, the subdocument and
|
// our @font-face rule was loaded. However, the subdocument and
|
||||||
// outer document can't share CSS rules, so the inner document
|
// outer document can't share CSS rules, so the inner document
|
||||||
// is only part of the puzzle. The second piece is an invisible
|
// is only part of the puzzle. The second piece is an invisible
|
||||||
// paragraph created in order to force loading of the @font-face
|
// div created in order to force loading of the @font-face in
|
||||||
// in the *outer* document. (The font still needs to be loaded
|
// the *outer* document. (The font still needs to be loaded for
|
||||||
// for its metrics, for reflow). We create the <p> first (in
|
// its metrics, for reflow). We create the div first for the
|
||||||
// |bindDom()| function below), for the outer document, then
|
// outer document, then create the iframe. Unless something
|
||||||
// create the iframe. Unless something goes really wonkily, we
|
// goes really wonkily, we expect the @font-face for the outer
|
||||||
// expect the @font-face for the outer document to be processed
|
// document to be processed before the inner. That's still
|
||||||
// before the inner. That's still fragile, but seems to work in
|
// fragile, but seems to work in practice.
|
||||||
// practice.
|
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.setAttribute("style",
|
||||||
|
'visibility: hidden;'+
|
||||||
|
'width: 10px; height: 10px;'+
|
||||||
|
'position: absolute; top: 0px; left: 0px;');
|
||||||
|
var html = '';
|
||||||
|
for (var i = 0; i < names.length; ++i) {
|
||||||
|
html += '<span style="font-family:'+ names[i] +'">Hi</span>';
|
||||||
|
}
|
||||||
|
div.innerHTML = html;
|
||||||
|
document.body.appendChild(div);
|
||||||
|
|
||||||
// XXX we should have a time-out here too, and maybe fire
|
// XXX we should have a time-out here too, and maybe fire
|
||||||
// pdfjsFontLoadFailed?
|
// pdfjsFontLoadFailed?
|
||||||
@ -218,7 +233,7 @@ var FontLoader = {
|
|||||||
src += ' }';
|
src += ' }';
|
||||||
src += '</script></head><body>';
|
src += '</script></head><body>';
|
||||||
for (var i = 0; i < names.length; ++i) {
|
for (var i = 0; i < names.length; ++i) {
|
||||||
src += '<p style="font-family:\''+ fontName +'\'">Hello</p>';
|
src += '<p style="font-family:\''+ fontName +'\'">Hi</p>';
|
||||||
}
|
}
|
||||||
src += '</body></html>';
|
src += '</body></html>';
|
||||||
var frame = document.createElement("iframe");
|
var frame = document.createElement("iframe");
|
||||||
@ -891,7 +906,7 @@ var Font = (function () {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
bindDOM: function font_bindDom(data, rules, names) {
|
bindDOM: function font_bindDom(data) {
|
||||||
var fontName = this.name;
|
var fontName = this.name;
|
||||||
|
|
||||||
// Add the @font-face rule to the document
|
// Add the @font-face rule to the document
|
||||||
@ -900,17 +915,7 @@ var Font = (function () {
|
|||||||
var styleSheet = document.styleSheets[0];
|
var styleSheet = document.styleSheets[0];
|
||||||
styleSheet.insertRule(rule, styleSheet.length);
|
styleSheet.insertRule(rule, styleSheet.length);
|
||||||
|
|
||||||
var p = document.createElement("p");
|
return rule;
|
||||||
p.setAttribute("style",
|
|
||||||
'font-family: "'+ fontName +'";'+
|
|
||||||
'visibility: hidden;'+
|
|
||||||
'width: 10px; height: 10px;'+
|
|
||||||
'position: absolute; top: 0px; left: 0px;');
|
|
||||||
p.innerHTML = 'Hello';
|
|
||||||
document.body.appendChild(p);
|
|
||||||
|
|
||||||
rules.push(rule);
|
|
||||||
names.push(fontName);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user