diff --git a/mkxp.json b/mkxp.json index 5cd3cd09..1df827fd 100644 --- a/mkxp.json +++ b/mkxp.json @@ -129,10 +129,10 @@ // "syncToRefreshrate": false, - // Don't use alpha blending when rendering text - // (default: disabled) + // A list of fonts to render without alpha blending. + // (default: none) // - // "solidFonts": false, + // "solidFonts": ["Arial", "Times New Roman"] // Prefer the use of Metal over OpenGL on macOS. diff --git a/src/config.cpp b/src/config.cpp index ae58a255..74eb3c79 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -141,7 +141,7 @@ void Config::read(int argc, char *argv[]) { {"fixedFramerate", 0}, {"frameSkip", false}, {"syncToRefreshrate", false}, - {"solidFonts", false}, + {"solidFonts", json::array({})}, #if defined(__APPLE__) && defined(__aarch64__) {"preferMetalRenderer", true}, #else @@ -262,7 +262,7 @@ try { exp } catch (...) {} SET_OPT(fixedFramerate, integer); SET_OPT(frameSkip, boolean); SET_OPT(syncToRefreshrate, boolean); - SET_OPT(solidFonts, boolean); + fillStringVec(opts["solidFonts"], solidFonts); #ifdef __APPLE__ SET_OPT(preferMetalRenderer, boolean); #endif @@ -327,6 +327,12 @@ static void setupScreenSize(Config &conf) { conf.defScreenH = (conf.rgssVersion == 1 ? 480 : 416); } +bool Config::fontIsSolid(const char *fontName) const { + for (std::string solidfont : solidFonts) + if (!strcmp(solidfont.c_str(), fontName)) return true; + + return false; +} void Config::readGameINI() { if (!customScript.empty()) { diff --git a/src/config.h b/src/config.h index 1e5faf6d..71ec1cc5 100644 --- a/src/config.h +++ b/src/config.h @@ -53,7 +53,7 @@ struct Config { bool frameSkip; bool syncToRefreshrate; - bool solidFonts; + std::vector solidFonts; bool subImageFix; bool enableBlitting; @@ -148,6 +148,8 @@ struct Config { Config(); + bool fontIsSolid(const char *fontName) const; + void read(int argc, char *argv[]); void readGameINI(); }; diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index 2948f6f7..c71f8a72 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -1546,7 +1546,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align) SDL_Surface *txtSurf; - if (shState->rtData().config.solidFonts) + if (p->font->isSolid()) txtSurf = TTF_RenderUTF8_Solid(font, str, c); else txtSurf = TTF_RenderUTF8_Blended(font, str, c); @@ -1567,7 +1567,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align) SDL_Surface *outline; /* set the next font render to render the outline */ TTF_SetFontOutline(font, OUTLINE_SIZE); - if (shState->rtData().config.solidFonts) + if (p->font->isSolid()) outline = TTF_RenderUTF8_Solid(font, str, co); else outline = TTF_RenderUTF8_Blended(font, str, co); diff --git a/src/display/font.cpp b/src/display/font.cpp index b515984e..9b8007d5 100644 --- a/src/display/font.cpp +++ b/src/display/font.cpp @@ -291,6 +291,8 @@ struct FontPrivate * (when it is queried by a Bitmap), prior it is * set to null */ TTF_Font *sdlFont; + + bool isSolid; FontPrivate(int size) : size(size), @@ -302,7 +304,8 @@ struct FontPrivate outColor(&outColorTmp), colorTmp(*defaultColor), outColorTmp(*defaultOutColor), - sdlFont(0) + sdlFont(0), + isSolid(false) {} FontPrivate(const FontPrivate &other) @@ -316,7 +319,8 @@ struct FontPrivate outColor(&outColorTmp), colorTmp(*other.color), outColorTmp(*other.outColor), - sdlFont(other.sdlFont) + sdlFont(other.sdlFont), + isSolid(false) {} void operator=(const FontPrivate &o) @@ -331,6 +335,7 @@ struct FontPrivate *outColor = *o.outColor; sdlFont = 0; + isSolid = o.isSolid; } }; @@ -348,6 +353,10 @@ Color FontPrivate::defaultOutColorTmp(0, 0, 0, 128); std::vector FontPrivate::initialDefaultNames; +bool Font::isSolid() const { + return p->isSolid; +} + bool Font::doesExist(const char *name) { if (!name) @@ -387,6 +396,7 @@ const Font &Font::operator=(const Font &o) void Font::setName(const std::vector &names) { pickExistingFontName(names, p->name, shState->fontState()); + p->isSolid = strcmp(p->name.c_str(), "") && shState->config().fontIsSolid(p->name.c_str()); p->sdlFont = 0; } diff --git a/src/display/font.h b/src/display/font.h index 63970f18..e3580d8c 100644 --- a/src/display/font.h +++ b/src/display/font.h @@ -103,6 +103,7 @@ public: const SharedFontState &sfs); static const std::vector &getInitialDefaultNames(); + bool isSolid() const; /* Assigns heap allocated objects to object properties; * using this in pure C++ will cause memory leaks