mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: yeet more usingns
This commit is contained in:
@ -2,11 +2,11 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const graphics = @import("../graphics.zig");
|
||||
const context = @import("context.zig");
|
||||
const Context = @import("context.zig").Context;
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const BitmapContext = opaque {
|
||||
pub usingnamespace context.Context(BitmapContext);
|
||||
pub const context = Context(BitmapContext);
|
||||
|
||||
pub fn create(
|
||||
data: ?[]u8,
|
||||
|
@ -8,6 +8,8 @@ const c = @import("c.zig").c;
|
||||
/// given type.
|
||||
pub fn Context(comptime T: type) type {
|
||||
return struct {
|
||||
value: *T,
|
||||
|
||||
pub fn release(self: *T) void {
|
||||
c.CGContextRelease(@ptrCast(self));
|
||||
}
|
||||
|
@ -1,14 +1,34 @@
|
||||
pub const c = @import("text/c.zig");
|
||||
pub usingnamespace @import("text/font.zig");
|
||||
pub usingnamespace @import("text/font_collection.zig");
|
||||
pub usingnamespace @import("text/font_descriptor.zig");
|
||||
pub usingnamespace @import("text/font_manager.zig");
|
||||
pub usingnamespace @import("text/frame.zig");
|
||||
pub usingnamespace @import("text/framesetter.zig");
|
||||
pub usingnamespace @import("text/line.zig");
|
||||
pub usingnamespace @import("text/paragraph_style.zig");
|
||||
pub usingnamespace @import("text/run.zig");
|
||||
pub usingnamespace @import("text/stylized_strings.zig");
|
||||
const font = @import("text/font.zig");
|
||||
const font_collection = @import("text/font_collection.zig");
|
||||
const font_descriptor = @import("text/font_descriptor.zig");
|
||||
const font_manager = @import("text/font_manager.zig");
|
||||
const frame = @import("text/frame.zig");
|
||||
const framesetter = @import("text/framesetter.zig");
|
||||
const line = @import("text/line.zig");
|
||||
const paragraph_style = @import("text/paragraph_style.zig");
|
||||
const run = @import("text/run.zig");
|
||||
const stylized_strings = @import("text/stylized_strings.zig");
|
||||
|
||||
pub const c = @import("text/c.zig").c;
|
||||
pub const Font = font.Font;
|
||||
pub const FontTableTag = font.FontTableTag;
|
||||
pub const FontCollection = font_collection.FontCollection;
|
||||
pub const FontDescriptor = font_descriptor.FontDescriptor;
|
||||
pub const FontAttribute = font_descriptor.FontAttribute;
|
||||
pub const FontTraitKey = font_descriptor.FontTraitKey;
|
||||
pub const FontVariationAxisKey = font_descriptor.FontVariationAxisKey;
|
||||
pub const FontSymbolicTraits = font_descriptor.FontSymbolicTraits;
|
||||
pub const createFontDescriptorsFromURL = font_manager.createFontDescriptorsFromURL;
|
||||
pub const createFontDescriptorsFromData = font_manager.createFontDescriptorsFromData;
|
||||
pub const Frame = frame.Frame;
|
||||
pub const Framesetter = framesetter.Framesetter;
|
||||
pub const Line = line.Line;
|
||||
pub const ParagraphStyle = paragraph_style.ParagraphStyle;
|
||||
pub const ParagraphStyleSetting = paragraph_style.ParagraphStyleSetting;
|
||||
pub const ParagraphStyleSpecifier = paragraph_style.ParagraphStyleSpecifier;
|
||||
pub const WritingDirection = paragraph_style.WritingDirection;
|
||||
pub const Run = run.Run;
|
||||
pub const StringAttribute = stylized_strings.StringAttribute;
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
@ -1,3 +1,3 @@
|
||||
pub usingnamespace @cImport({
|
||||
pub const c = @cImport({
|
||||
@cInclude("CoreText/CoreText.h");
|
||||
});
|
||||
|
@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const Font = opaque {
|
||||
pub fn createWithFontDescriptor(desc: *const text.FontDescriptor, size: f32) Allocator.Error!*Font {
|
||||
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const FontCollection = opaque {
|
||||
pub fn createFromAvailableFonts() Allocator.Error!*FontCollection {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const FontDescriptor = opaque {
|
||||
pub fn createWithNameAndSize(name: *foundation.String, size: f64) Allocator.Error!*FontDescriptor {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array {
|
||||
return @ptrFromInt(@intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL(
|
||||
|
@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const Frame = opaque {
|
||||
pub fn release(self: *Frame) void {
|
||||
|
@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const Framesetter = opaque {
|
||||
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter {
|
||||
|
@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const Line = opaque {
|
||||
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line {
|
||||
|
@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
// https://developer.apple.com/documentation/coretext/ctparagraphstyle?language=objc
|
||||
pub const ParagraphStyle = opaque {
|
||||
|
@ -4,7 +4,7 @@ const Allocator = std.mem.Allocator;
|
||||
const foundation = @import("../foundation.zig");
|
||||
const graphics = @import("../graphics.zig");
|
||||
const text = @import("../text.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const Run = opaque {
|
||||
pub fn release(self: *Run) void {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const foundation = @import("../foundation.zig");
|
||||
const c = @import("c.zig");
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const StringAttribute = enum {
|
||||
font,
|
||||
|
@ -338,6 +338,7 @@ pub const Face = struct {
|
||||
defer alloc.free(buf);
|
||||
@memset(buf, 0);
|
||||
|
||||
const context = macos.graphics.BitmapContext.context;
|
||||
const ctx = try macos.graphics.BitmapContext.create(
|
||||
buf,
|
||||
width,
|
||||
@ -347,15 +348,15 @@ pub const Face = struct {
|
||||
color.space,
|
||||
color.context_opts,
|
||||
);
|
||||
defer ctx.release();
|
||||
defer context.release(ctx);
|
||||
|
||||
// Perform an initial fill. This ensures that we don't have any
|
||||
// uninitialized pixels in the bitmap.
|
||||
if (color.color)
|
||||
ctx.setRGBFillColor(1, 1, 1, 0)
|
||||
context.setRGBFillColor(ctx, 1, 1, 1, 0)
|
||||
else
|
||||
ctx.setGrayFillColor(0, 0);
|
||||
ctx.fillRect(.{
|
||||
context.setGrayFillColor(ctx, 0, 0);
|
||||
context.fillRect(ctx, .{
|
||||
.origin = .{ .x = 0, .y = 0 },
|
||||
.size = .{
|
||||
.width = @floatFromInt(width),
|
||||
@ -363,22 +364,22 @@ pub const Face = struct {
|
||||
},
|
||||
});
|
||||
|
||||
ctx.setAllowsFontSmoothing(true);
|
||||
ctx.setShouldSmoothFonts(opts.thicken); // The amadeus "enthicken"
|
||||
ctx.setAllowsFontSubpixelQuantization(true);
|
||||
ctx.setShouldSubpixelQuantizeFonts(true);
|
||||
ctx.setAllowsFontSubpixelPositioning(true);
|
||||
ctx.setShouldSubpixelPositionFonts(true);
|
||||
ctx.setAllowsAntialiasing(true);
|
||||
ctx.setShouldAntialias(true);
|
||||
context.setAllowsFontSmoothing(ctx, true);
|
||||
context.setShouldSmoothFonts(ctx, opts.thicken); // The amadeus "enthicken"
|
||||
context.setAllowsFontSubpixelQuantization(ctx, true);
|
||||
context.setShouldSubpixelQuantizeFonts(ctx, true);
|
||||
context.setAllowsFontSubpixelPositioning(ctx, true);
|
||||
context.setShouldSubpixelPositionFonts(ctx, true);
|
||||
context.setAllowsAntialiasing(ctx, true);
|
||||
context.setShouldAntialias(ctx, true);
|
||||
|
||||
// Set our color for drawing
|
||||
if (color.color) {
|
||||
ctx.setRGBFillColor(1, 1, 1, 1);
|
||||
ctx.setRGBStrokeColor(1, 1, 1, 1);
|
||||
context.setRGBFillColor(ctx, 1, 1, 1, 1);
|
||||
context.setRGBStrokeColor(ctx, 1, 1, 1, 1);
|
||||
} else {
|
||||
ctx.setGrayFillColor(1, 1);
|
||||
ctx.setGrayStrokeColor(1, 1);
|
||||
context.setGrayFillColor(ctx, 1, 1);
|
||||
context.setGrayStrokeColor(ctx, 1, 1);
|
||||
}
|
||||
|
||||
// We want to render the glyphs at (0,0), but the glyphs themselves
|
||||
|
Reference in New Issue
Block a user