From 2690ea43e2fbfa0ffe0cfcada3187bd1573bdff0 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sun, 19 Jul 2026 10:50:07 +0000 Subject: [PATCH 16/71] fix(macos): give the render probe a real DPI and font size (rev 10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root of the vanishing-space: the probe used FontDescriptions with dpi {0,0} (the "auto-fill" default that was never filled), producing a degenerate ~7px cell. At that size a wide capital's shaped advance rounds up to two cells (advanceToCells rounds to nearest; >=11px over a 7px cell -> 2), drifting the following glyphs right and consuming the space between "macOS" and "PowerPC". Set a realistic dpi (96x96) and size (14pt) so the cell is a normal width and per-glyph advances round cleanly to one cell. This does not touch glyph rendering, clip, scale, or force overlap — it just renders at a sensible size. Print the resulting cell size to confirm. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01AeG2jwYMX5gdvvtUnx3PJa --- src/contour_macos/render_probe.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/contour_macos/render_probe.cpp b/src/contour_macos/render_probe.cpp index 7d68f45b..155b5565 100644 --- a/src/contour_macos/render_probe.cpp +++ b/src/contour_macos/render_probe.cpp @@ -59,7 +59,7 @@ void writePpm(std::string const& path, contour_macos::PixelBuffer const& buf) // produced it. __DATE__/__TIME__ update whenever THIS translation unit is recompiled, so the // printed line is a reliable "is the running binary built from the current source?" signal // without needing a full rebuild. -#define RENDER_PROBE_REVISION 9 +#define RENDER_PROBE_REVISION 10 int main(int argc, char** argv) { @@ -88,6 +88,10 @@ int main(int argc, char** argv) // A real monospace family must be named; the default "regular" resolves to no font and // the renderer would throw. Menlo ships with macOS since 10.6. auto fonts = FontDescriptions {}; + // A real DPI and size: the default dpi {0,0} produced a tiny ~7px cell where per-glyph + // advance rounding is fragile (a wide cap rounds to 2 cells and drifts, eating spaces). + fonts.dpi = text::DPI { 96, 96 }; + fonts.size = text::font_size { 14.0 }; char const* const family = argc > 2 ? argv[2] : "Menlo"; for (text::font_description* fd: { &fonts.regular, &fonts.bold, &fonts.italic, &fonts.boldItalic }) { @@ -133,6 +137,14 @@ int main(int argc, char** argv) Decorator::CurlyUnderline }; auto const cellSize = renderer.gridMetrics().cellSize; + std::printf("cellSize = %dx%d px (dpi=%dx%d size=%.1f)\n", + (int) unbox(cellSize.width), + (int) unbox(cellSize.height), + (int) fonts.dpi.x, + (int) fonts.dpi.y, + fonts.size.pt); + std::fflush(stdout); + // A small page margin so the first column's glyph bearing is not clipped at the left edge. int const margin = 2; auto const pixelWidth =