Skip to content

Prebuilt binaries on Windows not working correctly with registerFont #2524

@ThanatosGit

Description

@ThanatosGit

There are many issues regarding loading custom fonts on Windows. #2522 #2519 #2408 #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

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:\<redacted>\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:\<redacted>\project> cd .\node_modules\canvas\
PS C:\<redacted>\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\<redacted>\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"
<output omitted>

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions