Skip to content

Commit 42172c5

Browse files
committed
Fix font cache collision for fonts with missing postscript name or bad TTF metadata #1384 #691
1 parent 8b20d07 commit 42172c5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Update linebreak to 1.1
77
- Add support for spot colors
88
- Fix sets tab order to "Structure" when a document is tagged
9+
- Fix font cache collision for fonts with missing postscript name or bad TTF metadata
910
- Fix measuring text when OpenType features are passed in to .text()
1011

1112
### [v0.15.2] - 2024-12-15

lib/mixins/fonts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import PDFFontFactory from '../font_factory';
22

3+
const isEqualFont = (font1, font2) => {
4+
// compare font name table
5+
return (JSON.stringify(font1.font._tables?.name?.records) === JSON.stringify(font2.font._tables?.name?.records))
6+
}
7+
38
export default {
49
initFonts(defaultFont = 'Helvetica') {
510
// Lookup table for embedded fonts
@@ -52,7 +57,7 @@ export default {
5257

5358
// check for existing font familes with the same name already in the PDF
5459
// useful if the font was passed as a buffer
55-
if ((font = this._fontFamilies[this._font.name])) {
60+
if ((font = this._fontFamilies[this._font.name]) && isEqualFont(this._font, font)) {
5661
this._font = font;
5762
return this;
5863
}

0 commit comments

Comments
 (0)