Automattic / Automattic/node-canvas

Prebuilt binaries on Windows not working correctly with `registerFont`

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

Description

There are many issues regarding loading custom fonts on Windows. https://github.com/Automattic/node-canvas/issues/2522 https://github.com/Automattic/node-canvas/issues/2519 https://github.com/Automattic/node-canvas/issues/2408 https://github.com/Automattic/node-canvas/issues/2469 etc.
I'm on version 3.1.2 and a simple rebuild via `node-gyp` fixes the problem on my machine.
If you ask me, it would probably be a good idea to change the CI environment and steps such that it creates a fully working version.

You can see the versions used in my log but here is a summary:
Node 22.13.0, node-gyp 11.2.0, Python 3.12.1, BuildTools VS2022 (17.7.34024.191). GTK is the Win64 version linked in https://github.com/Automattic/node-canvas/wiki/Installation:-Windows and I just placed it under C:\GTK

```javascript
import { createCanvas, registerFont } from "canvas";

registerFont("fonts/Roboto-Bold.ttf", { family: "Roboto", weight: "bold" });
const canvas = createCanvas(128, 128);
const ctx = canvas.getContext("2d");
ctx.font = `bold 28px Roboto`;
ctx.fillText("AB", 10, 64);
canvas.toDataURL();
```
```
PS C:\\project> node .\test-canvas.js
(process:15352): Pango-WARNING **: 11:05:00.608: couldn't load font "Roboto Bold Not-Rotated 28px", falling back to "Sans Bold Not-Rotated 28px",
expect ugly output.
PS C:\\project> cd .\node_modules\canvas\
PS C:\\project\node_modules\canvas> node-gyp rebuild

gyp info it worked if it ends with ok
gyp info using node-gyp@11.2.0
gyp info using node@22.13.0 | win32 | x64
gyp info find Python using Python version 3.12.1 found at "C:\Users\\AppData\Local\Programs\Python\Python312\python.exe"

gyp info find VS using VS2022 (17.7.34024.191) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"

PS C:\\project\node_modules\canvas> cd ..\..
PS C:\\project> node .\test-canvas.js
PS C:\\project>
```

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.