From 4de6afcbd1066d4cb95fdf57124809d00cb1d1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 7 Aug 2023 01:02:16 -0300 Subject: [PATCH] Font Family support WIP. --- include/eepp/graphics/font.hpp | 22 +- include/eepp/graphics/fontbmfont.hpp | 9 +- include/eepp/graphics/fontsprite.hpp | 9 +- include/eepp/graphics/fonttruetype.hpp | 49 +++- include/eepp/system/inifile.hpp | 2 +- projects/macos/ee.files | 78 ++++++ projects/macos/ee.includes | 3 +- src/eepp/graphics/fontbmfont.cpp | 14 +- src/eepp/graphics/fontsprite.cpp | 10 +- src/eepp/graphics/fonttruetype.cpp | 225 ++++++++++++++---- src/eepp/graphics/text.cpp | 41 ++-- src/eepp/system/inifile.cpp | 2 +- src/eepp/ui/uicodeeditor.cpp | 2 +- src/eepp/ui/uiconsole.cpp | 7 +- .../src/eterm/terminal/terminaldisplay.cpp | 10 +- src/tools/ecode/uitreeviewglobalsearch.cpp | 5 +- 16 files changed, 382 insertions(+), 106 deletions(-) diff --git a/include/eepp/graphics/font.hpp b/include/eepp/graphics/font.hpp index 5333fb718..802efb5c9 100644 --- a/include/eepp/graphics/font.hpp +++ b/include/eepp/graphics/font.hpp @@ -87,16 +87,18 @@ class EE_API Font { virtual const Info& getInfo() const = 0; virtual const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness = 0, Float maxWidth = 0 ) const = 0; + bool italic, Float outlineThickness = 0, + Float maxWidth = 0 ) const = 0; /** @return The glyph drawable that represents the glyph in a texture. The glyph drawable * allocation is managed by the font. */ virtual GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold = false, Float outlineThickness = 0, + bool bold = false, bool italic = false, + Float outlineThickness = 0, const Float& forzeSize = 0 ) const = 0; - virtual Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, - bool bold ) const = 0; + virtual Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold, + bool italic ) const = 0; virtual Float getLineSpacing( unsigned int characterSize ) const = 0; @@ -106,6 +108,18 @@ class EE_API Font { virtual Texture* getTexture( unsigned int characterSize ) const = 0; + virtual bool isBold() const { return false; } + + virtual bool isItalic() const { return false; } + + virtual bool isBoldItalic() const { return false; } + + virtual bool hasBold() { return false; } + + virtual bool hasItalic() { return false; } + + virtual bool hasBoldItalic() { return false; } + virtual bool loaded() const = 0; /** Push a new on resource change callback. diff --git a/include/eepp/graphics/fontbmfont.hpp b/include/eepp/graphics/fontbmfont.hpp index 983783904..be8575255 100644 --- a/include/eepp/graphics/fontbmfont.hpp +++ b/include/eepp/graphics/fontbmfont.hpp @@ -36,14 +36,15 @@ class EE_API FontBMFont : public Font { const Font::Info& getInfo() const; - const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, + const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic, Float outlineThickness = 0, Float maxWidth = 0 ) const; GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold = false, Float outlineThickness = 0, - const Float& maxWidth = 0 ) const; + bool bold = false, bool italic = false, + Float outlineThickness = 0, const Float& maxWidth = 0 ) const; - Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold ) const; + Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold, + bool italic ) const; Float getLineSpacing( unsigned int characterSize ) const; diff --git a/include/eepp/graphics/fontsprite.hpp b/include/eepp/graphics/fontsprite.hpp index b11a202fb..3fe60a980 100644 --- a/include/eepp/graphics/fontsprite.hpp +++ b/include/eepp/graphics/fontsprite.hpp @@ -40,14 +40,15 @@ class EE_API FontSprite : public Font { const Font::Info& getInfo() const; - const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, + const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic, Float outlineThickness = 0, Float maxWidth = 0 ) const; GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold = false, Float outlineThickness = 0, - const Float& maxWidth = 0 ) const; + bool bold = false, bool italic = false, + Float outlineThickness = 0, const Float& maxWidth = 0 ) const; - Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold ) const; + Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold, + bool italic ) const; Float getLineSpacing( unsigned int characterSize ) const; diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index dd55ed51d..2317f5bc0 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -32,17 +32,18 @@ class EE_API FontTrueType : public Font { const Font::Info& getInfo() const; - const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, + const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic, Float outlineThickness = 0, Float maxWidth = 0 ) const; - const Glyph& getGlyphByIndex( Uint32 index, unsigned int characterSize, bool bold, + const Glyph& getGlyphByIndex( Uint32 index, unsigned int characterSize, bool bold, bool italic, Float outlineThickness = 0 ) const; GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold = false, Float outlineThickness = 0, - const Float& maxWidth = 0 ) const; + bool bold = false, bool italic = false, + Float outlineThickness = 0, const Float& maxWidth = 0 ) const; - Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold ) const; + Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold, + bool italic ) const; Float getLineSpacing( unsigned int characterSize ) const; @@ -102,6 +103,26 @@ class EE_API FontTrueType : public Font { void setAntialiasing( FontAntialiasing antialiasing ); + bool isRegular() const { return !mIsBold && !mIsItalic; } + + virtual bool isBold() const { return mIsBold && !mIsItalic; } + + virtual bool isItalic() const { return mIsItalic && !mIsBold; } + + virtual bool isBoldItalic() const { return mIsBold && mIsItalic; } + + virtual bool hasBold() { return mIsBold || mFontBold != nullptr; } + + virtual bool hasItalic() { return mIsItalic || mFontItalic != nullptr; } + + virtual bool hasBoldItalic() { return isBoldItalic() || mFontBoldItalic; } + + void setBoldFont( FontTrueType* fontBold ); + + void setItalicFont( FontTrueType* fontItalic ); + + void setBoldItalicFont( FontTrueType* fontBoldItalic ); + protected: explicit FontTrueType( const std::string& FontName ); @@ -134,15 +155,15 @@ class EE_API FontTrueType : public Font { void cleanup(); - const Glyph& getGlyphByIndex( Uint32 index, unsigned int characterSize, bool bold, + const Glyph& getGlyphByIndex( Uint32 index, unsigned int characterSize, bool bold, bool italic, Float outlineThickness, Page& page, const Float& maxWidth ) const; - const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, + const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic, Float outlineThickness, Page& page, const Float& maxWidth ) const; Uint32 getGlyphIndex( const Uint32& codePoint ) const; - Glyph loadGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, + Glyph loadGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, bool italic, Float outlineThickness, Page& page, const Float& maxWidth = 0.f ) const; Rect findGlyphRect( Page& page, unsigned int width, unsigned int height ) const; @@ -172,17 +193,29 @@ class EE_API FontTrueType : public Font { bool mIsColorEmojiFont{ false }; bool mIsEmojiFont{ false }; mutable bool mIsMonospace{ false }; + mutable bool mIsMonospaceComplete{ false }; + mutable bool mUsingFallback{ false }; bool mEnableEmojiFallback{ true }; bool mEnableFallbackFont{ true }; bool mEnableDynamicMonospace{ false }; + bool mIsBold{ false }; + bool mIsItalic{ false }; mutable std::unordered_map mClosestCharacterSize; mutable std::unordered_map mCodePointIndexCache; FontHinting mHinting{ FontHinting::Full }; FontAntialiasing mAntialiasing{ FontAntialiasing::Grayscale }; + FontTrueType* mFontBold{ nullptr }; + FontTrueType* mFontItalic{ nullptr }; + FontTrueType* mFontBoldItalic{ nullptr }; + Uint32 mFontBoldCb{ 0 }; + Uint32 mFontItalicCb{ 0 }; + Uint32 mFontBoldItalicCb{ 0 }; void updateFontInternalId(); bool setFontFace( void* face ); + + void updateMonospaceState(); }; }} // namespace EE::Graphics diff --git a/include/eepp/system/inifile.hpp b/include/eepp/system/inifile.hpp index fb62738c3..d6dd78779 100644 --- a/include/eepp/system/inifile.hpp +++ b/include/eepp/system/inifile.hpp @@ -135,7 +135,7 @@ class EE_API IniFile { double getValueF( std::string const keyname, std::string const valuename, double const defValue = 0.0 ) const; - /** This is a variable length formatted GetValue routine. All these voids + /** This is a variable length formatted getValue routine. All these voids ** are required because there is no vsscanf() like there is a vsprintf(). ** Only a maximum of 8 variable can be read. */ unsigned getValueV( std::string const keyname, std::string const valuename, char* format, diff --git a/projects/macos/ee.files b/projects/macos/ee.files index 18a331b57..9283ff6c2 100644 --- a/projects/macos/ee.files +++ b/projects/macos/ee.files @@ -618,6 +618,26 @@ ../../src/eepp/graphics/vertexbuffervbo.cpp ../../src/eepp/graphics/view.cpp ../../src/eepp/main/eepp_main.cpp +../../src/eepp/ui/doc/languages/odin.hpp +../../src/eepp/ui/doc/languages/pascal.hpp +../../src/eepp/ui/doc/languages/perl.hpp +../../src/eepp/ui/doc/languages/pico-8.hpp +../../src/eepp/ui/doc/languages/po.hpp +../../src/eepp/ui/doc/languages/postgresql.hpp +../../src/eepp/ui/doc/languages/r.hpp +../../src/eepp/ui/doc/languages/rust.hpp +../../src/eepp/ui/doc/languages/sass.hpp +../../src/eepp/ui/doc/languages/solidity.hpp +../../src/eepp/ui/doc/languages/sql.hpp +../../src/eepp/ui/doc/languages/swift.hpp +../../src/eepp/ui/doc/languages/teal.hpp +../../src/eepp/ui/doc/languages/toml.hpp +../../src/eepp/ui/doc/languages/v.hpp +../../src/eepp/ui/doc/languages/vb.hpp +../../src/eepp/ui/doc/languages/verilog.hpp +../../src/eepp/ui/doc/languages/x86assembly.hpp +../../src/eepp/ui/doc/languages/xml.hpp +../../src/eepp/ui/doc/languages/zig.hpp ../../src/modules/maps/src/eepp/maps/gameobject.cpp ../../src/modules/maps/src/eepp/maps/gameobjectobject.cpp ../../src/modules/maps/src/eepp/maps/gameobjectpolygon.cpp @@ -822,6 +842,64 @@ ../../src/eepp/ui/css/stylesheetvariable.cpp ../../src/eepp/ui/css/timingfunction.cpp ../../src/eepp/ui/css/transitiondefinition.cpp +../../src/eepp/ui/doc/languages/angelscript.cpp +../../src/eepp/ui/doc/languages/angelscript.hpp +../../src/eepp/ui/doc/languages/batchscript.cpp +../../src/eepp/ui/doc/languages/batchscript.hpp +../../src/eepp/ui/doc/languages/crystal.cpp +../../src/eepp/ui/doc/languages/crystal.hpp +../../src/eepp/ui/doc/languages/css.cpp +../../src/eepp/ui/doc/languages/css.hpp +../../src/eepp/ui/doc/languages/d.cpp +../../src/eepp/ui/doc/languages/d.hpp +../../src/eepp/ui/doc/languages/elixir.cpp +../../src/eepp/ui/doc/languages/elixir.hpp +../../src/eepp/ui/doc/languages/elm.cpp +../../src/eepp/ui/doc/languages/elm.hpp +../../src/eepp/ui/doc/languages/fstab.cpp +../../src/eepp/ui/doc/languages/fstab.hpp +../../src/eepp/ui/doc/languages/gdscript.cpp +../../src/eepp/ui/doc/languages/gdscript.hpp +../../src/eepp/ui/doc/languages/glsl.cpp +../../src/eepp/ui/doc/languages/glsl.hpp +../../src/eepp/ui/doc/languages/hare.cpp +../../src/eepp/ui/doc/languages/hare.hpp +../../src/eepp/ui/doc/languages/hlsl.cpp +../../src/eepp/ui/doc/languages/hlsl.hpp +../../src/eepp/ui/doc/languages/htaccess.cpp +../../src/eepp/ui/doc/languages/htaccess.hpp +../../src/eepp/ui/doc/languages/html.cpp +../../src/eepp/ui/doc/languages/html.hpp +../../src/eepp/ui/doc/languages/julia.cpp +../../src/eepp/ui/doc/languages/julia.hpp +../../src/eepp/ui/doc/languages/kotlin.cpp +../../src/eepp/ui/doc/languages/kotlin.hpp +../../src/eepp/ui/doc/languages/markdown.cpp +../../src/eepp/ui/doc/languages/markdown.hpp +../../src/eepp/ui/doc/languages/nelua.cpp +../../src/eepp/ui/doc/languages/nelua.hpp +../../src/eepp/ui/doc/languages/objeck.cpp +../../src/eepp/ui/doc/languages/objeck.hpp +../../src/eepp/ui/doc/languages/odin.cpp +../../src/eepp/ui/doc/languages/pascal.cpp +../../src/eepp/ui/doc/languages/perl.cpp +../../src/eepp/ui/doc/languages/pico-8.cpp +../../src/eepp/ui/doc/languages/po.cpp +../../src/eepp/ui/doc/languages/postgresql.cpp +../../src/eepp/ui/doc/languages/r.cpp +../../src/eepp/ui/doc/languages/rust.cpp +../../src/eepp/ui/doc/languages/sass.cpp +../../src/eepp/ui/doc/languages/solidity.cpp +../../src/eepp/ui/doc/languages/sql.cpp +../../src/eepp/ui/doc/languages/swift.cpp +../../src/eepp/ui/doc/languages/teal.cpp +../../src/eepp/ui/doc/languages/toml.cpp +../../src/eepp/ui/doc/languages/v.cpp +../../src/eepp/ui/doc/languages/vb.cpp +../../src/eepp/ui/doc/languages/verilog.cpp +../../src/eepp/ui/doc/languages/x86assembly.cpp +../../src/eepp/ui/doc/languages/xml.cpp +../../src/eepp/ui/doc/languages/zig.cpp ../../src/eepp/ui/doc/syntaxcolorscheme.cpp ../../src/eepp/ui/doc/syntaxdefinition.cpp ../../src/eepp/ui/doc/syntaxdefinitionmanager.cpp diff --git a/projects/macos/ee.includes b/projects/macos/ee.includes index abbae5bff..36e5390bb 100644 --- a/projects/macos/ee.includes +++ b/projects/macos/ee.includes @@ -6,8 +6,7 @@ ../../src/thirdparty/efsw/src ../../src/thirdparty/libvorbis/include ../../src/thirdparty/mbedtls/include -/usr/include/freetype2/ -/usr/lib64/gcc/x86_64-suse-linux/10/include +../../src/thirdparty/freetype2/include ../../src/modules/eterm/src/ ../../src/modules/eterm/include/ ../../src/modules/maps/include/ diff --git a/src/eepp/graphics/fontbmfont.cpp b/src/eepp/graphics/fontbmfont.cpp index f3cc6b6fe..ab1b521e5 100644 --- a/src/eepp/graphics/fontbmfont.cpp +++ b/src/eepp/graphics/fontbmfont.cpp @@ -157,8 +157,8 @@ bool FontBMFont::loadFromStream( IOStream& stream ) { glyph.textureRect = Rect( charX, charY, charWidth, charHeight ); } - const Glyph& gl1 = getGlyph( '@', mFontSize, false ); - const Glyph& gl2 = getGlyph( '.', mFontSize, false ); + const Glyph& gl1 = getGlyph( '@', mFontSize, false, false ); + const Glyph& gl2 = getGlyph( '.', mFontSize, false, false ); mIsMonospace = gl1.advance == gl2.advance; sendEvent( Event::Load ); @@ -186,7 +186,7 @@ const FontBMFont::Info& FontBMFont::getInfo() const { } const Glyph& FontBMFont::getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness, Float ) const { + bool /*italic*/, Float outlineThickness, Float ) const { GlyphTable& glyphs = mPages[characterSize].glyphs; GlyphTable::const_iterator it = glyphs.find( codePoint ); @@ -200,15 +200,15 @@ const Glyph& FontBMFont::getGlyph( Uint32 codePoint, unsigned int characterSize, } GlyphDrawable* FontBMFont::getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold, Float outlineThickness, + bool bold, bool italic, Float outlineThickness, const Float& ) const { GlyphDrawableTable& drawables = mPages[characterSize].drawables; auto it = drawables.find( codePoint ); if ( it != drawables.end() ) { return it->second; } else { - const Glyph& glyph = getGlyph( codePoint, characterSize, bold, outlineThickness ); - auto& page = mPages[characterSize]; + const Glyph& glyph = getGlyph( codePoint, characterSize, bold, italic, outlineThickness ); + const auto& page = mPages[characterSize]; GlyphDrawable* region = GlyphDrawable::New( page.texture, glyph.textureRect, glyph.bounds.getSize(), String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); @@ -237,7 +237,7 @@ Glyph FontBMFont::loadGlyph( Uint32 codePoint, unsigned int characterSize, bool, return glyph; } -Float FontBMFont::getKerning( Uint32, Uint32, unsigned int, bool ) const { +Float FontBMFont::getKerning( Uint32, Uint32, unsigned int, bool, bool ) const { return 0; } diff --git a/src/eepp/graphics/fontsprite.cpp b/src/eepp/graphics/fontsprite.cpp index 016af423b..77e822dff 100644 --- a/src/eepp/graphics/fontsprite.cpp +++ b/src/eepp/graphics/fontsprite.cpp @@ -163,7 +163,7 @@ const FontSprite::Info& FontSprite::getInfo() const { return mInfo; } -const Glyph& FontSprite::getGlyph( Uint32 codePoint, unsigned int characterSize, bool, Float, +const Glyph& FontSprite::getGlyph( Uint32 codePoint, unsigned int characterSize, bool, bool, Float, Float ) const { GlyphTable& glyphs = mPages[characterSize].glyphs; @@ -178,15 +178,15 @@ const Glyph& FontSprite::getGlyph( Uint32 codePoint, unsigned int characterSize, } GlyphDrawable* FontSprite::getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold, Float outlineThickness, + bool bold, bool italic, Float outlineThickness, const Float& ) const { GlyphDrawableTable& drawables = mPages[characterSize].drawables; auto it = drawables.find( codePoint ); if ( it != drawables.end() ) { return it->second; } else { - const Glyph& glyph = getGlyph( codePoint, characterSize, bold, outlineThickness ); - auto& page = mPages[characterSize]; + const Glyph& glyph = getGlyph( codePoint, characterSize, bold, italic, outlineThickness ); + const auto& page = mPages[characterSize]; GlyphDrawable* region = GlyphDrawable::New( page.texture, glyph.textureRect, glyph.bounds.getSize(), String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); @@ -215,7 +215,7 @@ Glyph FontSprite::loadGlyph( Uint32 codePoint, unsigned int characterSize ) cons return glyph; } -Float FontSprite::getKerning( Uint32, Uint32, unsigned int, bool ) const { +Float FontSprite::getKerning( Uint32, Uint32, unsigned int, bool, bool ) const { return 0; } diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 740a5d169..8ce67c168 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -48,15 +48,18 @@ template inline T reinterpret( const U& input ) { namespace EE { namespace Graphics { -static std::map fontsInternalIds; +static std::unordered_map fontsInternalIds; static std::atomic fontInternalIdCounter{ 0 }; -// Combine outline thickness, boldness and font glyph index into a single 64-bit key -static inline Uint64 getIndexKey( Uint32 fontInternalId, Uint32 index, bool bold, +// Combine outline thickness, boldness, italics and font glyph index into a single 64-bit key +static inline Uint64 getIndexKey( Uint32 fontInternalId, Uint32 index, bool bold, bool italics, Float outlineThickness ) { return ( static_cast( reinterpret( fontInternalId ) ) << 48 ) | - ( static_cast( reinterpret( outlineThickness * 100 ) ) << 33 ) | - ( static_cast( bold ) << 32 ) | index; + ( static_cast( + reinterpret( static_cast( outlineThickness ) * 1000 ) ) + << 34 ) | + ( static_cast( bold ) << 33 ) | + ( static_cast( italics ) << 32 ) | index; } FontTrueType* FontTrueType::New( const std::string& FontName ) { @@ -225,9 +228,11 @@ bool FontTrueType::loadFromPack( Pack* pack, std::string filePackPath ) { bool FontTrueType::setFontFace( void* _face ) { FT_Face face = (FT_Face)_face; mFace = face; - mIsMonospace = FT_IS_FIXED_WIDTH( face ); + mIsMonospaceComplete = mIsMonospace = FT_IS_FIXED_WIDTH( face ); mIsColorEmojiFont = checkIsColorEmojiFont( face ); mIsEmojiFont = FT_Get_Char_Index( face, 0x1F600 ) != 0; + mIsBold = face->style_flags & FT_STYLE_FLAG_BOLD; + mIsItalic = face->style_flags & FT_STYLE_FLAG_ITALIC; if ( mIsColorEmojiFont && FontManager::instance()->getColorEmojiFont() == nullptr ) FontManager::instance()->setColorEmojiFont( this ); @@ -298,7 +303,7 @@ Uint32 FontTrueType::getGlyphIndex( const Uint32& codePoint ) const { } const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness, Float maxWidth ) const { + bool italic, Float outlineThickness, Float maxWidth ) const { if ( mEnableEmojiFallback && Font::isEmojiCodePoint( codePoint ) && !mIsColorEmojiFont && !mIsEmojiFont ) { if ( !mIsColorEmojiFont && FontManager::instance()->getColorEmojiFont() != nullptr && @@ -312,8 +317,8 @@ const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSiz FontTrueType* fontEmoji = static_cast( FontManager::instance()->getColorEmojiFont() ); if ( 0 != fontEmoji->getGlyphIndex( codePoint ) ) - return fontEmoji->getGlyph( codePoint, characterSize, bold, outlineThickness, - getPage( characterSize ), maxWidth ); + return fontEmoji->getGlyph( codePoint, characterSize, bold, italic, + outlineThickness, getPage( characterSize ), maxWidth ); } else if ( !mIsEmojiFont && FontManager::instance()->getEmojiFont() != nullptr && FontManager::instance()->getEmojiFont()->getType() == FontType::TTF ) { @@ -325,42 +330,61 @@ const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSiz FontTrueType* fontEmoji = static_cast( FontManager::instance()->getEmojiFont() ); if ( 0 != fontEmoji->getGlyphIndex( codePoint ) ) - return fontEmoji->getGlyph( codePoint, characterSize, bold, outlineThickness, - getPage( characterSize ), maxWidth ); + return fontEmoji->getGlyph( codePoint, characterSize, bold, italic, + outlineThickness, getPage( characterSize ), maxWidth ); } } + if ( bold && italic && mFontBoldItalic != nullptr && + 0 != mFontBoldItalic->getGlyphIndex( codePoint ) ) { + return mFontBoldItalic->getGlyph( codePoint, characterSize, false, false, outlineThickness, + getPage( characterSize ), maxWidth ); + } + + if ( bold && !italic && mFontBold != nullptr && 0 != mFontBold->getGlyphIndex( codePoint ) ) { + return mFontBold->getGlyph( codePoint, characterSize, false, false, outlineThickness, + getPage( characterSize ), maxWidth ); + } + + if ( italic && !bold && mFontItalic != nullptr && + 0 != mFontItalic->getGlyphIndex( codePoint ) ) { + return mFontItalic->getGlyph( codePoint, characterSize, false, false, outlineThickness, + getPage( characterSize ), maxWidth ); + } + Uint32 glyphIndex = getGlyphIndex( codePoint ); if ( 0 == glyphIndex && mEnableFallbackFont && FontManager::instance()->getFallbackFont() && FontManager::instance()->getFallbackFont()->getType() == FontType::TTF ) { FontTrueType* fallbackFont = static_cast( FontManager::instance()->getFallbackFont() ); if ( 0 != fallbackFont->getGlyphIndex( codePoint ) ) { - if ( mIsMonospace && mEnableDynamicMonospace ) - mIsMonospace = false; - return fallbackFont->getGlyph( codePoint, characterSize, bold, outlineThickness, + if ( mIsMonospace && mEnableDynamicMonospace ) { + mIsMonospaceComplete = false; + mUsingFallback = true; + } + return fallbackFont->getGlyph( codePoint, characterSize, bold, italic, outlineThickness, getPage( characterSize ), maxWidth ); } } - return getGlyphByIndex( glyphIndex, characterSize, bold, outlineThickness ); + return getGlyphByIndex( glyphIndex, characterSize, bold, italic, outlineThickness ); } const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness, Page& page, + bool italic, Float outlineThickness, Page& page, const Float& maxWidth ) const { Uint32 index = getGlyphIndex( codePoint ); - return getGlyphByIndex( index, characterSize, bold, outlineThickness, page, maxWidth ); + return getGlyphByIndex( index, characterSize, bold, italic, outlineThickness, page, maxWidth ); } const Glyph& FontTrueType::getGlyphByIndex( Uint32 index, unsigned int characterSize, bool bold, - Float outlineThickness, Page& page, + bool italic, Float outlineThickness, Page& page, const Float& maxWidth ) const { // Get the page corresponding to the character size GlyphTable& glyphs = page.glyphs; // Build the key by combining the code point, bold flag, and outline thickness - Uint64 key = getIndexKey( mFontInternalId, index, bold, outlineThickness ); + Uint64 key = getIndexKey( mFontInternalId, index, bold, italic, outlineThickness ); // Search the glyph into the cache GlyphTable::const_iterator it = glyphs.find( key ); @@ -369,20 +393,21 @@ const Glyph& FontTrueType::getGlyphByIndex( Uint32 index, unsigned int character return it->second; } else { // Not found: we have to load it - Glyph glyph = loadGlyph( index, characterSize, bold, outlineThickness, page, maxWidth ); + Glyph glyph = + loadGlyph( index, characterSize, bold, italic, outlineThickness, page, maxWidth ); return glyphs.insert( std::make_pair( key, glyph ) ).first->second; } } const Glyph& FontTrueType::getGlyphByIndex( Uint32 index, unsigned int characterSize, bool bold, - Float outlineThickness ) const { - return getGlyphByIndex( index, characterSize, bold, outlineThickness, getPage( characterSize ), - 0.f ); + bool italic, Float outlineThickness ) const { + return getGlyphByIndex( index, characterSize, bold, italic, outlineThickness, + getPage( characterSize ), 0.f ); } GlyphDrawable* FontTrueType::getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold, Float outlineThickness, + bool bold, bool italic, Float outlineThickness, const Float& maxWidth ) const { Page& page = getPage( characterSize ); GlyphDrawableTable& drawables = page.drawables; @@ -431,33 +456,65 @@ GlyphDrawable* FontTrueType::getGlyphDrawable( Uint32 codePoint, unsigned int ch if ( 0 != tGlyphIndex ) { glyphIndex = tGlyphIndex; fontInternalId = fontFallback->getFontInternalId(); - if ( mIsMonospace && mEnableDynamicMonospace ) - mIsMonospace = false; + if ( mIsMonospace && mEnableDynamicMonospace ) { + mIsMonospaceComplete = false; + mUsingFallback = true; + } } else { glyphIndex = getGlyphIndex( codePoint ); } } - Uint64 key = getIndexKey( fontInternalId, glyphIndex, bold, outlineThickness ); + Uint64 key = getIndexKey( fontInternalId, glyphIndex, bold, italic, outlineThickness ); auto it = drawables.find( key ); if ( it != drawables.end() ) { return it->second; } else { - const Glyph& glyph = getGlyph( codePoint, characterSize, bold, outlineThickness, maxWidth ); - GlyphDrawable* region = GlyphDrawable::New( - page.texture, glyph.textureRect, glyph.size, - String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); - region->setGlyphOffset( { glyph.bounds.Left - outlineThickness, - characterSize + glyph.bounds.Top - outlineThickness } ); + GlyphDrawable* region = nullptr; + const Glyph* glyph = nullptr; - drawables[key] = region; - return region; + if ( bold && italic && mFontBoldItalic != nullptr && + 0 != mFontBoldItalic->getGlyphIndex( codePoint ) ) { + glyph = &mFontBoldItalic->getGlyph( codePoint, characterSize, false, false, + outlineThickness, maxWidth ); + region = GlyphDrawable::New( page.texture, glyph->textureRect, glyph->size, + String::format( "%s_%d_%u_bold_italic", mFontName.c_str(), + characterSize, codePoint ) ); + } else if ( bold && !italic && mFontBold != nullptr && + 0 != mFontBold->getGlyphIndex( codePoint ) ) { + glyph = &mFontBold->getGlyph( codePoint, characterSize, false, false, outlineThickness, + maxWidth ); + region = GlyphDrawable::New( + page.texture, glyph->textureRect, glyph->size, + String::format( "%s_%d_%u_bold", mFontName.c_str(), characterSize, codePoint ) ); + } else if ( italic && !bold && mFontItalic != nullptr && + 0 != mFontItalic->getGlyphIndex( codePoint ) ) { + glyph = &mFontItalic->getGlyph( codePoint, characterSize, false, false, + outlineThickness, maxWidth ); + region = GlyphDrawable::New( + page.texture, glyph->textureRect, glyph->size, + String::format( "%s_%d_%u_italic", mFontName.c_str(), characterSize, codePoint ) ); + } else { + glyph = &getGlyph( codePoint, characterSize, bold, italic, outlineThickness, maxWidth ); + region = GlyphDrawable::New( + page.texture, glyph->textureRect, glyph->size, + String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); + } + + if ( region != nullptr ) { + region->setGlyphOffset( { glyph->bounds.Left - outlineThickness, + characterSize + glyph->bounds.Top - outlineThickness } ); + + drawables[key] = region; + return region; + } } + return nullptr; } -Float FontTrueType::getKerning( Uint32 first, Uint32 second, unsigned int characterSize, - bool bold ) const { +Float FontTrueType::getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold, + bool italic ) const { // Special case where first or second is 0 (null character) if ( first == 0 || second == 0 || isMonospace() ) return 0.f; @@ -470,9 +527,10 @@ Float FontTrueType::getKerning( Uint32 first, Uint32 second, unsigned int charac FT_UInt index2 = getGlyphIndex( second ); // Retrieve position compensation deltas generated by FT_LOAD_FORCE_AUTOHINT flag - auto firstRsbDelta = static_cast( getGlyph( first, characterSize, bold ).rsbDelta ); + auto firstRsbDelta = + static_cast( getGlyph( first, characterSize, bold, italic ).rsbDelta ); auto secondLsbDelta = - static_cast( getGlyph( second, characterSize, bold ).lsbDelta ); + static_cast( getGlyph( second, characterSize, bold, italic ).lsbDelta ); // Get the kerning vector FT_Vector kerning; @@ -587,6 +645,21 @@ void FontTrueType::cleanup() { if ( FontManager::existsSingleton() && FontManager::instance()->getColorEmojiFont() == this ) FontManager::instance()->setColorEmojiFont( nullptr ); + if ( mFontBoldItalicCb != 0 && mFontBoldItalic != nullptr ) { + mFontBoldItalic->popFontEventCallback( mFontBoldItalicCb ); + mFontBoldItalicCb = 0; + } + + if ( mFontBoldCb != 0 && mFontBold != nullptr ) { + mFontBold->popFontEventCallback( mFontBoldCb ); + mFontBoldCb = 0; + } + + if ( mFontItalicCb != 0 && mFontItalic != nullptr ) { + mFontItalic->popFontEventCallback( mFontItalicCb ); + mFontItalicCb = 0; + } + mCallbacks.clear(); mNumCallBacks = 0; @@ -656,7 +729,7 @@ fontSetRenderOptions( FT_Library library, FontAntialiasing antialiasing, FontHin return FT_RENDER_MODE_NORMAL; } -Glyph FontTrueType::loadGlyph( Uint32 index, unsigned int characterSize, bool bold, +Glyph FontTrueType::loadGlyph( Uint32 index, unsigned int characterSize, bool bold, bool italic, Float outlineThickness, Page& page, const Float& maxWidth ) const { // The glyph to return Glyph glyph; @@ -1132,7 +1205,7 @@ void FontTrueType::setIsEmojiFont( bool isEmojiFont ) { } void FontTrueType::setForceIsMonospace( bool isMonospace ) { - mIsMonospace = isMonospace; + mIsMonospaceComplete = isMonospace; } void FontTrueType::setIsColorEmojiFont( bool isColorEmojiFont ) { @@ -1144,7 +1217,7 @@ bool FontTrueType::isColorEmojiFont() const { } bool FontTrueType::isMonospace() const { - return mIsMonospace; + return mIsMonospaceComplete; } bool FontTrueType::isScalable() const { @@ -1163,6 +1236,74 @@ void FontTrueType::setBoldAdvanceSameAsRegular( bool boldAdvanceSameAsRegular ) mBoldAdvanceSameAsRegular = boldAdvanceSameAsRegular; } +void FontTrueType::updateMonospaceState() { + mIsMonospaceComplete = mIsMonospace && !mUsingFallback; + if ( mIsMonospaceComplete && mFontBold != nullptr ) { + mIsMonospaceComplete = mIsMonospaceComplete && mFontBold->isMonospace() && + getGlyph( ' ', 10, false, false ).advance == + mFontBold->getGlyph( ' ', 10, false, false ).advance; + } + if ( mIsMonospaceComplete && mFontItalic != nullptr ) { + mIsMonospaceComplete = mIsMonospaceComplete && mFontItalic->isMonospace() && + getGlyph( ' ', 10, false, false ).advance == + mFontItalic->getGlyph( ' ', 10, false, false ).advance; + } + if ( mIsMonospaceComplete && mFontBoldItalic != nullptr ) { + mIsMonospaceComplete = mIsMonospaceComplete && mFontBoldItalic->isMonospace() && + getGlyph( ' ', 10, false, false ).advance == + mFontBoldItalic->getGlyph( ' ', 10, false, false ).advance; + } +} + +void FontTrueType::setBoldFont( FontTrueType* fontBold ) { + if ( fontBold == mFontBold ) + return; + mFontBold = fontBold; + if ( mFontBold != nullptr ) { + mFontBoldCb = mFontBold->pushFontEventCallback( [this]( Uint32, Event event, Font* ) { + if ( event == Font::Event::Unload ) { + // Maybe we should recreate the page table + mFontBold = nullptr; + mFontBoldCb = 0; + } + } ); + } + updateMonospaceState(); +} + +void FontTrueType::setItalicFont( FontTrueType* fontItalic ) { + if ( fontItalic == mFontItalic ) + return; + mFontItalic = fontItalic; + if ( mFontItalic != nullptr ) { + mFontItalicCb = mFontItalic->pushFontEventCallback( [this]( Uint32, Event event, Font* ) { + if ( event == Font::Event::Unload ) { + // Maybe we should recreate the page table + mFontItalic = nullptr; + mFontItalicCb = 0; + } + } ); + } + updateMonospaceState(); +} + +void FontTrueType::setBoldItalicFont( FontTrueType* fontBoldItalic ) { + if ( fontBoldItalic == mFontBoldItalic ) + return; + mFontBoldItalic = fontBoldItalic; + if ( mFontBoldItalic != nullptr ) { + mFontBoldItalicCb = + mFontBoldItalic->pushFontEventCallback( [this]( Uint32, Event event, Font* ) { + if ( event == Font::Event::Unload ) { + // Maybe we should recreate the page table + mFontBoldItalic = nullptr; + mFontBoldItalicCb = 0; + } + } ); + } + updateMonospaceState(); +} + FontTrueType::Page::Page( const Uint32 fontInternalId ) : texture( NULL ), nextRow( 3 ), fontInternalId( fontInternalId ) { // Make sure that the texture is initialized by default diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 314546d91..979d3805d 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -421,12 +421,13 @@ Float Text::getTextWidth( Font* font, const Uint32& fontSize, const String& stri String::StringBaseType rune; Uint32 prevChar = 0; bool bold = ( style & Text::Bold ) != 0; - Float hspace = static_cast( font->getGlyph( L' ', fontSize, bold ).advance ); + bool italic = ( style & Text::Italic ) != 0; + Float hspace = static_cast( font->getGlyph( L' ', fontSize, bold, italic ).advance ); for ( std::size_t i = 0; i < string.size(); ++i ) { rune = string.at( i ); - Glyph glyph = font->getGlyph( rune, fontSize, bold, outlineThickness ); + Glyph glyph = font->getGlyph( rune, fontSize, bold, italic, outlineThickness ); if ( rune != '\r' && rune != '\t' ) { - width += font->getKerning( prevChar, rune, fontSize, bold ); + width += font->getKerning( prevChar, rune, fontSize, bold, italic ); prevChar = rune; width += glyph.advance; } else if ( rune == '\t' ) { @@ -452,7 +453,8 @@ Vector2f Text::findCharacterPos( std::size_t index, Font* font, const Uint32& fo // Precompute the variables needed by the algorithm bool bold = ( style & Text::Bold ) != 0; - Float hspace = static_cast( font->getGlyph( L' ', fontSize, bold ).advance ); + bool italic = ( style & Italic ) != 0; + Float hspace = static_cast( font->getGlyph( L' ', fontSize, bold, italic ).advance ); Float vspace = static_cast( font->getLineSpacing( fontSize ) ); // Compute the position @@ -462,7 +464,7 @@ Vector2f Text::findCharacterPos( std::size_t index, Font* font, const Uint32& fo String::StringBaseType curChar = string[i]; // Apply the kerning offset - position.x += static_cast( font->getKerning( prevChar, curChar, fontSize, bold ) ); + position.x += static_cast( font->getKerning( prevChar, curChar, fontSize, bold, italic ) ); prevChar = curChar; // Handle special characters @@ -504,9 +506,10 @@ Int32 Text::findCharacterFromPos( const Vector2i& pos, bool returnNearest, Font* Int32 curDist = -1; std::size_t tSize = string.size(); bool bold = ( style & Text::Bold ) != 0; + bool italic = ( style & Italic ) != 0; Vector2f fpos( pos.asFloat() ); - Float hspace = static_cast( font->getGlyph( L' ', fontSize, bold ).advance ); + Float hspace = static_cast( font->getGlyph( L' ', fontSize, bold, italic ).advance ); for ( std::size_t i = 0; i < tSize; ++i ) { rune = string[i]; @@ -515,7 +518,7 @@ Int32 Text::findCharacterFromPos( const Vector2i& pos, bool returnNearest, Font* lWidth = width; if ( rune != '\r' && rune != '\t' ) { - width += font->getKerning( prevChar, rune, fontSize, bold ); + width += font->getKerning( prevChar, rune, fontSize, bold, italic ); prevChar = rune; width += glyph.advance; } else if ( rune == '\t' ) { @@ -572,17 +575,18 @@ void Text::getWidthInfo() { Uint32 prevChar = 0; mLargestLineCharCount = 0; bool bold = ( mStyle & Bold ) != 0; + bool italic = ( mStyle & Italic ) != 0; mLinesStartIndex.push_back( 0 ); - Float hspace = static_cast( mFont->getGlyph( L' ', mRealFontSize, bold ).advance ); + Float hspace = static_cast( mFont->getGlyph( L' ', mRealFontSize, bold, italic ).advance ); for ( std::size_t i = 0; i < mString.size(); ++i ) { CharID = static_cast( mString.at( i ) ); Glyph glyph = mFont->getGlyph( CharID, mRealFontSize, bold, mOutlineThickness ); if ( CharID != '\r' && CharID != '\t' ) { - Width += mFont->getKerning( prevChar, CharID, mRealFontSize, bold ); + Width += mFont->getKerning( prevChar, CharID, mRealFontSize, bold, italic ); prevChar = CharID; Width += glyph.advance; } @@ -629,8 +633,9 @@ void Text::wrapText( const Uint32& maxWidth ) { String::StringBaseType* tLastSpace = NULL; Uint32 prevChar = 0; bool bold = ( mStyle & Bold ) != 0; + bool italic = ( mStyle & Italic ) != 0; - Float hspace = static_cast( mFont->getGlyph( L' ', mRealFontSize, bold ).advance ); + Float hspace = static_cast( mFont->getGlyph( L' ', mRealFontSize, bold, italic ).advance ); while ( *tChar ) { Glyph pChar = mFont->getGlyph( *tChar, mRealFontSize, bold, mOutlineThickness ); @@ -646,7 +651,7 @@ void Text::wrapText( const Uint32& maxWidth ) { tWordWidth += fCharWidth; if ( *tChar != '\r' ) { - tWordWidth += mFont->getKerning( prevChar, *tChar, mRealFontSize, bold ); + tWordWidth += mFont->getKerning( prevChar, *tChar, mRealFontSize, bold, italic ); prevChar = *tChar; } @@ -904,9 +909,10 @@ void Text::ensureGeometryUpdate() { // Compute values related to the text style bool bold = ( mStyle & Bold ) != 0; + bool reqItalic = ( mStyle & Italic ) != 0; bool underlined = ( mStyle & Underlined ) != 0; bool strikeThrough = ( mStyle & StrikeThrough ) != 0; - Float italic = ( mStyle & Italic ) ? 0.208f : 0.f; // 12 degrees + Float italic = reqItalic && !mFont->hasItalic() ? 0.208f : 0.f; // 12 degrees Float underlineOffset = mFont->getUnderlinePosition( mRealFontSize ); Float underlineThickness = mFont->getUnderlineThickness( mRealFontSize ); @@ -915,12 +921,13 @@ void Text::ensureGeometryUpdate() { // We reuse the underline thickness as the thickness of the strike through as well Float strikeThroughOffset = 0; if ( strikeThrough ) { - Rectf xBounds = mFont->getGlyph( L'x', mRealFontSize, bold ).bounds; + Rectf xBounds = mFont->getGlyph( L'x', mRealFontSize, bold, reqItalic ).bounds; strikeThroughOffset = xBounds.Top + xBounds.Bottom / 2.f; } // Precompute the variables needed by the algorithm - Float hspace = static_cast( mFont->getGlyph( L' ', mRealFontSize, bold ).advance ); + Float hspace = static_cast( + mFont->getGlyph( L' ', mRealFontSize, bold, reqItalic ).advance ); Float vspace = static_cast( mFont->getLineSpacing( mRealFontSize ) ); Float x = 0.f; Float y = static_cast( mRealFontSize ); @@ -950,7 +957,7 @@ void Text::ensureGeometryUpdate() { Uint32 curChar = mString[i]; // Apply the kerning offset - x += mFont->getKerning( prevChar, curChar, mRealFontSize, bold ); + x += mFont->getKerning( prevChar, curChar, mRealFontSize, bold, reqItalic ); prevChar = curChar; // If we're using the underlined style and there's a new line, draw a line @@ -1042,7 +1049,7 @@ void Text::ensureGeometryUpdate() { } // Extract the current glyph's description - const Glyph& glyph = mFont->getGlyph( curChar, mRealFontSize, bold ); + const Glyph& glyph = mFont->getGlyph( curChar, mRealFontSize, bold, reqItalic ); // Add the glyph to the vertices addGlyphQuad( mVertices, Vector2f( x, y ), glyph, italic, 0, centerDiffX ); @@ -1114,7 +1121,7 @@ void Text::ensureColorUpdate() { if ( mContainsColorEmoji ) { auto positions = Font::emojiCodePointsPositions( mString ); - for ( auto& position : positions ) + for ( const auto& position : positions ) setFillColor( Color( 255, 255, 255, mFillColor.a ), position, position ); } } diff --git a/src/eepp/system/inifile.cpp b/src/eepp/system/inifile.cpp index a5899f8c7..cf475e0f6 100644 --- a/src/eepp/system/inifile.cpp +++ b/src/eepp/system/inifile.cpp @@ -330,7 +330,7 @@ bool IniFile::setValueV( std::string const keyname, std::string const valuename, #ifdef EE_COMPILER_MSVC vsprintf_s( value, MAX_VALUEDATA, format, args ); #else - vsprintf( value, format, args ); + vsnprintf( value, MAX_VALUEDATA, format, args ); #endif va_end( args ); return setValue( keyname, valuename, value ); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index ffff30080..32d385949 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -2418,7 +2418,7 @@ Float UICodeEditor::getGlyphWidth() const { } void UICodeEditor::udpateGlyphWidth() { - mGlyphWidth = mFont->getGlyph( '@', getCharacterSize(), false ).advance; + mGlyphWidth = mFont->getGlyph( '@', getCharacterSize(), false, false ).advance; invalidateLongestLineWidth(); } diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index 28b11c6ca..ac9b31657 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -394,8 +394,8 @@ void UIConsole::draw() { size_t pos = 0; Float curY; Float lineHeight = getLineHeight(); - Float cw = - mFontStyleConfig.Font->getGlyph( '_', mFontStyleConfig.CharacterSize, false ).advance; + Float cw = mFontStyleConfig.Font->getGlyph( '_', mFontStyleConfig.CharacterSize, false, false ) + .advance; mCon.min = eemax( 0, (Int32)mCmdLog.size() - linesInScreen ); mCon.max = (int)mCmdLog.size() - 1; @@ -457,7 +457,8 @@ void UIConsole::draw() { if ( mShowFps ) { Float cw = - mFontStyleConfig.Font->getGlyph( '_', mFontStyleConfig.CharacterSize, false ).advance; + mFontStyleConfig.Font->getGlyph( '_', mFontStyleConfig.CharacterSize, false, false ) + .advance; Text& text = mTextCache[mTextCache.size() - 3].text; Color OldColor1( text.getColor() ); text.setStyleConfig( mFontStyleConfig ); diff --git a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp index c79f925ac..9b21d4c5c 100644 --- a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp @@ -377,7 +377,7 @@ std::shared_ptr TerminalDisplay::create( static Sizei gridSizeFromTermDimensions( Font* font, const Float& fontSize, const Sizef& pixelsSize ) { auto fontHeight = (Float)font->getFontHeight( fontSize ); - auto spaceCharAdvanceX = font->getGlyph( 'A', fontSize, false ).advance; + auto spaceCharAdvanceX = font->getGlyph( 'A', fontSize, false, false ).advance; auto clipColumns = (int)std::floor( std::max( 1.0f, pixelsSize.getWidth() / spaceCharAdvanceX ) ); auto clipRows = (int)std::floor( std::max( 1.0f, pixelsSize.getHeight() / fontHeight ) ); @@ -1081,7 +1081,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) { mFrameBuffer->bind(); auto fontSize = mFont->getFontHeight( mFontSize ); - auto spaceCharAdvanceX = mFont->getGlyph( 'A', mFontSize, false ).advance; + auto spaceCharAdvanceX = mFont->getGlyph( 'A', mFontSize, false, false ).advance; float x = 0.0f; float y = pos.y; @@ -1089,7 +1089,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) { auto defaultFg = mColorScheme.getForeground(); auto defaultBg = mColorScheme.getBackground(); auto cursorThickness = Math::roundDown( PixelDensity::dpToPx( 1.f ) ); - Rectf xBounds = mFont->getGlyph( L'x', mFontSize, false ).bounds; + Rectf xBounds = mFont->getGlyph( L'x', mFontSize, false, false ).bounds; Float strikeThroughOffset = lineHeight + xBounds.Top + cursorThickness; mPrimitives.setForceDraw( false ); @@ -1236,7 +1236,7 @@ void TerminalDisplay::drawGrid( const Vector2f& pos ) { if ( mVBForeground ) mVBForeground->setQuadColor( mCurGridPos, Color::Transparent ); } else { - auto* gd = mFont->getGlyphDrawable( glyph.u, mFontSize, glyph.mode & ATTR_BOLD, 0, + auto* gd = mFont->getGlyphDrawable( glyph.u, mFontSize, glyph.mode & ATTR_BOLD, glyph.mode & ATTR_ITALIC, 0, advanceX ); if ( ( glyph.mode & ATTR_EMOJI ) && FontManager::instance()->getColorEmojiFont() ) { @@ -1412,7 +1412,7 @@ Vector2i TerminalDisplay::positionToGrid( const Vector2i& pos ) { int mouseY = 0; auto fontSize = (Float)mFont->getFontHeight( mFontSize ); - auto spaceCharAdvanceX = mFont->getGlyph( 'A', mFontSize, false ).advance; + auto spaceCharAdvanceX = mFont->getGlyph( 'A', mFontSize, false, false ).advance; auto clipColumns = (int)std::floor( std::max( 1.0f, mSize.getWidth() / spaceCharAdvanceX ) ); auto clipRows = (int)std::floor( std::max( 1.0f, mSize.getHeight() / fontSize ) ); diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 0a85f2c56..2d315347d 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -194,8 +194,9 @@ void UITreeViewCellGlobalSearch::draw() { if ( getCurIndex().internalId() != -1 && mSearchStrPos.first != std::string::npos && mSearchStrPos.second > 0 && mSearchStrPos.second <= mTextBox->getText().length() ) { UITreeViewGlobalSearch* pp = getParent()->getParent()->asType(); - auto hspace = - mTextBox->getFont()->getGlyph( L' ', mTextBox->getPixelsFontSize(), false ).advance; + auto hspace = mTextBox->getFont() + ->getGlyph( L' ', mTextBox->getPixelsFontSize(), false, false ) + .advance; Primitives p; p.setColor( pp->getColorScheme().getEditorSyntaxStyle( "selection" ).color ); Vector2f screenPos( mScreenPos );