whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
7.87k stars 2.58k forks source link

Add support for obtaining display's physical dimensions in millimeters #6712

Open juj opened 3 years ago

juj commented 3 years ago

Currently it is not possible to obtain the display's physical pixels-per-inch value. This prevents users e.g. from calculating what the width and height of the physical display is in millimeters, and the diagonal size of the display in inches.

As a result, it is difficult to create unified cross-platform experiences that would follow responsive design practices across devices.

There are existing workaround attempts, like calling window.matchMedia("(min-resolution: xxxdpi)") to probe what the dpi setting would be, or measuring the width of a 1em dash in centimeters, or the size of an 1inch DOM element. Based on testing at http://clb.confined.space/dump/dpitest.html , none of these work when tested on Windows, MacBook or an iPhone.

This issue is continuously affecting Unity users, who are creating UIs that should work consistently when deployed across native platforms on Windows, Android, iOS, but also when targeting the web. A common use case is to utilize a "Constant Physical Size" metric for UI elements to produce readable sized text that scales well on all platforms, along with a simulated "reading distance: mobile = 50cm, desktop = 1m, TV = 5m" factors, but this is something that does not currently work on the web due to this platform limitation. A recent user report is here: https://forum.unity.com/threads/constant-physical-size-differences-between-webgl-and-standalone.1113298/#post-7162492

As a result, UIs are off for users, and they need to rely on hacky scaling factors on top of window.devicePixelRatio to get things to match up, and sniffing the user agent to detect Android, iOS vs desktop browsers that then each come with their own hacky scaling factors.

Would it be possible to fix this long-standing issue and add to the web a direct API for obtaining the display's physical width and height in millimeters values?

pshaughn commented 3 years ago

Two things occur to me about this. One is that often the operating system doesn't even know the physical size, so the returned values from such an API still ultimately need to be taken with a grain of salt by authors; Windows often falls back to just guessing that a 1080 display is 96DPI. The other is that it could raise fingerprinting concerns, since monitor physical sizes have more variation than monitor pixel counts.