mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-05-19 14:48:37 +03:00
pkg/macos: font draw glyphs
This commit is contained in:
@ -3,6 +3,7 @@ pub usingnamespace @import("graphics/affine_transform.zig");
|
||||
pub usingnamespace @import("graphics/bitmap_context.zig");
|
||||
pub usingnamespace @import("graphics/color_space.zig");
|
||||
pub usingnamespace @import("graphics/font.zig");
|
||||
pub usingnamespace @import("graphics/point.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
10
pkg/macos/graphics/point.zig
Normal file
10
pkg/macos/graphics/point.zig
Normal file
@ -0,0 +1,10 @@
|
||||
const c = @import("c.zig");
|
||||
|
||||
pub const Point = extern struct {
|
||||
x: c.CGFloat,
|
||||
y: c.CGFloat,
|
||||
|
||||
pub fn cval(self: Point) c.struct_CGPoint {
|
||||
return @bitCast(c.struct_CGPoint, self);
|
||||
}
|
||||
};
|
@ -32,6 +32,22 @@ pub const Font = opaque {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn drawGlyphs(
|
||||
self: *Font,
|
||||
glyphs: []const graphics.Glyph,
|
||||
positions: []const graphics.Point,
|
||||
context: anytype, // Must be some context type from graphics
|
||||
) void {
|
||||
assert(positions.len == glyphs.len);
|
||||
c.CTFontDrawGlyphs(
|
||||
@ptrCast(c.CTFontRef, self),
|
||||
glyphs.ptr,
|
||||
@ptrCast([*]const c.struct_CGPoint, positions.ptr),
|
||||
glyphs.len,
|
||||
@ptrCast(c.CGContextRef, context),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() {
|
||||
return @intToPtr(attr.Value(), @ptrToInt(c.CTFontCopyAttribute(
|
||||
@ptrCast(c.CTFontRef, self),
|
||||
@ -64,4 +80,19 @@ test {
|
||||
&glyphs,
|
||||
));
|
||||
try testing.expect(glyphs[0] > 0);
|
||||
|
||||
// Draw
|
||||
{
|
||||
const cs = try graphics.ColorSpace.createDeviceGray();
|
||||
defer cs.release();
|
||||
const ctx = try graphics.BitmapContext.create(null, 80, 80, 8, 80, cs);
|
||||
defer ctx.release();
|
||||
|
||||
var pos = [_]graphics.Point{.{ .x = 0, .y = 0 }};
|
||||
font.drawGlyphs(
|
||||
&glyphs,
|
||||
&pos,
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user