Automattic / Automattic/node-canvas

Canvas::RegisterFont does not detect font family on Alpine and end up "Could not parse font file"

Open
#1,164 24 comments 2 reactions 0 assignees View on GitHub
Bug Text & Fonts
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

I have an application where users are allowed to upload their fonts. Some of them do not have a font family defined. When you use a font file like that you get always an error `Could not parse font file`.

The check is here
https://github.com/Automattic/node-canvas/blob/06fbaf9e1bb51009c5170a337d67c3cbdf70dd6d/src/register_font.cc#L207

and came with this commit:

https://github.com/Automattic/node-canvas/commit/06fbaf9e1bb51009c5170a337d67c3cbdf70dd6d

This function `get_pango_font_description` is called by `Canvas::RegisterFont` which has the fontFamily as argument value, so theoretically we have all information in place and should not return with an error if the font file has no font family.

I made already changes to support this and also to improve error messages. We currently get always 'Could not parse font file', no matter what the error was inside of `get_pango_font_description`, so it was really hard for me to debug this case. I'm not sure if this project is still kind of active, so I'd appreciate some feedback whether a PR is welcomed before I actually provide a PR.

---

There might be another issue with this as I saw the font I'm using (a .ttf) is shown in my OSX with a font name, however node canvas says it can't find a font family name, so it might be that `get_family_name` is not fully functional.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.