diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-02 12:28:25 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-01-02 12:28:25 +0100 |
commit | 8793424b343155269011c05cba37b8a094edc120 (patch) | |
tree | e12b182660ec2e62b6eaf5457fabca655d7a84e4 /vncviewer/fltk | |
parent | eff7fdd81bed6761a29f85b7dfa39f07d3015ea4 (diff) | |
download | tigervnc-8793424b343155269011c05cba37b8a094edc120.tar.gz tigervnc-8793424b343155269011c05cba37b8a094edc120.zip |
Keep font name in permanent memory
Fl::set_font() doesn't keep its own copy, so we need to make sure the
font string doesn't get freed or overwritten at a later point.
Diffstat (limited to 'vncviewer/fltk')
-rw-r--r-- | vncviewer/fltk/theme.cxx | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/vncviewer/fltk/theme.cxx b/vncviewer/fltk/theme.cxx index cb786e4c..d6748091 100644 --- a/vncviewer/fltk/theme.cxx +++ b/vncviewer/fltk/theme.cxx @@ -41,6 +41,10 @@ void init_theme() { +#if defined(WIN32) || defined(__APPLE__) + static char font_name[256]; +#endif + // Basic text size (10pt @ 96 dpi => 13px) FL_NORMAL_SIZE = 13; @@ -62,21 +66,22 @@ void init_theme() NONCLIENTMETRICS metrics; metrics.cbSize = sizeof(metrics); if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, - sizeof(metrics), &metrics, 0)) - Fl::set_font(FL_HELVETICA, metrics.lfMessageFont.lfFaceName); + sizeof(metrics), &metrics, 0)) { + strcpy(font_name, metrics.lfMessageFont.lfFaceName); + Fl::set_font(FL_HELVETICA, font_name); + } #elif defined(__APPLE__) CTFontRef font; CFStringRef name; - char cname[256]; font = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 0.0, NULL); if (font != NULL) { name = CTFontCopyFullName(font); if (name != NULL) { - CFStringGetCString(name, cname, sizeof(cname), + CFStringGetCString(name, font_name, sizeof(font_name), kCFStringEncodingUTF8); - Fl::set_font(FL_HELVETICA, cname); + Fl::set_font(FL_HELVETICA, strdup(font_name)); CFRelease(name); } |