mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Start adding a FontLoader class to isolate the font-loaded hack
This commit is contained in:
parent
40006194ea
commit
86f197daba
2 changed files with 41 additions and 47 deletions
35
viewer.js
35
viewer.js
|
@ -3,7 +3,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var pdfDocument, canvas, pageDisplay, pageNum, numPages, pageInterval;
|
||||
var pdfDocument, canvas, pageDisplay, pageNum, numPages, pageTimeout;
|
||||
function load(userInput) {
|
||||
canvas = document.getElementById("canvas");
|
||||
canvas.mozOpaque = true;
|
||||
|
@ -52,7 +52,7 @@ function gotoPage(num) {
|
|||
}
|
||||
|
||||
function displayPage(num) {
|
||||
window.clearInterval(pageInterval);
|
||||
window.clearTimeout(pageTimeout);
|
||||
|
||||
document.getElementById("pageNumber").value = num;
|
||||
|
||||
|
@ -75,28 +75,12 @@ function displayPage(num) {
|
|||
page.compile(gfx, fonts);
|
||||
var t2 = Date.now();
|
||||
|
||||
var fontsReady = true;
|
||||
|
||||
// Inspect fonts and translate the missing one
|
||||
var count = fonts.length;
|
||||
for (var i = 0; i < count; i++) {
|
||||
var font = fonts[i];
|
||||
if (Fonts[font.name]) {
|
||||
fontsReady = fontsReady && !Fonts[font.name].loading;
|
||||
continue;
|
||||
function loadFont() {
|
||||
if (!FontsLoader.bind(fonts)) {
|
||||
pageTimeout = window.setTimeout(loadFont, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
new Font(font.name, font.file, font.properties);
|
||||
fontsReady = false;
|
||||
}
|
||||
|
||||
function delayLoadFont() {
|
||||
for (var i = 0; i < count; i++) {
|
||||
if (Fonts[font.name].loading)
|
||||
return;
|
||||
}
|
||||
window.clearInterval(pageInterval);
|
||||
|
||||
var t3 = Date.now();
|
||||
|
||||
page.display(gfx);
|
||||
|
@ -106,12 +90,7 @@ function displayPage(num) {
|
|||
var infoDisplay = document.getElementById("info");
|
||||
infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
|
||||
};
|
||||
|
||||
if (fontsReady) {
|
||||
delayLoadFont();
|
||||
} else {
|
||||
pageInterval = setInterval(delayLoadFont, 10);
|
||||
}
|
||||
loadFont();
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue