mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Added option to define true type fonts size for each xbrz mode
This commit is contained in:
parent
e035ae8b48
commit
8367729235
@ -27,19 +27,25 @@ std::pair<std::unique_ptr<ui8[]>, ui64> CTrueTypeFont::loadData(const JsonNode &
|
||||
return CResourceHandler::get()->load(ResourcePath(filename, EResType::TTF_FONT))->readAll();
|
||||
}
|
||||
|
||||
int CTrueTypeFont::getPointSize(const JsonNode & config) const
|
||||
{
|
||||
int scalingFactor = getScalingFactor();
|
||||
|
||||
if (config.isNumber())
|
||||
return config.Integer() * scalingFactor;
|
||||
else
|
||||
return config[scalingFactor-1].Integer();
|
||||
}
|
||||
|
||||
TTF_Font * CTrueTypeFont::loadFont(const JsonNode &config)
|
||||
{
|
||||
int pointSizeBase = static_cast<int>(config["size"].Float());
|
||||
int scalingFactor = getScalingFactor();
|
||||
int pointSize = pointSizeBase * scalingFactor;
|
||||
|
||||
if(!TTF_WasInit() && TTF_Init()==-1)
|
||||
throw std::runtime_error(std::string("Failed to initialize true type support: ") + TTF_GetError() + "\n");
|
||||
|
||||
return TTF_OpenFontRW(SDL_RWFromConstMem(data.first.get(), (int)data.second), 1, pointSize);
|
||||
return TTF_OpenFontRW(SDL_RWFromConstMem(data.first.get(), data.second), 1, getPointSize(config["size"]));
|
||||
}
|
||||
|
||||
int CTrueTypeFont::getFontStyle(const JsonNode &config)
|
||||
int CTrueTypeFont::getFontStyle(const JsonNode &config) const
|
||||
{
|
||||
const JsonVector & names = config["style"].Vector();
|
||||
int ret = 0;
|
||||
|
@ -30,7 +30,8 @@ class CTrueTypeFont final : public IFont
|
||||
|
||||
std::pair<std::unique_ptr<ui8[]>, ui64> loadData(const JsonNode & config);
|
||||
TTF_Font * loadFont(const JsonNode & config);
|
||||
int getFontStyle(const JsonNode & config);
|
||||
int getPointSize(const JsonNode & config) const;
|
||||
int getFontStyle(const JsonNode & config) const;
|
||||
|
||||
void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const override;
|
||||
public:
|
||||
|
@ -19,7 +19,11 @@
|
||||
// Should be in format:
|
||||
// <replaced bitmap font name, case-sensetive> : <true type font description>
|
||||
// "file" - file to load font from, must be in data/ directory
|
||||
// "size" - point size of font
|
||||
// "size" - point size of font. Can be defined in two forms:
|
||||
// a) single number, e.g. 10. In this case, game will automatically multiply font size by upscaling factor when xBRZ is in use,
|
||||
// so xbrz 2x will use 20px, xbrz 3x will use 30px, etc
|
||||
// b) list of scaling factors for each scaling mode, e.g. [ 10, 16, 22, 26]. In this case game will select point size according to xBRZ scaling factor
|
||||
// so unscaled mode will use 10px, xbrz2 will use 16px, and xbrz3 will use 22
|
||||
// "style" - italic and\or bold, indicates font style
|
||||
// "blend" - if set to true, font will be antialiased
|
||||
"trueType":
|
||||
|
Loading…
Reference in New Issue
Block a user