freetype: Bitmap Handling 100% Coverage

This commit is contained in:
alichraghi 2022-07-22 15:24:58 +04:30 committed by Stephen Gutekanst
parent fbc9cee4cc
commit 0aa9cc4a04
3 changed files with 41 additions and 0 deletions

View file

@ -1,6 +1,7 @@
pub usingnamespace @cImport({
@cInclude("hb-ft.h");
@cInclude("freetype/ftbbox.h");
@cInclude("freetype/ftbitmap.h");
@cInclude("freetype/ftcolor.h");
@cInclude("freetype/ftlcdfil.h");
@cInclude("freetype/ftsizes.h");

View file

@ -60,6 +60,10 @@ pub fn format(self: GlyphSlot) GlyphFormat {
return @intToEnum(GlyphFormat, self.handle.*.format);
}
pub fn ownBitmap(self: GlyphSlot) Error!void {
try intToError(c.FT_GlyphSlot_Own_Bitmap(self.handle));
}
pub fn bitmap(self: GlyphSlot) Bitmap {
return .{ .handle = self.handle.*.bitmap };
}

View file

@ -1,5 +1,9 @@
const std = @import("std");
const c = @import("c");
const intToError = @import("error.zig").intToError;
const Error = @import("error.zig").Error;
const Library = @import("Library.zig");
const Color = @import("color.zig").Color;
pub const Outline = @import("Outline.zig");
@ -29,6 +33,38 @@ pub const GlyphFormat = enum(u32) {
pub const Bitmap = struct {
handle: c.FT_Bitmap,
pub fn init() Bitmap {
var b: c.FT_Bitmap = undefined;
c.FT_Bitmap_Init(&b);
return .{ .handle = b };
}
pub fn deinit(self: *Bitmap, lib: Library) void {
_ = c.FT_Bitmap_Done(lib.handle, &self.handle);
}
pub fn copy(self: Bitmap, lib: Library) Error!Bitmap {
var b: c.FT_Bitmap = undefined;
try intToError(c.FT_Bitmap_Copy(lib.handle, &self.handle, &b));
return Bitmap{ .handle = b };
}
pub fn embolden(self: *Bitmap, lib: Library, x_strength: i32, y_strength: i32) Error!void {
try intToError(c.FT_Bitmap_Embolden(lib.handle, &self.handle, x_strength, y_strength));
}
pub fn convert(self: Bitmap, lib: Library, alignment: u29) Error!Bitmap {
var b: c.FT_Bitmap = undefined;
try intToError(c.FT_Bitmap_Convert(lib.handle, &self.handle, &b, alignment));
return Bitmap{ .handle = b };
}
pub fn blend(self: *Bitmap, lib: Library, source_offset: Vector, target_offset: *Vector, color: Color) Error!void {
var b: c.FT_Bitmap = undefined;
c.FT_Bitmap_Init(&b);
try intToError(c.FT_Bitmap_Blend(lib.handle, &self.handle, source_offset, &b, target_offset, color));
}
pub fn width(self: Bitmap) u32 {
return self.handle.width;
}