From e3dd329739ac1b89fc7263041becccfa42f4bc52 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Mon, 5 Sep 2011 16:40:15 -0700 Subject: [PATCH] Move ensureFont code part of Page into its own function --- pdf.js | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/pdf.js b/pdf.js index 7122c0eb4..475137475 100644 --- a/pdf.js +++ b/pdf.js @@ -3356,6 +3356,7 @@ var Page = (function() { } return shadow(this, 'rotate', rotate); }, + startRendering: function(canvasCtx, continuation) { var self = this; var stats = self.stats; @@ -3399,28 +3400,14 @@ var Page = (function() { fonts.push(font); } - var fontObjs = FontLoader.bind( - fonts, - function() { - // Rebuild the FontsMap. This is emulating the behavior of the main - // thread. - if (fontObjs) { - // Replace the FontsMap hash with the fontObjs. - for (var i = 0; i < fontObjs.length; i++) { - FontsMap[fontObjs[i].loadedName] = {fontObj: fontObjs[i]}; - } - } - - stats.fonts = Date.now(); - images.notifyOnLoad(function() { - stats.images = Date.now(); - displayContinuation(); - }); - } - ); + this.ensureFonts(fonts, function() { + images.notifyOnLoad(function() { + stats.images = Date.now(); + displayContinuation(); + }); + }) }, - compile: function(gfx, fonts, images) { if (this.code) { // content was compiled @@ -3439,6 +3426,27 @@ var Page = (function() { } this.code = gfx.compile(content, xref, resources, fonts, images); }, + + ensureFonts: function(fonts, callback) { + var fontObjs = FontLoader.bind( + fonts, + function() { + // Rebuild the FontsMap. This is emulating the behavior of the main + // thread. + if (fontObjs) { + // Replace the FontsMap hash with the fontObjs. + for (var i = 0; i < fontObjs.length; i++) { + FontsMap[fontObjs[i].loadedName] = {fontObj: fontObjs[i]}; + } + } + + this.stats.fonts = Date.now(); + + callback.call(this); + }.bind(this) + ); + }, + display: function(gfx) { assert(this.code instanceof Function, 'page content must be compiled first');