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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(glyphgrid): one stacking order for chrome and text, and glyphs the font can't be trusted with
enesc725e16f3c5f
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.mdindex 971d3cfb2..fbfdedc3f 100644--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md@@ -54,6 +54,21 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- [ ] **2.2 Side-by-side parity.** Same screens as 1.3, now in Shared: glyph shapes, spacing,baseline and line height match the DOM screenshots. No clipped descenders, no overlapbetween adjacent cells, no visible atlas seams.+- [ ] **2.2b Box drawing and block art (round 4).** The item the round-3 screenshots failed. Draw a+ table or a framed TUI (`claude` / `codex` panels, `htop`, `tmux` borders, `lsd --tree`) and a+ piece of block art (the nodeterm mascot, `▀▄█▌▐`, a `░▒▓` ramp). Expected now that these two+ ranges are drawn GEOMETRICALLY instead of with the font (`box-glyphs.ts`):+ **separators are continuous** — a run of `───` shows no gap at any cell boundary, and corners+ and tees join their arms with no notch; **block elements tile exactly** — `▀`/`▄` and+ `▌`/`▐` meet on a shared edge with no dark seam and no overlap, the eighth blocks step+ evenly, and the mascot is the right shape with no dark artifacts; the shade ramp `░▒▓` reads+ as three distinct densities. Known v1 approximations, not defects: **rounded corners+ `╭╮╯╰` render SQUARE**, the diagonals `╱╲╳` still come from the font, and the double-line+ tees `╠╣╦╩` keep the crossing rail continuous where the printed glyph breaks it.+ The round-3 report's "blockier / heavier than GPU mode" should be GONE for line and block art.+ If PLAIN TEXT still reads heavier or softer than the per-terminal GPU renderer, that is a+ **separate finding** — file it against 2.2/2.7, not here, since nothing in this change touches+ how ordinary glyphs are rasterized.- [ ] **2.3 Colors.** `ls --color` and `htop`: foreground/background colors, bold and dim, and the256-color/truecolor ramps match the DOM rendering. Reverse-video cells (selected row in`htop`, `vim` visual mode) are inverted, not blank.@@ -126,9 +141,22 @@ Auto after you switched builds, that is why: re-select Shared and carry on.- [ ] **3.8 Overlap occlusion.** Drag two terminals until they overlap: the one on top hides theone below — its text does not bleed through, and the lower one's text does not paint overthe upper node's chrome.-- [ ] **3.9 Selecting the LOWER of two overlapping terminals.** Click the partially-covered one:- React Flow elevates it, and its TEXT comes up with it — it must not stay occluded by the- other node's plate.+- [ ] **3.9 Selecting the LOWER of two overlapping terminals.** Click the partially-covered one.+ **CHANGED in round 4:** clicking no longer raises it. While Shared is on, selection does not+ elevate anything (`elevateNodesOnSelect={false}`) — whichever node is later in the array is on+ top in BOTH the DOM and the canvas, selected or not. What you must confirm is that the two+ agree: the selection ring appears on the lower node, its chrome stays under the upper node's,+ and its text stays under the upper node's plate. The failure this replaced is the one to watch+ for — the upper node's crisp chrome with the LOWER node's text legible through its body.+ Bring a node to the front the ordinary way (drag it / re-create it) rather than by selecting.+- [ ] **3.9b Overlap, contents vs frame (round 4).** With two terminals overlapping, look at the+ covered region closely. Expected: the upper node's CONTENTS occlude the lower one's+ completely — no text, no cursor, no selection band from the lower node is readable through+ the upper node's body. The one artifact that REMAINS is **L15**: the lower node's thin+ border/frame (and the hairline where its header meets its body) may ghost through the upper+ node's transparent body window, because that chrome is DOM and the upper node's occluding+ plate is canvas. A HAIRLINE is expected; **report anything more than a hairline** — a visible+ band, a readable label, or any of the lower node's text — as a defect, not as L15.- [ ] **3.10 Group-parented terminal.** A terminal inside a group frame: its text sits exactly inits body (offset chain resolves through the parent), and its paint order relative toungrouped terminals is sane (known limitation L7).@@ -300,6 +328,24 @@ Auto after you switched builds, that is why: re-select Shared and carry on.`warnOnCellDrift` logs one `[glyphgrid] atlas cell … does not match …` line per context lifetime,so a soft terminal can be told apart from a soft display. Phase 2 (re-rasterize on`document.fonts.ready` / per-cell atlas pages).+- **L15 — Where two terminals overlap, the LOWER one's frame can ghost through the upper one's+ body.** A shared-mode terminal body is transparent — its text lives on the one shared canvas+ underneath the node layer — so the upper node's occluding surface is its canvas PLATE, and a+ plate is painted below all DOM chrome. Contents therefore occlude correctly (the upper plate is+ drawn after the lower one, so no text, cursor or selection band from the lower node survives),+ but the lower node's own chrome — its 1px border, the seam under its header — is DOM and paints+ over the plate. What remains visible is a hairline of the lower node's frame inside the upper+ node's body window. **This is the residue of a much worse bug, and the trade was deliberate.**+ Before round 4 the DOM and the canvas ordered the nodes DIFFERENTLY: React Flow's+ `elevateNodesOnSelect` lifted the selected node's chrome to z 1000 while the canvas painted grids+ in the order Canvas pushed, so the two disagreed about which node was on top and the user saw one+ node's crisp chrome with the OTHER node's text readable through it. Turning that prop off while+ the layer is active (Canvas.tsx, `elevateNodesOnSelect={!glyphLayerActive}`) makes array order+ the single rule on both sides; the hairline is what is left, and it cannot be removed by any+ ordering because canvas can never paint over DOM. The two real fixes are Phase 2 questions: draw+ the node frame into the shared canvas too, or give the plate the node's full chrome geometry.+ Side effect to be aware of: **clicking a covered terminal no longer brings it to the front** in+ shared mode (checklist 3.9) — selection is no longer a stacking input there.---diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex fad1cd84f..505c194ff 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -4967,12 +4967,11 @@ export function Canvas() {// false for every user today, the signature memo short-circuits on it, and setSharedGlyphCamera// is a field write plus a null check when no engine exists.const glyphLayerActive = useSharedGlyphActive()- // The terminal nodes' paint order IS the grids' z order — array order, with SELECTED nodes- // elevated above unselected ones, mirroring React Flow's own `elevateNodesOnSelect` (on by- // default). `nodeOrderSig` owns that rule; its comment explains why a grid z that ignored- // selection punches a hole through the selected node's text. One string so the effect below- // fires on a real order change only — a drag or an edit rebuilds `nodes` many times per second- // with the order untouched.+ // The terminal nodes' paint order IS the grids' z order — plain ARRAY order, which is exactly+ // what the DOM does too while the layer is on (see `elevateNodesOnSelect` on <ReactFlow> below+ // for the invariant that ties the two together). `nodeOrderSig` owns the rule. One string so the+ // effect below fires on a real order change only — a drag or an edit rebuilds `nodes` many times+ // per second with the order untouched.const glyphOrderSig = useMemo(() => (glyphLayerActive ? nodeOrderSig(nodes) : ''),[glyphLayerActive, nodes]@@ -7492,6 +7491,19 @@ export function Canvas() {zoomActivationKeyCode={null}snapToGrid={settings.snapToGrid}snapGrid={[settings.gridSize, settings.gridSize]}+ // INVARIANT (shared glyph layer): the shared canvas can only paint in ONE global order,+ // so every DOM stacking rule that diverges from array order — `elevateNodesOnSelect`,+ // React Flow's default-on lift of the selected node to z 1000, is the only one we use —+ // must be disabled while the shared layer is on, or chrome and text disagree about who+ // is on top. That disagreement is not cosmetic: a shared-mode terminal body is+ // TRANSPARENT (the glyphs are on the canvas underneath), so with the two orders split+ // the user sees the upper node's opaque chrome AND the lower node's text through the+ // same rectangle — "this node is on top, and I can read the other one through it".+ // Mirroring the elevation in `nodeOrderSig` (what round 3 did) cannot fix it, because+ // canvas text can never paint over DOM chrome; only agreeing on array order can.+ // Dynamic, and false ONLY while shared is active: the default renderer modes have opaque+ // bodies and keep React Flow's normal selection behavior, untouched.+ elevateNodesOnSelect={!glyphLayerActive}><Backgroundvariant={BackgroundVariant.Dots}diff --git a/src/renderer/canvas/SharedGlyphLayer.test.ts b/src/renderer/canvas/SharedGlyphLayer.test.tsindex dda17f580..fb6d74ce4 100644--- a/src/renderer/canvas/SharedGlyphLayer.test.ts+++ b/src/renderer/canvas/SharedGlyphLayer.test.ts@@ -58,32 +58,35 @@ describe('nodeOrderSig', () => {expect(a).not.toBe(b)})- it('elevates a SELECTED terminal above the unselected ones, wherever it sits in the array', () => {- // React Flow's elevateNodesOnSelect (default on) lifts the selected node's DOM to z 1000; a- // grid z that followed the array alone would leave its text under the other grid's plate.+ it('does NOT elevate a selected terminal — selection is not a stacking input here', () => {+ // Round 3 sorted selected nodes last, mirroring React Flow's elevateNodesOnSelect. Round 4+ // turns that PROP off while the shared layer is active (Canvas.tsx) instead, because the DOM+ // and the canvas have to agree on ONE order: a selected node whose grid was on top but whose+ // chrome sat under its neighbour's showed both nodes' contents in the same rectangle. With the+ // elevation disabled, array order is the whole rule on both sides.const sig = nodeOrderSig([{ id: 'a', type: 'terminal' },{ id: 'b', type: 'terminal', selected: true },{ id: 'c', type: 'terminal' }])- expect(idsFromOrderSig(sig)).toEqual(['a', 'c', 'b'])+ expect(idsFromOrderSig(sig)).toEqual(['a', 'b', 'c'])})- it('keeps selected nodes in their own relative order (a multi-select is stable)', () => {+ it('a multi-select changes nothing at all', () => {const sig = nodeOrderSig([{ id: 'a', type: 'terminal', selected: true },{ id: 'b', type: 'terminal' },{ id: 'c', type: 'terminal', selected: true }])- expect(idsFromOrderSig(sig)).toEqual(['b', 'a', 'c'])+ expect(idsFromOrderSig(sig)).toEqual(['a', 'b', 'c'])})- it('an all-selected canvas keeps plain array order', () => {- const sig = nodeOrderSig([- { id: 'a', type: 'terminal', selected: true },- { id: 'b', type: 'terminal', selected: true }- ])- expect(idsFromOrderSig(sig)).toEqual(['a', 'b'])+ it('selecting and deselecting does not churn the signature (no needless z re-push)', () => {+ const nodes = [+ { id: 'a', type: 'terminal' },+ { id: 'b', type: 'terminal' }+ ]+ expect(nodeOrderSig(nodes)).toBe(nodeOrderSig(nodes.map((n) => ({ ...n, selected: true }))))})it('an untyped node is not a terminal (React Flow defaults type to "default")', () => {diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsxindex 3b6ee692c..168092a9e 100644--- a/src/renderer/canvas/SharedGlyphLayer.tsx+++ b/src/renderer/canvas/SharedGlyphLayer.tsx@@ -187,27 +187,32 @@ const zListeners = new Set<() => void>()* Only terminals: they are the only kind that registers a grid, and mixing other kinds in would* churn the signature on every sticky edit.*- * **The rule is array order, with SELECTED nodes elevated above unselected ones** (stable within- * each group) — not array order alone. React Flow's `elevateNodesOnSelect` defaults to true, so- * selecting a node lifts its DOM z-index to 1000 regardless of where it sits in the array. With a- * grid z that only followed the array, clicking a terminal that overlaps another would raise its- * chrome while its TEXT stayed underneath the other grid's opaque plate — the node visibly on top- * with a hole punched through its glyphs. Mirroring the elevation here is what keeps the canvas and- * the DOM telling the same story.+ * **The rule is plain ARRAY order, and nothing else.** It used to mirror React Flow's+ * `elevateNodesOnSelect` by sorting selected nodes last, because that prop (on by default) lifts a+ * selected node's DOM z-index to 1000 wherever it sits in the array. Mirroring it fixed one half of+ * the overlap and created the other: the shared canvas paints in ONE global order, so with the+ * selected node's grid on top, its text correctly occluded the neighbour's text — while the+ * neighbour's opaque DOM chrome still sat over the selected node's TRANSPARENT body. The user saw+ * crisp chrome from one node and the other node's text through it, in the same rectangle. There is+ * no ordering of the grids that fixes that, because canvas text can never paint over DOM chrome.+ *+ * The fix is upstream: while the shared layer is active Canvas passes `elevateNodesOnSelect={false}`+ * so the DOM follows the array too, and both worlds agree that "later in the array is on top". The+ * elevation this function existed to mirror no longer happens in the only mode that reads this+ * signature, so the selection-awareness is gone with it — see the invariant at that prop.*/+// `selected` is still in the accepted shape and deliberately unread: it says out loud that the+// signature SEES the selection and chooses to ignore it, which is the thing a future reader is+// most likely to try to "fix" back.export function nodeOrderSig(nodes: readonly { id: string; type?: string; selected?: boolean }[]): string {- let base = ''- let elevated = ''+ let sig = ''for (const n of nodes) {if (n.type !== 'terminal') continue- if (n.selected) elevated = elevated === '' ? n.id : elevated + ORDER_SEP + n.id- else base = base === '' ? n.id : base + ORDER_SEP + n.id+ sig = sig === '' ? n.id : sig + ORDER_SEP + n.id}- if (base === '') return elevated- if (elevated === '') return base- return base + ORDER_SEP + elevated+ return sig}export function idsFromOrderSig(sig: string): string[] {diff --git a/src/renderer/glyphgrid/box-glyphs.test.ts b/src/renderer/glyphgrid/box-glyphs.test.tsnew file mode 100644index 000000000..14ddef482--- /dev/null+++ b/src/renderer/glyphgrid/box-glyphs.test.ts@@ -0,0 +1,326 @@+import { describe, expect, it } from 'vitest'+import { boxGlyphOps, type PaintOp } from './box-glyphs'++// The cell used by most of these: 10 × 20 device px, so light = round(20/16) = 1 and the centre+// lines fall on .0 / .0 — the arithmetic is checkable by hand.+const W = 10+const H = 20++function ops(ch: string, cellW = W, cellH = H): PaintOp[] {+ const r = boxGlyphOps(ch.codePointAt(0)!, cellW, cellH)+ expect(r).not.toBeNull()+ return r!+}++/** Total ink coverage of an op list, counting a pixel once (the ops may overlap at a junction). */+function covered(list: PaintOp[], cellW: number, cellH: number): Set<string> {+ const set = new Set<string>()+ for (const o of list) {+ for (let y = Math.floor(o.y); y < Math.ceil(o.y + o.h); y++) {+ for (let x = Math.floor(o.x); x < Math.ceil(o.x + o.w); x++) {+ if (x >= 0 && y >= 0 && x < Math.ceil(cellW) && y < Math.ceil(cellH)) set.add(`${x},${y}`)+ }+ }+ }+ return set+}++describe('boxGlyphOps — the range gate', () => {+ it('returns null for ordinary text, so it falls through to fillText', () => {+ expect(boxGlyphOps(0x41, W, H)).toBeNull() // 'A'+ expect(boxGlyphOps(0x20, W, H)).toBeNull() // space+ expect(boxGlyphOps(0x4e2d, W, H)).toBeNull() // 中+ })++ it('returns null for the DIAGONALS — a rect list cannot express them (v1 font fallback)', () => {+ for (const ch of ['╱', '╲', '╳']) {+ expect(boxGlyphOps(ch.codePointAt(0)!, W, H)).toBeNull()+ }+ })++ it('returns null for a degenerate cell instead of emitting NaN rects', () => {+ expect(boxGlyphOps(0x2500, 0, H)).toBeNull()+ expect(boxGlyphOps(0x2500, W, 0)).toBeNull()+ expect(boxGlyphOps(0x2500, Number.NaN, H)).toBeNull()+ })++ it('covers the whole box-drawing and block ranges except the three diagonals', () => {+ const missing: string[] = []+ for (let c = 0x2500; c <= 0x259f; c++) {+ if (c >= 0x2571 && c <= 0x2573) continue+ if (boxGlyphOps(c, W, H) === null) missing.push(c.toString(16))+ }+ expect(missing).toEqual([])+ })+})++describe('box drawing — the full-cell invariant', () => {+ it('U+2500 ─ is ONE rect spanning the full width at centred thickness', () => {+ const [r, ...rest] = ops('─')+ expect(rest).toEqual([])+ expect(r.x).toBe(0)+ expect(r.x + r.w).toBe(W) // exactly the cell edge — the anti-gap rule+ expect(r.h).toBe(1) // light at cellH 20+ // A 1px rule cannot be centred to better than half a pixel on an even cell.+ expect(Math.abs(r.y + r.h / 2 - H / 2)).toBeLessThanOrEqual(1)+ })++ it('U+2502 │ is ONE rect spanning the full height at centred thickness', () => {+ const [r, ...rest] = ops('│')+ expect(rest).toEqual([])+ expect(r.y).toBe(0)+ expect(r.y + r.h).toBe(H)+ expect(r.w).toBe(1)+ expect(Math.abs(r.x + r.w / 2 - W / 2)).toBeLessThanOrEqual(1)+ })++ it('a FRACTIONAL cell still ends exactly on the boundary — no sub-pixel gap is representable', () => {+ // 8.4 × 17.6 is the shape of a real device cell (charWidth * dpr). Rounding the outer edge+ // here is what put a hairline between every pair of ─ cells.+ const [r] = ops('─', 8.4, 17.6)+ expect(r.x).toBe(0)+ expect(r.x + r.w).toBe(8.4)+ const [v] = ops('│', 8.4, 17.6)+ expect(v.y).toBe(0)+ expect(v.y + v.h).toBe(17.6)+ })++ it('the HEAVY line is thicker than the light one, both still full width', () => {+ const [light] = ops('─', W, 64)+ const [heavy] = ops('━', W, 64)+ expect(heavy.h).toBe(light.h * 2)+ expect(heavy.x).toBe(0)+ expect(heavy.x + heavy.w).toBe(W)+ })++ it('never emits a zero-sized rect, however small the cell', () => {+ for (const [cw, ch] of [+ [1, 1],+ [3, 5],+ [6.2, 11.7]+ ] as const) {+ for (const glyph of ['─', '│', '┼', '╬', '█', '▏']) {+ for (const o of ops(glyph, cw, ch)) {+ expect(o.w).toBeGreaterThanOrEqual(1)+ expect(o.h).toBeGreaterThanOrEqual(1)+ }+ }+ }+ })+})++describe('box drawing — arms', () => {+ it('┌ produces exactly its two arms: right to the edge, down to the edge, nothing left/up', () => {+ const list = ops('┌')+ expect(list).toHaveLength(2)+ const horizontal = list.find((o) => o.w > o.h)!+ const vertical = list.find((o) => o.h > o.w)!+ expect(horizontal.x + horizontal.w).toBe(W) // reaches the RIGHT edge+ expect(horizontal.x).toBeGreaterThan(0) // does NOT reach the left edge+ expect(vertical.y + vertical.h).toBe(H) // reaches the BOTTOM edge+ expect(vertical.y).toBeGreaterThan(0) // does NOT reach the top edge+ })++ it('┘ is the mirror of ┌ — left and up arms only', () => {+ const list = ops('┘')+ expect(list).toHaveLength(2)+ const horizontal = list.find((o) => o.w > o.h)!+ const vertical = list.find((o) => o.h > o.w)!+ expect(horizontal.x).toBe(0)+ expect(horizontal.x + horizontal.w).toBeLessThan(W)+ expect(vertical.y).toBe(0)+ expect(vertical.y + vertical.h).toBeLessThan(H)+ })++ it('the four corners fill the JUNCTION — an arm extends past the centre, never notches it', () => {+ // The naive "draw each arm from the edge to the centre" leaves the far quadrant of the corner+ // empty. Check the centre pixel is inked for every corner.+ for (const ch of ['┌', '┐', '└', '┘', '╭', '╮', '╯', '╰', '┏', '┓', '┗', '┛']) {+ const set = covered(ops(ch, 12, 24), 12, 24)+ expect(set.has('6,12')).toBe(true)+ }+ })++ it('├ is a full-height vertical plus a right arm to the edge', () => {+ const list = ops('├')+ expect(list).toHaveLength(2)+ const vertical = list.find((o) => o.h > o.w)!+ const horizontal = list.find((o) => o.w > o.h)!+ expect(vertical.y).toBe(0)+ expect(vertical.y + vertical.h).toBe(H)+ expect(horizontal.x + horizontal.w).toBe(W)+ expect(horizontal.x).toBeGreaterThan(0)+ })++ it('┬ is a full-WIDTH horizontal plus a down arm — the through-line is one rect', () => {+ const list = ops('┬')+ expect(list).toHaveLength(2)+ const horizontal = list.find((o) => o.w > o.h)!+ const vertical = list.find((o) => o.h > o.w)!+ expect(horizontal.x).toBe(0)+ expect(horizontal.x + horizontal.w).toBe(W)+ expect(vertical.y + vertical.h).toBe(H)+ expect(vertical.y).toBeGreaterThan(0)+ })++ it('┼ is the full cross: both through-lines edge to edge', () => {+ const list = ops('┼')+ expect(list).toHaveLength(2)+ const horizontal = list.find((o) => o.w > o.h)!+ const vertical = list.find((o) => o.h > o.w)!+ expect([horizontal.x, horizontal.x + horizontal.w]).toEqual([0, W])+ expect([vertical.y, vertical.y + vertical.h]).toEqual([0, H])+ })++ it('the stubs ╴╵╶╷ each produce ONE arm reaching its own edge only', () => {+ const cases: [string, 'l' | 'u' | 'r' | 'd'][] = [+ ['╴', 'l'],+ ['╵', 'u'],+ ['╶', 'r'],+ ['╷', 'd']+ ]+ for (const [ch, side] of cases) {+ const list = ops(ch)+ expect(list).toHaveLength(1)+ const o = list[0]+ if (side === 'l') expect(o.x).toBe(0)+ if (side === 'r') expect(o.x + o.w).toBe(W)+ if (side === 'u') expect(o.y).toBe(0)+ if (side === 'd') expect(o.y + o.h).toBe(H)+ }+ })++ it('a mixed-weight tee keeps each arm at its own weight (┝ = light vertical, heavy right)', () => {+ const list = ops('┝', W, 64)+ const vertical = list.find((o) => o.h > o.w)!+ const horizontal = list.find((o) => o.w > o.h)!+ expect(horizontal.h).toBe(vertical.w * 2)+ })++ it('rounded corners are their SQUARE counterparts in v1 (documented approximation)', () => {+ expect(ops('╭')).toEqual(ops('┌'))+ expect(ops('╮')).toEqual(ops('┐'))+ expect(ops('╯')).toEqual(ops('┘'))+ expect(ops('╰')).toEqual(ops('└'))+ })+})++describe('box drawing — doubles and dashes', () => {+ it('═ is TWO full-width rails, not one line and not four', () => {+ const list = ops('═', W, 64)+ expect(list).toHaveLength(2)+ for (const o of list) {+ expect(o.x).toBe(0)+ expect(o.x + o.w).toBe(W)+ }+ expect(list[0].y).not.toBe(list[1].y)+ })++ it('║ is TWO full-height rails', () => {+ const list = ops('║', 32, H)+ expect(list).toHaveLength(2)+ for (const o of list) {+ expect(o.y).toBe(0)+ expect(o.y + o.h).toBe(H)+ }+ })++ it('╔ is a double corner: each rail reaches its own edge, none reaches the empty quadrant edges', () => {+ const list = ops('╔', 32, 64)+ expect(list).toHaveLength(4)+ const right = list.filter((o) => o.x + o.w === 32)+ const down = list.filter((o) => o.y + o.h === 64)+ expect(right).toHaveLength(2)+ expect(down).toHaveLength(2)+ // Nothing runs to the LEFT or TOP edge — that is the empty quadrant of a ╔.+ expect(list.some((o) => o.x === 0 && o.w > 4)).toBe(false)+ expect(list.some((o) => o.y === 0 && o.h > 4)).toBe(false)+ })++ it('╬ crosses as four rails with an OPEN centre', () => {+ const list = ops('╬', 32, 64)+ expect(list).toHaveLength(4)+ const set = covered(list, 32, 64)+ expect(set.has('16,32')).toBe(false) // the centre square is empty, as in the real glyph+ })++ it('a dashed rule leaves GAPS on purpose — it must not tile like a solid one', () => {+ const list = ops('┄', 24, 32)+ expect(list).toHaveLength(3)+ expect(list[0].x).toBe(0)+ expect(list[list.length - 1].x + list[list.length - 1].w).toBeLessThan(24)+ })++ it('the dash count follows the character (triple / quadruple / double)', () => {+ expect(ops('┄', 24, 32)).toHaveLength(3)+ expect(ops('┈', 24, 32)).toHaveLength(4)+ expect(ops('╌', 24, 32)).toHaveLength(2)+ expect(ops('┆', 24, 32)).toHaveLength(3)+ })+})++describe('block elements', () => {+ it('▀ is EXACTLY the top half of the cell', () => {+ const list = ops('▀')+ expect(list).toEqual([{ x: 0, y: 0, w: W, h: H / 2 }])+ })++ it('▄ is exactly the bottom half, and the two tile the cell with no seam', () => {+ const [top] = ops('▀')+ const [bottom] = ops('▄')+ expect(bottom.y).toBe(top.y + top.h) // the seam is shared, not overlapped or gapped+ expect(bottom.y + bottom.h).toBe(H)+ })++ it('█ is the WHOLE cell, to the exact edges', () => {+ expect(ops('█')).toEqual([{ x: 0, y: 0, w: W, h: H }])+ expect(ops('█', 8.4, 17.6)).toEqual([{ x: 0, y: 0, w: 8.4, h: 17.6 }])+ })++ it('▌ and ▐ are the two halves and tile horizontally', () => {+ const [l] = ops('▌')+ const [r] = ops('▐')+ expect(l.x).toBe(0)+ expect(r.x).toBe(l.x + l.w)+ expect(r.x + r.w).toBe(W)+ })++ it('the eighth blocks step monotonically', () => {+ const heights = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'].map((c) => ops(c, 16, 32)[0].h)+ for (let i = 1; i < heights.length; i++) expect(heights[i]).toBeGreaterThan(heights[i - 1])+ expect(heights[heights.length - 1]).toBe(32)+ })++ it('the quadrants are the four corners, and the composites are their unions', () => {+ const ul = covered(ops('▘', 16, 32), 16, 32)+ const ur = covered(ops('▝', 16, 32), 16, 32)+ const ll = covered(ops('▖', 16, 32), 16, 32)+ const lr = covered(ops('▗', 16, 32), 16, 32)+ expect(ul.size).toBe(8 * 16)+ // ▚ = upper-left + lower-right+ const diag = covered(ops('▚', 16, 32), 16, 32)+ expect(diag.size).toBe(ul.size + lr.size)+ // ▟ = upper-right + lower-left + lower-right+ const three = covered(ops('▟', 16, 32), 16, 32)+ expect(three.size).toBe(ur.size + ll.size + lr.size)+ })++ it('the shades are full-cell ALPHA fills, strictly increasing ░ < ▒ < ▓', () => {+ const light = ops('░')+ const medium = ops('▒')+ const dark = ops('▓')+ for (const l of [light, medium, dark]) {+ expect(l).toHaveLength(1)+ expect(l[0]).toMatchObject({ x: 0, y: 0, w: W, h: H })+ }+ expect(light[0].alpha!).toBeLessThan(medium[0].alpha!)+ expect(medium[0].alpha!).toBeLessThan(dark[0].alpha!)+ expect(dark[0].alpha!).toBeLessThan(1)+ })++ it('only the shades carry an alpha — everything else is opaque ink', () => {+ for (const ch of ['─', '┼', '█', '▀', '╬']) {+ for (const o of ops(ch)) expect(o.alpha).toBeUndefined()+ }+ })+})diff --git a/src/renderer/glyphgrid/box-glyphs.ts b/src/renderer/glyphgrid/box-glyphs.tsnew file mode 100644index 000000000..4346e1f34--- /dev/null+++ b/src/renderer/glyphgrid/box-glyphs.ts@@ -0,0 +1,405 @@+/**+ * GEOMETRIC glyphs for the box-drawing and block-element ranges.+ *+ * Why this exists at all: the shared rasterizer draws every code point with `fillText`, and a font+ * does not guarantee that its box/block glyphs fill the whole cell. Most monospace faces draw+ * U+2500 ─ a pixel or two short of the advance width, which is invisible in a word processor and+ * catastrophic in a terminal — a horizontal rule made of 60 of them shows 60 hairline GAPS, one at+ * every cell boundary. The block elements are worse: ▀▄█▌▐ and the eighth/quadrant family are+ * expected to tile EXACTLY, and a face whose ink is inset by the tiniest amount turns a piece of+ * block art into a lattice of dark seams.+ *+ * This is exactly why xterm's own renderers ship `CustomGlyphs.ts` (both the canvas addon and the+ * WebglAddon, `customGlyphs: true` by default): for these two ranges they stop trusting the font+ * and DRAW the shapes. We do the same, one step earlier — into the atlas instead of onto the+ * screen — so the geometry is rasterized once per code point and every grid samples it.+ *+ * The module is deliberately PURE: it returns rectangles, and knows nothing about a canvas, a+ * context or the atlas. `raster.ts` fills them; everything here is unit-testable arithmetic.+ *+ * ## The FULL-CELL invariant+ *+ * Every arm and every block edge that reaches a cell boundary is emitted at the EXACT boundary —+ * `x === 0` / `x + w === cellW` — never at a rounded approximation of it. Device cells are+ * fractional in general (xterm's `device.cell.width` is `charWidth * dpr`), so rounding the outer+ * edge of a full-width line to whole pixels is precisely how you re-introduce the gap this module+ * exists to remove. Only INTERIOR edges are snapped to whole device pixels (`snapX`/`snapY`),+ * which is what keeps a 1px line from being smeared across two columns of texels by antialiasing.+ *+ * ## v1 approximations (deliberate, documented)+ *+ * - **Rounded corners are drawn SQUARE.** U+256D–U+2570 (╭╮╯╰) use their sharp counterparts' arm+ * table. A rect-only op list cannot express an arc; the alternative was to leave them to+ * `fillText`, which would make a rounded box's corners the only part of the frame with gaps.+ * - **Diagonals fall back to the font.** U+2571–U+2573 (╱╲╳) are not axis-aligned and return+ * `null`, so `fillText` draws them as before. They do not tile, so the gap problem does not+ * apply to them.+ * - **Double-line junctions are drawn as rails, not as nested corners.** A double arm is two+ * parallel light rails; where two double arms meet, each rail stops at the near or the far+ * perpendicular rail (see `pushDoubleArm`). This is exact for the corners (╔╗╚╝) and the plain+ * crossings, and slightly over-draws the tees (╠╣╦╩ keep the crossing rail continuous where the+ * real glyph breaks it). Every case connects edge-to-edge, which is the property that matters.+ * - **Heavy/light is a thickness distinction only** — heavy is exactly twice light, which is what+ * xterm does too.+ */++/** One axis-aligned fill, in CELL-LOCAL device pixels. `alpha` is the shade level (the shade+ * blocks ░▒▓); absent means fully opaque. Rects only — see the module comment. */+export interface PaintOp {+ x: number+ y: number+ w: number+ h: number+ alpha?: number+}++// ---------------------------------------------------------------------------------------------+// Box drawing — the arm table+// ---------------------------------------------------------------------------------------------++/**+ * One entry per code point in U+2500–U+257F, as the four ARMS in clock order **U R D L**, each+ * `0` none / `1` light / `2` heavy / `3` double. An empty string means "not described by arms":+ * the dashed variants (handled by `DASHED` below) and the diagonals (font fallback).+ *+ * Reading a row: `'0110'` is U=0 R=1 D=1 L=0 — a light arm to the right and a light arm down,+ * i.e. ┌. The whole geometry of the range falls out of this table plus `pushArm`, which is why+ * it is transcribed in full rather than special-cased per character.+ */+const ARMS: readonly string[] = [+ // 0x2500 ─ ━ │ ┃, then the light/heavy triple- and quadruple-dash variants (DASHED), then ┌┍┎┏+ '0101', '0202', '1010', '2020', '', '', '', '',+ '', '', '', '', '0110', '0210', '0120', '0220',+ // 0x2510 ┐┑┒┓ └┕┖┗ ┘┙┚┛ ├┝┞┟+ '0011', '0012', '0021', '0022', '1100', '1200', '2100', '2200',+ '1001', '1002', '2001', '2002', '1110', '1210', '2110', '1120',+ // 0x2520 ┠┡┢┣ ┤┥┦┧ ┨┩┪┫ ┬┭┮┯+ '2120', '2210', '1220', '2220', '1011', '1012', '2011', '1021',+ '2021', '2012', '1022', '2022', '0111', '0112', '0211', '0212',+ // 0x2530 ┰┱┲┳ ┴┵┶┷ ┸┹┺┻ ┼┽┾┿+ '0121', '0122', '0221', '0222', '1101', '1102', '1201', '1202',+ '2101', '2102', '2201', '2202', '1111', '1112', '1211', '1212',+ // 0x2540 ╀╁╂╃ ╄╅╆╇ ╈╉╊╋, then the light/heavy double-dash variants (DASHED)+ '2111', '1121', '2121', '2112', '2211', '1122', '1221', '2212',+ '1222', '2122', '2221', '2222', '', '', '', '',+ // 0x2550 ═║ ╒╓╔ ╕╖╗ ╘╙╚ ╛╜╝ ╞╟+ '0303', '3030', '0310', '0130', '0330', '0013', '0031', '0033',+ '1300', '3100', '3300', '1003', '3001', '3003', '1310', '3130',+ // 0x2560 ╠╡╢╣ ╤╥╦ ╧╨╩ ╪╫╬, then the arcs ╭╮╯ (square in v1)+ '3330', '1013', '3031', '3033', '0313', '0131', '0333', '1303',+ '3101', '3303', '1313', '3131', '3333', '0110', '0011', '1001',+ // 0x2570 ╰, the diagonals ╱╲╳ (font fallback), then the stubs ╴╵╶╷ ╸╹╺╻ ╼╽╾╿+ '1100', '', '', '', '0001', '1000', '0100', '0010',+ '0002', '2000', '0200', '0020', '0201', '1020', '0102', '2010'+]++/** The dashed variants: `[vertical, dashCount, heavy]`. Drawn as real dashes rather than as their+ * solid equivalents — a dashed rule that renders solid is a different character, and unlike the+ * solid lines these are not supposed to tile. */+const DASHED: Readonly<Record<number, readonly [boolean, number, boolean]>> = {+ 0x2504: [false, 3, false], 0x2505: [false, 3, true],+ 0x2506: [true, 3, false], 0x2507: [true, 3, true],+ 0x2508: [false, 4, false], 0x2509: [false, 4, true],+ 0x250a: [true, 4, false], 0x250b: [true, 4, true],+ 0x254c: [false, 2, false], 0x254d: [false, 2, true],+ 0x254e: [true, 2, false], 0x254f: [true, 2, true]+}++// ---------------------------------------------------------------------------------------------+// Block elements — the eighths table+// ---------------------------------------------------------------------------------------------++/**+ * U+2580–U+259F as rectangles on an 8×8 sub-cell grid (`[x, y, w, h]` in eighths), the same+ * quantisation xterm's `blockElementDefinitions` uses — these characters are DEFINED in halves,+ * quarters and eighths of the cell, so eighths is the grid on which they are exact.+ *+ * The three shade blocks ░▒▓ are not in here: they are a full-cell fill at increasing alpha+ * (`SHADES`), which is how every renderer draws them.+ */+const BLOCKS: Readonly<Record<number, readonly (readonly [number, number, number, number])[]>> = {+ 0x2580: [[0, 0, 8, 4]], // ▀ upper half+ 0x2581: [[0, 7, 8, 1]], // ▁ lower one eighth+ 0x2582: [[0, 6, 8, 2]], // ▂ lower one quarter+ 0x2583: [[0, 5, 8, 3]], // ▃ lower three eighths+ 0x2584: [[0, 4, 8, 4]], // ▄ lower half+ 0x2585: [[0, 3, 8, 5]], // ▅ lower five eighths+ 0x2586: [[0, 2, 8, 6]], // ▆ lower three quarters+ 0x2587: [[0, 1, 8, 7]], // ▇ lower seven eighths+ 0x2588: [[0, 0, 8, 8]], // █ full block+ 0x2589: [[0, 0, 7, 8]], // ▉ left seven eighths+ 0x258a: [[0, 0, 6, 8]], // ▊ left three quarters+ 0x258b: [[0, 0, 5, 8]], // ▋ left five eighths+ 0x258c: [[0, 0, 4, 8]], // ▌ left half+ 0x258d: [[0, 0, 3, 8]], // ▍ left three eighths+ 0x258e: [[0, 0, 2, 8]], // ▎ left one quarter+ 0x258f: [[0, 0, 1, 8]], // ▏ left one eighth+ 0x2590: [[4, 0, 4, 8]], // ▐ right half+ 0x2594: [[0, 0, 8, 1]], // ▔ upper one eighth+ 0x2595: [[7, 0, 1, 8]], // ▕ right one eighth+ 0x2596: [[0, 4, 4, 4]], // ▖ quadrant lower left+ 0x2597: [[4, 4, 4, 4]], // ▗ quadrant lower right+ 0x2598: [[0, 0, 4, 4]], // ▘ quadrant upper left+ 0x2599: [[0, 0, 4, 8], [0, 4, 8, 4]], // ▙ upper left + lower left + lower right+ 0x259a: [[0, 0, 4, 4], [4, 4, 4, 4]], // ▚ upper left + lower right+ 0x259b: [[0, 0, 4, 8], [4, 0, 4, 4]], // ▛ upper left + upper right + lower left+ 0x259c: [[0, 0, 8, 4], [4, 0, 4, 8]], // ▜ upper left + upper right + lower right+ 0x259d: [[4, 0, 4, 4]], // ▝ quadrant upper right+ 0x259e: [[4, 0, 4, 4], [0, 4, 4, 4]], // ▞ upper right + lower left+ 0x259f: [[4, 0, 4, 8], [0, 4, 8, 4]] // ▟ upper right + lower left + lower right+}++/** ░▒▓ — a full-cell fill at a third, a half and two thirds… in practice the conventional+ * quarter/half/three-quarter ramp every terminal renderer uses. The only contract the rest of the+ * system relies on is that they are strictly increasing. */+const SHADES: Readonly<Record<number, number>> = {+ 0x2591: 0.25,+ 0x2592: 0.5,+ 0x2593: 0.75+}++// ---------------------------------------------------------------------------------------------+// Geometry+// ---------------------------------------------------------------------------------------------++/**+ * Geometric ops for one code point, in cell-local device pixels, or `null` when this module has+ * nothing to say about it — the caller then draws the glyph with the font, exactly as before.+ *+ * `null` is the important half of the contract: it is what keeps this module OPT-IN per code+ * point. Everything outside U+2500–U+259F, the diagonals, and any cell size that is not a+ * positive number falls through to `fillText`.+ */+export function boxGlyphOps(code: number, cellW: number, cellH: number): PaintOp[] | null {+ if (!Number.isFinite(cellW) || !Number.isFinite(cellH) || cellW <= 0 || cellH <= 0) return null+ if (code >= 0x2580 && code <= 0x259f) return blockOps(code, cellW, cellH)+ if (code >= 0x2500 && code <= 0x257f) return boxOps(code, cellW, cellH)+ return null+}++function blockOps(code: number, cellW: number, cellH: number): PaintOp[] | null {+ const shade = SHADES[code]+ if (shade !== undefined) return [{ x: 0, y: 0, w: cellW, h: cellH, alpha: shade }]+ const spec = BLOCKS[code]+ if (!spec) return null+ const ops: PaintOp[] = []+ for (const [x, y, w, h] of spec) {+ push(ops, cellW, cellH, (x / 8) * cellW, (y / 8) * cellH, ((x + w) / 8) * cellW, ((y + h) / 8) * cellH)+ }+ return ops+}++function boxOps(code: number, cellW: number, cellH: number): PaintOp[] | null {+ const dash = DASHED[code]+ if (dash) return dashOps(dash[0], dash[1], dash[2], cellW, cellH)++ const arms = ARMS[code - 0x2500]+ if (!arms) return null++ const light = lightWidth(cellH)+ const heavy = light * 2+ const t = (w: number): number => (w === 1 ? light : w === 2 ? heavy : w === 3 ? light * 3 : 0)++ const up = arms.charCodeAt(0) - 48+ const right = arms.charCodeAt(1) - 48+ const down = arms.charCodeAt(2) - 48+ const left = arms.charCodeAt(3) - 48++ const cx = cellW / 2+ const cy = cellH / 2+ // How far the PERPENDICULAR stem reaches across the junction. An arm must extend half of this+ // past the centre or the far quadrant of the corner stays unfilled — the notch a naive+ // "draw each arm from the edge to the centre" produces on every ┐┘└┌.+ const vSpan = Math.max(t(up), t(down))+ const hSpan = Math.max(t(left), t(right))+ const ops: PaintOp[] = []++ // Horizontal. A through-line of equal weight is ONE rect edge to edge: two overlapping arms+ // would paint the same pixels, and the single rect is what the full-cell invariant is easiest+ // to read off.+ if (left !== 0 && left === right && left !== 3) {+ const th = t(left)+ push(ops, cellW, cellH, 0, cy - th / 2, cellW, cy + th / 2)+ } else {+ if (left === 3) pushDoubleArm(ops, cellW, cellH, false, -1, light, cx, cy, right, up, down, vSpan)+ else if (left !== 0) pushArm(ops, cellW, cellH, false, -1, t(left), cx, cy, vSpan, right !== 0, up === 3 || down === 3, light)+ if (right === 3) pushDoubleArm(ops, cellW, cellH, false, 1, light, cx, cy, left, up, down, vSpan)+ else if (right !== 0) pushArm(ops, cellW, cellH, false, 1, t(right), cx, cy, vSpan, left !== 0, up === 3 || down === 3, light)+ }++ // Vertical — the same three cases, transposed.+ if (up !== 0 && up === down && up !== 3) {+ const th = t(up)+ push(ops, cellW, cellH, cx - th / 2, 0, cx + th / 2, cellH)+ } else {+ if (up === 3) pushDoubleArm(ops, cellW, cellH, true, -1, light, cx, cy, down, left, right, hSpan)+ else if (up !== 0) pushArm(ops, cellW, cellH, true, -1, t(up), cx, cy, hSpan, down !== 0, left === 3 || right === 3, light)+ if (down === 3) pushDoubleArm(ops, cellW, cellH, true, 1, light, cx, cy, up, left, right, hSpan)+ else if (down !== 0) pushArm(ops, cellW, cellH, true, 1, t(down), cx, cy, hSpan, up !== 0, left === 3 || right === 3, light)+ }++ return ops+}++/**+ * The stroke width of a LIGHT line, in device px.+ *+ * Derived from the cell HEIGHT because that is what tracks the font size across dpr (the width+ * varies with the face's advance ratio). `cellH / 16` lands on 1 device px at a typical 13px font+ * on a 1x display and 2 on a retina one, which is what xterm's own `lineWidth` resolves to — thin+ * enough to read as a rule rather than a bar. Never 0: a zero-width line is an invisible one.+ */+function lightWidth(cellH: number): number {+ return Math.max(1, Math.round(cellH / 16))+}++/**+ * One light/heavy arm, from its cell EDGE inward.+ *+ * `dir` is -1 for the left/up arm and +1 for the right/down one; the arm always starts at the+ * corresponding cell edge (the full-cell invariant) and stops at an inner bound:+ *+ * - a **through** arm (its opposite number exists) or a plain corner/tee stops half the+ * perpendicular stem past the centre, which fills the junction square;+ * - a **stem** meeting a DOUBLE perpendicular (┬ on ═, i.e. ╤ ╥ ╟ ╢ …) instead stops at the near+ * rail, so the single line ends where the double line begins rather than crossing both rails and+ * leaving a stub sticking out the far side.+ */+function pushArm(+ ops: PaintOp[],+ cellW: number,+ cellH: number,+ vertical: boolean,+ dir: -1 | 1,+ thick: number,+ cx: number,+ cy: number,+ perpSpan: number,+ hasOpposite: boolean,+ perpIsDouble: boolean,+ light: number+): void {+ const centre = vertical ? cy : cx+ const inner =+ perpIsDouble && !hasOpposite+ ? centre + dir * (light / 2)+ : centre - dir * (Math.max(perpSpan, thick) / 2)+ const cross = vertical ? cx : cy+ const a = cross - thick / 2+ const b = cross + thick / 2+ const from = dir === -1 ? 0 : inner+ const to = dir === -1 ? inner : vertical ? cellH : cellW+ if (vertical) push(ops, cellW, cellH, a, from, b, to)+ else push(ops, cellW, cellH, from, a, to, b)+}++/**+ * One DOUBLE arm: two light rails offset ±`light` from the centre line.+ *+ * Where each rail stops is the whole subtlety of the double family, and it is decided by two+ * questions:+ *+ * 1. **Is the opposite arm also double?** Then the rails run edge to edge (═ ║ ╪ ╫ ╬) and only the+ * `dir === 1` side emits, so the pair is not drawn twice.+ * 2. **Is there a double arm on the perpendicular axis?** If not, the rails stop where the (single+ * or heavy) perpendicular stem is — the same `perpSpan / 2` rule `pushArm` uses — so the two+ * meet flush instead of the rails poking out the far side of the line they land on (╥ ╨ ╞ ╡).+ * If there is, each rail stops at the perpendicular rail it corners with: the rail on the SAME+ * side as the perpendicular arm's direction is the INNER corner (it stops at the near rail), the+ * other is the OUTER corner (it runs on to the far rail). That single rule is what makes ╔╗╚╝+ * come out as proper double corners and ╠╣╦╩ as proper double tees.+ */+function pushDoubleArm(+ ops: PaintOp[],+ cellW: number,+ cellH: number,+ vertical: boolean,+ dir: -1 | 1,+ light: number,+ cx: number,+ cy: number,+ opposite: number,+ perpA: number,+ perpB: number,+ perpSpan: number+): void {+ // perpA is the -1 side of the perpendicular axis (up for a horizontal arm, left for a vertical+ // one), perpB the +1 side.+ if (opposite === 3 && dir === -1) return+ const centre = vertical ? cy : cx+ const cross = vertical ? cx : cy+ const far = vertical ? cellH : cellW+ const bothPerp = perpA === 3 && perpB === 3+ const anyPerp = perpA === 3 || perpB === 3++ for (const side of [-1, 1] as const) {+ const railCentre = cross + side * light+ const a = railCentre - light / 2+ const b = railCentre + light / 2+ let inner: number+ if (opposite === 3) inner = dir === -1 ? far : 0+ else if (!anyPerp) inner = centre - (dir * Math.max(perpSpan, light)) / 2+ else {+ const matches = bothPerp || (side === -1 && perpA === 3) || (side === 1 && perpB === 3)+ inner = matches ? centre + dir * light : centre - dir * light+ }+ const from = dir === -1 ? 0 : inner+ const to = dir === -1 ? inner : far+ if (vertical) push(ops, cellW, cellH, a, from, b, to)+ else push(ops, cellW, cellH, from, a, to, b)+ }+}++/** The dashed rules: `count` evenly spaced dashes with `count` gaps, centred on the cell's mid+ * line. Unlike the solid lines these deliberately do NOT reach the cell edges — the gap IS the+ * character. */+function dashOps(+ vertical: boolean,+ count: number,+ heavy: boolean,+ cellW: number,+ cellH: number+): PaintOp[] {+ const light = lightWidth(cellH)+ const thick = heavy ? light * 2 : light+ const extent = vertical ? cellH : cellW+ const cross = (vertical ? cellW : cellH) / 2+ const a = cross - thick / 2+ const b = cross + thick / 2+ // A dash plus its trailing gap is one period; the dash gets two thirds of it, which is the+ // proportion the reference glyphs use and keeps the shortest dash at least a pixel.+ const period = extent / count+ const ops: PaintOp[] = []+ for (let i = 0; i < count; i++) {+ const from = i * period+ const to = from + period * (2 / 3)+ if (vertical) push(ops, cellW, cellH, a, from, b, to)+ else push(ops, cellW, cellH, from, a, to, b)+ }+ return ops+}++/**+ * Append one rect, snapping INTERIOR edges to whole device pixels and leaving edges that sit on+ * the cell boundary exactly where they are.+ *+ * Both halves matter. Snapping the interior is what stops a 1px rule from being antialiased across+ * two texel columns (which is what "blocky/soft" looked like in the report). NOT snapping the+ * boundary is the full-cell invariant: `cellW` is fractional in general, so `Math.round(cellW)`+ * would leave a sub-pixel of background between two adjacent ─ cells — the gap this module exists+ * to close. A rect that rounds away to nothing is kept at one pixel: an invisible line is worse+ * than a slightly fat one.+ */+function push(ops: PaintOp[], cellW: number, cellH: number, x0: number, y0: number, x1: number, y1: number): void {+ const x = snap(x0, cellW)+ const y = snap(y0, cellH)+ const w = Math.max(1, snap(x1, cellW) - x)+ const h = Math.max(1, snap(y1, cellH) - y)+ ops.push({ x, y, w, h })+}++function snap(v: number, extent: number): number {+ if (v <= 0) return 0+ if (v >= extent) return extent+ return Math.round(v)+}diff --git a/src/renderer/glyphgrid/raster.ts b/src/renderer/glyphgrid/raster.tsindex a5077ce73..26cdcd3ae 100644--- a/src/renderer/glyphgrid/raster.ts+++ b/src/renderer/glyphgrid/raster.ts@@ -1,4 +1,5 @@import type { GlyphRasterizer } from './atlas'+import { boxGlyphOps } from './box-glyphs'export interface RasterFont {family: string@@ -49,7 +50,12 @@ function baselineIn(ctx: OffscreenCanvasRenderingContext2D, font: RasterFont): n* full-surface fill would put ink under it. A slot-granular clear (evicting one glyph to* reuse its cell) is a legitimate future need and does not violate this.* 2. Every draw is CLIPPED to its cell rect, so a glyph wider than cellW (a CJK cell, an- * overhanging italic) cannot bleed into the neighbouring slot's texels. */+ * overhanging italic) cannot bleed into the neighbouring slot's texels.+ *+ * And one thing it must not START doing: draw the box-drawing / block-element ranges with the+ * FONT. `boxGlyphOps` gets first refusal on every code point (see box-glyphs.ts for why — fonts+ * do not fill the cell, so a run of ─ came out as a dashed line and block art as a dark lattice),+ * and `fillText` is the fallback for everything it declines. */export function createCanvasRasterizer(font: RasterFont,atlasSizePx: number@@ -72,8 +78,23 @@ export function createCanvasRasterizer(ctx.beginPath()ctx.rect(x, y, font.cellW, font.cellH)ctx.clip()- ctx.font = `${italic ? 'italic ' : ''}${bold ? 'bold ' : ''}${font.sizePx}px ${font.family}`- ctx.fillText(String.fromCodePoint(code), x, y + baseline)+ // Geometry first: these ranges are DEFINED as fractions of the cell, so drawing them is+ // both more correct and cheaper than trusting the face. The ops are already snapped to+ // device px (interior edges) and to the exact cell bounds (outer edges), so no seam can+ // appear between two adjacent cells and no rect lands on a half pixel.+ const geometry = boxGlyphOps(code, font.cellW, font.cellH)+ if (geometry) {+ for (const op of geometry) {+ ctx.globalAlpha = op.alpha ?? 1+ ctx.fillRect(x + op.x, y + op.y, op.w, op.h)+ }+ // `restore()` puts globalAlpha back anyway; reset it explicitly so a future edit that+ // moves a draw out of the save/restore pair cannot inherit a shade's alpha.+ ctx.globalAlpha = 1+ } else {+ ctx.font = `${italic ? 'italic ' : ''}${bold ? 'bold ' : ''}${font.sizePx}px ${font.family}`+ ctx.fillText(String.fromCodePoint(code), x, y + baseline)+ }ctx.restore()}}