Ensure dependent font data is available before calling startRenderingIRQueue
This commit is contained in:
parent
cc661f44af
commit
86b8f12b92
10
pdf.js
10
pdf.js
@ -3363,12 +3363,12 @@ var Page = (function() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// this.ensureFonts(fonts, function() {
|
this.ensureFonts(fonts, function() {
|
||||||
displayContinuation();
|
displayContinuation();
|
||||||
// });
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getIRQueue: function(handler) {
|
getIRQueue: function(handler, dependency) {
|
||||||
if (this.IRQueue) {
|
if (this.IRQueue) {
|
||||||
// content was compiled
|
// content was compiled
|
||||||
return this.IRQueue;
|
return this.IRQueue;
|
||||||
@ -3387,7 +3387,7 @@ var Page = (function() {
|
|||||||
|
|
||||||
var pe = this.pe = new PartialEvaluator();
|
var pe = this.pe = new PartialEvaluator();
|
||||||
var IRQueue = {};
|
var IRQueue = {};
|
||||||
return this.IRQueue = pe.getIRQueue(content, xref, resources, IRQueue, handler, "p" + this.pageNumber + "_");
|
return this.IRQueue = pe.getIRQueue(content, xref, resources, IRQueue, handler, "p" + this.pageNumber + "_", dependency);
|
||||||
},
|
},
|
||||||
|
|
||||||
ensureFonts: function(fonts, callback) {
|
ensureFonts: function(fonts, callback) {
|
||||||
@ -4353,7 +4353,7 @@ var PartialEvaluator = (function() {
|
|||||||
if (font.translated) {
|
if (font.translated) {
|
||||||
// keep track of each font we translated so the caller can
|
// keep track of each font we translated so the caller can
|
||||||
// load them asynchronously before calling display on a page
|
// load them asynchronously before calling display on a page
|
||||||
var loadedName = uniquePrefix + "font_" + (FontLoadedCounter++);
|
var loadedName = "font_" + getIRQueue + + (FontLoadedCounter++);
|
||||||
font.translated.properties.loadedName = loadedName;
|
font.translated.properties.loadedName = loadedName;
|
||||||
FontsMap[loadedName] = font;
|
FontsMap[loadedName] = font;
|
||||||
|
|
||||||
|
37
worker.js
37
worker.js
@ -120,6 +120,8 @@ var Promise = (function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Promise.prototype = {
|
Promise.prototype = {
|
||||||
|
hasData: false,
|
||||||
|
|
||||||
set data(data) {
|
set data(data) {
|
||||||
if (data === undefined) {
|
if (data === undefined) {
|
||||||
return;
|
return;
|
||||||
@ -128,6 +130,11 @@ var Promise = (function() {
|
|||||||
throw "Promise " + this.name + ": Cannot set the data of a promise twice";
|
throw "Promise " + this.name + ": Cannot set the data of a promise twice";
|
||||||
}
|
}
|
||||||
this.$data = data;
|
this.$data = data;
|
||||||
|
this.hasData = true;
|
||||||
|
|
||||||
|
if (this.$onDataCallback) {
|
||||||
|
this.$onDataCallback(data);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get data() {
|
get data() {
|
||||||
@ -136,6 +143,14 @@ var Promise = (function() {
|
|||||||
}
|
}
|
||||||
return this.$data;
|
return this.$data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onData: function(callback) {
|
||||||
|
if (this.$data !== EMPTY_PROMISE) {
|
||||||
|
callback(this.$data);
|
||||||
|
} else {
|
||||||
|
this.$onDataCallback = callback;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
resolve: function(data) {
|
resolve: function(data) {
|
||||||
if (this.isResolved) {
|
if (this.isResolved) {
|
||||||
@ -203,8 +218,26 @@ var WorkerPDFDoc = (function() {
|
|||||||
processorHandler.on("page", function(data) {
|
processorHandler.on("page", function(data) {
|
||||||
var pageNum = data.pageNum;
|
var pageNum = data.pageNum;
|
||||||
var page = this.pageCache[pageNum];
|
var page = this.pageCache[pageNum];
|
||||||
|
|
||||||
page.startRenderingFromIRQueue(data.IRQueue, data.fonts);
|
var depFonts = data.depFonts;
|
||||||
|
|
||||||
|
function checkFontData() {
|
||||||
|
// Check if all fontObjs have been processed. If not, shedule a
|
||||||
|
// callback that is called once the data arrives and that checks
|
||||||
|
// the next fonts.
|
||||||
|
for (var i = 0; i < depFonts.length; i++) {
|
||||||
|
var fontName = depFonts[i];
|
||||||
|
var fontObj = Objects.get(fontName);
|
||||||
|
if (!fontObj.hasData) {
|
||||||
|
fontObj.onData(checkFontData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point, all font data ia loaded. Start the actuall rendering.
|
||||||
|
page.startRenderingFromIRQueue(data.IRQueue, depFonts);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFontData();
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
processorHandler.on("obj", function(data) {
|
processorHandler.on("obj", function(data) {
|
||||||
|
@ -21,8 +21,11 @@ var WorkerProcessorHandler = {
|
|||||||
var gfx = new CanvasGraphics(null);
|
var gfx = new CanvasGraphics(null);
|
||||||
|
|
||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
|
|
||||||
|
var dependency = [];
|
||||||
|
|
||||||
// Pre compile the pdf page and fetch the fonts/images.
|
// Pre compile the pdf page and fetch the fonts/images.
|
||||||
var IRQueue = page.getIRQueue(handler);
|
var IRQueue = page.getIRQueue(handler, dependency);
|
||||||
|
|
||||||
console.log("page=%d - getIRQueue: time=%dms, len=%d", pageNum, Date.now() - start, IRQueue.fnArray.length);
|
console.log("page=%d - getIRQueue: time=%dms, len=%d", pageNum, Date.now() - start, IRQueue.fnArray.length);
|
||||||
|
|
||||||
@ -42,11 +45,22 @@ var WorkerProcessorHandler = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("cmds", JSON.stringify(cmdMap));
|
console.log("cmds", JSON.stringify(cmdMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter the dependecies for fonts.
|
||||||
|
var fonts = {};
|
||||||
|
for (var i = 0; i < dependency.length; i++) {
|
||||||
|
var dep = dependency[i];
|
||||||
|
if (dep.indexOf('font_') == 0) {
|
||||||
|
fonts[dep] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
handler.send("page", {
|
handler.send("page", {
|
||||||
pageNum: pageNum,
|
pageNum: pageNum,
|
||||||
IRQueue: IRQueue,
|
IRQueue: IRQueue,
|
||||||
|
depFonts: Object.keys(fonts)
|
||||||
});
|
});
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user