Enforced the inclusion of windows headers before nethack headers.

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.
This commit is contained in:
Bart House
2018-11-12 01:58:56 -08:00
parent e87496b897
commit 8944235282
17 changed files with 276 additions and 124 deletions

View File

@@ -12,12 +12,13 @@
/* #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

View 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;
}

View 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);

View 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"
@@ -17,12 +18,14 @@
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);
}

View 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 =

View 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);