2d46230d23
For years now, the `Font.exportData` method has (because of its previous implementation) been exporting many properties despite them being completely unused on the main-thread and/or in the API. This is unfortunate, since among those properties there's a number of potentially very large data-structures, containing e.g. Arrays and Objects, which thus have to be first structured cloned and then stored on the main-thread. With the changes in this patch, we'll thus by default save memory for *every* `Font` instance created (there can be a lot in longer documents). The memory savings obviously depends a lot on the actual font data, but some approximate figures are: For non-embedded fonts it can save a couple of kilobytes, for simple embedded fonts a handful of kilobytes, and for composite fonts the size of this auxiliary can even be larger than the actual font program itself. All-in-all, there's no good reason to keep exporting these properties by default when they're unused. However, since we cannot be sure that every property is unused in custom implementations of the PDF.js library, this patch adds a new `getDocument` option (named `fontExtraProperties`) that still allows access to the following properties: - "cMap": An internal data structure, only used with composite fonts and never really intended to be exposed on the main-thread and/or in the API. Note also that the `CMap`/`IdentityCMap` classes are a lot more complex than simple Objects, but only their "internal" properties survive the structured cloning used to send data to the main-thread. Given that CMaps can often be *very* large, not exporting them can also save a fair bit of memory. - "defaultEncoding": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful. - "differences": An internal property used with simple fonts, and used when building the glyph mapping on the worker-thread. Considering how complex that topic is, and given that not all font types are handled identically, exposing this on the main-thread and/or in the API most likely isn't useful. - "isSymbolicFont": An internal property, used during font parsing and building of the glyph mapping on the worker-thread. - "seacMap": An internal map, only potentially used with *some* Type1/CFF fonts and never intended to be exposed in the API. The existing `Font.{charToGlyph, charToGlyphs}` functionality already takes this data into account when handling text. - "toFontChar": The glyph map, necessary for mapping characters to glyphs in the font, which is built upon the various encoding information contained in the font dictionary and/or font program. This is not directly used on the main-thread and/or in the API. - "toUnicode": The unicode map, necessary for text-extraction to work correctly, which is built upon the ToUnicode/CMap information contained in the font dictionary, but not directly used on the main-thread and/or in the API. - "vmetrics": An array of width data used with fonts which are composite *and* vertical, but not directly used on the main-thread and/or in the API. - "widths": An array of width data used with most fonts, but not directly used on the main-thread and/or in the API. |
||
---|---|---|
.. | ||
images | ||
.eslintrc | ||
.gitignore | ||
annotation_layer_builder.css | ||
annotation_layer_builder.js | ||
app_options.js | ||
app.js | ||
base_viewer.js | ||
chrome-i18n-allow-access-to-file-urls.json | ||
chromecom.js | ||
compressed.tracemonkey-pldi-09.pdf | ||
debugger.js | ||
download_manager.js | ||
firefox_print_service.js | ||
firefoxcom.js | ||
genericcom.js | ||
genericl10n.js | ||
grab_to_pan.js | ||
interfaces.js | ||
overlay_manager.js | ||
password_prompt.js | ||
pdf_attachment_viewer.js | ||
pdf_cursor_tools.js | ||
pdf_document_properties.js | ||
pdf_find_bar.js | ||
pdf_find_controller.js | ||
pdf_find_utils.js | ||
pdf_history.js | ||
pdf_link_service.js | ||
pdf_outline_viewer.js | ||
pdf_page_view.js | ||
pdf_presentation_mode.js | ||
pdf_print_service.js | ||
pdf_rendering_queue.js | ||
pdf_sidebar_resizer.js | ||
pdf_sidebar.js | ||
pdf_single_page_viewer.js | ||
pdf_thumbnail_view.js | ||
pdf_thumbnail_viewer.js | ||
pdf_viewer.component.js | ||
pdf_viewer.css | ||
pdf_viewer.js | ||
pdfjs.js | ||
preferences.js | ||
secondary_toolbar.js | ||
text_layer_builder.css | ||
text_layer_builder.js | ||
toolbar.js | ||
ui_utils.js | ||
view_history.js | ||
viewer_compatibility.js | ||
viewer-snippet-chrome-extension.html | ||
viewer-snippet-chrome-overlays.html | ||
viewer-snippet-firefox-extension.html | ||
viewer-snippet-minified.html | ||
viewer-snippet.html | ||
viewer.css | ||
viewer.html | ||
viewer.js |