admin管理员组文章数量:1122832
I'm using node-canvas to generate an image with custom fonts. I've included a .ttf file and registered it using registerFont, but the font doesn't apply correctly to the text in the final image. Here's a simplified version of my code:
const { createCanvas, registerFont } = require('canvas');
const path = require('path');
const fontPath = path.join(__dirname, 'font.ttf');
registerFont(fontPath, { family: 'CustomFont' });
const canvas = createCanvas(800, 600);
const ctx = canvas.getContext('2d');
ctx.font = '30px "CustomFont", sans-serif';
ctx.fillStyle = 'black';
ctx.fillText('Hello World', 50, 50);
When I run this, the text renders, but the custom font is not applied. I'm suspecting the issue might be with the family name provided in registerFont.
How can I confirm the correct family name for the font I'm using? I've tried the following without success:
- Checking the font file name (e.g., font.ttf) and using it as the family name.
- Changing the font style in the ctx.font property.
Are there any reliable ways to extract the family name from the .ttf file or confirm what node-canvas recognizes? Any other debugging tips would be appreciated!
本文标签: javascriptFont Not Applying in nodecanvasStack Overflow
版权声明:本文标题:javascript - Font Not Applying in node-canvas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301073a1931052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论