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

Using font family multiple times results in default font #977

Closed
saschagehlich opened this issue Aug 30, 2017 · 6 comments
Closed

Using font family multiple times results in default font #977

saschagehlich opened this issue Aug 30, 2017 · 6 comments

Comments

@saschagehlich
Copy link
Contributor

Issue or Feature

When registering multiple font files with the same font family, but different styles (like in examples/font.js), the default font is used instead of the given font files. When using different font family names for every font file, it works.

Right now, examples/font.js creates this image:

font2

As you can see, the Pfennig font is not used at all.

Changing the font definitions like this (and changing the font property on the rendering context accordingly):

Canvas.registerFont(fontFile('Pfennig.ttf'), {family: 'Pfennig'})
Canvas.registerFont(fontFile('PfennigBold.ttf'), {family: 'PfennigBold', weight: 'bold'})
Canvas.registerFont(fontFile('PfennigItalic.ttf'), {family: 'PfennigItalic', style: 'italic'})
Canvas.registerFont(fontFile('PfennigBoldItalic.ttf'), {family: 'PfennigBoldItalic', weight: 'bold', style: 'italic'})

This results in:

font

Your Environment

  • Version of node-canvas (e.g. 1.4.0): 2.0.0-alpha.3
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): node 7.9.0 on macOS 10.12.6
@chearon
Copy link
Collaborator

chearon commented Aug 30, 2017

Spent an hour trying to figure out why, and then I remembered that I already know why.

The three consecutive registerFont calls basically add 3 PangoFontDescriptions to an internal list held in node-canvas. When you set ctx.font = "pfennigFont" it finds 3 matches, and joins the real font names with commas before it sends the font query to Pango. So what gets sent to the OS in this case would be {family: "Pfennig, Pfennig, Pfennig"}.

That's a totally valid query, and it works on Linux and Windows. But this bug in Pango causes the bug you're seeing. See my comment on the original Canvas.registerFont PR here. I submitted a patch to Pango here but they haven't said anything, I'll see if I can ping Behdad or someone else, but in the meantime I could probably update the code so that it doesn't send duplicate font names, which would also fix it.

@saschagehlich
Copy link
Contributor Author

Thanks a lot for investigating @chearon!

@chearon
Copy link
Collaborator

chearon commented Aug 30, 2017

No problem, thanks for reporting. I plan on making a PR soon. This should work out-of-the-box on macOS.

chearon added a commit to chearon/node-canvas that referenced this issue Sep 1, 2017
Works around https://bugzilla.gnome.org/show_bug.cgi?id=762873 for when
`ctx.font` is set to something that resolves to more than one registered
font with identical SFNT names
LinusU added a commit that referenced this issue Sep 2, 2017
macOS font selection improvement (see #977)
@pravdomil
Copy link
Contributor

@LinusU
Copy link
Collaborator

LinusU commented Sep 12, 2018

Should be fixed in pango 1.42.3? Could someone confirm?

@chearon
Copy link
Collaborator

chearon commented Feb 27, 2021

Yep, fixed in exactly that version.

@chearon chearon closed this as completed Feb 27, 2021
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

5 participants