diff --git a/CHANGELOG.md b/CHANGELOG.md index c478dbd5..14e2bb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Update linebreak to 1.1 - Add support for spot colors - Fix sets tab order to "Structure" when a document is tagged +- Fix font cache collision for fonts with missing postscript name or bad TTF metadata - Fix measuring text when OpenType features are passed in to .text() ### [v0.15.2] - 2024-12-15 diff --git a/lib/mixins/fonts.js b/lib/mixins/fonts.js index d66d4a71..b8a8295d 100644 --- a/lib/mixins/fonts.js +++ b/lib/mixins/fonts.js @@ -1,5 +1,10 @@ import PDFFontFactory from '../font_factory'; +const isEqualFont = (font1, font2) => { + // compare font name table + return (JSON.stringify(font1.font._tables?.name?.records) === JSON.stringify(font2.font._tables?.name?.records)) +} + export default { initFonts(defaultFont = 'Helvetica') { // Lookup table for embedded fonts @@ -52,7 +57,7 @@ export default { // check for existing font familes with the same name already in the PDF // useful if the font was passed as a buffer - if ((font = this._fontFamilies[this._font.name])) { + if ((font = this._fontFamilies[this._font.name]) && isEqualFont(this._font, font)) { this._font = font; return this; }