Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registerFromPath() works but register() does not with the same file #847

Open
ghost opened this issue Jun 25, 2024 · 0 comments
Open

registerFromPath() works but register() does not with the same file #847

ghost opened this issue Jun 25, 2024 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 25, 2024

Hey, I'm using @napi-rs/canvas (^0.1.53) under Bunjs (1.1.17) and Windows 11.
When I load a font with the registerFromPath() method, everything works normally. But when I load a buffer of some kind or a buffer of this same file, the text no longer appears on my canvas. How do I get .register() to work?

Work:

GlobalFonts.registerFromPath(process.cwd() + "/assets/fonts/Poppins-Bold.ttf", "Poppins Bold"); // return true

// ...

ctx.font = "36px Poppins Bold";
ctx.fillText("1x8S7bjie...", x, y);

Result:

image

Don't work:

const buffer = readFileSync(process.cwd() + "/assets/fonts/Poppins-Bold.ttf");
// or
const buffer = Buffer.from("<myBase64FontFile>", "base64");

GlobalFonts.register(buffer, "Poppins Bold"); // return true

// ...

ctx.font = "36px Poppins Bold";
ctx.fillText("1x8S7bjie...", x, y);

Result:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants