mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Re-factor the glyph-cache lookup in the Font._charToGlyph
method
With the changes in the previous patch we can move the glyph-cache lookup to the top of the method and thus avoid a bunch of, in *almost* every case, completely unnecessary re-parsing for every `charCode`.
This commit is contained in:
parent
3e391aaed9
commit
fd35cda8bc
1 changed files with 18 additions and 18 deletions
|
@ -3225,6 +3225,12 @@ class Font {
|
|||
* @private
|
||||
*/
|
||||
_charToGlyph(charcode, isSpace = false) {
|
||||
let glyph = this._glyphCache[charcode];
|
||||
// All `Glyph`-properties, except `isSpace` in multi-byte strings,
|
||||
// depend indirectly on the `charcode`.
|
||||
if (glyph && glyph.isSpace === isSpace) {
|
||||
return glyph;
|
||||
}
|
||||
let fontCharCode, width, operatorListId;
|
||||
|
||||
let widthCode = charcode;
|
||||
|
@ -3289,24 +3295,18 @@ class Font {
|
|||
}
|
||||
}
|
||||
|
||||
let glyph = this._glyphCache[charcode];
|
||||
// All `Glyph`-properties, except `isSpace` in multi-byte strings,
|
||||
// depend indirectly on the `charcode`.
|
||||
if (!glyph || glyph.isSpace !== isSpace) {
|
||||
glyph = new Glyph(
|
||||
charcode,
|
||||
fontChar,
|
||||
unicode,
|
||||
accent,
|
||||
width,
|
||||
vmetric,
|
||||
operatorListId,
|
||||
isSpace,
|
||||
isInFont
|
||||
);
|
||||
this._glyphCache[charcode] = glyph;
|
||||
}
|
||||
return glyph;
|
||||
glyph = new Glyph(
|
||||
charcode,
|
||||
fontChar,
|
||||
unicode,
|
||||
accent,
|
||||
width,
|
||||
vmetric,
|
||||
operatorListId,
|
||||
isSpace,
|
||||
isInFont
|
||||
);
|
||||
return (this._glyphCache[charcode] = glyph);
|
||||
}
|
||||
|
||||
charsToGlyphs(chars) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue