]> granicus.if.org Git - nethack/commitdiff
Enforced the inclusion of windows headers before nethack headers.
authorBart House <bart@barthouse.com>
Mon, 12 Nov 2018 09:58:56 +0000 (01:58 -0800)
committerBart House <bart@barthouse.com>
Mon, 12 Nov 2018 09:58:56 +0000 (01:58 -0800)
Moved the code page 437 mapping table to winnt.c so that it could be
used in window and console clients.
Added check that fonts support unicode values we use from code page 437.
Use unicode to draw text if font supports it otherwise use ASCII.

17 files changed:
sys/share/pcmain.c
sys/winnt/nh340key.c
sys/winnt/nhdefkey.c
sys/winnt/nhraykey.c
sys/winnt/ntsound.c
sys/winnt/nttty.c
sys/winnt/stubs.c
sys/winnt/win32api.h
sys/winnt/winnt.c
sys/winnt/winos.h [new file with mode: 0644]
util/recover.c
win/share/tile2bmp.c
win/win32/mhfont.c
win/win32/mhfont.h
win/win32/mhmap.c
win/win32/mhmenu.c
win/win32/mhstatus.c

index c55805b098e1e395c51ee6d81b3cbe357c8fc711..cc60b3b3cbe77ba7ec57195aaf7c19c92069fe5c 100644 (file)
@@ -5,6 +5,10 @@
 
 /* main.c - MSDOS, OS/2, ST, Amiga, and Windows NetHack */
 
+#ifdef WIN32
+#include "win32api.h" /* for GetModuleFileName */
+#endif
+
 #include "hack.h"
 #include "dlb.h"
 
 #endif
 #endif
 
-#ifdef WIN32
-#include "win32api.h" /* for GetModuleFileName */
-#endif
-
 #ifdef __DJGPP__
 #include <unistd.h> /* for getcwd() prototype */
 #endif
index 8d512142ea7eb9b282c665b5a74be59c9a0332de..78600ec67ee924398e58acbaf2e4bb99a0ee3738 100644 (file)
@@ -13,9 +13,9 @@
 static char where_to_get_source[] = "http://www.nethack.org/";
 static char author[] = "The NetHack Development Team";
 
+#include "win32api.h"
 #include "hack.h"
 #include "wintty.h"
-#include "win32api.h"
 
 extern HANDLE hConIn;
 extern INPUT_RECORD ir;
index 5f7390955308b5a09356a9465c8692c6228ac0d4..f6d110adbb2ea84a25802cfd86ed59c2c358e6c5 100644 (file)
@@ -19,9 +19,9 @@
 static char where_to_get_source[] = "http://www.nethack.org/";
 static char author[] = "The NetHack Development Team";
 
+#include "win32api.h"
 #include "hack.h"
 #include "wintty.h"
-#include "win32api.h"
 
 extern HANDLE hConIn;
 extern INPUT_RECORD ir;
index 3b0a6ef044a08e54a6d0ad01a5d1eb0fc874fe9e..a1f7af3ca1e9ec5845f06fdebe8d6446eed3b494 100644 (file)
 static char where_to_get_source[] = "http://www.nethack.org/";
 static char author[] = "Ray Chason";
 
+#include "win32api.h"
 #include "hack.h"
 #include "wintty.h"
-#include "win32api.h"
 
 extern HANDLE hConIn;
 extern INPUT_RECORD ir;
index 0e4efbf16422ac53b817ea437e1d3338db07652d..c8ec07450cc4b10a36d93e8d524af2dc787882b1 100644 (file)
@@ -10,8 +10,8 @@
  *
  */
 
-#include "hack.h"
 #include "win32api.h"
+#include "hack.h"
 #include <mmsystem.h>
 
 #ifdef USER_SOUNDS
index 0409d333650c6c8213bd97ea503081bcd1d8b19a..63ef24020f73cf9a14bf3f9ecbff88748943f95e 100644 (file)
 
 #ifdef WIN32
 #define NEED_VARARGS /* Uses ... */
+#include "win32api.h"
+#include "winos.h"
 #include "hack.h"
 #include "wintty.h"
 #include <sys\types.h>
 #include <sys\stat.h>
