Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(glyphgrid): shrink a glyph whose ink exceeds its cell instead of slicing it

enesa382bec5fb4c
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
index 6f1dbd03c..5f60136a7 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -344,6 +344,20 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
this change, that host's tmux is the one on the old table (a build without utf8proc) — report
it as such; the fix is that tmux, not a return to Unicode 6.
+- [ ] **2.18 A symbol wider than its cell is COMPLETE, not sliced.** The other half of the
+ 2026-08-05 round: an agent CLI's task-list icon rendered with its right edge cut off in
+ Shared while GPU mode drew it whole. Ink overflowing a cell used to be clipped (and the clip
+ cannot be relaxed — see L16); it is now SHRUNK to fit. Run an agent CLI and look at its task
+ list, its tool-result connectors and any status glyphs, then compare the same line against
+ **GPU per terminal**: no glyph may have a straight vertical edge where its shape should
+ continue.
+ **Expected difference, not a defect:** an oversized symbol renders slightly SMALLER here than
+ in GPU mode, which overhangs into the neighbouring cell instead. Smaller-and-whole is the
+ trade. Report anything still SEVERED, and report a glyph that shrank so far it is hard to
+ read (that is `MIN_INK_FIT_SCALE` set wrong, not the mechanism failing). Ordinary text must
+ be untouched — if plain Latin text looks smaller or unevenly sized after this, the tolerance
+ is misfiring and that is a **release blocker**.
+
## 3. Interactions
- [ ] **3.1 Wheel scrolls tmux history.** Wheel over a terminal scrolls tmux's own scrollback, the
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsx
index c00dff6f3..d35761685 100644
--- a/src/renderer/canvas/SharedGlyphLayer.tsx
+++ b/src/renderer/canvas/SharedGlyphLayer.tsx
@@ -724,15 +724,15 @@ function glyphDebugOn(): boolean {
function glyphDebugTap(): ((info: GlyphSlotAllocation) => void) | undefined {
if (!glyphDebugOn()) return undefined
- return ({ slot, code, bold, italic, x, y, fg, bg, half }): void => {
+ return ({ slot, code, bold, italic, x, y, fg, bg, part }): void => {
console.warn(
`[glyphgrid] slot ${slot} code 0x${code.toString(16)} ${JSON.stringify(
String.fromCodePoint(code)
)}${bold ? ' bold' : ''}${italic ? ' italic' : ''}${
- // Only the RIGHT half is called out. Every ordinary glyph is a left half, so printing that
- // on every line would be noise on the one log a device round reads line by line — and a
- // wide character not showing its pair here is exactly the failure worth spotting.
- half === 1 ? ' right-half' : ''
+ // Only a WIDE part is called out. Every ordinary glyph is 'whole', so printing that on
+ // every line would be noise on the one log a device round reads line by line — and a wide
+ // character showing no PAIR here is exactly the failure worth spotting.
+ part === 'whole' ? '' : ` ${part}`
} at ${x},${y} fg=${fg.toString(16)} bg=${bg.toString(16)}`
)
}
diff --git a/src/renderer/glyphgrid/atlas.test.ts b/src/renderer/glyphgrid/atlas.test.ts
index 549f4243c..6f1377ce5 100644
--- a/src/renderer/glyphgrid/atlas.test.ts
+++ b/src/renderer/glyphgrid/atlas.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest'
-import { GUTTER_PX, GlyphAtlas, type GlyphRasterizer, type GlyphSlotAllocation } from './atlas'
+import {
+ GUTTER_PX,
+ GlyphAtlas,
+ type GlyphPart,
+ type GlyphRasterizer,
+ type GlyphSlotAllocation
+} from './atlas'
/** Colors reach the atlas as opaque packed lanes — it never decodes them, so small distinct
* numbers keep the recorded call strings readable. */
@@ -9,21 +15,21 @@ const BG = 22
function fakeRasterizer(
cellW = 10,
cellH = 20
-): GlyphRasterizer & { calls: string[]; halves: number[] } {
+): GlyphRasterizer & { calls: string[]; parts: GlyphPart[] } {
const calls: string[] = []
- // Which half of a double-width character each draw was for, at the same index as `calls` (the
- // CLEAR entries aside). Its own array so the recorded call STRING — read verbatim by a dozen
- // layout assertions below — keeps its shape.
- const halves: number[] = []
+ // Which PART of its character each draw was for, at the same index as `calls` (the CLEAR entries
+ // aside). Its own array so the recorded call STRING — read verbatim by a dozen layout assertions
+ // below — keeps its shape.
+ const parts: GlyphPart[] = []
return {
cellW,
cellH,
calls,
- halves,
+ parts,
source: null,
- draw(code, bold, italic, x, y, fg, bg, half = 0) {
+ draw(code, bold, italic, x, y, fg, bg, part = 'whole') {
calls.push(`${code}|${bold ? 'b' : ''}${italic ? 'i' : ''}|${fg}|${bg}@${x},${y}`)
- halves.push(half)
+ parts.push(part)
},
// Logged into the SAME array as the draws, so "the page was blanked BEFORE the triggering
// glyph was drawn into it" is one ordering assertion rather than two independent counters.
@@ -84,7 +90,7 @@ describe('GlyphAtlas', () => {
atlas.glyphFor(0x41, false, true, FG, BG), // italic
atlas.glyphFor(0x41, false, false, FG + 1, BG), // fg
atlas.glyphFor(0x41, false, false, FG, BG + 1), // bg
- atlas.glyphFor(0x41, false, false, FG, BG, 1) // half
+ atlas.glyphFor(0x41, false, false, FG, BG, 'wide-right') // half
]
expect(new Set(slots).size).toBe(slots.length)
})
@@ -96,27 +102,36 @@ describe('GlyphAtlas', () => {
it('are separate slots, and the second is drawn shifted one cell left', () => {
const r = fakeRasterizer()
const atlas = new GlyphAtlas(r, 100)
- const left = atlas.glyphFor(0x4e2d, false, false, FG, BG, 0)
- const right = atlas.glyphFor(0x4e2d, false, false, FG, BG, 1)
+ const left = atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-left')
+ const right = atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-right')
expect(right).not.toBe(left)
// The atlas does NOT shift anything itself — it hands the rasterizer this slot's own ink
- // origin and the half, and the shift is raster.ts's (see its `inkX`). Pinned here because
- // a half that never reached the rasterizer would key two slots and paint them identically.
- expect(r.halves).toEqual([0, 1])
+ // origin and the part, and the shift is raster.ts's (see its `inkX`). Pinned here because
+ // a part that never reached the rasterizer would key two slots and paint them identically.
+ expect(r.parts).toEqual(['wide-left', 'wide-right'])
})
it('cache independently — asking for one never returns the other', () => {
const atlas = new GlyphAtlas(fakeRasterizer(), 100)
- const left = atlas.glyphFor(0x4e2d, false, false, FG, BG, 0)
- const right = atlas.glyphFor(0x4e2d, false, false, FG, BG, 1)
- expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 0)).toBe(left)
- expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 1)).toBe(right)
+ const left = atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-left')
+ const right = atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-right')
+ expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-left')).toBe(left)
+ expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-right')).toBe(right)
})
- it('default to the LEFT half, so every existing caller is unchanged', () => {
+ it("default to 'whole', so every existing caller is unchanged", () => {
const atlas = new GlyphAtlas(fakeRasterizer(), 100)
const implicit = atlas.glyphFor(0x41, false, false, FG, BG)
- expect(atlas.glyphFor(0x41, false, false, FG, BG, 0)).toBe(implicit)
+ expect(atlas.glyphFor(0x41, false, false, FG, BG, 'whole')).toBe(implicit)
+ })
+
+ it("'wide-left' is NOT 'whole', even though both draw from the character's left edge", () => {
+ // They differ in ENTITLEMENT, which is what raster.ts's shrink measures against: a 'whole'
+ // glyph may spread over one cell, a 'wide-left' one over two. Sharing a slot would shrink
+ // an emoji's left half to fit a single cell — the fragment this all exists to prevent.
+ const atlas = new GlyphAtlas(fakeRasterizer(), 100)
+ const whole = atlas.glyphFor(0x4e2d, false, false, FG, BG, 'whole')
+ expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 'wide-left')).not.toBe(whole)
})
})
@@ -528,12 +543,12 @@ describe('GlyphAtlas', () => {
atlas.glyphFor(0x78, true, false, FG, BG) // a different style IS a different slot
atlas.glyphFor(0x78, false, false, FG + 1, BG) // …and so is a different colour
atlas.glyphFor(0x20, false, false, FG, BG) // the blank slot is never an allocation
- atlas.glyphFor(0x78, false, false, FG, BG, 1) // …and so is the other half
+ atlas.glyphFor(0x78, false, false, FG, BG, 'wide-right') // …and so is the other half
expect(seen).toEqual([
- { slot: 1, code: 0x78, bold: false, italic: false, x: 16, y: 2, fg: FG, bg: BG, half: 0 },
- { slot: 2, code: 0x78, bold: true, italic: false, x: 30, y: 2, fg: FG, bg: BG, half: 0 },
- { slot: 3, code: 0x78, bold: false, italic: false, x: 44, y: 2, fg: FG + 1, bg: BG, half: 0 },
- { slot: 4, code: 0x78, bold: false, italic: false, x: 58, y: 2, fg: FG, bg: BG, half: 1 }
+ { slot: 1, code: 0x78, bold: false, italic: false, x: 16, y: 2, fg: FG, bg: BG, part: 'whole' as const },
+ { slot: 2, code: 0x78, bold: true, italic: false, x: 30, y: 2, fg: FG, bg: BG, part: 'whole' as const },
+ { slot: 3, code: 0x78, bold: false, italic: false, x: 44, y: 2, fg: FG + 1, bg: BG, part: 'whole' as const },
+ { slot: 4, code: 0x78, bold: false, italic: false, x: 58, y: 2, fg: FG, bg: BG, part: 'wide-right' as const }
])
})
diff --git a/src/renderer/glyphgrid/atlas.ts b/src/renderer/glyphgrid/atlas.ts
index 98e4e6128..a84650532 100644
--- a/src/renderer/glyphgrid/atlas.ts
+++ b/src/renderer/glyphgrid/atlas.ts
@@ -20,8 +20,8 @@ export interface GlyphRasterizer {
* cell — see GUTTER_PX); `fg`/`bg` are packColor lanes, the FINAL per-cell colours with
* selection/cursor already applied by the caller.
*
- * `half` selects WHICH cell-wide window of a DOUBLE-WIDTH character this slot holds: 0 the left
- * (every ordinary glyph, and a wide glyph's lead), 1 the right. See `glyphFor`. */
+ * `part` says which cell-wide window of the character this slot holds, and how many cells the
+ * character is entitled to. See `GlyphPart` and `glyphFor`. */
draw(
code: number,
bold: boolean,
@@ -30,7 +30,7 @@ export interface GlyphRasterizer {
y: number,
fg: number,
bg: number,
- half?: 0 | 1
+ part?: GlyphPart
): void
/** Blank the whole page. Called by `GlyphAtlas.reset()` and by nothing else: the bookkeeping and
* the pixels have to be emptied in the same breath or a stale slot keeps its old ink. */
@@ -38,6 +38,25 @@ export interface GlyphRasterizer {
readonly source: TexImageSource | null
}
+/**
+ * Which part of a character a slot holds — and, the half that is easy to miss, how many CELLS that
+ * character is entitled to.
+ *
+ * Both numbers are needed downstream. `raster.ts` clips ink to one cell and, since 2026-08-05,
+ * SHRINKS a glyph whose ink exceeds what it is entitled to rather than cutting it. A double-width
+ * character is entitled to TWO cells, so measuring one against a single cell would squash every
+ * emoji back into the fragment the two-slot mechanism exists to prevent.
+ *
+ * That is why this is an enum rather than the `half: 0 | 1` it started as: a boolean cannot tell a
+ * NARROW glyph from the LEFT half of a wide one, and those two want opposite answers.
+ */
+export type GlyphPart = 'whole' | 'wide-left' | 'wide-right'
+
+/** How many cells a part's character occupies — the single copy of that mapping. */
+export function partCells(part: GlyphPart): 1 | 2 {
+ return part === 'whole' ? 1 : 2
+}
+
/**
* The margin, in page texels, on EVERY side of a slot's cell rect that belongs to this slot alone.
* Exported because three modules have to agree on it: this file lays the page out with it,
@@ -123,9 +142,9 @@ export interface GlyphSlotAllocation {
/** The packed colour lanes the slot was rasterized in — part of its key. */
fg: number
bg: number
- /** Which half of a double-width character this slot holds (see `GlyphRasterizer.draw`). 0 for
- * every ordinary glyph, so a dump that never shows a 1 means nothing wide was drawn. */
- half: 0 | 1
+ /** Which part of its character this slot holds (see `GlyphPart`). 'whole' for every ordinary
+ * glyph, so a dump that never shows a wide-* means nothing double-width was drawn. */
+ part: GlyphPart
}
/** What `onReset` hands back. A plain disposable rather than an unsubscribe function so the call
@@ -314,25 +333,26 @@ export class GlyphAtlas {
* The slot holding this glyph in this style and these colours, allocating and rasterizing it on
* first sight.
*
- * `half` is what makes a DOUBLE-WIDTH character (an emoji, a CJK ideograph) whole. Such a
- * character occupies two terminal cells, but a slot's ink box is exactly ONE cell and raster.ts
- * CUTS whatever overflows it — so before this parameter existed the lead cell showed the left
- * portion of the glyph and the follower showed nothing at all. The 2026-08-05 device round is
- * that loss: ⭐ arriving as a fragment.
+ * `part` is what makes a DOUBLE-WIDTH character (an emoji, a CJK ideograph) whole. Such a
+ * character occupies two terminal cells, but a slot's ink box is exactly ONE cell — so before
+ * this parameter existed the lead cell showed the left portion of the glyph and the follower
+ * showed nothing at all. The 2026-08-05 device round is that loss: ⭐ arriving as a fragment.
*
- * The fix is to let the follower ask for the SAME character's other half. `half: 1` returns a
+ * The fix is to let the follower ask for the SAME character's other part. 'wide-right' returns a
* SECOND slot, rasterized with the glyph shifted one cell left so the window this slot's clip
* keeps is the character's right half; the feed then writes that slot into the follower's lane
* instead of the blank it used to write. The two halves land in the two cells the terminal has
* already reserved for this character, so the composed result is the whole glyph.
*
- * Note what this deliberately is NOT: the ink-sized-slot escalation raster.ts's header describes.
- * That one is for glyphs whose ink exceeds the cell WITHOUT the terminal knowing (an ornate
- * script face, real side bearings), and it reaches into the allocator, the slot-rect derivation
- * and the shader's uv maths at once. This reaches none of them — every slot is still exactly one
- * cell, still clipped to its own cell box, still 2*GUTTER_PX from its neighbour's ink, and the
- * shader is untouched. It only spends a second slot on a character the BUFFER already says is
- * two cells wide. A glyph wider than two cells is still cut, as before.
+ * It also carries the character's ENTITLEMENT — one cell or two — which is what `raster.ts`
+ * measures its shrink-to-fit against. 'wide-left' is not the same request as 'whole' even though
+ * both draw from the character's left edge: one may spread over two cells, the other may not.
+ *
+ * Note what this deliberately is NOT: the ink-sized-slot escalation raster.ts's header describes,
+ * which reaches into the allocator, the slot-rect derivation and the shader's uv maths at once.
+ * This reaches none of them — every slot is still exactly one cell, still clipped to its own cell
+ * box, still 2*GUTTER_PX from its neighbour's ink, and the shader is untouched. It only spends a
+ * second slot on a character the BUFFER already says is two cells wide.
*/
glyphFor(
code: number,
@@ -340,7 +360,7 @@ export class GlyphAtlas {
italic: boolean,
fg: number,
bg: number,
- half: 0 | 1 = 0
+ part: GlyphPart = 'whole'
): number {
if (code === 0x20 || code === 0) return 0
// `>>> 0` on both lanes: `0xff << 24` is NEGATIVE in JS (packColor carries the same note), so
@@ -348,9 +368,10 @@ export class GlyphAtlas {
// lane. Keying the two spellings separately would put identical pixels in two slots — wasted
// page, and resets arriving twice as fast.
//
- // `half` is IN the key: the two halves of one character are different pixels, and keying them
- // together would hand the follower the lead's slot and paint the left half twice.
- const key = `${code}|${bold ? 1 : 0}${italic ? 1 : 0}|${fg >>> 0}|${bg >>> 0}|${half}`
+ // `part` is IN the key: the two halves of one character are different pixels, and keying them
+ // together would hand the follower the lead's slot and paint the left half twice. 'whole' and
+ // 'wide-left' differ too — same drawing, different entitlement, so a different shrink.
+ const key = `${code}|${bold ? 1 : 0}${italic ? 1 : 0}|${fg >>> 0}|${bg >>> 0}|${part}`
const hit = this.slots.get(key)
if (hit !== undefined) return hit
if (this.nextSlot >= this.capacity) {
@@ -371,14 +392,14 @@ export class GlyphAtlas {
}
const slot = this.nextSlot++
const { x, y } = this.cellXY(slot)
- this.rasterizer.draw(code, bold, italic, x, y, fg, bg, half)
+ this.rasterizer.draw(code, bold, italic, x, y, fg, bg, part)
this.slots.set(key, slot)
this.dirtyFlag = true
// LAST, and guarded: the tap is a debug aid, so a throwing callback must cost a log line, not
// the glyph — everything above is already committed by the time it runs.
if (this.onAllocate) {
try {
- this.onAllocate({ slot, code, bold, italic, x, y, fg, bg, half })
+ this.onAllocate({ slot, code, bold, italic, x, y, fg, bg, part })
} catch {
/* a debug tap never breaks a frame */
}
diff --git a/src/renderer/glyphgrid/feed.test.ts b/src/renderer/glyphgrid/feed.test.ts
index cb8431e77..169bae117 100644
--- a/src/renderer/glyphgrid/feed.test.ts
+++ b/src/renderer/glyphgrid/feed.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { CELL_STRIDE, FLAG_BOLD, FLAG_CURSOR, FLAG_ITALIC, FLAG_SELECTED, FLAG_UNDERLINE, FLAG_WIDE, packColor, readCell } from './cells'
-import type { GlyphAtlas } from './atlas'
+import type { GlyphAtlas, GlyphPart } from './atlas'
import type { DecorationReader } from './decorations'
import { packViewportRow, setBlankCellProbe, type BlankCellReport, type CellView, type RowFeedOpts, type ThemeLanes } from './feed'
@@ -26,7 +26,7 @@ const THEME: ThemeLanes = {
function fakeAtlas(): Pick<GlyphAtlas, 'glyphFor'> & {
calls: Array<[number, boolean, boolean]>
colors: Array<[number, number]>
- halves: number[]
+ parts: GlyphPart[]
} {
const calls: Array<[number, boolean, boolean]> = []
const colors: Array<[number, number]> = []
@@ -34,22 +34,22 @@ function fakeAtlas(): Pick<GlyphAtlas, 'glyphFor'> & {
// character a cell asks for is part of the key, and it is the difference between an emoji
// rendering whole and rendering as its left fragment. Kept out of `calls` so the many
// assertions that pin `calls` verbatim stay about what they were written for.
- const halves: number[] = []
+ const parts: GlyphPart[] = []
return {
calls,
colors,
- halves,
+ parts,
glyphFor(
code: number,
bold: boolean,
italic: boolean,
fg: number,
bg: number,
- half: 0 | 1 = 0
+ part: GlyphPart = 'whole'
): number {
calls.push([code, bold, italic])
colors.push([fg, bg])
- halves.push(half)
+ parts.push(part)
return 900 + calls.length
}
}
@@ -228,7 +228,7 @@ describe('packViewportRow — wide and zero-width cells', () => {
expect(lead.flags & FLAG_WIDE).toBe(FLAG_WIDE)
// A slot's ink box is ONE cell and the overflow is cut, so a blank follower here threw the
// character's right half away — the 2026-08-05 ⭐ report. It asks for that half instead, from
- // its OWN slot: same character and style, `half: 1`.
+ // its OWN slot: same character and style, 'wide-right'.
expect(tail.glyph).toBe(902)
expect(tail.glyph).not.toBe(lead.glyph)
expect(tail.bg).toBe(lead.bg) // unbroken background run under the glyph
@@ -237,7 +237,7 @@ describe('packViewportRow — wide and zero-width cells', () => {
[0x4e2d, false, false],
[0x4e2d, false, false]
])
- expect(atlas.halves).toEqual([0, 1])
+ expect(atlas.parts).toEqual(['wide-left', 'wide-right'])
})
it('the follower inherits the LEAD’s style, not its own empty cell’s', () => {
@@ -675,7 +675,7 @@ describe('packViewportRow — the colours the atlas is asked for', () => {
[THEME.cursorFg, THEME.cursorBg],
[THEME.cursorFg, THEME.cursorBg]
])
- expect(atlas.halves).toEqual([0, 1])
+ expect(atlas.parts).toEqual(['wide-left', 'wide-right'])
expect(readCell(out, 1).bg).toBe(THEME.cursorBg)
})
})
diff --git a/src/renderer/glyphgrid/feed.ts b/src/renderer/glyphgrid/feed.ts
index 3a1149024..0cc338ad5 100644
--- a/src/renderer/glyphgrid/feed.ts
+++ b/src/renderer/glyphgrid/feed.ts
@@ -5,7 +5,7 @@
* color space). That is what keeps it pure, headless-testable and free of a dependency on
* xterm's internals, which are the part of that library most likely to move under us. */
-import type { GlyphAtlas } from './atlas'
+import type { GlyphAtlas, GlyphPart } from './atlas'
import type { CursorShape } from './cursor'
import { decorationAt, type DecorationReader } from './decorations'
import {
@@ -224,7 +224,8 @@ function resolveBg(cell: CellView, theme: ThemeLanes): number {
* WIDE / ZERO-WIDTH cells are one mechanism seen from two sides. A double-width glyph occupies
* two buffer cells: the lead reports width 2, and the cell right after it reports width 0. The
* lead carries the glyph's LEFT half (plus FLAG_WIDE) and the follower its RIGHT half — the same
- * character, same style, same colors, asked of the atlas as `half: 1` (see `GlyphAtlas.glyphFor`).
+ * character, same style, same colors, asked of the atlas as 'wide-right' (see
+ * `GlyphAtlas.glyphFor`).
* Carrying the LEAD's colors into the follower is what keeps the background under a wide glyph —
* a selection, the cursor, a colored block — one unbroken run instead of two halves that can
* disagree. The follower is never skipped: this row buffer is REUSED across frames, so "write
@@ -323,8 +324,9 @@ export function packViewportRow(
let code = 0
let bold = false
let italic = false
- /** Which cell-wide window of `code` this cell draws — 1 only on a wide glyph's follower. */
- let half: 0 | 1 = 0
+ /** Which part of `code` this cell draws, and how many cells that character is entitled to.
+ * 'whole' unless we are inside a double-width character. */
+ let part: GlyphPart = 'whole'
// Debug-only witnesses, read at the bottom of the loop. -1 distinguishes "no cell" from a cell
// that reported width 0; `getChars()` is only called when the probe is installed, because it
// allocates a string per cell and this loop runs for every cell of every packed row.
@@ -362,7 +364,7 @@ export function packViewportRow(
code = carryCode
bold = carryBold
italic = carryItalic
- half = 1
+ part = 'wide-right'
}
carryPending = false
carryCursor = false
@@ -377,6 +379,10 @@ export function packViewportRow(
if (cell.isUnderline() !== 0) flags |= FLAG_UNDERLINE
if (width === 2) {
flags |= FLAG_WIDE
+ // The LEFT half of a two-cell character, which is a different request from 'whole' even
+ // though both draw from the character's left edge: this one is allowed to spread over two
+ // cells, so the rasterizer must not shrink it to fit one.
+ part = 'wide-left'
carryPending = true
// The lead's RESOLVED colors, captured before the selection/decoration overrides on
// purpose: those are decided per COLUMN, so the follower applies whichever ones cover IT.
@@ -419,7 +425,7 @@ export function packViewportRow(
}
// fg/bg are FINAL here — this is the only place the atlas may be asked, see the doc comment.
- const glyph = isRenderableCode(code) ? atlas.glyphFor(code, bold, italic, fg, bg, half) : 0
+ const glyph = isRenderableCode(code) ? atlas.glyphFor(code, bold, italic, fg, bg, part) : 0
// A cell that HOLDS something and still draws nothing is the defect under investigation. A
// space is excluded because that is the correct answer for it, not a loss.
if (blankProbe && glyph === 0 && probeChars !== '' && probeChars !== ' ') {
diff --git a/src/renderer/glyphgrid/raster.test.ts b/src/renderer/glyphgrid/raster.test.ts
index 5d2655ef8..9d697b41d 100644
--- a/src/renderer/glyphgrid/raster.test.ts
+++ b/src/renderer/glyphgrid/raster.test.ts
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it } from 'vitest'
import { GlyphAtlas, GUTTER_PX } from './atlas'
import { packColor } from './cells'
-import { createCanvasRasterizer } from './raster'
+import { createCanvasRasterizer, shrinkToFit } from './raster'
/**
* These tests pin the three rects a colored draw uses, because the whole mip story rests on them:
@@ -20,7 +20,7 @@ import { createCanvasRasterizer } from './raster'
*/
interface Op {
- kind: 'fillRect' | 'fillText' | 'clip' | 'clearRect' | 'drawImage'
+ kind: 'fillRect' | 'fillText' | 'clip' | 'clearRect' | 'drawImage' | 'translate' | 'scale'
fill?: string
args: number[]
text?: string
@@ -44,7 +44,13 @@ type Clip = { x0: number; y0: number; x1: number; y1: number } | null
* these tests, it is the case they need — an ordinary letter is exactly a glyph whose ink stays
* inside the cell, and the model then shows the replication copying background over background.
*/
-function stubCanvas(sizePx = 256): {
+function stubCanvas(
+ sizePx = 256,
+ /** The INK width `measureText` reports, in px, split evenly either side of the origin. The
+ * default is comfortably inside the 10px cell, which is what every test that predates
+ * shrink-to-fit assumes; a test about an oversized glyph passes its own. */
+ inkWidth = 8
+): {
ops: Op[]
pixelAt: (x: number, y: number) => string
/** The page-wide `imageSmoothingEnabled` as it stands NOW — for asserting it was restored. */
@@ -116,6 +122,15 @@ function stubCanvas(sizePx = 256): {
fillText(text: string, x: number, y: number) {
ops.push({ kind: 'fillText', fill: ctx.fillStyle, args: [x, y], text })
},
+ // Recorded, NOT applied to the pixel model — which costs these tests nothing, because the
+ // model's `fillText` paints no pixels either (there is no font engine here). What the shrink
+ // tests need is the TRANSFORM the rasterizer asked for, and that is exactly what this keeps.
+ translate(x: number, y: number) {
+ ops.push({ kind: 'translate', args: [x, y] })
+ },
+ scale(sx: number, sy: number) {
+ ops.push({ kind: 'scale', args: [sx, sy] })
+ },
/** Only the 9-argument form, and only with WHOLE-texel destination rects — which is all the
* rasterizer's gutter replication uses. Nearest-neighbour sampling off a SNAPSHOT of the page,
* which is what the spec guarantees for a self-referencing drawImage.
@@ -151,8 +166,16 @@ function stubCanvas(sizePx = 256): {
}
}
},
- // A face whose line box exactly fills a 20px cell, so the baseline math is not the subject.
- measureText: () => ({ fontBoundingBoxAscent: 16, fontBoundingBoxDescent: 4 })
+ // The ascent/descent pin the baseline (a face whose line box exactly fills the 20px cell), so
+ // the baseline math is not the subject here. The actualBoundingBox pair is the INK extent
+ // shrink-to-fit measures — `left: 0` puts the ink
+ // entirely to the right of the origin, which is where a normal glyph's ink sits.
+ measureText: () => ({
+ fontBoundingBoxAscent: 16,
+ fontBoundingBoxDescent: 4,
+ actualBoundingBoxLeft: 0,
+ actualBoundingBoxRight: inkWidth
+ })
}
const prev = (globalThis as Record<string, unknown>).OffscreenCanvas
;(globalThis as Record<string, unknown>).OffscreenCanvas = class {
@@ -252,7 +275,7 @@ describe('createCanvasRasterizer', () => {
expect(Number.isInteger(ink.args[1])).toBe(true)
})
- describe('the right half of a double-width character (`half: 1`)', () => {
+ describe("the right half of a double-width character ('wide-right')", () => {
// A slot's ink box is one cell and step 2 CUTS the overflow, so a character the terminal gave
// two cells to was rendered as its first cell alone — the 2026-08-05 ⭐ report. The follower
// cell asks for the same character's other half, which is the same draw with the glyph's
@@ -262,7 +285,7 @@ describe('createCanvasRasterizer', () => {
active = stub
const r = createCanvasRasterizer(FONT, 256)!
stub.ops.length = 0
- r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 1)
+ r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 'wide-right')
const ink = stub.ops.find((o) => o.kind === 'fillText')!
expect(ink.args[0]).toBe(INK_X - FONT.cellW)
// The baseline does not move: only the horizontal window changes.
@@ -277,7 +300,7 @@ describe('createCanvasRasterizer', () => {
active = stub
const r = createCanvasRasterizer(FONT, 256)!
stub.ops.length = 0
- r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 1)
+ r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 'wide-right')
expect(stub.ops.find((o) => o.kind === 'clip')).toEqual({
kind: 'clip',
args: [INK_X, INK_Y, FONT.cellW, FONT.cellH]
@@ -291,7 +314,7 @@ describe('createCanvasRasterizer', () => {
active = stub
const r = createCanvasRasterizer(FONT, 256)!
stub.ops.length = 0
- r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 1)
+ r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 'wide-right')
expect(stub.ops[0]).toEqual({
kind: 'fillRect',
fill: BG_CSS,
@@ -305,11 +328,83 @@ describe('createCanvasRasterizer', () => {
createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG)
const explicit = stubCanvas()
active = explicit
- createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG, 0)
+ createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG, 'whole')
expect(withDefault.ops).toEqual(explicit.ops)
})
})
+ /**
+ * The 2026-08-05 device finding: an agent CLI's task-list icon rendered with its right edge
+ * sliced off, while GPU mode showed it whole. A symbol whose ink is wider than its cell used to
+ * be CUT by the ink clip, and the clip cannot be relaxed — ink in the gutter is what the
+ * MAX_SAFE_LOD derivation forbids. So the glyph is made to fit instead of trimmed to fit.
+ */
+ describe('shrink-to-fit for a glyph whose ink exceeds its cell', () => {
+ /** The `fillText` op, and the transform (if any) that was in effect for it. */
+ function inkOp(ops: Op[]): { text: Op; scale?: Op; translate?: Op } {
+ return {
+ text: ops.find((o) => o.kind === 'fillText')!,
+ scale: ops.find((o) => o.kind === 'scale'),
+ translate: ops.find((o) => o.kind === 'translate')
+ }
+ }
+
+ it('an ordinary glyph is drawn by the SAME call as before — no transform at all', () => {
+ // Load-bearing: a scale of exactly 1 must take the untouched path, so nothing anyone has
+ // already looked at moves. 8px of ink in a 10px cell is an ordinary letter.
+ const stub = stubCanvas(256, 8)
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x41, false, false, INK_X, INK_Y, FG, BG)
+ const { text, scale, translate } = inkOp(stub.ops)
+ expect(scale).toBeUndefined()
+ expect(translate).toBeUndefined()
+ expect(text.args).toEqual([INK_X, INK_Y + 16])
+ })
+
+ it('an oversized glyph is SCALED to its cell instead of being clipped', () => {
+ // 14px of ink entitled to one 10px cell: without this it lost 4px off its right edge.
+ const stub = stubCanvas(256, 14)
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x29c9, false, false, INK_X, INK_Y, FG, BG)
+ const { text, scale, translate } = inkOp(stub.ops)
+ expect(scale!.args).toEqual([10 / 14, 10 / 14])
+ // Scaled about the BASELINE, so the glyph keeps sitting on its neighbours' line, and
+ // re-centred inside the cell — here the scaled ink is exactly the cell, so the centring term
+ // is zero and the ink starts at the ink origin.
+ expect(translate!.args).toEqual([INK_X, INK_Y + 16])
+ expect(text.args).toEqual([0, 0])
+ })
+
+ it('a slight overhang is left alone — the tolerance absorbs an antialiasing fringe', () => {
+ // 10.3px in a 10px cell is a full-bleed glyph measuring a fraction over, not an oversized
+ // symbol. Scaling it would buy nothing and could open a hairline in a run of `───`.
+ const stub = stubCanvas(256, 10.3)
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x41, false, false, INK_X, INK_Y, FG, BG)
+ expect(inkOp(stub.ops).scale).toBeUndefined()
+ })
+
+ it('a DOUBLE-WIDTH character is measured against TWO cells, not one', () => {
+ // The regression this guards is severe and silent: an emoji's ink is ~1.7 cells, so measuring
+ // either half against ONE cell would shrink every emoji back into the fragment the two-slot
+ // mechanism exists to prevent. 18px of ink is inside a 20px entitlement — leave it alone.
+ for (const part of ['wide-left', 'wide-right'] as const) {
+ const stub = stubCanvas(256, 18)
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x1f44d, false, false, INK_X, INK_Y, FG, BG, part)
+ expect(inkOp(stub.ops).scale, part).toBeUndefined()
+ }
+ })
+ })
+
// The claim is about GEOMETRY, not about pixels: no glyph may generate NEW ink outside the slot's
// own WHOLE-TEXEL CELL BOX, because the MAX_SAFE_LOD derivation counts on 2*GUTTER_PX texels
// between two slots' inks. The gutter is not required to be BACKGROUND — the edge-extension
@@ -863,3 +958,47 @@ describe('createCanvasRasterizer', () => {
})
})
})
+
+/**
+ * The shrink factor on its own — the arithmetic, without a canvas in the way.
+ *
+ * Separate from the draw tests because the interesting cases are the EDGES (the tolerance, the
+ * floor, a platform that reports no ink box), and each of those is one number rather than a
+ * rendering.
+ */
+describe('shrinkToFit', () => {
+ const metrics = (left: number, right: number): TextMetrics =>
+ ({ actualBoundingBoxLeft: left, actualBoundingBoxRight: right }) as TextMetrics
+
+ it('returns exactly 1 for ink that fits, so the caller takes the untouched path', () => {
+ expect(shrinkToFit(metrics(0, 8), 10)).toBe(1)
+ expect(shrinkToFit(metrics(2, 6), 10)).toBe(1)
+ })
+
+ it('scales an oversized glyph down to its allowance', () => {
+ expect(shrinkToFit(metrics(0, 14), 10)).toBeCloseTo(10 / 14)
+ // The ink box is measured either side of the ORIGIN — a glyph with a left side bearing that
+ // reaches back past it is just as oversized as one that runs long to the right.
+ expect(shrinkToFit(metrics(4, 10), 10)).toBeCloseTo(10 / 14)
+ })
+
+ it('tolerates a small overhang', () => {
+ expect(shrinkToFit(metrics(0, 10.4), 10)).toBe(1) // 4% — the fringe
+ expect(shrinkToFit(metrics(0, 10.5), 10)).toBeLessThan(1) // past it
+ })
+
+ it('stops shrinking at the floor — a legible fragment beats an illegible whole', () => {
+ // 25px in a 10px cell would be a 0.4 scale. Clamped, so the excess is clipped as it always was
+ // (L16) rather than rendering something too small to read.
+ expect(shrinkToFit(metrics(0, 25), 10)).toBe(0.6)
+ })
+
+ it('declines to shrink when the platform reports no usable ink box', () => {
+ // The failure to avoid is a NaN scale silently blanking every glyph. Declining restores the
+ // pre-2026-08-05 behaviour for that platform, which is a correct outcome, not a broken one.
+ expect(shrinkToFit({} as TextMetrics, 10)).toBe(1)
+ expect(shrinkToFit(metrics(NaN, NaN), 10)).toBe(1)
+ expect(shrinkToFit(metrics(0, 0), 10)).toBe(1)
+ expect(shrinkToFit(metrics(0, 14), 0)).toBe(1)
+ })
+})
diff --git a/src/renderer/glyphgrid/raster.ts b/src/renderer/glyphgrid/raster.ts
index f4f0cfd66..d903ff6de 100644
--- a/src/renderer/glyphgrid/raster.ts
+++ b/src/renderer/glyphgrid/raster.ts
@@ -1,4 +1,4 @@
-import { GUTTER_PX, slotPitch, type GlyphRasterizer } from './atlas'
+import { GUTTER_PX, partCells, slotPitch, type GlyphRasterizer } from './atlas'
import { boxGlyphOps } from './box-glyphs'
import { unpackColor } from './cells'
@@ -30,6 +30,52 @@ export interface RasterFont {
* `GlyphAtlas.glyphFor` applies to its KEY, kept here so the two can never disagree about what
* "the same colour" means.
*/
+/**
+ * How much a glyph's ink may exceed what its character is entitled to before it is shrunk.
+ *
+ * Not zero, and the direction matters. `actualBoundingBox*` reports the ANTIALIASED extent, so a
+ * perfectly cell-sized glyph routinely measures a fraction of a pixel over — and a zero tolerance
+ * would put every full-bleed box-drawing character through a 0.99 scale for nothing, which is both
+ * wasted work and a way to introduce a hairline gap in a run of `───` that is currently seamless.
+ * (The box-drawing ranges take the geometric path and never reach this, but the aliases and the
+ * faces that draw to the cell edge do.)
+ *
+ * 4% is comfortably above that fringe and far below a real overflow: the 2026-08-05 icon measured
+ * roughly a quarter over its cell, and the class this exists for — symbols drawn to a square box in
+ * a font whose advance is not square — is never marginal.
+ */
+const INK_FIT_TOLERANCE = 1.04
+
+/**
+ * The floor on shrinking. Below this a glyph has stopped being small and started being unreadable,
+ * and a legible fragment beats an illegible whole — so past the floor the clip takes over again and
+ * the old truncation is what happens, which is exactly what L16 already describes.
+ *
+ * Reached only by ink more than ~1.7 cells wide on a character entitled to one, which is not a
+ * symbol-in-a-monospace-face any more; it is a face being used at the wrong size.
+ */
+const MIN_INK_FIT_SCALE = 0.6
+
+/**
+ * The factor a glyph must be drawn at to fit its entitlement, or exactly 1 for "draw it unchanged".
+ *
+ * Returning the literal 1 is part of the contract, not an optimisation: the caller branches on it
+ * to take the untouched `fillText` path, so every glyph that was never oversized is rasterized by
+ * the same call it was before shrink-to-fit existed.
+ *
+ * A metrics object without `actualBoundingBox*` (or with nonsense in it) yields 1 as well. The
+ * fields are standard but this runs on whatever canvas the platform gives us, and the failure to
+ * avoid is a NaN scale silently blanking every glyph — declining to shrink just restores the older
+ * behaviour for that platform.
+ */
+export function shrinkToFit(metrics: TextMetrics, allowance: number): number {
+ const inkW = metrics.actualBoundingBoxLeft + metrics.actualBoundingBoxRight
+ if (!Number.isFinite(inkW) || inkW <= 0) return 1
+ if (!Number.isFinite(allowance) || allowance <= 0) return 1
+ if (inkW <= allowance * INK_FIT_TOLERANCE) return 1
+ return Math.max(MIN_INK_FIT_SCALE, allowance / inkW)
+}
+
function cssColor(packed: number): string {
const { r, g, b } = unpackColor(packed >>> 0)
return `rgb(${r},${g},${b})`
@@ -288,11 +334,11 @@ export function createCanvasRasterizer(
/** `x, y` is the INK origin the atlas hands us — already one gutter inside the pitch cell on
* each axis (`GlyphAtlas.cellXY`) — and `fg`/`bg` are the FINAL packed colour lanes for this
* slot. Two DIFFERENT rects are involved; see the header's invariants 3 and 4. */
- draw(code, bold, italic, x, y, fg, bg, half = 0) {
- // The glyph's own origin inside this slot. `half: 1` is the RIGHT half of a double-width
+ draw(code, bold, italic, x, y, fg, bg, part = 'whole') {
+ // The glyph's own origin inside this slot. 'wide-right' is the RIGHT half of a double-width
// character (see `GlyphAtlas.glyphFor`): the character is drawn one cell FURTHER LEFT, so the
// window this slot's clip keeps is its second cell instead of its first. Everything else
- // below is untouched — same clip, same pitch fill, same edge extension — because the fix is
+ // below is untouched — same clip, same pitch fill, same edge extension — because that fix is
// about WHICH part of the glyph a cell-sized slot holds, not about the slot's size.
//
// The shift is the FRACTIONAL cell, not a whole texel, so the two halves meet exactly where
@@ -301,7 +347,12 @@ export function createCanvasRasterizer(
// its antialiasing can differ by a fraction of a pixel along the seam. That is the honest
// trade: a phase difference is a hairline, a whole-texel shift would be a visible break in
// the character.
- const inkX = half === 1 ? x - font.cellW : x
+ const inkX = part === 'wide-right' ? x - font.cellW : x
+ // What this character is ENTITLED to, in px — one cell, or two for a double-width one. The
+ // shrink below measures against this, never against the slot: both halves of a wide glyph are
+ // the same drawing spread over two cells, so measuring either against ONE cell would squash
+ // it back into the fragment the two-slot mechanism exists to prevent.
+ const allowance = partCells(part) * font.cellW
// 1. THE BACKGROUND, over the whole PITCH rect — gutters included. The atlas passes the INK
// origin, so the pitch cell's corner is one gutter back on each axis; its extent is the
// pitch, which is `ceil(cell) + 2*GUTTER_PX`. Both are whole texels and consecutive pitch
@@ -397,7 +448,48 @@ export function createCanvasRasterizer(
}
} else {
ctx.font = `${italic ? 'italic ' : ''}${bold ? 'bold ' : ''}${font.sizePx}px ${font.family}`
- ctx.fillText(String.fromCodePoint(code), inkX, y + baseline)
+ const glyph = String.fromCodePoint(code)
+ // SHRINK-TO-FIT, the 2026-08-05 device finding (an agent CLI's task-list icon rendering
+ // with its right edge sliced off; GPU mode showed it whole).
+ //
+ // A symbol whose ink is wider than its cell used to be CUT by the clip above, and the clip
+ // cannot simply be relaxed — ink in the gutter is what the MAX_SAFE_LOD derivation forbids,
+ // and the result is a ghost of this glyph in a neighbour's minified texels. So the glyph is
+ // made to fit instead of being trimmed to fit.
+ //
+ // WHY THIS RATHER THAN WHAT XTERM DOES. xterm measures every glyph, sizes its atlas slot to
+ // the INK and emits a quad of that size, so ink legitimately overhangs into neighbouring
+ // cells. That is the honest answer and it is also the expensive one: it reaches the atlas
+ // allocator, the slot-rect derivation and the shader's uv maths at once, and it rewrites
+ // what the gutter argument defends. This is the cheap approximation of the same intent, and
+ // its cost is stated plainly: an oversized glyph renders slightly SMALLER here than in GPU
+ // mode. Smaller and whole beats full-size and severed — but it is not parity, and the
+ // ink-sized-slot escalation is still the thing that would deliver parity.
+ //
+ // Ordinary text is untouched, and that is load-bearing: a Latin glyph's ink never
+ // approaches its advance, the tolerance absorbs an antialiasing fringe, and a scale of
+ // exactly 1 takes the SAME `fillText` call the code took before this existed. So no
+ // rendering anyone has already looked at moves.
+ const metrics = ctx.measureText(glyph)
+ const scale = shrinkToFit(metrics, allowance)
+ if (scale === 1) {
+ ctx.fillText(glyph, inkX, y + baseline)
+ } else {
+ // Scaled about the BASELINE, so the glyph keeps sitting on the same line as its
+ // neighbours — a symbol that shrank AND rose would read as misaligned rather than small.
+ // Horizontally it is re-centred inside the allowance, because an oversized glyph is
+ // typically a symbol drawn to fill its box: left-anchoring the shrunk version would park
+ // it against the previous character with a gap on the right.
+ const inkW = metrics.actualBoundingBoxLeft + metrics.actualBoundingBoxRight
+ ctx.save()
+ ctx.translate(
+ inkX + (allowance - scale * inkW) / 2 + scale * metrics.actualBoundingBoxLeft,
+ y + baseline
+ )
+ ctx.scale(scale, scale)
+ ctx.fillText(glyph, 0, 0)
+ ctx.restore()
+ }
}
ctx.restore()
// 3. THE EDGE EXTENSION — clamp-to-edge padding, the standard atlas technique. Replicate the