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.
This commit is contained in:
Bart House
2018-12-09 11:57:50 -08:00
parent 0573392f16
commit 88bbf781d1
2 changed files with 18 additions and 6 deletions
+3
View File
@@ -9,6 +9,9 @@
#include "winMS.h" #include "winMS.h"
#define MIN_FONT_WIDTH 9
#define MIN_FONT_HEIGHT 12
typedef struct cached_font { typedef struct cached_font {
int code; int code;
HFONT hFont; HFONT hFont;
+15 -6
View File
@@ -160,7 +160,10 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw)
// calculate back buffer scale // calculate back buffer scale
data->monitorScale = win10_monitor_scale(hWnd); 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; data->backScale = data->monitorScale;
} else { } else {
data->backScale = 1.0; 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->xBackTile = (int) (data->tileWidth * data->backScale);
data->yBackTile = (int) (data->tileHeight * data->backScale); data->yBackTile = (int) (data->tileHeight * data->backScale);
if (data->bAsciiMode || Is_rogue_level(&u.uz)) { if (bText) {
LOGFONT lgfnt; LOGFONT lgfnt;
ZeroMemory(&lgfnt, sizeof(lgfnt)); ZeroMemory(&lgfnt, sizeof(lgfnt));
@@ -195,21 +198,27 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw)
} }
TEXTMETRIC textMetrics; TEXTMETRIC textMetrics;
HFONT font; HFONT font = NULL;
while (1) { while (1) {
if (font != NULL)
DeleteObject(font);
font = CreateFontIndirect(&lgfnt); font = CreateFontIndirect(&lgfnt);
SelectObject(data->backBufferDC, font); SelectObject(data->backBufferDC, font);
GetTextMetrics(data->backBufferDC, &textMetrics); GetTextMetrics(data->backBufferDC, &textMetrics);
if (textMetrics.tmHeight > data->yBackTile) { if (textMetrics.tmHeight > data->yBackTile &&
lgfnt.lfHeight < -MIN_FONT_HEIGHT) {
lgfnt.lfHeight++; lgfnt.lfHeight++;
continue; continue;
} }
if (textMetrics.tmAveCharWidth > data->xBackTile) { if (textMetrics.tmAveCharWidth > data->xBackTile &&
lgfnt.lfWeight < -MIN_FONT_WIDTH) {
lgfnt.lfWidth++; lgfnt.lfWidth++;
continue; continue;
} }
@@ -270,7 +279,7 @@ mswin_map_stretch(HWND hWnd, LPSIZE map_size, BOOL redraw)
} else { } else {
if (data->bAsciiMode || Is_rogue_level(&u.uz)) { if (bText) {
data->frontScale = 1.0; data->frontScale = 1.0;
} else { } else {
data->frontScale = data->monitorScale; data->frontScale = data->monitorScale;