Canvas 中未显示字符

Characters are not displayed in Canvas

当我尝试使用 Canvas 在图片上显示文本时,某些字符和表情符号在 Windows 和 Ubuntu 上显示不正确。 1 个屏幕 - Windows,2 个屏幕 - Ubuntu。对于任何字体,情况都是如此。 Canvas 在 Windows 上,在 Ubuntu 上 我刚刚通过 npm install canvas.

安装

Windows

Ubuntu

代码:

const canvas = Canvas.createCanvas(1000,333)
const ctx = canvas.getContext('2d');
        
const background = await Canvas.loadImage('https://i.imgur.com/YzwG7yk.jpeg')
ctx.drawImage(background, 0, 0, canvas.width, canvas.height)
ctx.font = '300 30px "Arial"'
ctx.fillStyle = '#ffffff'
ctx.fillText(`\nマークとニック\nPzk`, 70, 70)
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'xp.png');
return message.channel.send(attachment)

您需要在服务器上安装能够呈现这些字形的字体。
如果您无法控制服务器上的字体,您可以使用 registerFont

加载网络字体

Live example.