Files
wehub-resource-sync bd44b5aa08
Nix / Required Checks: Nix (push) Blocked by required conditions
Nix / check-zig-cache-hash (push) Waiting to run
Test / skip (push) Waiting to run
Test / Required Checks: Test (push) Blocked by required conditions
Test / build-bench (push) Blocked by required conditions
Test / list-examples (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (Windows) (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (push) Blocked by required conditions
Test / build-cmake (push) Blocked by required conditions
Test / test-lib-vt-pkgconfig (push) Blocked by required conditions
Test / build-flatpak (push) Blocked by required conditions
Test / build-snap (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (wasm32-freestanding) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux-musl) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-ios) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Blocked by required conditions
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-windows (push) Blocked by required conditions
Test / build-libghostty-windows-gnu (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-linux-libghostty (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-dist (push) Blocked by required conditions
Test / build-dist-lib-vt (push) Blocked by required conditions
Test / trigger-snap (push) Blocked by required conditions
Test / trigger-flatpak (push) Blocked by required conditions
Test / build-macos (push) Blocked by required conditions
Test / build-macos-freetype (push) Blocked by required conditions
Test / test (push) Blocked by required conditions
Test / test-lib-vt (push) Blocked by required conditions
Test / GTK x11=false wayland=false (push) Blocked by required conditions
Test / GTK x11=true wayland=false (push) Blocked by required conditions
Test / GTK x11=false wayland=true (push) Blocked by required conditions
Test / GTK x11=true wayland=true (push) Blocked by required conditions
Test / Build -Dsimd=false (push) Blocked by required conditions
Test / Build -Dsimd=true (push) Blocked by required conditions
Test / Build -Dsentry=false (push) Blocked by required conditions
Test / Build -Dsentry=true (push) Blocked by required conditions
Test / test-macos (push) Blocked by required conditions
Test / test-windows (push) Blocked by required conditions
Test / Build -Di18n=false (push) Blocked by required conditions
Test / Build -Di18n=true (push) Blocked by required conditions
Test / Build test/fuzz-libghostty (push) Blocked by required conditions
Test / zig-fmt (push) Blocked by required conditions
Test / GitHub Actions Pins (push) Blocked by required conditions
Test / prettier (push) Blocked by required conditions
Test / swiftlint (push) Blocked by required conditions
Test / alejandra (push) Blocked by required conditions
Test / typos (push) Blocked by required conditions
Test / shellcheck (push) Blocked by required conditions
Test / translations (push) Blocked by required conditions
Test / blueprint-compiler (push) Blocked by required conditions
Test / Test pkg/wuffs (push) Blocked by required conditions
Test / Test build on Debian 13 (push) Blocked by required conditions
Test / valgrind (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 12:02:48 +08:00

173 lines
4.6 KiB
Zig

const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const graphics = @import("../graphics.zig");
const c = @import("c.zig").c;
/// Returns a struct that has all the shared context functions for the
/// given type.
pub fn Context(comptime T: type) type {
return struct {
value: *T,
pub fn release(self: *T) void {
c.CGContextRelease(@ptrCast(self));
}
pub fn setLineWidth(self: *T, width: f64) void {
c.CGContextSetLineWidth(
@ptrCast(self),
width,
);
}
pub fn setAllowsAntialiasing(self: *T, v: bool) void {
c.CGContextSetAllowsAntialiasing(
@ptrCast(self),
v,
);
}
pub fn setAllowsFontSmoothing(self: *T, v: bool) void {
c.CGContextSetAllowsFontSmoothing(
@ptrCast(self),
v,
);
}
pub fn setAllowsFontSubpixelPositioning(self: *T, v: bool) void {
c.CGContextSetAllowsFontSubpixelPositioning(
@ptrCast(self),
v,
);
}
pub fn setAllowsFontSubpixelQuantization(self: *T, v: bool) void {
c.CGContextSetAllowsFontSubpixelQuantization(
@ptrCast(self),
v,
);
}
pub fn setShouldAntialias(self: *T, v: bool) void {
c.CGContextSetShouldAntialias(
@ptrCast(self),
v,
);
}
pub fn setShouldSmoothFonts(self: *T, v: bool) void {
c.CGContextSetShouldSmoothFonts(
@ptrCast(self),
v,
);
}
pub fn setShouldSubpixelPositionFonts(self: *T, v: bool) void {
c.CGContextSetShouldSubpixelPositionFonts(
@ptrCast(self),
v,
);
}
pub fn setShouldSubpixelQuantizeFonts(self: *T, v: bool) void {
c.CGContextSetShouldSubpixelQuantizeFonts(
@ptrCast(self),
v,
);
}
pub fn setGrayFillColor(self: *T, gray: f64, alpha: f64) void {
c.CGContextSetGrayFillColor(
@ptrCast(self),
gray,
alpha,
);
}
pub fn setGrayStrokeColor(self: *T, gray: f64, alpha: f64) void {
c.CGContextSetGrayStrokeColor(
@ptrCast(self),
gray,
alpha,
);
}
pub fn setRGBFillColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
c.CGContextSetRGBFillColor(
@ptrCast(self),
r,
g,
b,
alpha,
);
}
pub fn setRGBStrokeColor(self: *T, r: f64, g: f64, b: f64, alpha: f64) void {
c.CGContextSetRGBStrokeColor(
@ptrCast(self),
r,
g,
b,
alpha,
);
}
pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void {
c.CGContextSetTextDrawingMode(
@ptrCast(self),
@intFromEnum(mode),
);
}
pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void {
c.CGContextSetTextMatrix(
@ptrCast(self),
@bitCast(matrix),
);
}
pub fn setTextPosition(self: *T, x: f64, y: f64) void {
c.CGContextSetTextPosition(
@ptrCast(self),
x,
y,
);
}
pub fn fillRect(self: *T, rect: graphics.Rect) void {
c.CGContextFillRect(
@ptrCast(self),
@bitCast(rect),
);
}
pub fn scaleCTM(self: *T, sx: c.CGFloat, sy: c.CGFloat) void {
c.CGContextScaleCTM(
@ptrCast(self),
sx,
sy,
);
}
pub fn translateCTM(self: *T, tx: c.CGFloat, ty: c.CGFloat) void {
c.CGContextTranslateCTM(
@ptrCast(self),
tx,
ty,
);
}
};
}
pub const TextDrawingMode = enum(c_int) {
fill = c.kCGTextFill,
stroke = c.kCGTextStroke,
fill_stroke = c.kCGTextFillStroke,
invisible = c.kCGTextInvisible,
fill_clip = c.kCGTextFillClip,
stroke_clip = c.kCGTextStrokeClip,
fill_stroke_clip = c.kCGTextFillStrokeClip,
clip = c.kCGTextClip,
};