[Webkit-unassigned] [Bug 142673] [GTK] Add settings to set font size in points, and deprecate the pixel size settings

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Oct 31 03:38:37 PDT 2017


https://bugs.webkit.org/show_bug.cgi?id=142673

--- Comment #18 from Gabriel Ivașcu <givascu at igalia.com> ---
(In reply to Michael Catanzaro from comment #17)
> Comment on attachment 325377 [details]
> Patch
>  
> (2) Your *_get_font_size_pts() functions only return a reasonable result if
> you first call the corresponding *_set_font_size_pts() function. Instead,
> they should do the right thing even if the user has only ever called the old
> *_set_font_size() function. So instead of saving the size in points in the
> priv struct, you'll actually need to do the reverse computation to change
> from pixels back to points. I'm not sure, but you might need to use round().
> Before you fix this, add tests for this, make sure the tests fail, and then
> write the implementation and make sure the tests pass.

This won't work correctly when the screen DPI changes. We need to save either the "initial" font size in points or the previous DPI to correctly calculate the new font size in pixels for the new DPI. I'll explain below.

The formulas for doing the conversions are:

(1) Pixels = Points * DPI / 72;
(2) Points = Pixels * 72 / DPI;

The 72 comes from the fact that 1 point is defined as 1/72 inches.

If we don't store Points anywhere, then that's fine only when the screen DPI remains constant. Because we can always convert back from Pixels to Points knowing the DPI. However, if the screen DPI varies, and we don't store the previous DPI either, then we can't convert back to the font size in points of the initial DPI, because we only know the current DPI which is the new one, and thus we cannot apply the scaling factor.

Here's an example:

Suppose that the initial DPI is 96 and the font size is 12 points, i.e. 16 pixels at this DPI. We only save the size in pixels. Then the DPI changes to 80, for example. Knowing only the current font size of 16 pixels and the current DPI of 80, we cannot really calculate the new font size value in pixels. Because we have no way to tell if those 16 pixels initially came from a font size of 12 points at 96 DPI. They might as well come from a font size of 8 points at 144 DPI, for example.

We can do this right only if:

A. We know that the initial font size in points was 12. Then formula (1) is used directly to calculate the new font size in pixels: 12 * 72 / 80 == 13.3 pixels. That's what my patch does now.

B. We know that the initial DPI was 96. Then both formulas (1) and (2) are used, first (2) to get the initial font size in points, and then (1) to calculate the new font size in pixels: (16 * 72 / 96) * 80 / 72 == 13.3 pixels. Here the scaling factor is basically the current DPI divided by the previous DPI, which is 80/96 in this case.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20171031/efddaad1/attachment.html>


More information about the webkit-unassigned mailing list