Browse Source

Move font translation to the worker

Yury Delendik 13 years ago
parent
commit
9fba150dd2
  1. 19
      src/api.js
  2. 27
      src/evaluator.js
  3. 18
      src/fonts.js

19
src/api.js

@ -575,24 +575,15 @@ var WorkerTransport = (function WorkerTransportClosure() { @@ -575,24 +575,15 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.objs.resolve(id, imageData);
break;
case 'Font':
var name = data[2];
var file = data[3];
var properties = data[4];
if (file) {
// Rewrap the ArrayBuffer in a stream.
var fontFileDict = new Dict();
file = new Stream(file, 0, file.length, fontFileDict);
}
var exportedData = data[2];
// At this point, only the font object is created but the font is
// not yet attached to the DOM. This is done in `FontLoader.bind`.
var font;
try {
font = new Font(name, file, properties);
} catch (e) {
font = new ErrorFont(e);
}
if ('error' in exportedData)
font = new ErrorFont(exportedData.error);
else
font = new Font(exportedData);
this.objs.resolve(id, font);
break;
default:

27
src/evaluator.js

@ -171,31 +171,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { @@ -171,31 +171,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
++self.objIdCounter;
if (!font.loadedName) {
font.translated = self.translateFont(font, xref, resources,
var translated = self.translateFont(font, xref, resources,
dependency);
if (font.translated) {
if (translated) {
// keep track of each font we translated so the caller can
// load them asynchronously before calling display on a page
loadedName = 'font_' + uniquePrefix + self.objIdCounter;
font.translated.properties.loadedName = loadedName;
translated.properties.loadedName = loadedName;
font.loadedName = loadedName;
font.translated = translated;
var translated = font.translated;
// Convert the file to an ArrayBuffer which will be turned back into
// a Stream in the main thread.
if (translated.file)
translated.file = translated.file.getBytes();
if (translated.properties.file) {
translated.properties.file =
translated.properties.file.getBytes();
var data;
try {
var fontObj = new Font(translated.name,
translated.file,
translated.properties);
data = fontObj.export();
} catch (e) {
data = { error: e };
}
handler.send('obj', [
loadedName,
'Font',
translated.name,
translated.file,
translated.properties
data
]);
}
}

18
src/fonts.js

@ -1526,6 +1526,15 @@ function fontCharsToUnicode(charCodes, fontProperties) { @@ -1526,6 +1526,15 @@ function fontCharsToUnicode(charCodes, fontProperties) {
*/
var Font = (function FontClosure() {
function Font(name, file, properties) {
if (arguments.length === 1) {
// importing translated data
var data = arguments[0];
for (var i in data) {
this[i] = data[i];
}
return;
}
this.name = name;
this.coded = properties.coded;
this.charProcOperatorList = properties.charProcOperatorList;
@ -2036,6 +2045,15 @@ var Font = (function FontClosure() { @@ -2036,6 +2045,15 @@ var Font = (function FontClosure() {
mimetype: null,
encoding: null,
export: function Font_export() {
var data = {};
for (var i in this) {
if (this.hasOwnProperty(i))
data[i] = this[i];
}
return data;
},
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
function readTableEntry(file) {
var tag = file.getBytes(4);

Loading…
Cancel
Save