The cell buffer describes the interface. GDI helps a host display the parts it cannot render itself.
Two different things can be true
A console application writes character cells and attributes. Reading those cells back can prove that a character or an attribute value was stored. It cannot prove that the current console host drew the intended pixels. That distinction matters for the COMMON_LVB flags: a screen-buffer readback may contain the grid bits even when the host ignores them visually. It matters just as much for Unicode. A successful write of a supplementary-plane code point says nothing about whether the current font has a usable glyph or whether the host composes it as expected.
The implementation here treats these as rendering capability gaps, not as reasons to move the UI model into GDI. The frame compositor and canvases still resolve characters, colors, and border intent into a final viewport. The console writer materializes ordinary cells. GDI is a last-mile drawing path for selected pixel content: large text blocks, glyphs that need a different rasterization route, and thin border strokes when native LVB rendering is unavailable.
Keep semantics in cells and pixels at the edge
The important boundary is ownership. An LVB canvas should say which cell edges are decorated and with what color. The compositor combines that declaration with the other layers and produces one resolved viewport. That same resolved result can go to a capable console host as character attributes or to the GDI fallback as pixel strokes. The fallback must not invent a second border model or recompute layout from the screenshot.
This also keeps the design ready for a later GPU backend. A future cell-surface or GPU path can consume the same resolved masks and colors. The GDI renderer is a CPU reference and a compatibility backend; it does not introduce a GPU dependency, and it does not change the compositor’s source of truth.
Probe capability, not the Windows version
The LVB grid flag is not a promise that every console window paints grid lines. Microsoft documents ENABLE_LVB_GRID_WORLDWIDE as a console output mode that permits line-drawing and reverse-video attributes to be used across code pages. It is off by default for compatibility with applications that historically used those attribute bits for other purposes. A useful renderer therefore distinguishes at least three states: the bits are present in the composed cells; the host supports the mode; and that mode is currently enabled. <a href="https://learn.microsoft.com/en-us/windows/console/char-info-str">Microsoft’s CHAR_INFO table</a> names 0x0400 as top horizontal, 0x0800 as left vertical, 0x1000 as right vertical, and 0x8000 as underscore. <a href="https://learn.microsoft.com/en-us/windows/console/setconsolemode">The console mode documentation</a> explains the enablement and compatibility behavior.
The probe should attempt the mode change, read back the result, and restore the original mode. A successful attribute round trip alone is insufficient. A host that cannot enable the mode takes the GDI branch. A host that can enable it may use native output, subject to the application’s explicit policy. That decision can be a flag because the more conservative GDI path adds work: scanning the viewport, grouping contiguous runs by edge and color, then drawing them. It should not run on every frame when native support is enabled and selected.
COMMON_LVB_GRID_HORIZONTAL 0x0400 top edge
COMMON_LVB_GRID_LVERTICAL 0x0800 left edge
COMMON_LVB_GRID_RVERTICAL 0x1000 right edge
COMMON_LVB_UNDERSCORE 0x8000 underline bit
GDI fallback mapping in this renderer:
GRID_HORIZONTAL -> first pixel row of the cell
GRID_LVERTICAL -> first pixel column of the cell
GRID_RVERTICAL -> last pixel column of the cell
UNDERSCORE -> last pixel row of the cellTurn the chosen bits into thin, aligned strokes
The CPU renderer receives flat, row-major arrays: a ushort-like mask per viewport cell and an RGB color per cell. It scans horizontal edges one row at a time and vertical edges one column at a time. Adjacent cells with the same edge bit and color become one run. One-pixel pens are placed on the first or last pixel row or column inside each cell. The scan is simple enough to audit, and run grouping avoids issuing a separate drawing command for every cell.
Color changes end a run. That detail preserves the resolved layer color at each cell instead of smearing one border’s color across a neighboring border. Clipping is naturally bounded by the viewport arrays; a production wrapper should also check pixel dimensions and client-area changes before drawing. A resize, font change, scroll, or console repaint invalidates the screen overlay and should schedule a fresh materialization from retained state.
Render text using the console’s measured geometry
Large type is another use of the same pixel boundary. Query the active console font face and its pixel cell size, then query the client area and visible viewport. Do not infer the viewport from the screen-buffer dimensions: a buffer can be taller than the visible window. Convert a cell rectangle to pixels using the measured cell width and height. When a font API reports a zero cell width, infer it only from client width divided by visible columns, and record that fallback in the metrics result.
For a multiline block, build a GDI+ path in the selected font, measure the path bounds, scale it uniformly to fit the target rectangle, and rasterize onto a transparent ARGB bitmap. Draw that bitmap at the cell-derived pixel origin on the console client DC. The bitmap path gives explicit control over fitting and background alpha. For individual supplementary characters, accept Unicode scalar values and construct the corresponding UTF-16 surrogate pair; never split the pair or treat a code unit as a full character. The GDI font may still lack the glyph, so keep a fallback glyph or visible diagnostic option.
using (Bitmap bitmap = RenderTextBlock(
metrics.FontFace, metrics.CellHeight * 3f,
cellWidth * cellCount, cellHeight * rowCount,
text, foreground, background))
{
WithConsoleGraphics(graphics =>
graphics.DrawImage(bitmap, new Rectangle(
cellX * metrics.CellWidth,
cellY * metrics.CellHeight,
cellCount * metrics.CellWidth,
rowCount * metrics.CellHeight)));
}int[] pieces = { 0x1CE1A, 0x1CE1B, 0x1CE1F, 0x1CE25 };
for (int i = 0; i < pieces.Length; i++)
{
int x = 4 + i * 5;
painter.DrawCellGlyphCodepoints(x, row, 3, 2, cellWidth, cellHeight,
new object[] { pieces[i] }, fontFace, cellHeight * 3f,
0xFFFF00, 0x000000);
}
A GDI overlay is temporary, so repaint from retained state
A GDI overlay is not written back into the console screen buffer. It can disappear when the host repaints, when another application writes, or when the window is uncovered. This is useful when a program should coexist with ordinary console output such as WScript.Echo: the compositor does not own every pixel or every write. But it means the program needs a deliberate refresh policy.
Treat the overlay as a cache of the latest composed frame. Keep the semantic cell state and the large-text content in the application model. When the console buffer changes outside the compositor, an optional buffer-diff mode can discover the change, rebuild the relevant frame, and redraw. That mode costs a read and compare over some or all of the buffer, so it belongs behind an explicit flag or policy. In the common compositor-owned path, known dirty regions can be redrawn without paying for a full buffer diff.
What the interactive probe established
The interactive probe ran in the connected Windows desktop session with an 80-by-25 viewport and Cascadia Code at 7-by-16 pixel cells. The host reported LVB grid support as false and the mode as disabled. The probe sent one viewport mask containing the top, left, right, and underscore bits to the GDI renderer. It also drew the large cyan text block and four supplementary type-piece code points (U+1CE1A, U+1CE1B, U+1CE1F, and U+1CE25).
The captured 560-by-400 image shows the cyan border, the large text, and four attempted type pieces. The console displays missing-glyph boxes for those supplementary scalars, while the GDI code-point route draws larger yellow forms in 3-by-2-cell regions. On this host, the pixel fallback supplies visible shapes that the native console font did not. This is a verified result for this host and font, not a claim about every Windows console.
The first capture attempt failed at BitBlt with Win32 error 6. Rerunning while the user session was connected produced the screenshot used here. That capture is a separate observation from the console buffer readback; it lets us verify the pixels rather than infer them from stored attributes.
Draw only what the console cannot draw
The practical approach is narrow: preserve the compositor’s cell model, measure the real console geometry, ask the host whether native LVB rendering is available, and route only the missing pixels through GDI. For borders, draw from resolved edge masks. For large type, rasterize using the selected font and a cell-aligned rectangle. Redraw after invalidation, and use capture as a separate verification step.
This gives a widget toolkit a dependable path to richer panels, separators, large headings, and diagnostics on older console hosts, without pretending that a console cell is a general graphics surface. It also leaves the door open for a later GPU renderer: the resolved viewport and measured geometry remain stable contracts; only the last-mile pixel backend changes.