-#include "win32api.h"
 
 extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
 extern int redirect_stdout;
@@ -569,6 +570,9 @@ char ch;
         }
         break;
     default:
+
+        // Temporary fix.  Tty putstatusfield()
+
         inverse = (console.current_nhattr[ATR_INVERSE] && iflags.wc_inverse);
         console.attr = (inverse) ?
                         ttycolors_inv[console.current_nhcolor] :
@@ -601,42 +605,6 @@ char ch;
  * for win32. It is used for glyphs only, not text.
  */
 
-/* CP437 to Unicode mapping according to the Unicode Consortium */
-static const WCHAR cp437[] = {
-    0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
-    0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C,
-    0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8,
-    0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC,
-    0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
-    0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
-    0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
-    0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
-    0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
-    0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
-    0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
-    0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
-    0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
-    0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
-    0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
-    0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302,
-    0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
-    0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
-    0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
-    0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
-    0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba,
-    0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
-    0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
-    0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
-    0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
-    0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
-    0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,
-    0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
-    0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
-    0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229,
-    0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248,
-    0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0
-};
-
 void
 g_putch(in_ch)
 int in_ch;
@@ -1690,12 +1658,17 @@ void set_cp_map()
     if (console.has_unicode) {
         UINT codePage = GetConsoleOutputCP();
 
-        for (int i = 0; i < 256; i++) {
-            char c = (char)i;
-            int count = MultiByteToWideChar(codePage, 0, &c, 1,
-                                            &console.cpMap[i], 1);
-            ntassert(count == 1);
+        if (codePage == 437) {
+            memcpy(console.cpMap, cp437, sizeof(console.cpMap));
+        } else {
+            for (int i = 0; i < 256; i++) {
+                char c = (char)i;
+                int count = MultiByteToWideChar(codePage, 0, &c, 1,
+                                                &console.cpMap[i], 1);
+                ntassert(count == 1);
+            }        
         }
+
     }
 }
 
index 64193ce179bc4211edb6ced09967fbb39ba69510..bb5ad82e432b246ea94bcf80a412f29f571af084 100644 (file)
@@ -2,6 +2,7 @@
 /*      Copyright (c) 2015 by Michael Allison              */
 /* NetHack may be freely redistributed.  See license for details. */
 
+#include "win32api.h"
 #include "hack.h"
 
 #ifdef GUISTUB
@@ -52,9 +53,6 @@ char *argv[];
 
 #ifdef TTYSTUB
 
-#include "hack.h"
-#include "win32api.h"
-
 HANDLE hConIn;
 HANDLE hConOut;
 int GUILaunched;
index b4dc7e4c81761ae740a63d5f2005cd35dd85f490..28514b0ce4739c02b0801f896f25b3431ba8ea09 100644 (file)
@@ -7,23 +7,37 @@
  * header files & NetHack before including windows.h, so all NetHack
  * files should include "win32api.h" rather than <windows.h>.
  */
+#ifndef WIN32API
+#define WIN32API
+
 #if defined(_MSC_VER)
-#undef strcmpi
-#undef min
-#undef max
+
+#if defined(HACK_H)
+#error win32api.h must be included before hack.h
+#endif
+
+#if defined(strcmpi)
+#error win32api.h should be included first
+#endif
+
+#if defined(min)
+#error win32api.h should be included first
+#endif
+
+#if defined(max)
+#error win32api.h should be included first
+#endif
+
+#if defined(Protection)
+#error win32api.h should be included first
+#endif
+
 #pragma warning(disable : 4142) /* Warning, Benign redefinition of type */
 #pragma pack(8)
-#endif
+#endif // _MSC_VER
 
 #define WIN32_LEAN_AND_MEAN
 
-#undef Protection /* We have a global name space collision.  No source file
-                     using win32api.h should be using the Protection macro
-                     from youprop.h.
-                     A better fix would be to ensure we include all window
-                     header files before we start clobbering the global name
-                     space with NetHack specific macros. */
-
 #include <windows.h>
 #include <commctrl.h>
 
@@ -31,4 +45,6 @@
 #pragma pack()
 #endif
 
+#endif // WIN32API
+
 /*win32api.h*/
