-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Issue:
Sometimes the text can be rendered correctly but sometimes it seems using another default font(same always), it works on one process but doesn't work on another process because I'm using cluster. Since there is a license for the font, I can't upload it here. And I think it should not be relevant to the font as sometimes it really works. It is not happening every time.
Note: The important is that it works fine if fork one process only!!! And it worked well on Canvas 1.6.11 as well before upgraded to 2.9.1
Code:
let cluster = require('cluster');
if(cluster.isPrimary) {
for (let i = 0; i < 8; i++) {
cluster.fork();
}
} else {
const {createCanvas, registerFont} = require('canvas');
const font_path = '/data/fonts/NaiveBold.ttf';
let font_name = 'NaiveBold';
registerFont(font_path, {family: font_name});
let canvas = createCanvas(300, 300);
let ctx = canvas.getContext('2d');
ctx.textAlign = 'left';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#000000;
ctx.font = '20px ' + font_name;
ctx.fillText('This is a test text.', 0, 0);
// Try to save the text into a file to see the issue
// And from here it will start a web server by express
}
Text images generated:
Correct font used:

Incorrect font used(always same font):

Environment:
Nodejs 16.14.0 on Ubontu
Canvas 2.9.1
Fontconfig 2.13.1
Freetype 2.10.4
Cairo 1.16.0
Pango 1.46.0
Are there any ideas? Thank you in advance.