A
A
AndreyKawilov2021-08-29 15:37:26
Canvas
AndreyKawilov, 2021-08-29 15:37:26

How can I include HYWenHei font in node js using Canvas?

Here is an example of my code:

const Canvas = require('canvas')
Canvas.registerFont(path.join(__dirname + `/HYWenHei-85W.ttf`), { family: 'myFont' })
const canvas = Canvas.createCanvas(1680, 800);
const context = canvas.getContext('2d');
context.fillStyle = 'white'
context.font = "100px myFont"; //HYWenHei 85W
context.fillText("LARKY", 635, 187);

I need the text on the image in HYWenHei font. But when I try to run it, I get the following error (more precisely, a varn, since everything continues to work except for the font):
(process:7752): Pango-WARNING **: 15:24:53.793: couldn't load font "HYWenHei 85W Not-Rotated 100px", falling back to "Sans Not-Rotated 100px", expect ugly output.


I tried to google for 2 days and did not find any solutions. I've been sitting on this all the time...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Khokhlov, 2021-08-29
@AndreyKawilov

Have you registered the font?
https://www.npmjs.com/package/canvas#registerfont

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question