Automattic / Automattic/node-canvas

Unexpected font fallback strategy on Linux

Open
#2,369 0 comments 1 reaction 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

## Issue or Feature
- [ ] If this is an issue with installation, I have read the [troubleshooting guide](https://github.com/Automattic/node-canvas/issues/1511).

## Steps to Reproduce

```shell
npm install canvas
npm rebuild canvas --build-from-source # work around #2332
wget https://github.com/lxgw/LxgwWenKai/releases/download/v1.315/LXGWWenKai-Regular.ttf
vim test.mjs
```

```js
// test.mjs
import { createCanvas, registerFont } from 'canvas';
import fs from 'fs';

const [_, __, family, font] = process.argv
console.log({family, font})
registerFont('LXGWWenKai-Regular.ttf', {family});
const canvas = createCanvas(128,128);
const ctx = canvas.getContext('2d');
ctx.font = `64px ${font}`;
ctx.fillText('test', 0, 64);

const data = canvas.toDataURL().replace(/^data:image\/\w+;base64,/, "");
fs.writeFileSync('out.png', data, 'base64');
```
```shell
node test.mjs test test && xdg-open out.png # good
node test.mjs test '"LXGW WenKai",Arial' && xdg-open out.png # good
node test.mjs test test,Arial && xdg-open out.png # uses Arial, bad
node test.mjs 'LXGW WenKai' '"LXGW WenKai",Arial' && xdg-open out.png # uses Arial, bad
```

Reproducible on Linux. Not reproducible on Windows.

## Your Environment
* Version of node-canvas (output of `npm list canvas` or `yarn list canvas`): 2.11.2
* Environment (e.g. node 20.9.0 on macOS 14.1.1): Debian 12

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.