mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Merge with upstream, reverse changeset 4e24288
since it brokes TTF on linux
This commit is contained in:
commit
dd923d5aea
28 changed files with 2946 additions and 416 deletions
46
fonts.js
46
fonts.js
|
@ -34,7 +34,7 @@ var kDisableFonts = false;
|
|||
* http://cgit.freedesktop.org/poppler/poppler/tree/poppler/GfxFont.cc#n65
|
||||
*/
|
||||
|
||||
var kScalePrecision = 100;
|
||||
var kScalePrecision = 40;
|
||||
var Fonts = {
|
||||
_active: null,
|
||||
|
||||
|
@ -68,8 +68,8 @@ var Fonts = {
|
|||
var unicode = encoding[charcode];
|
||||
|
||||
// Check if the glyph has already been converted
|
||||
if (unicode instanceof Name)
|
||||
unicode = encoding[unicode] = GlyphsUnicode[unicode.name];
|
||||
if (!IsNum(unicode))
|
||||
unicode = encoding[unicode] = GlyphsUnicode[unicode.name];
|
||||
|
||||
// Handle surrogate pairs
|
||||
if (unicode > 0xFFFF) {
|
||||
|
@ -95,7 +95,7 @@ var Fonts = {
|
|||
}
|
||||
};
|
||||
|
||||
var FontsLoader = {
|
||||
var FontLoader = {
|
||||
bind: function(fonts) {
|
||||
var worker = (typeof window == "undefined");
|
||||
var ready = true;
|
||||
|
@ -105,10 +105,10 @@ var FontsLoader = {
|
|||
if (Fonts[font.name]) {
|
||||
ready = ready && !Fonts[font.name].loading;
|
||||
continue;
|
||||
} else {
|
||||
ready = false;
|
||||
}
|
||||
|
||||
ready = false;
|
||||
|
||||
var obj = new Font(font.name, font.file, font.properties);
|
||||
|
||||
var str = "";
|
||||
|
@ -180,6 +180,7 @@ var Font = (function () {
|
|||
warn("Font " + properties.type + " is not supported");
|
||||
break;
|
||||
}
|
||||
this.data = data;
|
||||
|
||||
Fonts[name] = {
|
||||
data: data,
|
||||
|
@ -793,9 +794,18 @@ var Font = (function () {
|
|||
});
|
||||
},
|
||||
|
||||
bindDOM: function font_bindDom(data) {
|
||||
bindDOM: function font_bindDom(data, callback) {
|
||||
var fontName = this.name;
|
||||
|
||||
// Just adding the font-face to the DOM doesn't make it load. It
|
||||
// seems it's loaded once Gecko notices it's used. Therefore,
|
||||
// add a div on the page using the loaded font.
|
||||
var div = document.createElement("div");
|
||||
var style = 'font-family:"' + name +
|
||||
'";position: absolute;top:-99999;left:-99999;z-index:-99999';
|
||||
div.setAttribute("style", style);
|
||||
document.body.appendChild(div);
|
||||
|
||||
/** Hack begin */
|
||||
// Actually there is not event when a font has finished downloading so
|
||||
// the following code are a dirty hack to 'guess' when a font is ready
|
||||
|
@ -815,15 +825,19 @@ var Font = (function () {
|
|||
|
||||
// For some reasons the font has not loaded, so mark it loaded for the
|
||||
// page to proceed but cry
|
||||
if ((Date.now() - this.start) >= kMaxWaitForFontFace) {
|
||||
window.clearInterval(interval);
|
||||
Fonts[fontName].loading = false;
|
||||
warn("Is " + fontName + " loaded?");
|
||||
this.start = 0;
|
||||
} else if (textWidth != ctx.measureText(testString).width) {
|
||||
window.clearInterval(interval);
|
||||
Fonts[fontName].loading = false;
|
||||
this.start = 0;
|
||||
if (textWidth == ctx.measureText(testString).width) {
|
||||
if ((Date.now() - this.start) < kMaxWaitForFontFace) {
|
||||
return;
|
||||
} else {
|
||||
warn("Is " + fontName + " loaded?");
|
||||
}
|
||||
}
|
||||
|
||||
window.clearInterval(interval);
|
||||
Fonts[fontName].loading = false;
|
||||
this.start = 0;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}, 30, this);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue