foliojs / fontkit

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

Reading a ttf font file familyName returns a buffer #274

Closed ivantacca closed 2 years ago

ivantacca commented 2 years ago

Hi, I am trying to read the familyName of every font in my library, and I noticed that the result is not always a string.

Take this as an example:

let fontkit = require('fontkit')
var font = fontkit.openSync('/System/Library/Fonts/Supplemental/Zapfino.ttf');
console.log(font.fontName)

The code above is giving the following output

<Buffer 5a 61 70 66 69 6e 6f>

And this is happening for several font files, while the result for others is the actual family name.

Am I doing something wrong?

devongovett commented 2 years ago

That can happen if a string is in a non-standard (ie non Unicode) encoding. If you install iconv-lite, it should be able to decode it.

ivantacca commented 2 years ago

Thanks @devongovett, Actually it seems that even just .toString() does the trick. May I ask if this is made on purpose or a sort of exception we get from the library on certain fonts?

devongovett commented 2 years ago

If the text is in a non-standard encoding, then it may end up as a buffer if it is unable to be decoded. On my system, your example works and returns a string.