fix DpiAwareFont default size calculation #48

Open
momo wants to merge 4 commits from dpi-font-auto-calc into how_to_show_ur_pp
4 changed files with 1131 additions and 692 deletions

View File

@ -182,7 +182,7 @@ class DpiAwareFont:
# always going to hit that error in range mapping from inches:
# float to px size: int.
self._font_inches = inches
font_size = math.floor(inches * dpi)
font_size = math.floor(inches * pdpi)

Yeah, it’s funny that this worked for you since the non-physical DPI is supposed to be the one that “you perceive on screen given DE scaling compensation” ..

so it does indeed look like we might always want/need to do from-scratch analysis of every display’s reported DPI and totally ignore OS-dependent metrix/reports including those with supposed auto-scaling.

Yeah, it's funny that this worked for you since the non-physical DPI is supposed to be the one that "you perceive on screen given DE scaling compensation" .. so it does indeed look like we might **always** want/need to do from-scratch analysis of every display's reported DPI and totally ignore OS-dependent metrix/reports including those with supposed auto-scaling.
log.debug(
f"screen:{screen.name()}\n"

View File

@ -85,9 +85,6 @@ uis = [
# TODO: make sure the levenshtein shit compiles on nix..
# rapidfuzz = {extras = ["speedup"], version = "^0.18.0"}
"rapidfuzz >=3.2.0, <4.0.0",
"qdarkstyle >=3.0.2, <4.0.0",
"pyqt6 >=6.7.0, <7.0.0",
"pyqtgraph",
# for consideration,
# - 'visidata'
@ -118,6 +115,10 @@ dev = [
# ?from git, see below.
"xonsh",
"qdarkstyle >=3.0.2, <4.0.0",
"pyqt6 >=6.7.0, <7.0.0",
"pyqtgraph",
]
[tool.pytest.ini_options]

View File

@ -0,0 +1,36 @@
import pytest
from piker.ui._style import DpiAwareFont
class MockScreen:
def __init__(self, pdpi, ldpi, name="MockScreen"):
self._pdpi = pdpi
self._ldpi = ldpi
self._name = name
def physicalDotsPerInch(self):
return self._pdpi
def logicalDotsPerInch(self):
return self._ldpi
def name(self):
return self._name

woo nice!

this is a good start but we should wrap this in a pytest test-fn (function) so that it will report like the rest of the test suites ;)

https://docs.pytest.org/en/stable/getting-started.html#create-your-first-test

woo nice! this is a good start but we should wrap this in a `pytest` test-fn (function) so that it will report like the rest of the test suites ;) https://docs.pytest.org/en/stable/getting-started.html#create-your-first-test
@pytest.mark.parametrize(
"pdpi, ldpi, expected_px",
[
(96, 96, 9), # normal DPI
(169, 96, 15), # HiDPI
(120, 96, 10), # mid-DPI
]
)
def test_font_px_size(pdpi, ldpi, expected_px):
font = DpiAwareFont()
font.configure_to_dpi(screen=MockScreen(pdpi, ldpi))
px = font.px_size
print(f"{pdpi}x{ldpi} DPI -> Computed pixel size: {px}")
assert px == expected_px

1778
uv.lock

File diff suppressed because it is too large Load Diff