drawString function

This commit is contained in:
Emil Lerch 2023-03-30 08:45:17 -07:00
parent 60098caf01
commit 7fa10612e7
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -275,18 +275,8 @@ fn convertImage(alloc: std.mem.Allocator, filename: [:0]u8, pixels: *[WIDTH * HE
if (status == c.MagickFalse) if (status == c.MagickFalse)
return error.CouldNotSetExtent; return error.CouldNotSetExtent;
mw = try drawCharacter( mw = try drawString(mw, "hello, world!", 30, 38);
mw.?,
'4',
-5 * 3,
-8,
);
mw = try drawCharacter(
mw.?,
'2',
-5 * 4,
-8,
);
// We make the image monochrome by quantizing the image with 2 colors in the // We make the image monochrome by quantizing the image with 2 colors in the
// gray colorspace. See: // gray colorspace. See:
// https://www.imagemagick.org/Usage/quantize/#monochrome // https://www.imagemagick.org/Usage/quantize/#monochrome
@ -319,6 +309,18 @@ fn convertImage(alloc: std.mem.Allocator, filename: [:0]u8, pixels: *[WIDTH * HE
} }
} }
} }
fn drawString(mw: ?*c.MagickWand, str: []const u8, x: isize, y: isize) !?*c.MagickWand {
var rc = mw;
for (str, 0..) |ch, i| {
rc = try drawCharacter(
rc,
ch,
-(x + @intCast(isize, FONT_WIDTH * i)),
-y,
);
}
return rc;
}
fn drawCharacter(mw: ?*c.MagickWand, char: u8, x: isize, y: isize) !?*c.MagickWand { fn drawCharacter(mw: ?*c.MagickWand, char: u8, x: isize, y: isize) !?*c.MagickWand {
// Create a second wand. Does this need to exist after the block? // Create a second wand. Does this need to exist after the block?