Automattic / Automattic/node-canvas

Font problem with the pre-compiled node-canvas

Open
#2,332 1 comment 0 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

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

There is a problem with the pre-compiled node-canvas when I try to use it to render some texts. After I run `npm rebuild canvas --build-from-source`, the problem is gone.

## Steps to Reproduce

```sh
npm install canvas
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';

registerFont('LXGWWenKai-Regular.ttf', { family: 'LXGW' });
const canvas = createCanvas(800, 600);
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, 800, 600);
ctx.fillStyle = '#000000';
ctx.font = '150px LXGW';
ctx.fillText('测试 test', 0, 400);

const data = canvas.toDataURL().replace(/^data:image\/\w+;base64,/, "");
fs.writeFileSync('out.png', data, 'base64');
```
```sh
node test.mjs
xdg-open out.png
```
![out.png](https://github.com/Automattic/node-canvas/assets/26196187/4fc6de4c-7103-45cb-ac2c-77bc1b9619d8)
(Here the font of the Chinese chars is correct, but the font of the English chars is wrong.)
```sh
npm rebuild canvas --build-from-source
node test.mjs
xdg-open out.png
```
![out.png](https://github.com/Automattic/node-canvas/assets/26196187/a09cbc95-c39d-4364-8014-0f942460993c)
(Here the font of all the chars is correct.)

## Your Environment
* Version of node-canvas: 2.11.2
* Environment: Node.js 20.10.0, Ubuntu 20.04 (x86_64).

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.