Merge pull request #18 from WaywardHeart/font-families

Make font families case insensitive
This commit is contained in:
Splendide Imaginarius 2023-10-29 11:05:50 +00:00 committed by GitHub
commit 77dedd06db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -276,6 +276,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
@ -298,6 +301,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();

View file

@ -32,6 +32,8 @@
#include <string>
#include <utility>
#include <algorithm>
#include <cctype>
#ifdef MKXPZ_BUILD_XCODE
#include "filesystem/filesystem.h"
@ -149,6 +151,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];
@ -162,6 +167,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;
@ -219,6 +227,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];