X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/092e93956c7a7cf7efa3ad5f8ae32bcf9ebdc6ae..37f1ab78bc2f856eac57156e5aa591f535e0b442:/windows.c diff --git a/windows.c b/windows.c index 7fe11f3..7bdb5e2 100644 --- a/windows.c +++ b/windows.c @@ -154,11 +154,17 @@ void debug_printf(char *fmt, ...) { char buf[4096]; va_list ap; + static int debugging = -1; - va_start(ap, fmt); - _vsnprintf(buf, 4095, fmt, ap); - dputs(buf); - va_end(ap); + if (debugging == -1) + debugging = getenv("DEBUG_PUZZLES") ? 1 : 0; + + if (debugging) { + va_start(ap, fmt); + _vsnprintf(buf, 4095, fmt, ap); + dputs(buf); + va_end(ap); + } } #endif @@ -239,6 +245,7 @@ void frontend_free(frontend *fe) sfree(fe->brushes); sfree(fe->pens); sfree(fe->presets); + sfree(fe->fonts); sfree(fe); } @@ -601,10 +608,8 @@ static void win_draw_text(void *handle, int x, int y, int fonttype, HFONT oldfont; TEXTMETRIC tm; SIZE size; -#ifdef _WIN32_WCE TCHAR wText[256]; - MultiByteToWideChar (CP_ACP, 0, text, -1, wText, 256); -#endif + MultiByteToWideChar (CP_UTF8, 0, text, -1, wText, 256); oldfont = SelectObject(fe->hdc, fe->fonts[i].font); if (GetTextMetrics(fe->hdc, &tm)) { @@ -613,11 +618,7 @@ static void win_draw_text(void *handle, int x, int y, int fonttype, else xy.y -= tm.tmAscent; } -#ifndef _WIN32_WCE - if (GetTextExtentPoint32(fe->hdc, text, strlen(text), &size)) -#else - if (GetTextExtentPoint32(fe->hdc, wText, wcslen(wText), &size)) -#endif + if (GetTextExtentPoint32W(fe->hdc, wText, wcslen(wText), &size)) { if (align & ALIGN_HCENTRE) xy.x -= size.cx / 2; @@ -626,11 +627,7 @@ static void win_draw_text(void *handle, int x, int y, int fonttype, } SetBkMode(fe->hdc, TRANSPARENT); win_text_colour(fe, colour); -#ifndef _WIN32_WCE - TextOut(fe->hdc, xy.x, xy.y, text, strlen(text)); -#else - ExtTextOut(fe->hdc, xy.x, xy.y, 0, NULL, wText, wcslen(wText), NULL); -#endif + ExtTextOutW(fe->hdc, xy.x, xy.y, 0, NULL, wText, wcslen(wText), NULL); SelectObject(fe->hdc, oldfont); } } @@ -956,6 +953,15 @@ static void win_end_doc(void *handle) } } +char *win_text_fallback(void *handle, const char *const *strings, int nstrings) +{ + /* + * We assume Windows can cope with any UTF-8 likely to be + * emitted by a puzzle. + */ + return dupstr(strings[0]); +} + const struct drawing_api win_drawing = { win_draw_text, win_draw_rect, @@ -980,6 +986,7 @@ const struct drawing_api win_drawing = { win_end_doc, win_line_width, win_line_dotted, + win_text_fallback, }; void print(frontend *fe)