Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.08k stars 1.16k forks source link

Can't load custom font in windows device #2408

Open mahersalhani opened 1 month ago

mahersalhani commented 1 month ago

Issue

Steps to Reproduce

const { createCanvas, registerFont } = require("canvas");
const path = require("path");
const fs = require("fs");

const fontPath = path.join(__dirname, "Fancy Thread DEMO 400.ttf");
console.log(`Loading font from: ${fontPath}`);

if (fs.existsSync(fontPath)) {
  registerFont(fontPath, { family: "CustomFont" });
  console.log("Font registered successfully");
} else {
  console.error("Font file does not exist");
}

const canvas = createCanvas(800, 600);
const ctx = canvas.getContext("2d");

ctx.font = '48px "CustomFont"';
ctx.fillText("Hello, world!", 50, 100);

const buffer = canvas.toBuffer("image/png");
fs.writeFileSync("output.png", buffer);
console.log("Image saved as output.png");

Your Environment

I getting this message error (process:3048): Pango-WARNING **: 19:14:44.535: couldn't load font "Fancy Thread DEMO Not-Rotated 48px", falling back to "Sans Not-Rotated 48px", expect ugly output. I can't load custom font I tried in vps it worked the error only in windows

Andrekarma commented 1 month ago

I do have the same problem, i talked about it here https://github.com/Automattic/node-canvas/issues/2285

mahersalhani commented 1 month ago

I do have the same problem, i talked about it here #2285

I used The 2.10.2 vesion didn't work, it worked fine in my vps but not in my local device