From 42172c510282ec3ad22e71318460d671b0b21cb0 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Fri, 27 Dec 2024 12:07:52 +0100 Subject: [PATCH] Fix font cache collision for fonts with missing postscript name or bad TTF metadata #1384 #691 --- CHANGELOG.md | 1 + lib/mixins/fonts.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c478dbd5c..14e2bb7fc 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 d66d4a71f..b8a8295df 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; }