mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
TTF fonts will now be rendered correctly in upscaling mode
Note that TTF rendering bypasses xBRZ - TTF fonts are rendered at larger point size
This commit is contained in:
@@ -29,7 +29,9 @@ std::pair<std::unique_ptr<ui8[]>, ui64> CTrueTypeFont::loadData(const JsonNode &
|
||||
|
||||
TTF_Font * CTrueTypeFont::loadFont(const JsonNode &config)
|
||||
{
|
||||
int pointSize = static_cast<int>(config["size"].Float());
|
||||
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");
|
||||
@@ -74,7 +76,7 @@ size_t CTrueTypeFont::getLineHeight() const
|
||||
if (fallbackFont)
|
||||
return fallbackFont->getLineHeight();
|
||||
|
||||
return TTF_FontHeight(font.get());
|
||||
return TTF_FontHeight(font.get()) / getScalingFactor();
|
||||
}
|
||||
|
||||
size_t CTrueTypeFont::getGlyphWidth(const char *data) const
|
||||
@@ -83,19 +85,16 @@ size_t CTrueTypeFont::getGlyphWidth(const char *data) const
|
||||
return fallbackFont->getGlyphWidth(data);
|
||||
|
||||
return getStringWidth(std::string(data, TextOperations::getUnicodeCharacterSize(*data)));
|
||||
int advance;
|
||||
TTF_GlyphMetrics(font.get(), *data, nullptr, nullptr, nullptr, nullptr, &advance);
|
||||
return advance;
|
||||
}
|
||||
|
||||
size_t CTrueTypeFont::getStringWidth(const std::string & data) const
|
||||
{
|
||||
if (fallbackFont && fallbackFont->canRepresentString(data))
|
||||
return fallbackFont->getStringWidth(data);
|
||||
return fallbackFont->getStringWidth(data) / getScalingFactor();
|
||||
|
||||
int width;
|
||||
TTF_SizeUTF8(font.get(), data.c_str(), &width, nullptr);
|
||||
return width;
|
||||
return width / getScalingFactor();
|
||||
}
|
||||
|
||||
void CTrueTypeFont::renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
|
||||
@@ -107,7 +106,7 @@ void CTrueTypeFont::renderText(SDL_Surface * surface, const std::string & data,
|
||||
}
|
||||
|
||||
if (dropShadow && color.r != 0 && color.g != 0 && color.b != 0) // not black - add shadow
|
||||
renderText(surface, data, Colors::BLACK, pos + Point(1,1));
|
||||
renderText(surface, data, Colors::BLACK, pos + Point(1,1) * getScalingFactor());
|
||||
|
||||
if (!data.empty())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user