diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 857573fa4..3a89be860 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -93,7 +93,7 @@ class EE_API FontTrueType : public Font { void cleanup(); Glyph loadGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness, Page& page ) const; + Float outlineThickness, Page& page, const Float& forceSize = 0.f ) const; Rect findGlyphRect( Page& page, unsigned int width, unsigned int height ) const; diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 9440c1216..5e739032a 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -324,7 +324,7 @@ Uint64 FontTrueType::getCharIndexKey( Uint32 codePoint, bool bold, Float outline Uint64 key = combine( outlineThickness, bold, FT_Get_Char_Index( static_cast( mFace ), codePoint ) ); - if ( key == 0 && !mIsColorEmojiFont && Font::isEmojiCodePoint( codePoint ) && !isMonospace() ) { + if ( key == 0 && !mIsColorEmojiFont && Font::isEmojiCodePoint( codePoint ) ) { if ( FontManager::instance()->getColorEmojiFont() != nullptr && FontManager::instance()->getColorEmojiFont()->getType() == FontType::TTF ) { FontTrueType* fontEmoji = @@ -545,16 +545,25 @@ void FontTrueType::cleanup() { } Glyph FontTrueType::loadGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness, Page& page ) const { + Float outlineThickness, Page& page, const Float& forceSize ) const { // The glyph to return Glyph glyph; - if ( !mIsColorEmojiFont && Font::isEmojiCodePoint( codePoint ) && !isMonospace() ) { + if ( !mIsColorEmojiFont && Font::isEmojiCodePoint( codePoint ) ) { if ( FontManager::instance()->getColorEmojiFont() != nullptr && FontManager::instance()->getColorEmojiFont()->getType() == FontType::TTF ) { + + Float forcedSize = 0.f; + + if ( isMonospace() ) { + Glyph monospaceGlyph = getGlyph( ' ', characterSize, bold, outlineThickness ); + forcedSize = monospaceGlyph.advance; + } + FontTrueType* fontEmoji = static_cast( FontManager::instance()->getColorEmojiFont() ); - return fontEmoji->loadGlyph( codePoint, characterSize, bold, outlineThickness, page ); + return fontEmoji->loadGlyph( codePoint, characterSize, bold, outlineThickness, page, + forcedSize ); } } @@ -630,6 +639,10 @@ Glyph FontTrueType::loadGlyph( Uint32 codePoint, unsigned int characterSize, boo // Compute the glyph's advance offset glyph.advance = static_cast( face->glyph->metrics.horiAdvance ) / static_cast( 1 << 6 ); + + if ( forceSize > 0.f ) + glyph.advance = forceSize; + if ( bold && !mBoldAdvanceSameAsRegular ) glyph.advance += static_cast( weight ) / static_cast( 1 << 6 ); @@ -641,7 +654,9 @@ Glyph FontTrueType::loadGlyph( Uint32 codePoint, unsigned int characterSize, boo // pollute them with pixels from neighbors const int padding = 2; - Float scale = mIsColorEmojiFont ? (Float)characterSize / (Float)height : 1.f; + Float scale = mIsColorEmojiFont + ? (Float)( forceSize > 0.f ? forceSize : characterSize ) / (Float)height + : 1.f; int destWidth = width; int destHeight = height; @@ -649,7 +664,8 @@ Glyph FontTrueType::loadGlyph( Uint32 codePoint, unsigned int characterSize, boo if ( mIsColorEmojiFont ) { destWidth *= scale; destHeight *= scale; - glyph.advance *= scale; + if ( forceSize <= 0.f ) + glyph.advance *= scale; } width += 2 * padding;