Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

font.familyName on Wingdings and other fonts not in UTF8 #84

Closed
roncli opened this issue May 2, 2017 · 10 comments
Closed

font.familyName on Wingdings and other fonts not in UTF8 #84

roncli opened this issue May 2, 2017 · 10 comments

Comments

@roncli
Copy link

roncli commented May 2, 2017

In 1.5.5, some fonts (specifically Microsoft fonts) do not decode to as string like other fonts. For example:

Script:

var fontkit = require("fontkit");
fontkit.open("C:\\Windows\\Fonts\\Wingding.ttf", (err, font) => {
    console.log(font.familyName);
});

Output:

<Buffer 00 57 00 69 00 6e 00 67 00 64 00 69 00 6e 00 67 00 73>

The hex translates to  W i n g d i n g s, but I see no way of getting to that from a simple .toString(encoding) call. What can I do to decode this? Further, is there something that fontkit can do to ensure that we get strings back for the family name, even if the font might be encoded strangely?

@devongovett
Copy link
Member

Hmm, the hope was to avoid that. This commit changed the behavior to prefer strings over buffers: ff92ff5#diff-7e48a0b8d3d1d1ca0b56eefcf0328fcfR89.

Can you confirm that it was previously returning strings before 1.5.5 and is now returning buffers? If not, you may just need to install iconv-lite. That will enable broader encoding support.

@roncli
Copy link
Author

roncli commented May 3, 2017

No, it's returning buffers in 1.5.4, 1.5.5, and 1.5.7.

Seems as through records with nameID = 1 has the font name in a Buffer that's actually UTF8 convertible. Perhaps that can be a fallback?

@Pomax
Copy link
Contributor

Pomax commented May 3, 2017

Have you tried using toString('utf16le')? (name records with platform=3 are encoded using UTF16, and all those leading zeroes strongly suggest this is still a utf16 byte layout)

@roncli
Copy link
Author

roncli commented May 3, 2017

Yes, but I got gibberish.

Digging into it some more, the encoding appears to be UTF 16 Big Endian, which is not a native nodejs conversion.

@Pomax
Copy link
Contributor

Pomax commented May 3, 2017

Oh, that's a good point: everything in OpenType uses big endian ordering, even on hardware that does not use that ordering natively... I filed nodejs/node#12813 in the hopes that a next version of Node can address that, One comment there was that https://nodejs.org/api/buffer.html#buffer_buf_swap16 is available for this purpose.

@devongovett
Copy link
Member

@roncli I want to figure out why it is returning a buffer in the first place instead of decoding it. Can you please email me the exact font you're using? devongovett@gmail.com.

@roncli
Copy link
Author

roncli commented May 3, 2017

@Pomax Thanks for looking into this! I did see that nodejs rejected a similar issue back in 2012/13: nodejs/node-v0.x-archive#4365 The requester didn't have a compelling reason to add it, however, and it was noted if one existed they'd consider it.

@devongovett I'll be sending that tonight when I get home, about 5 or 6 hours from now.

@devongovett
Copy link
Member

The name table for that font includes strings in the Mac Roman encoding. There are no Unicode subtables. If you install iconv-lite alongside fontkit, more encodings will be supported. I tried it and it seemed to work.

@roncli
Copy link
Author

roncli commented May 9, 2017

Update on this, all I had to do was add iconv-lite to the dependencies of my project, and everything's fine. No code change was required.

Why is iconv-lite a devDependency for this project, out of curiosity? Seems this works like a charm.

@devongovett
Copy link
Member

Because it's kinda large, so we don't want to include it in most cases since most fonts have unicode name tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants