Add factor to fonts for scaling to higher size
This commit is contained in:
CodingJellyfish 2024-01-08 01:13:13 +08:00 committed by GitHub
parent 3928a49d5e
commit 2e89eeed1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 7 deletions

View File

@ -33,7 +33,7 @@ private:
// ------------------------------------------------------------------------
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; }
@ -47,6 +47,8 @@ public:
virtual void reset() OVERRIDE;
// ------------------------------------------------------------------------
virtual bool disableTextShaping() const OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual float getNativeScalingFactor() const OVERRIDE { return 0.5f; }
}; // DigitFace
#endif

View File

@ -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);
@ -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;
@ -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)

View File

@ -324,6 +324,10 @@ public:
// ------------------------------------------------------------------------
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

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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
// ----------------------------------------------------------------------------