Skip to content

Center glyphs vertically when lineSpacing > 1#585

Open
Coiggahou2002 wants to merge 1 commit into
migueldeicaza:mainfrom
Coiggahou2002:center-line-spacing
Open

Center glyphs vertically when lineSpacing > 1#585
Coiggahou2002 wants to merge 1 commit into
migueldeicaza:mainfrom
Coiggahou2002:center-line-spacing

Conversation

@Coiggahou2002

Copy link
Copy Markdown

What

When lineSpacing > 1, vertically center the glyph within the (now taller) cell, splitting the extra space above and below — instead of leaving it all above the text.

Why

lineSpacing scales the cell height in computeFontDimensions():

let cellHeight = ceil((lineAscent + lineDescent + lineLeading) * _lineSpacing)

but drawTerminalContents() still positions the baseline with the un-scaled offset:

let yOffset = ceil(lineDescent + lineLeading)

Since the row is drawn from the bottom up, the glyph baseline stays pinned to the bottom of the cell and all the added spacing ends up above the text. At larger values (e.g. 1.4–1.6) the lines look bottom-heavy — the gap sits entirely between a line and the line above it, not balanced around each line.

Change

Compute the extra height introduced by lineSpacing and split it evenly:

let extra = max(0, cellDimension.height - ceil(lineAscent + lineDescent + lineLeading))
let yOffset = ceil(lineDescent + lineLeading + extra / 2)
  • No behavior change at lineSpacing == 1.0 (extra == 0).
  • Backgrounds, selection and cursor already fill the full cell height, so only the glyph position changes.
  • Builds clean (swift build).

This matches how iTerm2 and WezTerm distribute their line spacing.

lineSpacing scales the cell height, but yOffset was left at descent+leading, so
all the added space piled above the glyph (text hugged the bottom of the cell).
Split the extra evenly above and below so text is vertically centered in the
taller cell, which reads better at larger line spacing.
@Coiggahou2002 Coiggahou2002 force-pushed the center-line-spacing branch from 2c8204f to 20e2b12 Compare July 1, 2026 09:33
@migueldeicaza

Copy link
Copy Markdown
Owner

I like the idea in principle, but this is not in sync with the caretView, we recently had to address that divergence, should be easy to test if you use a text editor and go to that line, the cursor is likely out of place,

This also does not cover metal.

Lastly, double-height characters might need to be addressed - check glyphSlotFit for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants