foliojs / fontkit

An advanced font engine for Node and the browser
1.45k stars 213 forks source link

Support Buffer postscriptName #266

Closed andreiaugustin closed 2 years ago

andreiaugustin commented 2 years ago

When using a .dfont on macOS (11.6), it seems like the postscriptName is of type Buffer instead of string, which leads to getFont failing and logging that an incorrect font is being used.

This is more of a workaround as ideally, the font's postscriptName should be consistent.

andreiaugustin commented 2 years ago

Does not seem to be a problem anymore in 12.0.1 - now Monaco seems to be a ttf rather than a dfont and problem doesn't seem to appear with other TTCs or third-party dfonts.

Unsure if it's worth still implementing a workaround in case the data ever comes back in as a Buffer instead of string?

andreiaugustin commented 2 years ago

Changed default font to Menlo and the problem is still there (ttc) unless using the changes in this PR.

Any chance of getting this merged?

devongovett commented 2 years ago

Probably related to #274. Did you try installing iconv-lite, which adds support for more encodings?

andreiaugustin commented 2 years ago

Installed iconv-lite as a package in my environment, but no difference in behaviour. I'm using fontkit as part of pdfkit, essentially doc.registerFont which points to a .ttc which when used to draw text via doc.font(the name of registered font).text(the text to draw), it crashes on macOS Monterey 12.3.1 (M1) but I think the same happens on Intel, node v16.14.0.

We've adapted our production scripts to the changes in this PR and haven't had a problem ever since!