win32u: Choose a smaller ppem to avoid exceeding the requested font height.
commit58b477d1581f715d75c2e117ffa9489c6e64a678
authorZhiyi Zhang <zzhang@codeweavers.com>
Fri, 12 Aug 2022 03:32:54 +0000 (12 11:32 +0800)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 19 Aug 2022 20:45:18 +0000 (19 22:45 +0200)
treec261ee3225c392135ffd5bcb6de0ecf15099558c
parent821b36e00bd99924a454bf2e982fe7d4924f08e7
win32u: Choose a smaller ppem to avoid exceeding the requested font height.

When height > 0, CreateFontA/W() should not return a font face exceeding the requested height.
For instance, Tahoma has 2049 units of ascent, 423 units of descent and its units per EM square is
2048. When requesting a font 20 pixels in height, ppem = units_per_EM * requested_height / (ascent + descent)
= 2048 * 20 / (2049 + 423) = 16.57 ~= 17. When getting the resulting height back from the ppem,
resulting_height = (ascent + descent) * ppem / units_per_EM = (2049.0 + 423) * 17 / 2048 = 20.52
~=21. So it ends up getting a larger font than requested and violates the spec.

Fix Nancy Drew: Legend of the Crystal Skull crash at start.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
dlls/gdi32/tests/font.c
dlls/win32u/freetype.c