index 966b268e0aca55a548aacdbc8ec87477f69c6c83..93f372d6223119d6bec0b47d53b3d25116d35b34 100644 (file)
@@ -11,6 +11,8 @@
  *
  */
 
+#include "winos.h"
+
 #define NEED_VARARGS
 #include "hack.h"
 #include <dos.h>
@@ -18,7 +20,6 @@
 #include <direct.h>
 #endif
 #include <ctype.h>
-#include "win32api.h"
 #ifdef TTY_GRAPHICS
 #include "wintty.h"
 #endif
@@ -491,6 +492,95 @@ void nethack_enter_winnt()
     nethack_enter_nttty();
 #endif
 }
+
+/* CP437 to Unicode mapping according to the Unicode Consortium */
+const WCHAR cp437[256] = {
+    0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
+    0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C,
+    0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8,
+    0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC,
+    0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
+    0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
+    0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+    0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
+    0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+    0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
+    0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
+    0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
+    0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+    0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
+    0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+    0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302,
+    0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7,
+    0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
+    0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
+    0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
+    0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba,
+    0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
+    0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
+    0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
+    0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
+    0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
+    0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,
+    0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
+    0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4,
+    0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229,
+    0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248,
+    0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0
+};
+
+WCHAR *
+winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength)
+{
+    size_t i = 0;
+    while(i < dstLength - 1 && src[i] != 0)
+        dst[i++] = cp437[src[i]];
+    dst[i] = 0;
+    return dst;
+}
+
+WCHAR
+winos_ascii_to_wide(const unsigned char c)
+{
+    return cp437[c];
+}
+
+BOOL winos_font_support_cp437(HFONT hFont)
+{
+    BOOL allFound = FALSE;
+    HDC hdc = GetDC(NULL);
+    HFONT oldFont = SelectObject(hdc, hFont);
+
+    DWORD size = GetFontUnicodeRanges(hdc, NULL);
+    GLYPHSET *glyphSet = (GLYPHSET *) malloc(size);
+
+    if (glyphSet != NULL) {
+        GetFontUnicodeRanges(hdc, glyphSet);
+
+        allFound = TRUE;
+        for (int i = 0; i < 256 && allFound; i++) {
+            WCHAR wc = cp437[i];
+            BOOL found = FALSE;
+            for (DWORD j = 0; j < glyphSet->cRanges && !found; j++) {
+                WCHAR first = glyphSet->ranges[j].wcLow;
+                WCHAR last = first + glyphSet->ranges[j].cGlyphs - 1;
+
+                if (wc >= first && wc <= last)
+                    found = TRUE;
+            }
+            if (!found)
+                allFound = FALSE;
+        }
+
+        free(glyphSet);
+    }
+
+    SelectObject(hdc, oldFont);
+    ReleaseDC(NULL, hdc);
+
+    return allFound;
+}
+
 #endif /* WIN32 */
 
