diff options
author | rubidium42 <rubidium@openttd.org> | 2021-04-28 17:10:15 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-13 23:13:17 +0200 |
commit | 77330d09fd8307261e94fe0eb0260f5ca5cc3898 (patch) | |
tree | 0a2d3efe86b4f0047b558bb668dc9ed17ac63d3f /src/os | |
parent | 65cbde4b30f8fdf6d4cf1196f6a596a5550c9aee (diff) | |
download | openttd-77330d09fd8307261e94fe0eb0260f5ca5cc3898.tar.xz |
Codechange: move font settings to std::string
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/macosx/font_osx.cpp | 12 | ||||
-rw-r--r-- | src/os/windows/font_win32.cpp | 21 |
2 files changed, 17 insertions, 16 deletions
diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index f5ceed850..295fcf257 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -359,7 +359,7 @@ void LoadCoreTextFont(FontSize fs) case FS_MONO: settings = &_freetype.mono; break; } - if (StrEmpty(settings->font)) return; + if (settings->font.empty()) return; CFAutoRelease<CTFontDescriptorRef> font_ref; @@ -375,10 +375,10 @@ void LoadCoreTextFont(FontSize fs) /* See if this is an absolute path. */ if (FileExists(settings->font)) { - path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font, kCFStringEncodingUTF8)); + path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8)); } else { /* Scan the search-paths to see if it can be found. */ - std::string full_font = FioFindFullPath(BASE_DIR, settings->font); + std::string full_font = FioFindFullPath(BASE_DIR, settings->font.c_str()); if (!full_font.empty()) { path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8)); } @@ -393,13 +393,13 @@ void LoadCoreTextFont(FontSize fs) font_ref.reset((CTFontDescriptorRef)CFArrayGetValueAtIndex(descs.get(), 0)); CFRetain(font_ref.get()); } else { - ShowInfoF("Unable to load file '%s' for %s font, using default OS font selection instead", settings->font, SIZE_TO_NAME[fs]); + ShowInfoF("Unable to load file '%s' for %s font, using default OS font selection instead", settings->font.c_str(), SIZE_TO_NAME[fs]); } } } if (!font_ref) { - CFAutoRelease<CFStringRef> name(CFStringCreateWithCString(kCFAllocatorDefault, settings->font, kCFStringEncodingUTF8)); + CFAutoRelease<CFStringRef> name(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8)); /* Simply creating the font using CTFontCreateWithNameAndSize will *always* return * something, no matter the name. As such, we can't use it to check for existence. @@ -417,7 +417,7 @@ void LoadCoreTextFont(FontSize fs) } if (!font_ref) { - ShowInfoF("Unable to use '%s' for %s font, using sprite font instead", settings->font, SIZE_TO_NAME[fs]); + ShowInfoF("Unable to use '%s' for %s font, using sprite font instead", settings->font.c_str(), SIZE_TO_NAME[fs]); return; } diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index 55d4193e8..6c4e67deb 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -588,8 +588,9 @@ void LoadWin32Font(FontSize fs) default: NOT_REACHED(); } - if (StrEmpty(settings->font)) return; + if (settings->font.empty()) return; + const char *font_name = settings->font.c_str(); LOGFONT logfont; MemSetT(&logfont, 0); logfont.lfPitchAndFamily = fs == FS_MONO ? FIXED_PITCH : VARIABLE_PITCH; @@ -599,19 +600,19 @@ void LoadWin32Font(FontSize fs) if (settings->os_handle != nullptr) { logfont = *(const LOGFONT *)settings->os_handle; - } else if (strchr(settings->font, '.') != nullptr) { + } else if (strchr(font_name, '.') != nullptr) { /* Might be a font file name, try load it. */ wchar_t fontPath[MAX_PATH] = {}; /* See if this is an absolute path. */ if (FileExists(settings->font)) { - convert_to_fs(settings->font, fontPath, lengthof(fontPath)); + convert_to_fs(font_name, fontPath, lengthof(fontPath)); } else { /* Scan the search-paths to see if it can be found. */ - std::string full_font = FioFindFullPath(BASE_DIR, settings->font); + std::string full_font = FioFindFullPath(BASE_DIR, font_name); if (!full_font.empty()) { - convert_to_fs(full_font.c_str(), fontPath, lengthof(fontPath)); + convert_to_fs(font_name, fontPath, lengthof(fontPath)); } } @@ -639,22 +640,22 @@ void LoadWin32Font(FontSize fs) _wsplitpath(fontPath, nullptr, nullptr, fname, nullptr); wcsncpy_s(logfont.lfFaceName, lengthof(logfont.lfFaceName), fname, _TRUNCATE); - logfont.lfWeight = strcasestr(settings->font, " bold") != nullptr || strcasestr(settings->font, "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts. + logfont.lfWeight = strcasestr(font_name, " bold") != nullptr || strcasestr(font_name, "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts. } } else { - ShowInfoF("Unable to load file '%s' for %s font, using default windows font selection instead", settings->font, SIZE_TO_NAME[fs]); + ShowInfoF("Unable to load file '%s' for %s font, using default windows font selection instead", font_name, SIZE_TO_NAME[fs]); } } } if (logfont.lfFaceName[0] == 0) { - logfont.lfWeight = strcasestr(settings->font, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts. - convert_to_fs(settings->font, logfont.lfFaceName, lengthof(logfont.lfFaceName)); + logfont.lfWeight = strcasestr(font_name, " bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts. + convert_to_fs(font_name, logfont.lfFaceName, lengthof(logfont.lfFaceName)); } HFONT font = CreateFontIndirect(&logfont); if (font == nullptr) { - ShowInfoF("Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", settings->font, SIZE_TO_NAME[fs], GetLastError()); + ShowInfoF("Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", font_name, SIZE_TO_NAME[fs], GetLastError()); return; } DeleteObject(font); |