From 88bbf781d146c022ecad1790b01e85bbb4ba0958 Mon Sep 17 00:00:00 2001 From: Bart House Date: Sun, 9 Dec 2018 11:57:50 -0800 Subject: [PATCH] Three fixes to NetHackW font handling. Check that player level is valid before checking if it is rogue. Prevent attempting to pick a font that is too small. Don't leak fonts when trying to find a font that fits. --- win/win32/mhfont.h | 3 +++ win/win32/mhmap.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/win/win32/mhfont.h b/win/win32/mhfont.h index 20b5d1400..9402d54a9 100644 --- a/win/win32/mhfont.h +++ b/win/win32/mhfont.h @@ -9,6 +9,9 @@ #include "winMS.h" +#define MIN_FONT_WIDTH 9 +#define MIN_FONT_HEIGHT 12 + typedef struct cached_font { int code; HFONT hFont; diff --git a/win/win32/mhmap.c b/win/win32/mhmap.c index d401c4c3c..067d9a6e9 100644 --- a/win/win32/mhmap.c +++ b/win/win32/mhmap.c @@ -160,7 +160,10 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw) // calculate back buffer scale data->monitorScale = win10_monitor_scale(hWnd); - if (data->bAsciiMode || Is_rogue_level(&u.uz)) { + boolean bText = data->bAsciiMode || + (u.uz.dlevel != 0 && Is_rogue_level(&u.uz)); + + if (bText) { data->backScale = data->monitorScale; } else { data->backScale = 1.0; @@ -170,7 +173,7 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw) data->xBackTile = (int) (data->tileWidth * data->backScale); data->yBackTile = (int) (data->tileHeight * data->backScale); - if (data->bAsciiMode || Is_rogue_level(&u.uz)) { + if (bText) { LOGFONT lgfnt; ZeroMemory(&lgfnt, sizeof(lgfnt)); @@ -195,21 +198,27 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw) } TEXTMETRIC textMetrics; - HFONT font; + HFONT font = NULL; while (1) { + + if (font != NULL) + DeleteObject(font); + font = CreateFontIndirect(&lgfnt); SelectObject(data->backBufferDC, font); GetTextMetrics(data->backBufferDC, &textMetrics); - if (textMetrics.tmHeight > data->yBackTile) { + if (textMetrics.tmHeight > data->yBackTile && + lgfnt.lfHeight < -MIN_FONT_HEIGHT) { lgfnt.lfHeight++; continue; } - if (textMetrics.tmAveCharWidth > data->xBackTile) { + if (textMetrics.tmAveCharWidth > data->xBackTile && + lgfnt.lfWeight < -MIN_FONT_WIDTH) { lgfnt.lfWidth++; continue; } @@ -270,7 +279,7 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw) } else { - if (data->bAsciiMode || Is_rogue_level(&u.uz)) { + if (bText) { data->frontScale = 1.0; } else { data->frontScale = data->monitorScale; -- 2.40.0