Skip to content

Commit

Permalink
Merge pull request #19200 from Snuffleupagus/delete-raw-path
Browse files Browse the repository at this point in the history
Remove the raw path-strings after creating the actual `Path2D` glyph-objects
  • Loading branch information
Snuffleupagus authored Dec 9, 2024
2 parents 99eefb7 + 6153b15 commit 39bfc92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,7 @@ class WorkerTransport {
: null;
const font = new FontFaceObject(exportedData, {
disableFontFace,
fontExtraProperties,
inspectFont,
});

Expand Down Expand Up @@ -3242,6 +3243,20 @@ class PDFObjects {
return !!obj && obj.data !== INITIAL_DATA;
}

/**
* @param {string} objId
* @returns {boolean}
*/
delete(objId) {
const obj = this.#objs[objId];
if (!obj || obj.data === INITIAL_DATA) {
// Only allow removing the object *after* it's been resolved.
return false;
}
delete this.#objs[objId];
return true;
}

/**
* Resolves the object `objId` with optional `data`.
*
Expand Down
17 changes: 14 additions & 3 deletions src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,17 @@ class FontLoader {
}

class FontFaceObject {
constructor(translatedData, { disableFontFace = false, inspectFont = null }) {
constructor(
translatedData,
{ disableFontFace = false, fontExtraProperties = false, inspectFont = null }
) {
this.compiledGlyphs = Object.create(null);
// importing translated data
for (const i in translatedData) {
this[i] = translatedData[i];
}
this.disableFontFace = disableFontFace === true;
this.fontExtraProperties = fontExtraProperties === true;
this._inspectFont = inspectFont;
}

Expand Down Expand Up @@ -420,13 +424,20 @@ class FontFaceObject {
return this.compiledGlyphs[character];
}

const objId = this.loadedName + "_path_" + character;
let cmds;
try {
cmds = objs.get(this.loadedName + "_path_" + character);
cmds = objs.get(objId);
} catch (ex) {
warn(`getPathGenerator - ignoring character: "${ex}".`);
}
return (this.compiledGlyphs[character] = new Path2D(cmds || ""));
const path = new Path2D(cmds || "");

if (!this.fontExtraProperties) {
// Remove the raw path-string, since we don't need it anymore.
objs.delete(objId);
}
return (this.compiledGlyphs[character] = path);
}
}

Expand Down

0 comments on commit 39bfc92

Please sign in to comment.