fix DpiAwareFont default size calculation #48
|
|
@ -182,7 +182,7 @@ class DpiAwareFont:
|
||||||
# always going to hit that error in range mapping from inches:
|
# always going to hit that error in range mapping from inches:
|
||||||
# float to px size: int.
|
# float to px size: int.
|
||||||
self._font_inches = inches
|
self._font_inches = inches
|
||||||
font_size = math.floor(inches * dpi)
|
font_size = math.floor(inches * pdpi)
|
||||||
|
|
|||||||
|
|
||||||
log.debug(
|
log.debug(
|
||||||
f"screen:{screen.name()}\n"
|
f"screen:{screen.name()}\n"
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,6 @@ uis = [
|
||||||
# TODO: make sure the levenshtein shit compiles on nix..
|
# TODO: make sure the levenshtein shit compiles on nix..
|
||||||
# rapidfuzz = {extras = ["speedup"], version = "^0.18.0"}
|
# rapidfuzz = {extras = ["speedup"], version = "^0.18.0"}
|
||||||
"rapidfuzz >=3.2.0, <4.0.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,
|
# for consideration,
|
||||||
# - 'visidata'
|
# - 'visidata'
|
||||||
|
|
@ -118,6 +115,10 @@ dev = [
|
||||||
|
|
||||||
# ?from git, see below.
|
# ?from git, see below.
|
||||||
"xonsh",
|
"xonsh",
|
||||||
|
"qdarkstyle >=3.0.2, <4.0.0",
|
||||||
|
"pyqt6 >=6.7.0, <7.0.0",
|
||||||
|
"pyqtgraph",
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
Loading…
Reference in New Issue
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.