Improve font selection for Win GUI plot window

Font Names from
https://docs.microsoft.com/en-us/typography/fonts/windows_10_font_list
without option or with Bold or Italic are supported, e.g.
setcs wfont="Cambria Bold Italic".
This commit is contained in:
Holger Vogt 2021-04-24 21:08:14 +02:00
parent 80e5f67466
commit 109e33f127
1 changed files with 19 additions and 5 deletions

View File

@ -15,6 +15,7 @@
#include "ngspice/ftedev.h" #include "ngspice/ftedev.h"
#include "ngspice/ftedbgra.h" #include "ngspice/ftedbgra.h"
#include "ngspice/fteext.h" #include "ngspice/fteext.h"
#include "ngspice/stringskip.h"
#include "../plotting/graf.h" #include "../plotting/graf.h"
#include "../plotting/graphdb.h" #include "../plotting/graphdb.h"
#include "windisp.h" #include "windisp.h"
@ -1090,17 +1091,30 @@ int WIN_Text(const char *text, int x, int y, int angle)
lfw.lfPitchAndFamily = 0; lfw.lfPitchAndFamily = 0;
/* set up fonts */ /* set up fonts */
if (!cp_getvar("wfont", CP_STRING, facename, sizeof(facename))) { if (!cp_getvar("wfont", CP_STRING, facename, sizeof(facename) - 1)) {
(void)lstrcpyW(lfw.lfFaceName, DEFW_FONTW); (void)lstrcpyW(lfw.lfFaceName, DEFW_FONTW);
} }
else { else {
/* Read a font name (see https://docs.microsoft.com/en-us/typography/fonts/windows_10_font_list)
Set lfw if Bold or Italic is found, remove both from facename, remove trailing spaces */
wchar_t wface[32]; wchar_t wface[32];
char* tmpstr = strstr(facename, "Bold");
if (tmpstr) {
lfw.lfWeight = 700;
memcpy(tmpstr, " ", 4);
}
char* tmpstr2 = strstr(facename, "Italic");
if (tmpstr2) {
lfw.lfItalic = TRUE;
memcpy(tmpstr2, " ", 6);
}
/* remove trailing spaces */
if (tmpstr || tmpstr2) {
char* const f_end = skip_back_ws(facename + strlen(facename), facename);
*f_end = '\0';
}
swprintf(wface, 32, L"%S", facename); swprintf(wface, 32, L"%S", facename);
(void)lstrcpyW(lfw.lfFaceName, wface); (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)) { if (!cp_getvar("wfont_size", CP_NUM, &(lfw.lfHeight), 0)) {
lfw.lfHeight = 18; lfw.lfHeight = 18;