Skip to content

Commit

Permalink
Reduce code-duplication when caching data in CompiledFont.getPathJs
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffleupagus committed Apr 29, 2024
1 parent 234067e commit 85ff8f3
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/core/font_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,25 +780,22 @@ class CompiledFont {

getPathJs(unicode) {
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
let fn = this.compiledGlyphs[glyphId];
let fn = this.compiledGlyphs[glyphId],
compileEx;
if (!fn) {
try {
fn = this.compiledGlyphs[glyphId] = this.compileGlyph(
this.glyphs[glyphId],
glyphId
);
fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
} catch (ex) {
// Avoid attempting to re-compile a corrupt glyph.
this.compiledGlyphs[glyphId] = NOOP;
fn = NOOP; // Avoid attempting to re-compile a corrupt glyph.

if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
this.compiledCharCodeToGlyphId[charCode] = glyphId;
}
throw ex;
compileEx = ex;
}
this.compiledGlyphs[glyphId] = fn;
}
if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
this.compiledCharCodeToGlyphId[charCode] = glyphId;
this.compiledCharCodeToGlyphId[charCode] ??= glyphId;

if (compileEx) {
throw compileEx;
}
return fn;
}
Expand Down

0 comments on commit 85ff8f3

Please sign in to comment.