Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ function createNameTable(name, proto) {
* decoding logics whatever type it is (assuming the font type is supported).
*/
class Font {
#charsCache = new Map();

#glyphCache = new Map();

constructor(name, file, properties, evaluatorOptions) {
this.name = name;
this.psName = null;
Expand All @@ -981,9 +985,6 @@ class Font {
this.missingFile = false;
this.cssFontInfo = properties.cssFontInfo;

this._charsCache = Object.create(null);
this._glyphCache = Object.create(null);

let isSerifFont = !!(properties.flags & FontFlags.Serif);
// Fallback to checking the font name, in order to improve text-selection,
// since the /Flags-entry is often wrong (fixes issue13845.pdf).
Expand Down Expand Up @@ -3385,7 +3386,7 @@ class Font {
* @private
*/
_charToGlyph(charcode, isSpace = false) {
let glyph = this._glyphCache[charcode];
let glyph = this.#glyphCache.get(charcode);
// All `Glyph`-properties, except `isSpace` in multi-byte strings,
// depend indirectly on the `charcode`.
if (glyph?.isSpace === isSpace) {
Expand Down Expand Up @@ -3480,12 +3481,13 @@ class Font {
isSpace,
isInFont
);
return (this._glyphCache[charcode] = glyph);
this.#glyphCache.set(charcode, glyph);
return glyph;
}

charsToGlyphs(chars) {
// If we translated this string before, just grab it from the cache.
let glyphs = this._charsCache[chars];
let glyphs = this.#charsCache.get(chars);
if (glyphs) {
return glyphs;
}
Expand Down Expand Up @@ -3517,7 +3519,8 @@ class Font {
}

// Enter the translated string into the cache.
return (this._charsCache[chars] = glyphs);
this.#charsCache.set(chars, glyphs);
return glyphs;
}

/**
Expand Down Expand Up @@ -3549,7 +3552,7 @@ class Font {
}

get glyphCacheValues() {
return Object.values(this._glyphCache);
return this.#glyphCache.values();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4100,7 +4100,7 @@ class AnnotationLayer {
}

getEditableAnnotations() {
return Array.from(this.#editableAnnotations.values());
return this.#editableAnnotations.values();
}

getEditableAnnotation(id) {
Expand Down
3 changes: 1 addition & 2 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ class AnnotationEditorLayer {
}

// Show the annotations that were hidden in enable().
const editables = annotationLayer.getEditableAnnotations();
for (const editable of editables) {
for (const editable of annotationLayer.getEditableAnnotations()) {
const { id } = editable.data;
if (this.#uiManager.isDeletedAnnotationElement(id)) {
editable.updateEdited({ deleted: true });
Expand Down