fix(gui): make SVG icon rasterization DPI-aware in loadPixmap (#189) #266

Merged
forbes merged 2 commits from fix/toolbar-icon-dpi-scaling into main 2026-02-18 18:57:15 +00:00
Owner

Summary

BitmapFactory::loadPixmap() rendered all SVGs at a hardcoded 64x64 pixels regardless of display DPI. On HiDPI screens, Qt downscaled these low-resolution pixmaps to the toolbar icon size, producing chunky/aliased icons.

Root Cause

loadPixmap() called pixmapFromSvg(content, QSize(64, 64)) without accounting for the device pixel ratio. A DPI-aware path already existed in the named pixmapFromSvg(const char*, QSizeF) overload, but the generic loadPixmap() path (used by all toolbar icons) never used it.

Fix

Multiply the render size by getMaximumDPR() and tag the resulting pixmap with setDevicePixelRatio(), matching the existing pattern in the named overload. This is a 3-line change in src/Gui/BitmapFactory.cpp.

Testing

  • Added tests/src/Gui/BitmapFactory.cpp with 3 GTest cases:
    • PixmapFromSvgContentRendersAtRequestedSize -- verifies the raw content path
    • MaximumDPRIsAtLeastOne -- sanity check on DPR utility
    • PixmapFromSvgFileHasCorrectDPR -- end-to-end test: writes SVG to temp dir, loads via pixmap(), verifies DPR and physical size

Verification

Visual inspection on HiDPI display recommended -- toolbar icons should appear crisp rather than chunky/aliased at all preference sizes (16, 24, 32, 48).

Closes #189

## Summary `BitmapFactory::loadPixmap()` rendered all SVGs at a hardcoded 64x64 pixels regardless of display DPI. On HiDPI screens, Qt downscaled these low-resolution pixmaps to the toolbar icon size, producing chunky/aliased icons. ## Root Cause `loadPixmap()` called `pixmapFromSvg(content, QSize(64, 64))` without accounting for the device pixel ratio. A DPI-aware path already existed in the named `pixmapFromSvg(const char*, QSizeF)` overload, but the generic `loadPixmap()` path (used by all toolbar icons) never used it. ## Fix Multiply the render size by `getMaximumDPR()` and tag the resulting pixmap with `setDevicePixelRatio()`, matching the existing pattern in the named overload. This is a 3-line change in `src/Gui/BitmapFactory.cpp`. ## Testing - Added `tests/src/Gui/BitmapFactory.cpp` with 3 GTest cases: - `PixmapFromSvgContentRendersAtRequestedSize` -- verifies the raw content path - `MaximumDPRIsAtLeastOne` -- sanity check on DPR utility - `PixmapFromSvgFileHasCorrectDPR` -- end-to-end test: writes SVG to temp dir, loads via `pixmap()`, verifies DPR and physical size ## Verification Visual inspection on HiDPI display recommended -- toolbar icons should appear crisp rather than chunky/aliased at all preference sizes (16, 24, 32, 48). Closes #189
forbes added 2 commits 2026-02-18 18:56:12 +00:00
loadPixmap() rendered all SVGs at a hardcoded 64x64 pixels regardless of
display DPI. On HiDPI screens, Qt then downscaled these low-resolution
pixmaps to the toolbar icon size, producing chunky/aliased icons.

Multiply the render size by getMaximumDPR() and tag the resulting pixmap
with the correct devicePixelRatio, matching the pattern already used in
pixmapFromSvg(const char* name, QSizeF size). This ensures SVGs are
rasterized at the physical resolution needed for crisp display.
test(gui): add BitmapFactory DPI-aware SVG rendering tests (#189)
All checks were successful
Build and Test / build (pull_request) Successful in 29m28s
ea49736549
Three tests for the loadPixmap() DPI fix:
- pixmapFromSvg(content, size) renders at the exact requested size
- getMaximumDPR() returns >= 1.0
- pixmap() loaded from an SVG file has correct devicePixelRatio and
  physical size matching 64 * DPR
forbes merged commit 41669eea8b into main 2026-02-18 18:57:15 +00:00
forbes deleted branch fix/toolbar-icon-dpi-scaling 2026-02-18 18:57:16 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#266