src/video/windows/SDL_windowsmessagebox.c
changeset 11303 23000b73ce4e
parent 11236 8c3cba28b1fd
child 11375 2dd1cac9e43a
     1.1 --- a/src/video/windows/SDL_windowsmessagebox.c	Mon Aug 14 21:40:40 2017 -0700
     1.2 +++ b/src/video/windows/SDL_windowsmessagebox.c	Mon Aug 14 23:45:06 2017 -0700
     1.3 @@ -411,14 +411,24 @@
     1.4      {
     1.5          /* Get the metrics to try and figure our DLU conversion. */
     1.6          GetTextMetrics(FontDC, &TM);
     1.7 -        s_BaseUnitsX = TM.tmAveCharWidth + 1;
     1.8 +
     1.9 +        /* Calculation from the following documentation:
    1.10 +         * https://support.microsoft.com/en-gb/help/125681/how-to-calculate-dialog-base-units-with-non-system-based-font
    1.11 +         * This fixes bug 2137, dialog box calculation with a fixed-width system font
    1.12 +         */
    1.13 +        {
    1.14 +            SIZE extent;
    1.15 +            GetTextExtentPoint32A(FontDC, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &extent);
    1.16 +            s_BaseUnitsX = (extent.cx / 26 + 1) / 2;
    1.17 +        }
    1.18 +        /*s_BaseUnitsX = TM.tmAveCharWidth + 1;*/
    1.19          s_BaseUnitsY = TM.tmHeight;
    1.20      }
    1.21  
    1.22      /* Measure the *pixel* size of the string. */
    1.23      wmessage = WIN_UTF8ToString(messageboxdata->message);
    1.24      SDL_zero(TextSize);
    1.25 -    Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
    1.26 +    DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
    1.27  
    1.28      /* Add some padding for hangs, etc. */
    1.29      TextSize.right += 2;