From 2d9c06231dd956903adb3024754c0ab77895cf19 Mon Sep 17 00:00:00 2001 From: Wayward Heart <91356680+WaywardHeart@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:39:38 -0500 Subject: [PATCH] Make font families case insensitive --- src/config.cpp | 6 ++++++ src/display/font.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index 79fc4268..6ef6543c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -266,6 +266,9 @@ try { exp } catch (...) {} SET_OPT(frameSkip, boolean); SET_OPT(syncToRefreshrate, boolean); fillStringVec(opts["solidFonts"], solidFonts); + for (std::string & solidFont : solidFonts) + std::transform(solidFont.begin(), solidFont.end(), solidFont.begin(), + [](unsigned char c) { return std::tolower(c); }); #ifdef __APPLE__ SET_OPT(preferMetalRenderer, boolean); #endif @@ -288,6 +291,9 @@ try { exp } catch (...) {} fillStringVec(opts["preloadScript"], preloadScripts); fillStringVec(opts["RTP"], rtps); fillStringVec(opts["fontSub"], fontSubs); + for (std::string & fontSub : fontSubs) + std::transform(fontSub.begin(), fontSub.end(), fontSub.begin(), + [](unsigned char c) { return std::tolower(c); }); fillStringVec(opts["rubyLoadpath"], rubyLoadpaths); auto &bnames = opts["bindingNames"].as_object(); diff --git a/src/display/font.cpp b/src/display/font.cpp index b42ef32f..713f3732 100644 --- a/src/display/font.cpp +++ b/src/display/font.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #ifdef MKXPZ_BUILD_XCODE #include "filesystem/filesystem.h" @@ -147,6 +149,9 @@ void SharedFontState::initFontSetCB(SDL_RWops &ops, std::string family = TTF_FontFaceFamilyName(font); std::string style = TTF_FontFaceStyleName(font); + std::transform(family.begin(), family.end(), family.begin(), + [](unsigned char c){ return std::tolower(c); }); + TTF_CloseFont(font); FontSet &set = p->sets[family]; @@ -160,6 +165,9 @@ void SharedFontState::initFontSetCB(SDL_RWops &ops, _TTF_Font *SharedFontState::getFont(std::string family, int size) { + std::transform(family.begin(), family.end(), family.begin(), + [](unsigned char c){ return std::tolower(c); }); + if (family.empty()) family = p->defaultFamily; @@ -217,6 +225,9 @@ _TTF_Font *SharedFontState::getFont(std::string family, bool SharedFontState::fontPresent(std::string family) const { + std::transform(family.begin(), family.end(), family.begin(), + [](unsigned char c){ return std::tolower(c); }); + /* Check for substitutions */ if (p->subs.contains(family)) family = p->subs[family];