Automattic / Automattic/node-canvas

Can't load custom fonts

Open
#2,097 8 comments 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

Can't load custom fonts that not installed to `/usr/share/fonts/`.

My font: https://fonts.google.com/specimen/Montserrat

It still loads fonts from `/usr/share/fonts`, but can't load fonts with `registerFont`

## Steps to Reproduce
1. Unzip font archive to `Montserrat/` into script `__dirname`
2. Run script:
```js
const path = require('path');
const fs = require('fs');
const { registerFont, createCanvas } = require('canvas');

registerFont(path.join(__dirname, 'Montserrat', 'static', 'Montserrat-Regular.ttf'), { family: 'Montserrat' });

const canvas = createCanvas(500, 500);
const ctx = canvas.getContext('2d');

ctx.font = '48px Montserrat';
ctx.textAlign = 'center';
ctx.fillText('Test text 123', 250, 250);

canvas.createPNGStream().pipe(fs.createWriteStream('image.png'));
```

## Your Environment
* Version of node-canvas (output of `npm list canvas` or `yarn list canvas`): canvas@2.9.3
* Environment (e.g. node 4.2.0 on Mac OS X 10.8): `node v16.14.2`, `Linux fedora 5.18.17-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 11 14:36:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux`

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.