Add Objects.clear() and fallback for testStr in FontMeasure

This commit is contained in:
Julian Viereck 2011-09-15 14:06:24 -07:00
parent fa9f9e0a7a
commit 9e84dd35b6
3 changed files with 30 additions and 13 deletions

View File

@ -224,11 +224,15 @@ var FontLoader = {
console.log("load font", objId); console.log("load font", objId);
var encoding = fontObj.encoding; var encoding = fontObj.encoding;
var testStr = ""; var testStr = "";
for (var enc in encoding) { // If the font has a encoding defined. If, use the characters of the
testStr += String.fromCharCode(encoding[enc].unicode); // encoding, otherwise use some dump string for testing.
if (testStr.length == 10) { if (Object.keys(encoding).length != 0) {
break; for (var enc in encoding) {
testStr += String.fromCharCode(encoding[enc].unicode);
} }
} else {
console.log("empty font.encoding");
testStr = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+='!";
} }
var before = this.measure(fontObj, testStr); var before = this.measure(fontObj, testStr);

2
pdf.js
View File

@ -5400,7 +5400,7 @@ var CanvasGraphics = (function() {
}, },
paintJpegXObject: function(objId, w, h) { paintJpegXObject: function(objId, w, h) {
var image = Objects[objId].data; var image = Objects.get(objId);
if (!image) { if (!image) {
error("Dependent image isn't ready yet"); error("Dependent image isn't ready yet");
} }

View File

@ -60,11 +60,14 @@ var WorkerPage = (function() {
// This holds a list of objects the IR queue depends on. // This holds a list of objects the IR queue depends on.
var Objects = { var Objects = {
hash: {},
getPromise: function(objId) { getPromise: function(objId) {
if (Objects[objId]) { var hash = this.hash;
return this[objId]; if (hash[objId]) {
return hash[objId];
} else { } else {
return this[objId] = new Promise(objId); return hash[objId] = new Promise(objId);
} }
}, },
@ -74,20 +77,26 @@ var Objects = {
}, },
resolve: function(objId, data) { resolve: function(objId, data) {
var hash = this.hash;
// In case there is a promise already on this object, just resolve it. // In case there is a promise already on this object, just resolve it.
if (Objects[objId]) { if (hash[objId]) {
Objects[objId].resolve(data); hash[objId].resolve(data);
} else { } else {
Objects[objId] = new Promise(objId, data); hash[objId] = new Promise(objId, data);
} }
}, },
get: function(objId) { get: function(objId) {
var obj = Objects[objId]; var obj = this.hash[objId];
if (!obj || !obj.isResolved) { if (!obj || !obj.isResolved) {
throw "Requesting object that isn't resolved yet " + objId; throw "Requesting object that isn't resolved yet " + objId;
} }
return obj.data; return obj.data;
},
clear: function() {
delete this.hash;
this.hash = {};
} }
}; };
@ -154,6 +163,10 @@ var Promise = (function() {
var WorkerPDFDoc = (function() { var WorkerPDFDoc = (function() {
function constructor(data) { function constructor(data) {
// For now, as we create a new WorkerPDFDoc, we clear all objects.
// TODO: Have the objects per WorkerPDFDoc.
Objects.clear();
this.data = data; this.data = data;
this.stream = new Stream(data); this.stream = new Stream(data);
this.pdf = new PDFDoc(this.stream); this.pdf = new PDFDoc(this.stream);