Skip to content

Commit

Permalink
Fix font cache collision for fonts with missing postscript name or ba…
Browse files Browse the repository at this point in the history
…d TTF metadata #1384 #691
  • Loading branch information
liborm85 committed Dec 27, 2024
1 parent 8b20d07 commit 42172c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/mixins/fonts.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 42172c5

Please sign in to comment.