Skip to content

Commit

Permalink
Fix #3471 v2 (#4989)
Browse files Browse the repository at this point in the history
Add factor to fonts for scaling to higher size
  • Loading branch information
CodingJellyfish authored Jan 7, 2024
1 parent 3928a49 commit 2e89eee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/font/digit_face.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DigitFace : public FontWithFace
// ------------------------------------------------------------------------
virtual unsigned int getGlyphPageSize() const OVERRIDE { return 256; }
// ------------------------------------------------------------------------
virtual float getScalingFactorOne() const OVERRIDE { return 0.7f; }
virtual float getScalingFactorOne() const OVERRIDE { return 1.4f; }
// ------------------------------------------------------------------------
virtual unsigned int getScalingFactorTwo() const OVERRIDE { return 40; }

Expand All @@ -47,6 +47,8 @@ class DigitFace : public FontWithFace
virtual void reset() OVERRIDE;
// ------------------------------------------------------------------------
virtual bool disableTextShaping() const OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual float getNativeScalingFactor() const OVERRIDE { return 0.5f; }
}; // DigitFace

#endif
Expand Down
11 changes: 7 additions & 4 deletions src/font/font_with_face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,12 @@ core::dimension2d<u32> FontWithFace::getDimension(const core::stringw& text,
if (GUIEngine::isNoGraphics())
return core::dimension2d<u32>(1, 1);

const float scale = font_settings ? font_settings->getScale() : 1.0f;
const float scale = (font_settings ? font_settings->getScale() : 1.0f)
* getNativeScalingFactor();
if (disableTextShaping())
{
return gui::getGlyphLayoutsDimension(text2GlyphsWithoutShaping(text),
m_font_max_height, 1.0f/*inverse shaping*/, scale);
m_font_max_height * scale, 1.0f/*inverse shaping*/, scale);
}

auto& gls = font_manager->getCachedLayouts(text);
Expand All @@ -525,7 +526,8 @@ int FontWithFace::getCharacterFromPos(const wchar_t* text, int pixel_x,
FontSettings* font_settings) const
{
#ifndef SERVER_ONLY
const float scale = font_settings ? font_settings->getScale() : 1.0f;
const float scale = (font_settings ? font_settings->getScale() : 1.0f)
* getNativeScalingFactor();
float x = 0;
int idx = 0;

Expand Down Expand Up @@ -574,7 +576,8 @@ void FontWithFace::render(const std::vector<gui::GlyphLayout>& gl,
font_settings->useBlackBorder() : false;
const bool colored_border = font_settings ?
font_settings->useColoredBorder() : false;
const float scale = font_settings ? font_settings->getScale() : 1.0f;
const float scale = (font_settings ? font_settings->getScale() : 1.0f)
* getNativeScalingFactor();
const float shadow = font_settings ? font_settings->useShadow() : false;

if (shadow)
Expand Down
4 changes: 4 additions & 0 deletions src/font/font_with_face.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ class FontWithFace : public NoCopy
// ------------------------------------------------------------------------
virtual bool useColorGlyphPage() const { return false; }
// ------------------------------------------------------------------------
/** Defined by sub-class about the native scaling factor, to provide */
/** a texture with higher resolution when the scale is > 1.0f */
virtual float getNativeScalingFactor() const { return 1.0f; }
// ------------------------------------------------------------------------
void setDPI();
}; // FontWithFace

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/stk_text_billboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ STKTextBillboard::STKTextBillboard(const video::SColor& color_top,
// ----------------------------------------------------------------------------
float STKTextBillboard::getDefaultScale(FontWithFace* face)
{
return 1.0f / (float)face->getDPI();
return 1.0f / (float)face->getDPI() / face->getNativeScalingFactor();
} // getDefaultScale

// ----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/guiengine/scalable_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ IGUISpriteBank* ScalableFont::getSpriteBank() const
// ----------------------------------------------------------------------------
s32 ScalableFont::getHeightPerLine() const
{
return m_face->getFontMaxHeight() * m_font_settings->getScale();
return m_face->getFontMaxHeight()
* m_face->getNativeScalingFactor()
* m_font_settings->getScale();
} // getHeightPerLine

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 2e89eee

Please sign in to comment.