mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
move Atlas to font
This commit is contained in:
@ -7,7 +7,7 @@ const imgui = @import("imgui");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const Atlas = @import("Atlas.zig");
|
||||
const font = @import("font/main.zig");
|
||||
const Window = @import("Window.zig");
|
||||
const renderer = @import("renderer.zig");
|
||||
const Config = @import("config.zig").Config;
|
||||
@ -141,7 +141,7 @@ fn helpMarker(desc: [:0]const u8) void {
|
||||
}
|
||||
}
|
||||
|
||||
fn atlasInfo(self: *const DevMode, atlas: *Atlas, tex: ?usize) !void {
|
||||
fn atlasInfo(self: *const DevMode, atlas: *font.Atlas, tex: ?usize) !void {
|
||||
_ = self;
|
||||
|
||||
imgui.text("Dimensions: %d x %d", atlas.size, atlas.size);
|
||||
|
@ -19,7 +19,7 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const testing = std.testing;
|
||||
const fastmem = @import("fastmem.zig");
|
||||
const fastmem = @import("../fastmem.zig");
|
||||
|
||||
/// Data is the raw texture data.
|
||||
data: []u8,
|
@ -15,7 +15,6 @@ const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const font = @import("main.zig");
|
||||
const Atlas = @import("../Atlas.zig");
|
||||
const DeferredFace = @import("main.zig").DeferredFace;
|
||||
const Face = @import("main.zig").Face;
|
||||
const Library = @import("main.zig").Library;
|
||||
@ -267,7 +266,7 @@ pub fn faceFromIndex(self: Group, index: FontIndex) !Face {
|
||||
pub fn renderGlyph(
|
||||
self: Group,
|
||||
alloc: Allocator,
|
||||
atlas: *Atlas,
|
||||
atlas: *font.Atlas,
|
||||
index: FontIndex,
|
||||
glyph_index: u32,
|
||||
max_height: ?u16,
|
||||
@ -293,7 +292,7 @@ test {
|
||||
const testEmoji = @import("test.zig").fontEmoji;
|
||||
const testEmojiText = @import("test.zig").fontEmojiText;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
var lib = try Library.init();
|
||||
@ -354,7 +353,7 @@ test "box glyph" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
var lib = try Library.init();
|
||||
@ -387,7 +386,7 @@ test "resize" {
|
||||
const alloc = testing.allocator;
|
||||
const testFont = @import("test.zig").fontRegular;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
var lib = try Library.init();
|
||||
@ -452,7 +451,7 @@ test "discover monospace with fontconfig and freetype" {
|
||||
try group.addFace(alloc, .regular, (try it.next()).?);
|
||||
|
||||
// Should find all visible ASCII
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
var i: u32 = 32;
|
||||
while (i < 127) : (i += 1) {
|
||||
|
@ -5,7 +5,6 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const Atlas = @import("../Atlas.zig");
|
||||
const font = @import("main.zig");
|
||||
const Face = @import("main.zig").Face;
|
||||
const DeferredFace = @import("main.zig").DeferredFace;
|
||||
@ -30,8 +29,8 @@ group: Group,
|
||||
|
||||
/// The texture atlas to store renders in. The GroupCache has to store these
|
||||
/// because the cached Glyph result is dependent on the Atlas.
|
||||
atlas_greyscale: Atlas,
|
||||
atlas_color: Atlas,
|
||||
atlas_greyscale: font.Atlas,
|
||||
atlas_color: font.Atlas,
|
||||
|
||||
const CodepointKey = struct {
|
||||
style: Style,
|
||||
@ -46,9 +45,9 @@ const GlyphKey = struct {
|
||||
|
||||
/// The GroupCache takes ownership of Group and will free it.
|
||||
pub fn init(alloc: Allocator, group: Group) !GroupCache {
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
errdefer atlas_greyscale.deinit(alloc);
|
||||
var atlas_color = try Atlas.init(alloc, 512, .rgba);
|
||||
var atlas_color = try font.Atlas.init(alloc, 512, .rgba);
|
||||
errdefer atlas_color.deinit(alloc);
|
||||
|
||||
var result: GroupCache = .{
|
||||
@ -132,7 +131,7 @@ pub fn renderGlyph(
|
||||
if (gop.found_existing) return gop.value_ptr.*;
|
||||
|
||||
// Uncached, render it
|
||||
const atlas: *Atlas = switch (try self.group.presentationFromIndex(index)) {
|
||||
const atlas: *font.Atlas = switch (try self.group.presentationFromIndex(index)) {
|
||||
.text => &self.atlas_greyscale,
|
||||
.emoji => &self.atlas_color,
|
||||
};
|
||||
@ -169,7 +168,7 @@ test {
|
||||
const testFont = @import("test.zig").fontRegular;
|
||||
// const testEmoji = @import("test.zig").fontEmoji;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
var lib = try Library.init();
|
||||
@ -238,7 +237,7 @@ test "resize" {
|
||||
const testFont = @import("test.zig").fontRegular;
|
||||
// const testEmoji = @import("test.zig").fontEmoji;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
var lib = try Library.init();
|
||||
|
@ -6,7 +6,6 @@ const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const harfbuzz = @import("harfbuzz");
|
||||
const trace = @import("tracy").trace;
|
||||
const Atlas = @import("../Atlas.zig");
|
||||
const font = @import("main.zig");
|
||||
const Face = @import("main.zig").Face;
|
||||
const DeferredFace = @import("main.zig").DeferredFace;
|
||||
|
@ -4,7 +4,6 @@ const Allocator = std.mem.Allocator;
|
||||
const macos = @import("macos");
|
||||
const harfbuzz = @import("harfbuzz");
|
||||
const font = @import("../main.zig");
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
|
||||
pub const Face = struct {
|
||||
/// Our font face
|
||||
@ -99,7 +98,7 @@ pub const Face = struct {
|
||||
pub fn renderGlyph(
|
||||
self: Face,
|
||||
alloc: Allocator,
|
||||
atlas: *Atlas,
|
||||
atlas: *font.Atlas,
|
||||
glyph_index: u32,
|
||||
max_height: ?u16,
|
||||
) !font.Glyph {
|
||||
@ -343,7 +342,7 @@ test {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var atlas = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas.deinit(alloc);
|
||||
|
||||
const name = try macos.foundation.String.createWithBytes("Monaco", .utf8, false);
|
||||
@ -391,7 +390,7 @@ test "in-memory" {
|
||||
const alloc = testing.allocator;
|
||||
const testFont = @import("../test.zig").fontRegular;
|
||||
|
||||
var atlas = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas.deinit(alloc);
|
||||
|
||||
var lib = try font.Library.init();
|
||||
|
@ -12,7 +12,6 @@ const resize = @import("stb_image_resize");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
const font = @import("../main.zig");
|
||||
const Glyph = font.Glyph;
|
||||
const Library = font.Library;
|
||||
@ -123,7 +122,7 @@ pub const Face = struct {
|
||||
pub fn renderGlyph(
|
||||
self: Face,
|
||||
alloc: Allocator,
|
||||
atlas: *Atlas,
|
||||
atlas: *font.Atlas,
|
||||
glyph_index: u32,
|
||||
max_height: ?u16,
|
||||
) !Glyph {
|
||||
@ -152,7 +151,7 @@ pub const Face = struct {
|
||||
// or color depth is as expected on the texture atlas. If format is null
|
||||
// it means there is no native color format for our Atlas and we must try
|
||||
// conversion.
|
||||
const format: ?Atlas.Format = switch (bitmap_ft.pixel_mode) {
|
||||
const format: ?font.Atlas.Format = switch (bitmap_ft.pixel_mode) {
|
||||
freetype.c.FT_PIXEL_MODE_MONO => null,
|
||||
freetype.c.FT_PIXEL_MODE_GRAY => .greyscale,
|
||||
freetype.c.FT_PIXEL_MODE_BGRA => .rgba,
|
||||
@ -476,7 +475,7 @@ test {
|
||||
var lib = try Library.init();
|
||||
defer lib.deinit();
|
||||
|
||||
var atlas = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas.deinit(alloc);
|
||||
|
||||
var ft_font = try Face.init(lib, testFont, .{ .points = 12, .xdpi = 96, .ydpi = 96 });
|
||||
@ -508,7 +507,7 @@ test "color emoji" {
|
||||
var lib = try Library.init();
|
||||
defer lib.deinit();
|
||||
|
||||
var atlas = try Atlas.init(alloc, 512, .rgba);
|
||||
var atlas = try font.Atlas.init(alloc, 512, .rgba);
|
||||
defer atlas.deinit(alloc);
|
||||
|
||||
var ft_font = try Face.init(lib, testFont, .{ .points = 12, .xdpi = 96, .ydpi = 96 });
|
||||
@ -532,7 +531,7 @@ test "metrics" {
|
||||
var lib = try Library.init();
|
||||
defer lib.deinit();
|
||||
|
||||
var atlas = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas.deinit(alloc);
|
||||
|
||||
var ft_font = try Face.init(lib, testFont, .{ .points = 12, .xdpi = 96, .ydpi = 96 });
|
||||
@ -568,7 +567,7 @@ test "mono to rgba" {
|
||||
var lib = try Library.init();
|
||||
defer lib.deinit();
|
||||
|
||||
var atlas = try Atlas.init(alloc, 512, .rgba);
|
||||
var atlas = try font.Atlas.init(alloc, 512, .rgba);
|
||||
defer atlas.deinit(alloc);
|
||||
|
||||
var ft_font = try Face.init(lib, testFont, .{ .points = 12 });
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! to do this (likely using SIMD), but I started simple.
|
||||
const std = @import("std");
|
||||
const freetype = @import("freetype");
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
const font = @import("../main.zig");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
@ -22,7 +22,7 @@ pub const Func = std.meta.FnPtr(fn (Allocator, Bitmap) Allocator.Error!Bitmap);
|
||||
/// Alias for the freetype FT_Bitmap type to make it easier to type.
|
||||
pub const Bitmap = freetype.c.struct_FT_Bitmap_;
|
||||
|
||||
const AtlasArray = std.EnumArray(Atlas.Format, ?Func);
|
||||
const AtlasArray = std.EnumArray(font.Atlas.Format, ?Func);
|
||||
|
||||
fn genMap() Map {
|
||||
var result: Map = undefined;
|
||||
|
@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const build_options = @import("build_options");
|
||||
|
||||
pub const Atlas = @import("Atlas.zig");
|
||||
pub const discovery = @import("discovery.zig");
|
||||
pub const face = @import("face.zig");
|
||||
pub const DeferredFace = @import("DeferredFace.zig");
|
||||
|
@ -17,7 +17,6 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
const pixman = @import("pixman");
|
||||
const font = @import("../main.zig");
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
|
||||
const log = std.log.scoped(.box_font);
|
||||
|
||||
@ -58,7 +57,7 @@ const Thickness = enum {
|
||||
pub fn renderGlyph(
|
||||
self: Box,
|
||||
alloc: Allocator,
|
||||
atlas: *Atlas,
|
||||
atlas: *font.Atlas,
|
||||
cp: u32,
|
||||
) !font.Glyph {
|
||||
// Create the canvas we'll use to draw
|
||||
@ -2708,7 +2707,7 @@ test "all" {
|
||||
var cp: u32 = 0x2500;
|
||||
const end = 0x2570;
|
||||
while (cp <= end) : (cp += 1) {
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
const face: Box = .{ .width = 18, .height = 36, .thickness = 2 };
|
||||
|
@ -6,7 +6,7 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const pixman = @import("pixman");
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
const font = @import("../main.zig");
|
||||
|
||||
/// The underlying image.
|
||||
image: *pixman.Image,
|
||||
@ -70,7 +70,7 @@ pub fn deinit(self: *Canvas, alloc: Allocator) void {
|
||||
}
|
||||
|
||||
/// Write the data in this drawing to the atlas.
|
||||
pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *Atlas) !Atlas.Region {
|
||||
pub fn writeAtlas(self: *Canvas, alloc: Allocator, atlas: *font.Atlas) !font.Atlas.Region {
|
||||
assert(atlas.format == .greyscale);
|
||||
|
||||
const width = @intCast(u32, self.image.getWidth());
|
||||
|
@ -18,7 +18,6 @@ const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const font = @import("../main.zig");
|
||||
const Sprite = font.sprite.Sprite;
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
const Box = @import("Box.zig");
|
||||
const underline = @import("underline.zig");
|
||||
|
||||
@ -46,7 +45,7 @@ pub fn hasCodepoint(self: Face, cp: u32, p: ?font.Presentation) bool {
|
||||
pub fn renderGlyph(
|
||||
self: Face,
|
||||
alloc: Allocator,
|
||||
atlas: *Atlas,
|
||||
atlas: *font.Atlas,
|
||||
cp: u32,
|
||||
) !font.Glyph {
|
||||
if (std.debug.runtime_safety) assert(self.hasCodepoint(cp, null));
|
||||
|
@ -13,12 +13,11 @@ const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const font = @import("../main.zig");
|
||||
const Sprite = font.sprite.Sprite;
|
||||
const Atlas = @import("../../Atlas.zig");
|
||||
|
||||
/// Draw an underline.
|
||||
pub fn renderGlyph(
|
||||
alloc: Allocator,
|
||||
atlas: *Atlas,
|
||||
atlas: *font.Atlas,
|
||||
sprite: Sprite,
|
||||
width: u32,
|
||||
height: u32,
|
||||
@ -172,7 +171,7 @@ test "single" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
_ = try renderGlyph(
|
||||
@ -190,7 +189,7 @@ test "curly" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var atlas_greyscale = try Atlas.init(alloc, 512, .greyscale);
|
||||
var atlas_greyscale = try font.Atlas.init(alloc, 512, .greyscale);
|
||||
defer atlas_greyscale.deinit(alloc);
|
||||
|
||||
_ = try renderGlyph(
|
||||
|
@ -207,7 +207,6 @@ fn glfwErrorCallback(code: glfw.Error, desc: [:0]const u8) void {
|
||||
}
|
||||
|
||||
test {
|
||||
_ = @import("Atlas.zig");
|
||||
_ = @import("Pty.zig");
|
||||
_ = @import("Command.zig");
|
||||
_ = @import("TempDir.zig");
|
||||
|
@ -10,7 +10,6 @@ const glfw = @import("glfw");
|
||||
const objc = @import("objc");
|
||||
const macos = @import("macos");
|
||||
const imgui = @import("imgui");
|
||||
const Atlas = @import("../Atlas.zig");
|
||||
const font = @import("../font/main.zig");
|
||||
const terminal = @import("../terminal/main.zig");
|
||||
const renderer = @import("../renderer.zig");
|
||||
@ -1017,7 +1016,7 @@ fn syncCells(
|
||||
/// Sync the atlas data to the given texture. This copies the bytes
|
||||
/// associated with the atlas to the given texture. If the atlas no longer
|
||||
/// fits into the texture, the texture will be resized.
|
||||
fn syncAtlasTexture(device: objc.Object, atlas: *const Atlas, texture: *objc.Object) !void {
|
||||
fn syncAtlasTexture(device: objc.Object, atlas: *const font.Atlas, texture: *objc.Object) !void {
|
||||
const width = texture.getProperty(c_ulong, "width");
|
||||
if (atlas.size > width) {
|
||||
// Free our old texture
|
||||
@ -1284,7 +1283,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
|
||||
}
|
||||
|
||||
/// Initialize a MTLTexture object for the given atlas.
|
||||
fn initAtlasTexture(device: objc.Object, atlas: *const Atlas) !objc.Object {
|
||||
fn initAtlasTexture(device: objc.Object, atlas: *const font.Atlas) !objc.Object {
|
||||
// Determine our pixel format
|
||||
const pixel_format: MTLPixelFormat = switch (atlas.format) {
|
||||
.greyscale => .r8unorm,
|
||||
|
@ -7,7 +7,6 @@ const glfw = @import("glfw");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Atlas = @import("../Atlas.zig");
|
||||
const font = @import("../font/main.zig");
|
||||
const imgui = @import("imgui");
|
||||
const renderer = @import("../renderer.zig");
|
||||
|
Reference in New Issue
Block a user