From 704a005ac246488142036bec0c5f59c7d15d017d Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Sat, 28 Dec 2024 13:34:00 +0100 Subject: [PATCH] Fix font cache collision identical metadata for different fonts #1330 --- CHANGELOG.md | 2 +- lib/mixins/fonts.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5983bc2b..15d43f2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - Add support to scale text horizontally - Add an option to keep the indentation after a new line starts and allow to indent a whole paragraph/text element - 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 font cache collision for fonts with missing postscript name or bad TTF metadata or identical metadata for different fonts - 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 b8a8295d..3a6e85fc 100644 --- a/lib/mixins/fonts.js +++ b/lib/mixins/fonts.js @@ -1,8 +1,17 @@ import PDFFontFactory from '../font_factory'; const isEqualFont = (font1, font2) => { + // compare font checksum + if (font1.font._tables?.head?.checkSumAdjustment !== font2.font._tables?.head?.checkSumAdjustment) { + return false; + } + // compare font name table - return (JSON.stringify(font1.font._tables?.name?.records) === JSON.stringify(font2.font._tables?.name?.records)) + if (JSON.stringify(font1.font._tables?.name?.records) !== JSON.stringify(font2.font._tables?.name?.records)) { + return false; + } + + return true; } export default {