Merge pull request #2111 from yurydelendik/move-font-conversion
Move font translation to the worker
This commit is contained in:
commit
6fc70bb2a7
19
src/api.js
19
src/api.js
@ -575,24 +575,15 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.objs.resolve(id, imageData);
|
this.objs.resolve(id, imageData);
|
||||||
break;
|
break;
|
||||||
case 'Font':
|
case 'Font':
|
||||||
var name = data[2];
|
var exportedData = 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// At this point, only the font object is created but the font is
|
// 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`.
|
// not yet attached to the DOM. This is done in `FontLoader.bind`.
|
||||||
var font;
|
var font;
|
||||||
try {
|
if ('error' in exportedData)
|
||||||
font = new Font(name, file, properties);
|
font = new ErrorFont(exportedData.error);
|
||||||
} catch (e) {
|
else
|
||||||
font = new ErrorFont(e);
|
font = new Font(exportedData);
|
||||||
}
|
|
||||||
this.objs.resolve(id, font);
|
this.objs.resolve(id, font);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -171,31 +171,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
++self.objIdCounter;
|
++self.objIdCounter;
|
||||||
if (!font.loadedName) {
|
if (!font.loadedName) {
|
||||||
font.translated = self.translateFont(font, xref, resources,
|
var translated = self.translateFont(font, xref, resources,
|
||||||
dependency);
|
dependency);
|
||||||
if (font.translated) {
|
if (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
|
||||||
loadedName = 'font_' + uniquePrefix + self.objIdCounter;
|
loadedName = 'font_' + uniquePrefix + self.objIdCounter;
|
||||||
font.translated.properties.loadedName = loadedName;
|
translated.properties.loadedName = loadedName;
|
||||||
font.loadedName = loadedName;
|
font.loadedName = loadedName;
|
||||||
|
font.translated = translated;
|
||||||
|
|
||||||
var translated = font.translated;
|
var data;
|
||||||
// Convert the file to an ArrayBuffer which will be turned back into
|
try {
|
||||||
// a Stream in the main thread.
|
var fontObj = new Font(translated.name,
|
||||||
if (translated.file)
|
translated.file,
|
||||||
translated.file = translated.file.getBytes();
|
translated.properties);
|
||||||
if (translated.properties.file) {
|
data = fontObj.export();
|
||||||
translated.properties.file =
|
} catch (e) {
|
||||||
translated.properties.file.getBytes();
|
data = { error: e };
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.send('obj', [
|
handler.send('obj', [
|
||||||
loadedName,
|
loadedName,
|
||||||
'Font',
|
'Font',
|
||||||
translated.name,
|
data
|
||||||
translated.file,
|
|
||||||
translated.properties
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
src/fonts.js
18
src/fonts.js
@ -1526,6 +1526,15 @@ function fontCharsToUnicode(charCodes, fontProperties) {
|
|||||||
*/
|
*/
|
||||||
var Font = (function FontClosure() {
|
var Font = (function FontClosure() {
|
||||||
function Font(name, file, properties) {
|
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.name = name;
|
||||||
this.coded = properties.coded;
|
this.coded = properties.coded;
|
||||||
this.charProcOperatorList = properties.charProcOperatorList;
|
this.charProcOperatorList = properties.charProcOperatorList;
|
||||||
@ -2036,6 +2045,15 @@ var Font = (function FontClosure() {
|
|||||||
mimetype: null,
|
mimetype: null,
|
||||||
encoding: 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) {
|
checkAndRepair: function Font_checkAndRepair(name, font, properties) {
|
||||||
function readTableEntry(file) {
|
function readTableEntry(file) {
|
||||||
var tag = file.getBytes(4);
|
var tag = file.getBytes(4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user