SharedFontState: Add 'defaultFontFamily' property

Some scripts may end up ignoring RGSS-side defaults and just
requesting invalid / empty family names; in this case
the internal default family will be substituted.
This commit is contained in:
Ancurio 2021-09-28 10:37:09 +02:00
parent 3d6b7d3b75
commit 5e3907c7f8
3 changed files with 32 additions and 0 deletions

View file

@ -27,6 +27,7 @@
#include "boost-hash.h"
#include "util.h"
#include "config.h"
#include "debugwriter.h"
#include <string>
#include <utility>
@ -77,6 +78,10 @@ struct SharedFontStatePrivate
/* Pool of already opened fonts; once opened, they are reused
* and never closed until the termination of the program */
BoostHash<FontKey, TTF_Font*> pool;
/* Internal default font family that is used anytime an
* empty/invalid family is requested */
std::string defaultFamily;
};
SharedFontState::SharedFontState(const Config &conf)
@ -132,6 +137,11 @@ void SharedFontState::initFontSetCB(SDL_RWops &ops,
_TTF_Font *SharedFontState::getFont(std::string family,
int size)
{
if (family.empty()) {
Debug() << "Invalid font family" << family << "requested, substituting internal default";
family = p->defaultFamily;
}
/* Check for substitutions */
if (p->subs.contains(family))
family = p->subs[family];
@ -202,6 +212,11 @@ _TTF_Font *SharedFontState::openBundled(int size)
return TTF_OpenFontRW(ops, 1, size);
}
void SharedFontState::setDefaultFontFamily(const std::string &family)
{
p->defaultFamily = family;
}
void pickExistingFontName(const std::vector<std::string> &names,
std::string &out,
const SharedFontState &sfs)

View file

@ -54,6 +54,8 @@ public:
static _TTF_Font *openBundled(int size);
void setDefaultFontFamily(const std::string &family);
private:
SharedFontStatePrivate *p;
};