Re: Non-integral scaling factors: best practices?



On 27 April 2017 at 22:56, Brion Vibber <brion pobox com> wrote:
GTK+3 added native support for user interface scaling to support HiDPI
displays with consistently sized resources and widgets, with the limitation
that the scaling factor is an integer (1x, 2x, 3x...)

It's not really a "limitation": it's purposefully designed that way,
for windowing system surfaces and graphical assets. Font sizes support
fractional values, and have been doing so for a long while (since the
GTK+ 2.x days)

In general, the toolkit has no code to detect scaling factors at all,
and it relies on the system to convey meaning to those values.

This seemed a good bet when the earliest HiDPI iOS, MacOS and ChromeOS
machines all came out at 2x, and holds for many high-end PCs... However, PC
laptops with 1920x1080 screens that need a 1.5x or so scaling factor are now
quite common, and a lot of people have CC'd themselves on this old bug
asking about it: https://bugzilla.gnome.org/show_bug.cgi?id=720502

To be fair, 1080p displays with higher-than-192 DPI densities are a
temporary oddity, and are being phased out to the lower end of the
spectrum by HiDPI displays on laptops, and by 4K and 5K displays on
desktops. The cost is still high, but we (Endless) have already
started seeing HiDPI panels in laptops that are starting to target
emerging markets In general, desktop environments will keep a scaling
factor of 1x on 1080p displays, regardless of DPI density. Changing
the font-scaling factor to increase the font size is a valid solution;
for instance, GNOME could keep the window scaling factor to 1x and
make fonts 1.25x bigger if it detects a 1080p display.

This also means non-integral scaling factors are common on Windows, which
may affect cross-platform apps using a GTK+ front-end.

Is there anything that could be done in the GTK+ 4 dev cycle to better
support non-integral scaling factors? I don't know if it's either feasible
or desirable to just rip out the integers and replace with floats...

No, it's not desirable.

Windowing system surfaces cannot be "half pixel" in size; graphical
assets and fonts positioned or sized with sub-pixel precision will
appear blurry and won't look right.

The appropriate way to do fractional scaled rendering at 1.5x is to
render at 3x scale, and have the compositor downscale by a factor of
2x; this is also what macOS does. Of course, this needs cooperation
from the windowing system, as the scaling must also affect the input.
This is why, on Linux, we're going to rely on Wayland compositors to
do the right thing (X11, sadly, cannot do input transformations).

Alternately, would it make sense to recommend best practices for
applications to make display sizes of non-text elements scale along with the
font scaling factor?

Applications shipping assets should ensure to have *at least* 2x
scaled images, and should be coded defensively in case the scaling
factor is >2x; they should also always ensure that everything is pixel
grid aligned when positioning and sizing assets manually, instead of
using the toolkit layout managers.

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[@] ebassi [@gmail.com]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]