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

fillText is drawn in only one font out of many. #201

Open
tinywolf3 opened this issue Jun 20, 2024 · 2 comments
Open

fillText is drawn in only one font out of many. #201

tinywolf3 opened this issue Jun 20, 2024 · 2 comments

Comments

@tinywolf3
Copy link

Expected Behaviour

  1. I want to output text in multiple fonts on a single image.

Actual Behaviour

  1. I run registerFont multiple times, but it only outputs the first registered font.

Steps To Reproduce

  1. You can test this with the code below.

Any Relevant Code Snippets

import { createWriteStream } from 'node:fs';
import { exec } from 'node:child_process';
import * as PImage from 'pureimage';

const fonts: PImage.Font[] = [];

async function test() {
	const font_list = [
		{ name: 'newbie', file: './fonts/SuperNormal.ttf' },
		{ name: 'easy', file: './fonts/SupplyCenter.ttf' },
		{ name: 'normal', file: './fonts/Dobidoo.ttf' },
		{ name: 'hard', file: './fonts/Youchat.ttf' },
		{ name: 'master', file: './fonts/Lazydog.ttf' },
	];
	for (const f of font_list) {
		const font = PImage.registerFont(f.file, f.name);
		await font.load();
		fonts.push(font);
	}

	const img = PImage.make(200, 200);
	const ctx = img.getContext('2d');
	ctx.fillStyle = '#ffffff';
	ctx.fillRect(0, 0, 200, 200);

	ctx.fillStyle = '#cccc00';
	ctx.font = "24pt 'newbie'";
	ctx.textAlign = 'center';
	ctx.fillText('newbie', 100, 40);

	ctx.fillStyle = '#00ff00';
	ctx.font = "24pt 'easy'";
	ctx.textAlign = 'center';
	ctx.fillText('easy', 100, 70);

	ctx.fillStyle = '#000000';
	ctx.font = "24pt 'normal'";
	ctx.textAlign = 'center';
	ctx.fillText('normal', 100, 100);

	ctx.fillStyle = '#ff0000';
	ctx.font = "24pt 'hard'";
	ctx.textAlign = 'center';
	ctx.fillText('hard', 100, 130);

	ctx.fillStyle = '#cc00cc';
	ctx.font = "24pt 'master'";
	ctx.textAlign = 'center';
	ctx.fillText('master', 100, 160);

	await PImage.encodePNGToStream(img, createWriteStream('./test.png'))
		.catch((e) => {
			console.error('there was an error image writing');
		});
	exec('open ./test.png');
}

test();

Platform

OS: macOS Sonoma 14.5
Node Version: v20.12.1
NPM Version: 10.8.1
PureImage Version: 0.4.13

Any Additional Info

result
test
expect
test

@unclexiao
Copy link

I get the same problem, can I unregister my font?

@joshmarinacci
Copy link
Owner

My apologies for not addressing this yet. It's been a crazy summer with travel and moving two houses. I should be able to get to the bugs after labor day.

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

3 participants