-/*winnt.c*/
+/*winnt.c*/
\ No newline at end of file
diff --git a/sys/winnt/winos.h b/sys/winnt/winos.h
new file mode 100644 (file)
index 0000000..39a4b40
--- /dev/null
@@ -0,0 +1,20 @@
+/* NetHack 3.6 winos.h $NHDT-Date: 1524321419 2018/04/21 14:36:59 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.30 $ */
+/* Copyright (c) NetHack PC Development Team 2018 */
+/* NetHack may be freely redistributed.  See license for details. */
+
+#ifndef WINOS_H
+#define WINOS_H
+
+#include "win32api.h"
+
+extern const WCHAR cp437[256];
+
+WCHAR *
+winos_ascii_to_wide_str(const unsigned char * src, WCHAR * dst, size_t dstLength);
+
+WCHAR
+winos_ascii_to_wide(const unsigned char c);
+
+BOOL winos_font_support_cp437(HFONT hFont);
+
+#endif // WINOS_H
index 27c58e709ce2a20edbe0b7cef4afba38473bafd8..415313bee61021e64f92919cde9d6a5cbc50fb8d 100644 (file)
@@ -7,15 +7,16 @@
  *  level files.  Requires that the `checkpoint' option be enabled at the
  *  time NetHack creates those level files.
  */
-#include "config.h"
-#if !defined(O_WRONLY) && !defined(LSC) && !defined(AZTEC_C)
-#include <fcntl.h>
-#endif
 #ifdef WIN32
 #include <errno.h>
 #include "win32api.h"
 #endif
 
+#include "config.h"
+#if !defined(O_WRONLY) && !defined(LSC) && !defined(AZTEC_C)
+#include <fcntl.h>
+#endif
+
 #ifdef VMS
 extern int FDECL(vms_creat, (const char *, unsigned));
 extern int FDECL(vms_open, (const char *, int, unsigned));
index d0fb36333a476fe087d9e3225f386d0e24064c7e..ca2c7dd734a2cd1180661450dee2d6c9d29ca263 100644 (file)
 
 /* #pragma warning(4103:disable) */
 
-#include "hack.h"
-#include "tile.h"
 #ifndef __GNUC__
 #include "win32api.h"
 #endif
 
+#include "hack.h"
+#include "tile.h"
+
 #include <stdint.h>
 #if defined(UINT32_MAX) && defined(INT32_MAX) && defined(UINT16_MAX)
 #define UINT8 uint8_t
index 1b802f2d064d3f18df721d06df693ee42b6c600c..12edec43962d655cd75e82d4a9c2fb6a215e2a82 100644 (file)
@@ -4,6 +4,7 @@
 
 /* font management and such */
 
+#include "winos.h"
 #include "mhfont.h"
 
 #define MAXFONTS 64
@@ -12,6 +13,7 @@
 static struct font_table_entry {
     int code;
     HFONT hFont;
+    BOOL supportsUnicode;
 } font_table[MAXFONTS];
 static int font_table_size = 0;
 HFONT version_splash_font;
@@ -50,6 +52,16 @@ mswin_destroy_splashfonts()
     DeleteObject(version_splash_font);
 }
 
+BOOL 
+mswin_font_supports_unicode(HFONT hFont)
+{
+    for (int i = 0; i < font_table_size; i++)
+        if (font_table[i].hFont == hFont)
+            return font_table[i].supportsUnicode;
+
+    return FALSE;
+}
+
 /* create font based on window type, charater attributes and
    window device context */
 HGDIOBJ
@@ -198,6 +210,8 @@ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
 
     font_table[font_index].code = NHFONT_CODE(win_type, attr);
     font_table[font_index].hFont = fnt;
+    font_table[font_index].supportsUnicode = winos_font_support_cp437(fnt);
+
     return fnt;
 }
 
index de5fdc8e53a426bd8ff31600df6846badb6d579f..76e651215f70d04e35a5bc1553f3c83bf43ff6aa 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "winMS.h"
 
+BOOL mswin_font_supports_unicode(HFONT hFont);
 HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace);
 void mswin_init_splashfonts(HWND hWnd);
 void mswin_destroy_splashfonts(void);
index 8b301da66cda4923445301a6ff02d5c32c63ab82..347de429c9831a82586540587774f0a16b26b1d8 100644 (file)
@@ -2,12 +2,13 @@
 /* Copyright (C) 2001 by Alex Kompel      */
 /* NetHack may be freely redistributed.  See license for details. */
 
-#include "winMS.h"
-#include "resource.h"
+#include "winos.h"
 #include "mhmap.h"
-#include "mhmsg.h"
-#include "mhinput.h"
 #include "mhfont.h"
+#include "mhinput.h"
+#include "mhmsg.h"
+#include "resource.h"
+#include "winMS.h"
 
 #include "color.h"
 #include "patchlevel.h"
 
 extern short glyph2tile[];
 
-#define TILEBMP_X(ntile) ((ntile % GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_X)
-#define TILEBMP_Y(ntile) ((ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y)
+#define TILEBMP_X(ntile) \
+    ((ntile % GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_X)
+#define TILEBMP_Y(ntile) \
+    ((ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y)
 
 /* map window data */
 typedef struct mswin_nethack_map_window {
-    int map[COLNO][ROWNO]; /* glyph map */
+    int map[COLNO][ROWNO];   /* glyph map */
     int bkmap[COLNO][ROWNO]; /* backround glyph map */
 
     int mapMode;              /* current map mode */
@@ -35,6 +38,7 @@ typedef struct mswin_nethack_map_window {
     POINT map_orig;           /* map origin point */
 
     HFONT hMapFont;           /* font for ASCII mode */
+    boolean bUnicodeFont;     /* font supports unicode page 437 */
 } NHMapWindow, *PNHMapWindow;
 
 static TCHAR szNHMapWindowClass[] = TEXT("MSNethackMapWndClass");
@@ -199,6 +203,7 @@ mswin_map_stretch(HWND hWnd, LPSIZE lpsz, BOOL redraw)
         NH_A2W(NHMAP_FONT_NAME, lgfnt.lfFaceName, LF_FACESIZE);
     }
     data->hMapFont = CreateFontIndirect(&lgfnt);
+    data->bUnicodeFont = winos_font_support_cp437(data->hMapFont);
 
     mswin_cliparound(data->xCur, data->yCur);
 
@@ -460,13 +465,13 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
             data->map[msg_data->x][msg_data->y] = msg_data->glyph;
             data->bkmap[msg_data->x][msg_data->y] = msg_data->bkglyph;
 
-            /* invalidate the update area. Erase backround if there 
+            /* invalidate the update area. Erase backround if there
                is nothing to paint or we are in text mode */
             nhcoord2display(data, msg_data->x, msg_data->y, &rt);
-            InvalidateRect(hWnd, &rt, 
-                           (((msg_data->glyph == NO_GLYPH) && (msg_data->bkglyph == NO_GLYPH))
-                            || data->bAsciiMode 
-                            || Is_rogue_level(&u.uz)));
+            InvalidateRect(hWnd, &rt,
+                           (((msg_data->glyph == NO_GLYPH)
+                             && (msg_data->bkglyph == NO_GLYPH))
+                            || data->bAsciiMode || Is_rogue_level(&u.uz)));
         }
     } break;
 
@@ -664,7 +669,7 @@ onPaint(HWND hWnd)
                 for (j = paint_rt.top; j < paint_rt.bottom; j++)
                     if (data->map[i][j] >= 0) {
                         char ch;
-                        TCHAR wch;
+                        WCHAR wch;
                         RECT glyph_rect;
                         int color;
                         unsigned special;
@@ -703,9 +708,15 @@ onPaint(HWND hWnd)
                             OldFg = SetTextColor(hDC, nhcolor_to_RGB(color));
                         }
 #endif
-
-                        DrawText(hDC, NH_A2W(&ch, &wch, 1), 1, &glyph_rect,
+                        if (data->bUnicodeFont) {
+                            wch = winos_ascii_to_wide(ch);
+                            DrawTextW(hDC, &wch, 1, &glyph_rect,
+                                     DT_CENTER | DT_VCENTER | DT_NOPREFIX);
+                        } else {
+                            DrawTextA(hDC, &ch, 1, &glyph_rect,
                                  DT_CENTER | DT_VCENTER | DT_NOPREFIX);
+                        }
+
                         SetTextColor(hDC, OldFg);
                     }
             SelectObject(hDC, oldFont);
@@ -741,7 +752,7 @@ onPaint(HWND hWnd)
                                    data->xScrTile, data->yScrTile, tileDC,
                                    t_x, t_y, GetNHApp()->mapTile_X,
                                    GetNHApp()->mapTile_Y, SRCCOPY);
-                        layer ++;
+                        layer++;
                     }
 
                     if ((glyph != NO_GLYPH) && (glyph != bkglyph)) {
@@ -753,8 +764,8 @@ onPaint(HWND hWnd)
                         if (layer > 0) {
                             (*GetNHApp()->lpfnTransparentBlt)(
                                 hDC, glyph_rect.left, glyph_rect.top,
-                                data->xScrTile, data->yScrTile, tileDC,
-                                t_x, t_y, GetNHApp()->mapTile_X,
+                                data->xScrTile, data->yScrTile, tileDC, t_x,
+                                t_y, GetNHApp()->mapTile_X,
                                 GetNHApp()->mapTile_Y, TILE_BK_COLOR);
                         } else {
                             StretchBlt(hDC, glyph_rect.left, glyph_rect.top,
@@ -763,18 +774,18 @@ onPaint(HWND hWnd)
                                        GetNHApp()->mapTile_Y, SRCCOPY);
                         }
 
-                        layer ++;
-                     }
+                        layer++;
+                    }
 
 #ifdef USE_PILEMARK
-                     /* rely on NetHack core helper routine */
-                     (void) mapglyph(data->map[i][j], &mgch, &color,
-                                        &special, i, j);
-                     if ((glyph != NO_GLYPH) && (special & MG_PET) 
+                    /* rely on NetHack core helper routine */
+                    (void) mapglyph(data->map[i][j], &mgch, &color, &special,
+                                    i, j);
+                    if ((glyph != NO_GLYPH) && (special & MG_PET)
 #else
-                     if ((glyph != NO_GLYPH) && glyph_is_pet(glyph)
+                    if ((glyph != NO_GLYPH) && glyph_is_pet(glyph)
 #endif
-                           && iflags.wc_hilite_pet) {
+                        && iflags.wc_hilite_pet) {
                         /* apply pet mark transparently over
                            pet image */
                         HDC hdcPetMark;
@@ -782,35 +793,35 @@ onPaint(HWND hWnd)
 
                         /* this is DC for petmark bitmap */
                         hdcPetMark = CreateCompatibleDC(hDC);
-                        bmPetMarkOld = SelectObject(
-                            hdcPetMark, GetNHApp()->bmpPetMark);
+                        bmPetMarkOld =
+                            SelectObject(hdcPetMark, GetNHApp()->bmpPetMark);
 
                         (*GetNHApp()->lpfnTransparentBlt)(
                             hDC, glyph_rect.left, glyph_rect.top,
-                            data->xScrTile, data->yScrTile, hdcPetMark, 0,
-                            0, TILE_X, TILE_Y, TILE_BK_COLOR);
+                            data->xScrTile, data->yScrTile, hdcPetMark, 0, 0,
+                            TILE_X, TILE_Y, TILE_BK_COLOR);
                         SelectObject(hdcPetMark, bmPetMarkOld);
                         DeleteDC(hdcPetMark);
                     }
 #ifdef USE_PILEMARK
-                    if ((glyph != NO_GLYPH)
-                        && (special & MG_OBJPILE) && iflags.hilite_pile) {
+                    if ((glyph != NO_GLYPH) && (special & MG_OBJPILE)
+                        && iflags.hilite_pile) {
                         /* apply pilemark transparently over other image */
                         HDC hdcPileMark;
                         HBITMAP bmPileMarkOld;
 
                         /* this is DC for pilemark bitmap */
                         hdcPileMark = CreateCompatibleDC(hDC);
-                        bmPileMarkOld = SelectObject(
-                            hdcPileMark, GetNHApp()->bmpPileMark);
+                        bmPileMarkOld = SelectObject(hdcPileMark,
+                                                     GetNHApp()->bmpPileMark);
 
                         (*GetNHApp()->lpfnTransparentBlt)(
                             hDC, glyph_rect.left, glyph_rect.top,
-                            data->xScrTile, data->yScrTile, hdcPileMark, 0,
-                            0, TILE_X, TILE_Y, TILE_BK_COLOR);
+                            data->xScrTile, data->yScrTile, hdcPileMark, 0, 0,
+                            TILE_X, TILE_Y, TILE_BK_COLOR);
                         SelectObject(hdcPileMark, bmPileMarkOld);
-                        DeleteDC(hdcPileMark);                        
-                   }
+                        DeleteDC(hdcPileMark);
+                    }
 #endif
                 }
 
@@ -1030,4 +1041,3 @@ nhcolor_to_RGB(int c)
         return GetNHApp()->regMapColors[c];
     return RGB(0x00, 0x00, 0x00);
 }
-
index 6b0b4fda2fcd4d328616bebd826afe71e9273c2f..a298f3893dfd0a3aad22b9f6f93a77f1ffdfe801 100644 (file)
@@ -561,7 +561,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
         saveFont =
             SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
         SetRect(&text_rt, 0, 0, 0, 0);
-        DrawText(hdc, msg_data->text, strlen(msg_data->text), &text_rt,
+        DrawTextA(hdc, msg_data->text, strlen(msg_data->text), &text_rt,
                  DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX
                      | DT_SINGLELINE);
         data->text.text_box_size.cx =
index 80799ad82c36d30eb26dfce4332a0b9bcc6d6511..0747628163a393f14d2de6cf37ec9f241f695412 100644 (file)
@@ -3,6 +3,7 @@
 /* NetHack may be freely redistributed.  See license for details. */
 
 #include <assert.h>
+#include "winos.h"
 #include "winMS.h"
 #include "mhstatus.h"
 #include "mhmsg.h"
@@ -278,7 +279,7 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
     int **fop;
     SIZE sz;
     HGDIOBJ normalFont, boldFont;
-    TCHAR wbuf[BUFSZ];
+    WCHAR wbuf[BUFSZ];
     RECT rt;
     PAINTSTRUCT ps;
     HDC hdc;
@@ -335,7 +336,8 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
             clr = data->colors[*f] & 0x00ff;
             atr = (data->colors[*f] & 0xff00) >> 8;
             vlen = strlen(data->vals[*f]);
-            NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
+
+            const char *str = data->vals[*f];
 
             if (atr & HL_BOLD)
                 fntatr = ATR_BOLD;
@@ -347,7 +349,13 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
                 fntatr = ATR_BLINK;
             else if (atr & HL_DIM)
                 fntatr = ATR_DIM;
+
             fnt = mswin_get_font(NHW_STATUS, fntatr, hdc, FALSE);
+
+            BOOL useUnicode = mswin_font_supports_unicode(fnt);
+
+            winos_ascii_to_wide_str(str, wbuf, SIZE(wbuf));
+
             nFg = (clr == NO_COLOR ? status_fg_color
                    : ((clr >= 0 && clr < CLR_MAX) ? nhcolor_to_RGB(clr)
                       : status_fg_color));
@@ -365,11 +373,19 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
                 /* SetTextColor(hdc, nhcolor_to_RGB(hpbar_color)); */
                                SetTextColor(hdc, status_fg_color);
 
-                /* get bounding rectangle */
-                GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
+                if (useUnicode) {
+                    /* get bounding rectangle */
+                    GetTextExtentPoint32W(hdc, wbuf, vlen, &sz);
 
-                /* first draw title normally */
-                DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
+                    /* first draw title normally */
+                    DrawTextW(hdc, wbuf, vlen, &rt, DT_LEFT);
+                } else {
+                    /* get bounding rectangle */
+                    GetTextExtentPoint32A(hdc, str, vlen, &sz);
+
+                    /* first draw title normally */
+                    DrawTextA(hdc, str, vlen, &rt, DT_LEFT);
+                }
 
                 if (hpbar_percent > 0) {
                     /* calc bar length */
@@ -385,7 +401,11 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
                     FillRect(hdc, &barrect, back_brush);
                     SetBkMode(hdc, TRANSPARENT);
                     SetTextColor(hdc, nBg);
-                    DrawText(hdc, wbuf, vlen, &barrect, DT_LEFT);
+
+                    if (useUnicode)
+                        DrawTextW(hdc, wbuf, vlen, &barrect, DT_LEFT);
+                    else
+                        DrawTextA(hdc, str, vlen, &barrect, DT_LEFT);
                 }
                 DeleteObject(back_brush);
             } else {
@@ -401,11 +421,19 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
                 SetBkColor(hdc, nBg);
                 SetTextColor(hdc, nFg);
 
-                /* get bounding rectangle */
-                GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
+                if (useUnicode) {
+                    /* get bounding rectangle */
+                    GetTextExtentPoint32W(hdc, wbuf, vlen, &sz);
 
-                /* draw */
-                DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
+                    /* draw */
+                    DrawTextW(hdc, wbuf, vlen, &rt, DT_LEFT);
+                } else {
+                    /* get bounding rectangle */
+                    GetTextExtentPoint32A(hdc, str, vlen, &sz);
+
+                    /* draw */
+                    DrawTextA(hdc, str, vlen, &rt, DT_LEFT);
+                }
             }
             assert(sz.cy >= 0);