diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/font/shape.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/font/shape.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/font/shape.zig | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/font/shape.zig b/vendor/libghostty-vt/src/font/shape.zig new file mode 100644 index 00000000..864c0f01 --- /dev/null +++ b/vendor/libghostty-vt/src/font/shape.zig @@ -0,0 +1,101 @@ +const std = @import("std"); +const options = @import("main.zig").options; +const run = @import("shaper/run.zig"); +const feature = @import("shaper/feature.zig"); +const configpkg = @import("../config.zig"); +const terminal = @import("../terminal/main.zig"); +const SharedGrid = @import("main.zig").SharedGrid; +pub const noop = @import("shaper/noop.zig"); +pub const harfbuzz = @import("shaper/harfbuzz.zig"); +pub const coretext = @import("shaper/coretext.zig"); +pub const web_canvas = @import("shaper/web_canvas.zig"); +pub const Cache = @import("shaper/Cache.zig"); +pub const TextRun = run.TextRun; +pub const RunIterator = run.RunIterator; +pub const Feature = feature.Feature; +pub const FeatureList = feature.FeatureList; +pub const default_features = feature.default_features; + +/// Shaper implementation for our compile options. +pub const Shaper = switch (options.backend) { + .freetype, + .fontconfig_freetype, + .coretext_freetype, + .coretext_harfbuzz, + => harfbuzz.Shaper, + + // Note that coretext_freetype cannot use the coretext + // shaper because the coretext shaper requests CoreText + // font faces. + .coretext => coretext.Shaper, + + .coretext_noshape => noop.Shaper, + + .web_canvas => web_canvas.Shaper, +}; + +/// A cell is a single glyph within a terminal that should be rendered +/// for a shaping call. Not all terminal cells may be present; only +/// cells that have a glyph that needs to be rendered. +pub const Cell = struct { + /// The X position of this shaper cell relative to the offset of the + /// run. Because runs are always within a single row, it is expected + /// that the caller can reconstruct the full position of the cell by + /// using the known Y position of the cell and adding the X position + /// to the run offset. + x: u16, + + /// An additional offset to apply to the rendering. + x_offset: i16 = 0, + y_offset: i16 = 0, + + /// The glyph index for this cell. The font index to use alongside + /// this cell is available in the text run. This glyph index is only + /// valid for a given GroupCache and FontIndex that was used to create + /// the runs. + glyph_index: u32, +}; + +/// Options for shapers. +pub const Options = struct { + /// Font features to use when shaping. + /// + /// Note: eventually, this will move to font.Face probably as we may + /// want to support per-face feature configuration. For now, we only + /// support applying features globally. + features: []const []const u8 = &.{}, +}; + +/// Options for runIterator. +pub const RunOptions = struct { + /// The font state for the terminal screen. This is mutable because + /// cached values may be updated during shaping. + grid: *SharedGrid, + + /// The cells for the row to shape. + cells: std.MultiArrayList(terminal.RenderState.Cell).Slice = .empty, + + /// The x boundaries of the selection in this row. + selection: ?[2]u16 = null, + + /// The cursor position within this row. This is used to break shaping + /// on cursor boundaries. This can be disabled by setting this to + /// null. + cursor_x: ?usize = null, + + /// Apply the font break configuration to the run. + pub fn applyBreakConfig( + self: *RunOptions, + config: configpkg.FontShapingBreak, + ) void { + if (!config.cursor) self.cursor_x = null; + } +}; + +test { + _ = Cache; + _ = Shaper; + + // Always test noop + _ = noop; +} |
