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

Multiple registerFont() declarations not being honoured #1683

Open
SAustin87 opened this issue Oct 20, 2020 · 1 comment
Open

Multiple registerFont() declarations not being honoured #1683

SAustin87 opened this issue Oct 20, 2020 · 1 comment

Comments

@SAustin87
Copy link

SAustin87 commented Oct 20, 2020

Issue or Feature

I have 3 custom fonts I'm trying to include in my canvas using registerFont(). The reason I'm trying to bring 3 in is that I've implemented (although removed for the purpose of this) the ability for the font to be changed via url param.

The problem I'm having is that only 1st and 3rd fonts are outputting as expected, while the 2nd (regular) is defaulting. See images below of font preview and output, and next section for code block.

HolidayExtrasSans-Light.ttf

Screenshot 2020-10-20 at 09 59 54

Screenshot 2020-10-20 at 09 58 56

HolidayExtrasSans-Regular.ttf

Screenshot 2020-10-20 at 10 00 07

Screenshot 2020-10-20 at 09 59 29

HolidayExtrasSans-Bold.ttf

Screenshot 2020-10-20 at 10 00 23

Screenshot 2020-10-20 at 09 58 35

I've tried a few different steps.

  • Originally I was using .OTF, so I changed to .TTF after reading about a previous issue.
  • I've tried with giving each file the same family and declaring the weight of each via the weight: '' declaration.
  • I've tried giving them each completely separate family names.
  • I've tried giving them the same family but appending a unique identifier on to the end (as is now).

I see there are other issues detailing difficulties with multiple fonts, but these seem to have been raised a number of years ago.

Thanks

Steps to Reproduce

registerFont('./fonts/HolidayExtrasSans-Light.ttf', { family: 'holiday extras light' });
registerFont('./fonts/HolidayExtrasSans-Regular.ttf', { family: 'holiday extras regular' }); // This font not outputting
registerFont('./fonts/HolidayExtrasSans-Bold.ttf', { family: 'holiday extras bold' })

context.font = "200px 'holiday extras regular'"

Your Environment

Canvas version: 2.6.1
node v10.15.1 on macOS Catalina 10.15.6

@chearon
Copy link
Collaborator

chearon commented Oct 20, 2020

The custom font system is imperfect because font APIs on the OS don't let you pick via file path, only by weight/family/style. node-canvas does its best to pick the weight/family/style that will resolve to the exact TTF you registered, but sometimes the OS returns the wrong font.

I see there are other issues detailing difficulties with multiple fonts, but these seem to have been raised a number of years ago.

Not much has changed since those issues, unfortunately. I see that you're having the issue on macOS which is the worst platform for font selection. Does your application run on Linux? Very soon we will have #1572 fixed which will mean near-perfect font selection, but only on Linux.

The other thing you can do is manually patch the fonts in something like FontForge. Tweak the weight or give each TTF a unique family name and that should do it.

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

No branches or pull requests

3 participants