From a5e4cccf13266dc5f9c6b9aa41e4ad6e51e65f4d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 30 Mar 2020 13:19:36 +0200 Subject: [PATCH] [api-minor] Prevent `Font.exportData` from exporting internal/unused properties A number of *internal* font properties, which only make sense on the worker-thread, were previously exported. Some of these properties could also contain potentially large Arrays/Objects, which thus unnecessarily increases memory usage since we're forced to copy these to the main-thread and also store them there. This patch stops exporting the following font properties: - "_shadowWidth": An internal property, which was never intended to be exported. - "charsCache": An internal cache, which was never intended to be exported and doesn't make any sense on the main-thread. Furthermore, by the time `Font.exportData` is called it's usually `undefined` or a mostly empty Object as well. - "cidEncoding": An internal property used with (some) composite fonts. As can be seen in the `PartialEvaluator.translateFont` method, `cidEncoding` will only be assigned a value when the font dictionary has an "Encoding" entry which is a `Name` (and not in the `Stream` case, since those obviously cannot be cloned). All-in-all this property doesn't really make sense on the main-thread and/or in the API, and note also that the resulting `cMap` property is (partially) available already. - "fallbackToUnicode": An internal map, part of the heuristics used to improve text-selection in (some) badly generated PDF documents with simple fonts. This was never intended to be exposed on the main-thread and/or in the API. - "glyphCache": An internal cache, which was never intended to be exported and which doesn't make any sense on the main-thread. Furthermore, by the time `Font.exportData` is called it's usually a mostly empty Object as well. - "isOpenType": An internal property, used only during font parsing on the worker-thread. In the *very* unlikely event that an API consumer actually needs that information, then `fontType` should be a (generally) much better property to use. Finally, in the (hopefully) unlikely event that any of these properties become necessary on the main-thread, re-adding them to the white-list is easy to do. --- src/core/fonts.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index 20fa51224..391ce45db 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -88,15 +88,12 @@ var PDF_GLYPH_SPACE_UNITS = 1000; var SEAC_ANALYSIS_ENABLED = true; const EXPORT_DATA_PROPERTIES = [ - "_shadowWidth", "ascent", "bbox", "black", "bold", "cMap", "charProcOperatorList", - "charsCache", - "cidEncoding", "composite", "data", "defaultEncoding", @@ -105,12 +102,9 @@ const EXPORT_DATA_PROPERTIES = [ "descent", "differences", "fallbackName", - "fallbackToUnicode", "fontMatrix", "fontType", - "glyphCache", "isMonospace", - "isOpenType", "isSerifFont", "isSymbolicFont", "isType3Font",