News for hackers. Stuff that matters.
Re:Let’s fix font size by greggman3 on Wednesday March 31, 2021 @12:22AM (#26643495)
Doesn't always work (may work for your use case). There are edgecases in the browser where at an HTML level the browser computes a CSS size but at compositing level (where devicePixelRatio is used) it might have clip by pixel here or there.

And example, lets say your windows 99 device pixel wide and a DRP of 2.0 and lets say you ask for 2 side by side elements (via flexbox or whatever) each width:50%. At the HTML level the browser will compute there are 49.5 CSS pixels available. It will then compute the size of each 50% as 24.25 CSS pixels but in order to fill the 99 pixels, one of those 2 elements has to be 50 pixels and the other 49. There is no part of the spec that says which side gets 50 and which get 49. Most browser compute 50 for both sides, the pass it up their compositor which will use 50 pixels of one and 49 of the other. The point is, you can't know which one will get which by doing CSSpx * dpr.

This is why ResizeObserver device-pixel-content-box was added. So that you can ask the browser what it did.

Re:Let’s fix font size by jan_Inkepa on Wednesday March 31, 2021 @07:39AM (#26645967)
> ResizeObserver

TIL. Oh gosh I don't know if I have the brain power to work through all the necessary rendering layers logic to fix up my game engine to make the pixels as they should be, but if I ever do and figure it out, great thanks to you! (and even otherwise, thanks!)

Re:Let’s fix font size by wffurr on Wednesday March 31, 2021 @07:40AM (#26645975)
I will check out that ResizeObserver property.

I hack around it by taking the CSS size of the container, finding the closest smaller integer device pixel size, and set the canvas context to that and the canvas CSS size to the fractional size, which can be smaller than the containers CSS size.

Basically rounding down.

Re:Let’s fix font size by greggman3 on Wednesday March 31, 2021 @09:12PM (#26655521)