update test_slave for the new font-loading API
This commit is contained in:
parent
5d1ed2405c
commit
bfff2ba63f
@ -88,43 +88,29 @@ function nextPage() {
|
|||||||
clear(ctx);
|
clear(ctx);
|
||||||
|
|
||||||
var fonts = [];
|
var fonts = [];
|
||||||
var fontsReady = true;
|
|
||||||
var gfx = new CanvasGraphics(ctx);
|
var gfx = new CanvasGraphics(ctx);
|
||||||
try {
|
try {
|
||||||
currentPage = pdfDoc.getPage(currentTask.pageNum);
|
currentPage = pdfDoc.getPage(currentTask.pageNum);
|
||||||
currentPage.compile(gfx, fonts);
|
currentPage.compile(gfx, fonts);
|
||||||
|
|
||||||
// Inspect fonts and translate the missing ones
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
new Font(font.name, font.file, font.properties);
|
|
||||||
fontsReady = false;
|
|
||||||
}
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
failure = 'compile: '+ e.toString();
|
failure = 'compile: '+ e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkFontsLoadedIntervalTimer = null;
|
var fontLoaderTimer = null;
|
||||||
function checkFontsLoaded() {
|
function checkFontsLoaded() {
|
||||||
for (var i = 0; i < count; i++) {
|
if (!FontLoader.bind(fonts)) {
|
||||||
if (Fonts[font.name].loading) {
|
fontLoaderTimer = window.setTimeout(checkFontsLoaded, 10);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
window.clearInterval(checkFontsLoadedIntervalTimer);
|
|
||||||
|
|
||||||
snapshotCurrentPage(gfx);
|
snapshotCurrentPage(gfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failure || fontsReady) {
|
if (failure) {
|
||||||
|
// Skip font loading if there was a failure, since the fonts might
|
||||||
|
// be in an inconsistent state.
|
||||||
snapshotCurrentPage(gfx);
|
snapshotCurrentPage(gfx);
|
||||||
} else {
|
} else {
|
||||||
checkFontsLoadedIntervalTimer = setInterval(checkFontsLoaded, 10);
|
checkFontsLoaded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user