Skip to content

Add ghostel-glyph-scale-floor: configurable minimum glyph scale#302

Merged
emil-e merged 1 commit into
dakra:mainfrom
emil-e:emil-e/cjk-scaling-floor
May 21, 2026
Merged

Add ghostel-glyph-scale-floor: configurable minimum glyph scale#302
emil-e merged 1 commit into
dakra:mainfrom
emil-e:emil-e/cjk-scaling-floor

Conversation

@emil-e
Copy link
Copy Markdown
Collaborator

@emil-e emil-e commented May 20, 2026

Closes #298.

Summary

Adds a buffer-local defcustom ghostel-glyph-scale-floor (number, 0.0–1.0, default 0.0) that clamps the computed glyph scale from below in adjustGlyph.

  • At 0.0 (default) the existing strict-grid behavior is completely unchanged.
  • At 1.0 CJK and other fallback glyphs render at natural font size, at the cost of slightly taller rows when fallback metrics exceed the primary cell size.
  • Values between 0 and 1 allow partial relief — e.g. 0.9 prevents shrinking below 90% while still correcting grossly oversized glyphs.

Being buffer-local means different ghostel buffers (a TUI session vs. a plain shell) can use different settings independently.

Implementation notes

  • One @max in adjustGlyph (Renderer.zig) after the existing @min
  • FontInfo carries glyph_scale_floor so a floor change triggers a full viewport invalidation without an extra symbol-value call per cell
  • emacs.zig gains asFloat(val, default) which uses (numberp) + (float) to safely coerce integers to f64, avoiding a wrong-type-argument signal that would corrupt the env's non-local exit state; std.math.clamp enforces the [0.0, 1.0] range on the Zig side regardless of what is set programmatically
  • updateFontInfo keeps env.eq as the outer gate so the nil-font case (no font before, no font now) correctly returns false and doesn't trigger a spurious force-full redraw
  • ERT test: ghostel-test-glyph-scale-floor-clamps-scale feeds a glyph larger than the cell with floor 1.0 and asserts it is not shrunk

Closes dakra#298.

Adds a buffer-local defcustom `ghostel-glyph-scale-floor` (number,
0.0–1.0, default 0.0) that clamps the computed glyph scale from below.
At 0.0 the existing strict-grid behavior is unchanged; at 1.0 CJK and
other fallback glyphs render at natural font size, at the cost of
slightly taller rows when fallback metrics exceed the primary cell.

Being buffer-local means different ghostel buffers can use different
settings independently.

Implementation:
- One @max in adjustGlyph (Renderer.zig) after the existing @min
- FontInfo carries glyph_scale_floor so a change triggers a full
  viewport invalidation without an extra symbol-value call per cell
- emacs.zig gains asFloat(val, default) which uses (numberp)+(float)
  to coerce integers to f64 and avoids a wrong-type-argument signal
  corrupting the env's non-local exit state; std.math.clamp enforces
  the [0.0, 1.0] range on the Zig side
- updateFontInfo fast-path keeps env.eq as the outer gate so the
  nil-font case (no font before, no font now) correctly returns false
- ERT test: ghostel-test-glyph-scale-floor-clamps-scale verifies the
  floor prevents shrinking below 1.0
@wd
Copy link
Copy Markdown

wd commented May 20, 2026

I just wanted to let you know that it works for me. (I had to fix the codesign issue in the brach)
This is the branch I tested: https://github.com/dakra/ghostel/compare/main...wd:ghostel:dong/test-pr-302?expand=1

You can see it is much better now. Thank you!!
image

@emil-e emil-e merged commit a1d51c7 into dakra:main May 21, 2026
42 checks passed
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.

Allow CJK / wide-character glyphs to render at natural size (configurable scale floor)

2 participants