Repository navigation
Draw full-width characters in the two cells they take - #79
Conversation
|
@sharamanie is attempting to deploy a commit to the Shubham Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
@greptile-apps review |
|
Make sure you do the changes Sensei
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryThe PR gives full-width BMP characters two canvas cells.
The four supplied, unnumbered previous findings are addressed in the current code. No new actionable issues were found. Reviews (4) · Last reviewed commit: "regenerate the skill's piece list for gt..." · Reviewed by Greptile |
|
Both faults Greptile found are fixed in b707322, plus a third one I found while checking them. Vacated cells were never cleared. The frame was compared to the previous one by string index. A character keeps its index while moving to another cell whenever a wide character earlier on the line changes width, so the cell it left kept its glyph. Measured on Colours were read by display column. A piece's colours are indexed by character position, so past a wide glyph every character took the colour of one further along the row. On a row of Narrow glyphs stay their full size. The cell-sized copy rectangle is restored; the padded-slot source it replaced was scaling every narrow glyph down by about 12% (20px to 17-18px at a 21px cell) and opening gaps in box drawing lines. One overflow case is now handled explicitly:
|
The framed button pads its label to the sidebar's width with `String.length`, which counts a full-width character as one. A label with CJK characters therefore came up short by one cell per character and pushed the right border past the frame; the ellipsis cut long labels at the wrong place for the same reason. Measure in cells instead: two for an East Asian Wide or Fullwidth character, one for the rest, and cut to a cell budget rather than to a character count. English labels render exactly as before. This is the label half of the CJK rendering problem. The glyphs themselves were also being drawn a cell wide, which is ascii.rest's mount(): see bas3line/ascii#79.
A canvas frame is laid out in cells, and mount() advanced one cell per character, so a full-width character (CJK, and the other East Asian Wide and Fullwidth characters) was drawn into a single cell and the characters after it each overlapped the previous one by half a cell. Advance by the character's cell width instead, and give the glyph atlas slots two cells across so a wide glyph is rasterised at the right size rather than squeezed into one cell. Narrow characters keep the one-cell slot they had, so their pixels are unchanged. This is what a piece rendering a label from a page in Chinese hits: dsh-theme-ascetic's framed New Session button drew 新会话 as one compressed smudge.
Three faults in the incremental canvas redraw, all reported in review. A frame was compared to the last one by string index. A character can keep its index while moving to another cell, which happens whenever a wide character before it on the line changes width; the cell it left was then never cleared and its glyph stayed behind. The comparison is now by cell, over a grid of what each cell of the canvas shows. Colours were read by display column. A piece's colours are indexed by character position, so past a wide glyph every colour was taken from further along the row. Each colour now travels with its character to the cell it is drawn in. The glyph was copied from the cell-sized rectangle only because an earlier mistake had it copying the padded slot; restoring that also restores narrow glyphs to their full width. A line carrying wide characters can now run past the last column, since `meta.cols` counts characters. What does not fit is dropped rather than wrapped onto the next row.
env.color holds one colour a character, row by row, with no entry for the newlines between rows. The draw loop read it at the character's index in the frame string, which counts those newlines, so row 1 took the colour of the cell after its own, row 2 two cells on, and the last row ran off the end of the buffer into palette colour 0. Every coloured piece on a canvas was off, wide characters or not. Count each character's place in its row and read its colour at y * cols + j. src/mount.test.ts drives mount() on a stubbed canvas: colours on every row, a wide glyph's two cells and the colours after it, and the cell a character leaves when a wide one before it narrows. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
d758a4e to
bc00859
Compare
What this fixes
On a canvas,
mount()lays a frame out in cells but advanced one cell per character. A full-width character therefore drew into a single cell, and every character after it overlapped the previous one by half a cell — a label like新会话came out as one compressed smudge.The New Session button in dsh-theme-ascetic renders the page's own label, so anyone running that skin on a Chinese (or Japanese/Korean) UI sees it.
What changed
src/width.ts—cellWidth(code): the East Asian Wide and Fullwidth ranges. BMP only; astral characters are two UTF-16 units and the cell model counts characters, so they stay out of scope.src/mount.tscellWidth(c)instead of 1;Narrow characters are unchanged: same one-cell slot geometry, same source rectangle, so existing pieces are pixel-identical. Verified by
npm run checkstaying at 240/240.The contract, and what I did not change
meta.colsstill counts characters, andscripts/check.tsstill asserts[...line].length === cols. So a piece that pads a label to a fixed grid must pad by cells, not byString.length— otherwise its row overflows and the last glyphs wrap. That is what the theme's own piece does, and it is out of scope here: telling piece authors to count cells is a contract change, and folding it into a rendering regression fix would hide it.If you'd rather this PR also make
colscell-based, say so and I'll extend it.Verification
npm run typecheck— cleannpm test— 525/525 (522 existing + 3 new insrc/width.test.ts)npm run check— 240/240npm run kit:docs/npm run kit:examples— all oknpm run gen— no drift insrc/pieces/index.ts,src/library.ts,skills/npm run checkoccasionally reportslake-pichola: slow: worst frame ... (budget 40ms)on my machine. Pre-existing flakiness, not this change: an unpatched checkout failed 3 of 6 runs, this branch failed 1 of 5.