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

2.9.1 fails to load the correct weights in the same font family #2041

Closed
soren121 opened this issue May 19, 2022 · 2 comments · Fixed by #2062
Closed

2.9.1 fails to load the correct weights in the same font family #2041

soren121 opened this issue May 19, 2022 · 2 comments · Fixed by #2062

Comments

@soren121
Copy link

soren121 commented May 19, 2022

Issue or Feature

When loading multiple font weights in the same font family, node-canvas 2.9.1 fails to render the correct font weight. This issue did not occur in 2.9.0.

I'm loading four styles of the free "Open Sans" font family: Light (300), Regular (400), Bold (700), and Extra Bold (800). When trying to render text in Regular and Extra Bold as follows, 2.9.1 seems to instead render in Light and Regular, respectively:

const defaultFontFamily = '"Open Sans"';
ctx.fillStyle = "#fff";

ctx.font = `400 40px ${defaultFontFamily}`;
ctx.fillText("REGULAR", 40, canvas.height / 2 - 50);

ctx.font = `800 40px ${defaultFontFamily}`;
ctx.fillText("EXTRABOLD", 40, canvas.height / 2);

Steps to Reproduce

I've created a barebones reproducible project, adapted from my actual project.

Running node index.js will generate an image named "canvas.png" in the same directory.

Project attached here: repro.zip

The following is how 2.9.1 incorrectly renders the example:

canvas

And how 2.9.0 correctly renders the example:

expected-2 9 0

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas): 2.9.1
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): node 14.18.2 on Debian 11 (via WSL2)
@mjgerace
Copy link

I can confirm this is occurring for me too, as well as font family in registerFont not working.

@chearon
Copy link
Collaborator

chearon commented Jun 24, 2022

Thanks for the repro. The issue happens if you have Pango > 1.47.0 and you call registerFont with the same family name and a different font file. I forgot about another part of the code when I wrote #1987 that tries to support doing that (not well). Working on a fix.

chearon added a commit that referenced this issue Jun 24, 2022
the problem was exposed by #1572, but was always there

fixes #2041
chearon added a commit that referenced this issue Jun 24, 2022
the problem was exposed by #1987, but was always there

fixes #2041
zbjornson pushed a commit that referenced this issue Jun 24, 2022
the problem was exposed by #1987, but was always there

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

Successfully merging a pull request may close this issue.

4 participants