Ghostty italic character rendering in monospace
Ghostty handles italic overflow through signed bearing offsets that allow glyphs to extend beyond their cell boundaries:
Italic synthesis: Uses a 15° skew transformation matrix (
tan(15°) ≈ 0.268) applied via CoreText/FreeType when no native italic font existsGlyph metrics: Each glyph stores
offset_xandoffset_yas signed integers — negativeoffset_xallows italic glyphs to extend left into the previous cellGPU rendering: The vertex shader simply applies these bearing offsets to position the glyph quad:
cell_pos = cell_pos + size * corner + offset; // offset can be negative!No clipping: Glyphs render freely in screen space — the renderer doesn't artificially clip to cell boundaries
For your Metal renderer, the key insight is:
- Store glyph bearings as signed (
i32) in your vertex data - In your vertex shader, add the bearing offset to the cell position
- Let the glyph naturally overflow — no special handling needed
This is simpler than trying to clip or rescale; you just let the slanted glyph draw where the font metrics say it should go.
Now I have a complete picture. Here's the comparison:
Comparison: Tucanty vs Ghostty Italic Rendering
| Aspect | Tucanty (current) | Ghostty |
|---|---|---|
| Font source | Loads separate italic font files (Berkeley Mono Oblique) | Uses native italic or synthesizes with 15° skew matrix |
| Glyph storage | TextAtlasGlyph stores width, height, ascender, x, y — no horizontal bearing |
Stores offset_x (signed), offset_y (signed) for bearing |
| Cell positioning | Positions at current_x, advances by glyph.width |
Positions at cell origin + signed bearing offset |
| Overflow handling | Calculates left_padding in atlas, but discards it at render time |
Passes signed bearing to GPU, glyph extends naturally |
| Aspect | Tucanty (current) | Ghostty |
|---|---|---|
| Font source | Loads separate italic font files (Berkeley Mono Oblique) | Uses native italic or synthesizes with 15° skew matrix |
| Glyph storage | TextAtlasGlyph stores width, height, ascender, x, y — no horizontal bearing |
Stores offset_x (signed), offset_y (signed) for bearing |
| Cell positioning | Positions at current_x, advances by glyph.width |
Positions at cell origin + signed bearing offset |
| Overflow handling | Calculates left_padding in atlas, but discards it at render time |
Passes signed bearing to GPU, glyph extends naturally |
The Problem in Tucanty
In renderer.rs lines 1079-1083, you correctly calculate left_padding for italic glyphs in the atlas:
let left_padding = if glyph_bearing_x < 0 { (-glyph_bearing_x) as u32 } else { 0 };
But in the render loop (lines 575-617), you position glyphs at current_x and advance by glyph_width_ndc — you never apply the bearing offset. The glyph is rendered aligned to the cell left edge, not offset by its bearing.
Fix
- Add
bearing_x: i32toTextAtlasGlyph - In the render loop, offset
pos_xby the bearing:let bearing_x_ndc = (glyph.bearing_x as f32 / window_width_px) * 2.0; let pos_x = current_x + bearing_x_ndc; - Advance by cell width (not glyph width) to maintain the monospace grid
I see now — your current code bakes the bearing into the atlas cell by adding left_padding and bitmap_x_offset. This means the glyph in the atlas is already positioned correctly within a wider cell that accounts for the bearing.
The issue is that you're then rendering this wider glyph starting at current_x and advancing by glyph_width instead of the cell width, which can cause spacing drift.
Current approach: Stores a wider glyph in atlas (bearing baked in), renders it at cell position, advances by glyph width.
Ghostty approach: Stores glyph at its natural size, passes signed bearing to GPU, renders offset from cell position, advances by cell width.
Your approach should work for properly-designed monospace italic fonts like Berkeley Mono, but may have issues with:
- Synthesized italics
- Fonts where italic glyphs genuinely extend past the cell
The screenshots look fine, so Berkeley Mono is well-behaved. Want me to proceed with the Ghostty-style fix anyway for correctness with other fonts, or leave it as-is since it works?
Done! The Ghostty-style approach is now implemented:
TextAtlasGlyphnow has abearing_x: i32field- Atlas storage: Glyphs are stored at their natural bitmap size (no padding)
- Render loop: Applies
bearing_xoffset when positioning, advances by cell width (not glyph width) to maintain the monospace grid
The before/after screenshots look identical, which is expected since Berkeley Mono Oblique is a well-designed monospace italic font. The real benefit comes with synthesized italics or fonts with more aggressive slant where glyphs genuinely extend past cell boundaries.
Let me check what monospace fonts are available on macOS and use Menlo (which has italic):
SF Mono has separate regular and italic files. Let me temporarily modify the font paths to test:
Let me also test with some characters that are known to have more aggressive italic slants:
Works well with SF Mono. Let me revert to the original fonts:
The Ghostty-style approach works with both Berkeley Mono and SF Mono. The key changes:
- Glyph stored at natural size — no padding baked into atlas
- Signed
bearing_xpassed through to render loop - Position offset by bearing —
pos_x = current_x + bearing_x_ndc - **Advance by cell