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

"(process:15840): Pango-WARNING **: 20:41:16.548: couldn't load font "sans serif Not-Rotated 10px", falling back to "Sans Not-Rotated 10px", expect ugly output." #1643

Closed
Pomax opened this issue Aug 6, 2020 · 9 comments · Fixed by #1647

Comments

@Pomax
Copy link
Contributor

Pomax commented Aug 6, 2020

Is there a way to prevent the warning (process:15840): Pango-WARNING **: 20:41:16.548: couldn't load font "sans serif Not-Rotated 10px", falling back to "Sans Not-Rotated 10px", expect ugly output.? My code doesn't issue a font instruction anywhere, so seeing it complain about not being able to fulfill "sans serif Not-Rotated 10px" is very odd indeed. I even tried setting an explicit ctx.font = "sans not-rotated 10px"; but the warning still shows up.

@chearon
Copy link
Collaborator

chearon commented Aug 12, 2020

The bit about not having any font instructions is surprising. That error gets triggered when Pango creates a cascade list for a section of text, which happens when you're rendering text, which happens due to fillText or strokeText. So I can't explain that, but the error itself seems to be happening for some people on Windows (eg #1608). Not sure why yet.

@Pomax
Copy link
Contributor Author

Pomax commented Aug 12, 2020

Ah yes, forgot that information: this is indeed Win10 pro x64 (with node 14.7), without even setting an explicit font.

Could it be that Pango is using the wrong naming format under water? (since "sans serif" is not a font, it's an entire category; not being able to find a single font in that category is basically impossible on any OS =)

@chearon
Copy link
Collaborator

chearon commented Aug 12, 2020

Could be, here's where Pango defines those categories:

https://github.com/GNOME/pango/blob/4ead5d2a2346c77a3dbc5e8d75221fa28e88f4e5/pango/pangowin32-fontmap.c#L464-L472

I don't know if sans-serif matches sans serif anywhere in the matching code, but if it doesn't, that would explain it. Do you see the error just by doing require('canvas') or does some drawing code trigger it?

@Pomax
Copy link
Contributor Author

Pomax commented Aug 12, 2020

This yields no errors:

import CanvasBuilder from 'canvas';
const canvas = CanvasBuilder.createCanvas(100,100);
const ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(100,0);
ctx.lineTo(100,100);
ctx.strokeStyle=`red`;
ctx.fillStyle=`green`;
ctx.stroke();

This does:

import CanvasBuilder from 'canvas';
const canvas = CanvasBuilder.createCanvas(100,100);
const ctx = canvas.getContext('2d');
ctx.fillText("and some text", 50, 50);

citing:

>node test.js

(process:14640): Pango-WARNING **: 10:09:32.235: couldn't load font "sans serif Not-Rotated 10px", falling back to "Sans Not-Rotated 10px", expect ugly output.

So I suspect pango doesn't even get initialised until the first time it's actually needed, evidenced by the fact that if I run multiple canvas sketches with text during the same Node run (e.g. multiple files that import canvas and generate distinct canvas objects), I only see the pango error once rather than one per canvas that uses fillText.

@chearon
Copy link
Collaborator

chearon commented Aug 12, 2020

You probably only see the error once because Pango caches font sets aggressively. I don't know how I'm just now realizing this, but CSS uses sans-serif and Pango uses sans.

> require('canvas').createCanvas(100, 100).getContext('2d').font
'10px sans-serif'

We just have to do the translation from "sans-serif" to "sans" internally. Only problem is I don't know if macOS understands sans-serif which would change results for users. And it's not unlikely someone has a FontConfig configuration that knows what sans-serif is. So it could be a breaking change, OTOH people should probably be setting font if they want it to be consistent...

I'll open that PR now

@Pomax
Copy link
Contributor Author

Pomax commented Aug 13, 2020

Nothing like a major semver update because "we fixed something, but it might have broken some people's configs, and we won't know until the bugs come rolling in" =P

@Pomax Pomax closed this as completed Aug 13, 2020
@Pomax Pomax reopened this Aug 13, 2020
@Pomax
Copy link
Contributor Author

Pomax commented Aug 13, 2020

that is not the button I wanted to press >_>

chearon added a commit that referenced this issue Aug 17, 2020
zbjornson pushed a commit that referenced this issue Aug 19, 2020
@KCSquid
Copy link

KCSquid commented Jan 19, 2021

Windows problem, you must install the font first on your pc or it will give that error

@Pomax
Copy link
Contributor Author

Pomax commented Jan 19, 2021

@KingCodeSquid how about reading the text of, and looking at the PR for, an issue, before commenting on something that's been resolved and closed for half a year, first =)

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

Successfully merging a pull request may close this issue.

4 participants
@chearon @Pomax @KCSquid and others