Automattic / Automattic/node-canvas
Unexpected font fallback strategy on Linux
- 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.