From c9a19c75695c88d6a0250111e774cccbe3f873c1 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 24 Apr 2021 17:29:28 +0200 Subject: [PATCH] Fix for bug 547 Reduce length of wchar_t strings to the minimum required for conversion Check if Bold or Italic is given in the font name, set corresponding variable --- src/frontend/wdisp/windisp.c | 11 ++++++++--- src/frontend/wdisp/winprint.c | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/frontend/wdisp/windisp.c b/src/frontend/wdisp/windisp.c index 5d13a3e3d..384da787c 100644 --- a/src/frontend/wdisp/windisp.c +++ b/src/frontend/wdisp/windisp.c @@ -1079,10 +1079,10 @@ int WIN_Text(const char *text, int x, int y, int angle) lfw.lfEscapement = angle * 10; lfw.lfOrientation = angle * 10; lfw.lfWeight = 500; - lfw.lfItalic = 0; + lfw.lfItalic = FALSE; lfw.lfUnderline = 0; lfw.lfStrikeOut = 0; - lfw.lfCharSet = 0; + lfw.lfCharSet = DEFAULT_CHARSET; lfw.lfOutPrecision = 0; lfw.lfClipPrecision = 0; lfw.lfQuality = 0; @@ -1096,6 +1096,10 @@ int WIN_Text(const char *text, int x, int y, int angle) wchar_t wface[32]; swprintf(wface, 32, L"%S", facename); (void)lstrcpyW(lfw.lfFaceName, wface); + if (strstr(facename, "Bold")) + lfw.lfWeight = 700; + if (strstr(facename, "Italic")) + lfw.lfItalic = TRUE; } if (!cp_getvar("wfont_size", CP_NUM, &(lfw.lfHeight), 0)) { lfw.lfHeight = 18; @@ -1113,8 +1117,9 @@ int WIN_Text(const char *text, int x, int y, int angle) #ifdef EXT_ASC TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text)); #else - const int n_byte_wide = 2 * (int) strlen(text) + 1; + const int n_byte_wide = (int) strlen(text); wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + /* wtext needs not to be NULL-terminated */ MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide); TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, wtext, n_byte_wide); diff --git a/src/frontend/wdisp/winprint.c b/src/frontend/wdisp/winprint.c index 8bf4e40ec..db5bfe577 100644 --- a/src/frontend/wdisp/winprint.c +++ b/src/frontend/wdisp/winprint.c @@ -305,7 +305,8 @@ int WPRINT_NewViewport(GRAPH * graph) TextOut(PrinterDC, PrinterWidth - graph->fontwidth, -1*yoffset, graph->plotname, (int)strlen(graph->plotname)); #else - const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1; + /* wtext needs not to be NULL-terminated */ + const int n_byte_wide = (int) strlen(graph->plotname); wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, n_byte_wide); @@ -458,7 +459,8 @@ int WPRINT_Text(char * text, int x, int y, int degrees) #ifdef EXT_ASC TextOut(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, text, (int)strlen(text)); #else - const int n_byte_wide = 2 * (int) strlen(text) + 1; + /* wtext needs not to be NULL-terminated */ + const int n_byte_wide = (int) strlen(text); wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide); TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight,