diff --git a/src/core/evaluator.js b/src/core/evaluator.js index fe79687c5..a39bc2055 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -94,6 +94,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { nativeImageDecoderSupport: NativeImageDecoding.DECODE, ignoreErrors: false, isEvalSupported: true, + fontExtraProperties: false, }; // eslint-disable-next-line no-shadow @@ -807,6 +808,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { loadedName: "g_font_error", font: new ErrorFont(`Type3 font load error: ${reason}`), dict: translated.font, + extraProperties: this.options.fontExtraProperties, }); }); }) @@ -956,15 +958,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { }, loadFont: function PartialEvaluator_loadFont(fontName, font, resources) { - function errorFont() { + const errorFont = () => { return Promise.resolve( new TranslatedFont({ loadedName: "g_font_error", font: new ErrorFont(`Font "${fontName}" is not available.`), dict: font, + extraProperties: this.options.fontExtraProperties, }) ); - } + }; var fontRef, xref = this.xref; @@ -1096,7 +1099,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { } translatedPromise - .then(function(translatedFont) { + .then(translatedFont => { if (translatedFont.fontType !== undefined) { var xrefFontStats = xref.stats.fontTypes; xrefFontStats[translatedFont.fontType] = true; @@ -1107,6 +1110,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { loadedName: font.loadedName, font: translatedFont, dict: font, + extraProperties: this.options.fontExtraProperties, }) ); }) @@ -1136,6 +1140,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { reason instanceof Error ? reason.message : reason ), dict: font, + extraProperties: this.options.fontExtraProperties, }) ); }); @@ -3273,10 +3278,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { })(); class TranslatedFont { - constructor({ loadedName, font, dict }) { + constructor({ loadedName, font, dict, extraProperties = false }) { this.loadedName = loadedName; this.font = font; this.dict = dict; + this._extraProperties = extraProperties; this.type3Loaded = null; this.sent = false; } @@ -3290,7 +3296,7 @@ class TranslatedFont { handler.send("commonobj", [ this.loadedName, "Font", - this.font.exportData(), + this.font.exportData(this._extraProperties), ]); } diff --git a/src/core/fonts.js b/src/core/fonts.js index add8fd973..241e50daf 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -92,21 +92,17 @@ const EXPORT_DATA_PROPERTIES = [ "bbox", "black", "bold", - "cMap", "charProcOperatorList", "composite", "data", - "defaultEncoding", "defaultVMetrics", "defaultWidth", "descent", - "differences", "fallbackName", "fontMatrix", "fontType", "isMonospace", "isSerifFont", - "isSymbolicFont", "isType3Font", "italic", "loadedName", @@ -114,12 +110,19 @@ const EXPORT_DATA_PROPERTIES = [ "missingFile", "name", "remeasure", - "seacMap", "subtype", - "toFontChar", - "toUnicode", "type", "vertical", +]; + +const EXPORT_DATA_EXTRA_PROPERTIES = [ + "cMap", + "defaultEncoding", + "differences", + "isSymbolicFont", + "seacMap", + "toFontChar", + "toUnicode", "vmetrics", "widths", ]; @@ -1295,10 +1298,14 @@ var Font = (function FontClosure() { return shadow(this, "renderer", renderer); }, - exportData() { + exportData(extraProperties = false) { + const exportDataProperties = extraProperties + ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES] + : EXPORT_DATA_PROPERTIES; + const data = Object.create(null); let property, value; - for (property of EXPORT_DATA_PROPERTIES) { + for (property of exportDataProperties) { value = this[property]; // Ignore properties that haven't been explicitly set. if (value !== undefined) { @@ -3352,7 +3359,7 @@ var ErrorFont = (function ErrorFontClosure() { charsToGlyphs: function ErrorFont_charsToGlyphs() { return []; }, - exportData: function ErrorFont_exportData() { + exportData(extraProperties = false) { return { error: this.error }; }, }; diff --git a/src/core/worker.js b/src/core/worker.js index ba565a487..b9afe7bed 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -403,6 +403,7 @@ var WorkerMessageHandler = { nativeImageDecoderSupport: data.nativeImageDecoderSupport, ignoreErrors: data.ignoreErrors, isEvalSupported: data.isEvalSupported, + fontExtraProperties: data.fontExtraProperties, }; getPdfManager(data, evaluatorOptions) diff --git a/src/display/api.js b/src/display/api.js index 4f5749f35..8921cc690 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -145,6 +145,11 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { * converted to OpenType fonts and loaded via font face rules. If disabled, * fonts will be rendered using a built-in font renderer that constructs the * glyphs with primitive path commands. The default value is `false`. + * @property {boolean} [fontExtraProperties] - Include additional properties, + * which are unused during rendering of PDF documents, when exporting the + * parsed font data from the worker-thread. This may be useful for debugging + * purposes (and backwards compatibility), but note that it will lead to + * increased memory usage. The default value is `false`. * @property {boolean} [disableRange] - Disable range request loading * of PDF files. When enabled, and if the server supports partial content * requests, then the PDF will be fetched in chunks. @@ -251,6 +256,7 @@ function getDocument(src) { params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE; params.CMapReaderFactory = params.CMapReaderFactory || DOMCMapReaderFactory; params.ignoreErrors = params.stopAtErrors !== true; + params.fontExtraProperties = params.fontExtraProperties === true; params.pdfBug = params.pdfBug === true; const NativeImageDecoderValues = Object.values(NativeImageDecoding); @@ -403,6 +409,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { nativeImageDecoderSupport: source.nativeImageDecoderSupport, ignoreErrors: source.ignoreErrors, isEvalSupported: source.isEvalSupported, + fontExtraProperties: source.fontExtraProperties, }) .then(function(workerId) { if (worker.destroyed) { diff --git a/web/app.js b/web/app.js index 5ddfd8adf..135882176 100644 --- a/web/app.js +++ b/web/app.js @@ -309,6 +309,8 @@ const PDFViewerApplication = { } if ("pdfbug" in hashParams) { AppOptions.set("pdfBug", true); + AppOptions.set("fontExtraProperties", true); + const enabled = hashParams["pdfbug"].split(","); waitOn.push(loadAndEnablePDFBug(enabled)); } diff --git a/web/app_options.js b/web/app_options.js index 3fa1187a1..0f3b5af25 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -193,6 +193,11 @@ const defaultOptions = { value: "", kind: OptionKind.API, }, + fontExtraProperties: { + /** @type {boolean} */ + value: false, + kind: OptionKind.API, + }, isEvalSupported: { /** @type {boolean} */ value: true,