-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
registerFont does not allow for two or more fonts with the same (preferred) family name, style, and weight #1572
Comments
At first I thought we did something wrong with the preferred family too, but then I noticed the decorated font actually has a different font weight, meaning our internal descriptors should be unique for each font. I tried it on Linux and couldn't repro. Tried it on macOS too. Do you know if you're using prebuilds or not? |
@chearon thank you so much for looking into this! I had referenced older versions of the example fonts, which indeed, have different weights, and thus the issue could not be reproduced. Copal Std Solid: https://www.download-free-fonts.com/details/72446/copal-std-solid which do have the same weight (900), for both fonts; thus the internal descriptors are not unique anymore. In the project that we're using node-canvas, we (potentially) render all fonts from Adobe Fonts, and found quite a few examples, besides Copal Std, that were hitting the same issue. So the issue is not isolated to this particular set of fonts, Copal Std, but reproduces for many more. And yes, we are using prebuilds. |
Ah that makes more sense! I took a look at FontConfig for reference and it seems equally fooled by these fonts. They're recognized as having the same weight and while it does read the preferred family and family name, if preferred matches it stops there: So we won't be able to get unique descriptors by searching for Probably this is not what you wanted to hear but I think for now I think the only solution is to patch the fonts. You'd think |
@chearon Thank you for the quick reply, much much appreciated. 🙇♀️ Yes, we did try patching the fonts themselves, by assigning unique identifiers to preferredFamily, family, and that worked with the current version of node-canvas. But, of course, patching the fonts is a very slow and costly process. I understand that doing font selection entirely in node-canvas is a larger undertaking. But what do you think about including I've also seen other projects that use pango directly overcoming this same issue, by using https://developer.gnome.org/pango/stable/pango-FreeType-Fonts-and-Rendering.html#pango-ft2-font-map-set-default-substitute. In the Again, thank you SO much for looking into this! |
I had no idea about this function! Is the postscript name usually unique? I've also had the idea that setting the The one roadblock I see is that
This is a good idea but I'm not sure if it will break selection on macOS/Windows since Pango won't use FontConfig if not on Linux (edit: I just realized we could obviously use an |
@chearon Yes, the postscript name is unique. I haven't found any case in which it was not. The code that is using Even though Hope this helps. I'd be thrilled to see this work in node-canvas. 😀 |
@chearon Just following up on this. Do you think using Much appreciated! |
Yes definitely, I hope to start implementing soon.
Brilliant. If PostScript name lookups work on macOS, this could solve an even larger problem space on that platform, where weight lookups are sort of unpredictable. (edit: there's nothing like Even if we find out that it doesn't work on certain platforms we can always put some |
@chearon Hearing this will be fixed in node-canvas is the best news of the week! Maybe even month! Doing a dance party to celebrate this 💃 . Thank you so much. |
@ihuzum unfortunately I've run into an issue with the way Pango's class hierarchy is setup. Want: So the functionality was added to something that doesn't benefit Cairo users. I don't understand what Anyways, the patch would be super easy and reasonable since 2/3 classes that inherit from |
I wrote a patch to add Then I went to go bother the Pango team and found that there had been mention of adding the very same function 13 years ago! Hopefully we can get this function 🤞I really want this because it would give us perfect matching on Linux, where most people have node-canvas running in prod. |
@chearon This is SUCH good & amazing news! It's awesome that you could write the patch for pango too and proved that it worked. Looking forward to trying it out, when this becomes available in node-canvas, whatever form (let me know). It's one of the last puzzle pieces in our project, so seeing it coming together is really exciting. |
@ihuzum it's amazing for me too, thanks for pointing me in the right direction! I have been wanting a more reliable way to select fonts for a while but I never thought of that. Yesterday I finally got around to making a merge request with Pango. Behdad himself responded to the original issue in support of it, so things are looking peachy. We'll have to wait for Pango 1.46 to justify a PR in node-canvas, but when we get there things should move quickly and node-canvas will get the upgrade. |
This is remarkable, and a great win for everyone! I can't wait to use this when it will finally get merged/published in node-canvas. |
My Pango PR is now merged, and will be in version 1.47. Looking at their release, history, that shouldn't be too long 🤞 |
Thanks, I hadn't noticed! If you want the better font selection, we have to make changes in node-canvas first. I'll have that PR this week. If your distro doesn't have it, you'll have to compile Pango yourself. Linux from scratch is a great guide. |
Hi @chearon and thank you for your contribution to Pango! Is there any news regarding leveraging that change in node-canvas? |
Yes, I've actually written the code already but I got hung up on something. I'll try to revive it now |
greatly improves font matching accuracy Fixes Automattic#1572
greatly improves font matching accuracy Fixes Automattic#1572
@chearon any updates on this? |
Second this, any updates? |
any updates? @chearon Will there be prebuilts for new version that fix the bug? |
Any further updates on this change? @chearon |
@chearon I wondering about the status of the code changes you made in node canvas. We were really looking forward to this fix. If you don't have time to make a PR, is there a branch with your changes that someone else might be able to pick up and push forward? |
Sorry guys. I'm trying to finish it today actually. I ran into a ton of problems with a cleanup commit, and problems with updating the Pango prebuild dependency that spawned more problems 😤. I will finish this week though. |
greatly improves font matching accuracy Fixes Automattic#1572
greatly improves font matching accuracy Fixes Automattic#1572
Hey @chearon, I've played around with your commit and it's solved all my font issues, I initially encountered some weird font spacing issues and found locking pango to 1.48.2-r0 resolved those issues. |
greatly improves font matching accuracy Fixes Automattic#1572
@chearon you are the best! If you ever want to meet up for a beer in Columbus, let me know (email in bio) |
greatly improves font matching accuracy Fixes Automattic#1572
greatly improves font matching accuracy Fixes Automattic#1572
greatly improves font matching accuracy Fixes Automattic#1572
greatly improves font matching accuracy Fixes #1572
@chearon which version of pango and cairo has been used to verify that this improvement works? Are there older version not being supported anymore? The font issues we had have been hard to reproduce and occurred form time to time. We use cairo 1.15.12-4.amzn2 and pango 1.42.4-4.amzn2, which is newest versions you get on Amazon Linux 2. Do you already now if there might be compatibility issues? Does someone else has experience? Anyway we will try it out and will update if we experience improvements for our issues. But the testing is complex and will take some time. |
Issue or Feature
Cannot use two or more fonts that have the same preferredFamily, and the same style and weight, even though they are different fonts (they do have different family name, different postScriptName).
Example fonts:
Can download the font here: http://fontsgeek.com/fonts/Copal-Std-Solid
Can download the font here: http://fontsgeek.com/fonts/Copal-Std-Decorated
The above properties can be inspected by uploading the font(s) here: https://opentype.js.org/font-inspector.html and looking at the Naming table.
Steps to Reproduce
The result of this sample code is that both texts are rendered Copal Std Decorated (the font that was registered first), and it's impossible to render a text with Copal Std Solid (font that has the same preferredFamily, even though it is a different font).
Expected:
Your Environment
The text was updated successfully, but these errors were encountered: