From a9e25ec67f15b4d1704fed7340c1a04971c8edab Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 2 Mar 2026 19:23:22 -0600 Subject: [PATCH] Re-select OEM font into DC before every render pass Relying on CS_OWNDC to retain the font between frames is fragile -- Delphi's Canvas infrastructure can deselect it during paint cycles. Without the OEM font, ExtTextOut renders with SYSTEM_FONT (ANSI_CHARSET), causing CP437 box-drawing glyphs to display as accented letters, cell metrics to mismatch (lines clipped), and cursor position to drift. Co-Authored-By: Claude Opus 4.6 --- delphi/KPANSI.PAS | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/delphi/KPANSI.PAS b/delphi/KPANSI.PAS index 2e2f4bf..c2f13f3 100644 --- a/delphi/KPANSI.PAS +++ b/delphi/KPANSI.PAS @@ -1139,8 +1139,12 @@ begin Exit; end; - { Render dirty rows directly to screen DC } + { Render dirty rows directly to screen DC. Re-select the OEM font each } + { frame because Delphi's Canvas infrastructure can deselect it from the } + { CS_OWNDC between paint cycles. } DC := GetDC(Handle); + SelectObject(DC, FPaintFont); + SetBkMode(DC, OPAQUE); for Row := 0 to FRows - 1 do begin if FAllDirty or FDirtyRow[Row] then @@ -1321,6 +1325,8 @@ begin { Full repaint: render each row directly to screen } FAllDirty := True; DC := Canvas.Handle; + SelectObject(DC, FPaintFont); + SetBkMode(DC, OPAQUE); for Row := 0 to FRows - 1 do begin