[Commits] SDL: Fixed bug 2137 - SDL Message Boxes don't cope with fixed wi...

libsdl.org revision control commits-owner at libsdl.org
Mon Aug 14 23:45:10 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/23000b73ce4e
changeset: 11303:23000b73ce4e
user:      Sam Lantinga <slouken at libsdl.org>
date:      Mon Aug 14 23:45:06 2017 -0700
description:
Fixed bug 2137 - SDL Message Boxes don't cope with fixed width fonts (in windows at least)

Pegasus Epsilon

With the system dialog font set to Arial or Tahoma or another variable-width font, everything works just as expected. When using a fixed-width font, like Courier or DejaVu Sans Mono, the text gets cut off. Example screenshots attached.

diffstat:

 src/video/windows/SDL_windowsmessagebox.c |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (30 lines):

diff -r 657c10a0a705 -r 23000b73ce4e src/video/windows/SDL_windowsmessagebox.c
--- a/src/video/windows/SDL_windowsmessagebox.c	Mon Aug 14 21:40:40 2017 -0700
+++ b/src/video/windows/SDL_windowsmessagebox.c	Mon Aug 14 23:45:06 2017 -0700
@@ -411,14 +411,24 @@
     {
         /* Get the metrics to try and figure our DLU conversion. */
         GetTextMetrics(FontDC, &TM);
-        s_BaseUnitsX = TM.tmAveCharWidth + 1;
+
+        /* Calculation from the following documentation:
+         * https://support.microsoft.com/en-gb/help/125681/how-to-calculate-dialog-base-units-with-non-system-based-font
+         * This fixes bug 2137, dialog box calculation with a fixed-width system font
+         */
+        {
+            SIZE extent;
+            GetTextExtentPoint32A(FontDC, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &extent);
+            s_BaseUnitsX = (extent.cx / 26 + 1) / 2;
+        }
+        /*s_BaseUnitsX = TM.tmAveCharWidth + 1;*/
         s_BaseUnitsY = TM.tmHeight;
     }
 
     /* Measure the *pixel* size of the string. */
     wmessage = WIN_UTF8ToString(messageboxdata->message);
     SDL_zero(TextSize);
-    Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
+    DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
 
     /* Add some padding for hangs, etc. */
     TextSize.right += 2;


More information about the commits mailing list