Skip to content

Fix pixel-perfect GL rendering at non-integer device pixel ratios#1709

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-font-scaling-issues
Closed

Fix pixel-perfect GL rendering at non-integer device pixel ratios#1709
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-font-scaling-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

At display scaling other than 100% (DPR ≠ 1), the OpenGL canvas renders text with visibly uneven stroke widths because glyph positions snap to CSS pixel boundaries rather than physical pixel boundaries, and pixel-grid alignment is disabled entirely for all non-1× DPR values.

Root causes

  • AlignToPixelGrid snapped to CSS pixel grid, not physical pixel grid. floor(v.x) + 0.5 centers on integer CSS pixels. At DPR=1.5, those land at 0.0, 1.5, 3.0… physical pixels — every other position off-center, producing alternating 1- and 2-pixel-wide strokes.

  • gridFit unconditionally disabled for DPR ≠ 1, so no pixel alignment was applied at any scaled DPI. The guard existed because the old snap formula was wrong for non-1× DPR.

  • (Web only) Canvas CSS display size not explicitly set after emscripten_set_canvas_element_size. The width: 100% rule could resolve to a fractional CSS size that doesn't divide evenly by DPR, causing the browser to apply bilinear interpolation over the bitmap.

Changes

  • src/render/render.cpp — Fix AlignToPixelGrid to snap to physical pixel centers for any DPR:

    // Before: snaps to CSS pixel centers only (correct at DPR=1, wrong otherwise)
    v.x = floor(v.x) + 0.5;
    
    // After: snaps to physical pixel centers at any DPR
    v.x = (floor(v.x * pixelRatio) + 0.5) / pixelRatio;
  • src/draw.cpp, src/textwin.cpp — Set gridFit = true unconditionally (was GetDevicePixelRatio() == 1). The fixed snap formula handles all DPR values correctly.

  • src/platform/guihtml.cpp — After resizing the canvas bitmap, override the inline CSS size to pixelWidth / DPR × pixelHeight / DPR px, ensuring the browser maps the bitmap 1:1 to physical pixels without any interpolation pass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • gitlab.com
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED rchives/libsm-de--gdwarf-5 rchi�� /local/bin/cmake-o rchives/xtrans-dCMakeFiles/mimalloc-static.dir/src/stats.c.o fig h/TryCompile-6O2/usr/local/bin/cmake systemd-journald-E systemd-networkdcmake_echo_color fig dedi�� ibdxfrw/intern graphics-window ibdxfrw e/extlib/libdxfrw -isystem /home/REDACTED/work/solvespace/solvespace/extlib/mimalloc/include -isy --global /opt/pipx_bin/gi/home/REDACTED/work/solvespace/solvespace/extlib/libdxfrw/intern e/git (dns block)
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED -dumpbase --de�� 36 p.ci vespace vespace/res kmsg dwgreader18.cpp./home/REDACTED/work/solvespace/solvespace/extlib/libdxfrw/intern iles/resources.d-I --fo�� ibdxfrw/intern --force-confdef ibdxfrw es --progress-nuas uild/CMakeFiles very window/other-sup-I (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix uneven stroke width in font rendering Fix pixel-perfect GL rendering at non-integer device pixel ratios Apr 1, 2026
Copilot AI requested a review from phkahler April 1, 2026 17:54
@ruevs
Copy link
Copy Markdown
Member

ruevs commented Apr 2, 2026

@phkahler I'll take a look...

@ruevs
Copy link
Copy Markdown
Member

ruevs commented Apr 2, 2026

This makes absolutely no difference:
After:
image

Before:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Font scales badly (uneven stroke width)

3 participants