diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 53a06fca2..db22f3aa8 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -146,6 +146,8 @@ class EE_API FontTrueType : public Font { void clearCache(); + void updateMonospaceState(); + protected: friend class Text; @@ -186,9 +188,8 @@ class EE_API FontTrueType : public Font { Float outlineThickness, Page& page, const Float& maxWidth ) const; GlyphDrawable* getGlyphDrawableFromGlyphIndex( Uint32 glyphIndex, unsigned int characterSize, - bool bold, bool italic, - Float outlineThickness, Page& page, - const Float& maxWidth = 0 ) const; + bool bold, bool italic, Float outlineThickness, + Page& page, const Float& maxWidth = 0 ) const; Uint32 getGlyphIndex( const Uint32& codePoint ) const; @@ -243,8 +244,6 @@ class EE_API FontTrueType : public Font { void updateFontInternalId(); bool setFontFace( void* face ); - - void updateMonospaceState(); }; }} // namespace EE::Graphics diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 2b9188ccf..aabcbc0f5 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -1424,6 +1424,8 @@ void FontTrueType::setBoldAdvanceSameAsRegular( bool boldAdvanceSameAsRegular ) void FontTrueType::updateMonospaceState() { mIsMonospaceComplete = mIsMonospace && !mUsingFallback; + if ( !Engine::isEngineRunning() ) + return; if ( mIsMonospaceComplete && mFontBold != nullptr ) { mIsMonospaceComplete = mIsMonospaceComplete && mFontBold->isMonospace() && getGlyph( ' ', 10, false, false ).advance == diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 9bce5b09b..71f6a2179 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3435,6 +3435,49 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe // Load terminal color schemes mTerminalManager->loadTerminalColorSchemes(); + // Load fonts + Clock fontsClock; + + mFont = loadFont( "sans-serif", mConfig.ui.serifFont, "fonts/NotoSans-Regular.ttf" ); + FontFamily::loadFromRegular( mFont ); + + mFontMono = loadFont( "monospace", mConfig.ui.monospaceFont, "fonts/DejaVuSansMono.ttf" ); + if ( mFontMono ) { + mFontMono->setEnableDynamicMonospace( true ); + mFontMono->setBoldAdvanceSameAsRegular( true ); + FontFamily::loadFromRegular( mFontMono ); + } + + loadFont( "NotoEmoji-Regular", "fonts/NotoEmoji-Regular.ttf" ); + +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN + loadFont( "NotoColorEmoji", "fonts/NotoColorEmoji.ttf" ); +#endif + + mIconFont = loadFont( "icon", "fonts/remixicon.ttf" ); + mMimeIconFont = loadFont( "nonicons", "fonts/nonicons.ttf" ); + mCodIconFont = loadFont( "codicon", "fonts/codicon.ttf" ); + + mTerminalFont = loadFont( "monospace-nerdfont", mConfig.ui.terminalFont, + "fonts/DejaVuSansMonoNerdFontComplete.ttf" ); + + if ( ( nullptr != mTerminalFont && mTerminalFont->getInfo().family == "DejaVuSansMono NF" && + mFontMono->getInfo().family == "DejaVu Sans Mono" ) || + ( nullptr != mTerminalFont && + mTerminalFont->getInfo().family == mFontMono->getInfo().family ) ) { + mTerminalFont->setBoldFont( mFontMono->getBoldFont() ); + mTerminalFont->setItalicFont( mFontMono->getItalicFont() ); + mTerminalFont->setBoldItalicFont( mFontMono->getBoldItalicFont() ); + } else { + FontFamily::loadFromRegular( mTerminalFont ); + } + + mFallbackFont = loadFont( "fallback-font", "fonts/DroidSansFallbackFull.ttf" ); + if ( mFallbackFont ) + FontManager::instance()->addFallbackFont( mFallbackFont ); + + Log::info( "Fonts loaded in: %s", fontsClock.getElapsedTime().toString() ); + mAsyncResourcesLoaded = true; mAsyncResourcesLoadCond.notify_all(); } ); @@ -3606,48 +3649,22 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe } mUISceneNode->setColorSchemePreference( mUIColorScheme ); - mFont = loadFont( "sans-serif", mConfig.ui.serifFont, "fonts/NotoSans-Regular.ttf" ); - FontFamily::loadFromRegular( mFont ); - - mFontMono = loadFont( "monospace", mConfig.ui.monospaceFont, "fonts/DejaVuSansMono.ttf" ); - if ( mFontMono ) { - mFontMono->setEnableDynamicMonospace( true ); - mFontMono->setBoldAdvanceSameAsRegular( true ); - FontFamily::loadFromRegular( mFontMono ); + if ( !mAsyncResourcesLoaded ) { + std::unique_lock syntaxLanguagesLock( mAsyncResourcesLoadMutex ); + mAsyncResourcesLoadCond.wait( syntaxLanguagesLock, + [this]() { return mAsyncResourcesLoaded; } ); } - loadFont( "NotoEmoji-Regular", "fonts/NotoEmoji-Regular.ttf" ); - -#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN - loadFont( "NotoColorEmoji", "fonts/NotoColorEmoji.ttf" ); -#endif - - FontTrueType* iconFont = loadFont( "icon", "fonts/remixicon.ttf" ); - FontTrueType* mimeIconFont = loadFont( "nonicons", "fonts/nonicons.ttf" ); - FontTrueType* codIconFont = loadFont( "codicon", "fonts/codicon.ttf" ); - - if ( !mFont || !mFontMono || !iconFont || !mimeIconFont || !codIconFont ) { + if ( !mFont || !mFontMono || !mIconFont || !mMimeIconFont || !mCodIconFont ) { printf( "Font not found!" ); Log::error( "Font not found!" ); return; } - mTerminalFont = loadFont( "monospace-nerdfont", mConfig.ui.terminalFont, - "fonts/DejaVuSansMonoNerdFontComplete.ttf" ); - if ( ( nullptr != mTerminalFont && mTerminalFont->getInfo().family == "DejaVuSansMono NF" && - mFontMono->getInfo().family == "DejaVu Sans Mono" ) || - ( nullptr != mTerminalFont && - mTerminalFont->getInfo().family == mFontMono->getInfo().family ) ) { - mTerminalFont->setBoldFont( mFontMono->getBoldFont() ); - mTerminalFont->setItalicFont( mFontMono->getItalicFont() ); - mTerminalFont->setBoldItalicFont( mFontMono->getBoldItalicFont() ); - } else { - FontFamily::loadFromRegular( mTerminalFont ); - } - - mFallbackFont = loadFont( "fallback-font", "fonts/DroidSansFallbackFull.ttf" ); - if ( mFallbackFont ) - FontManager::instance()->addFallbackFont( mFallbackFont ); + FontManager::instance()->each( []( auto& font ) { + if ( font.second->getType() == FontType::TTF ) + static_cast( font.second )->updateMonospaceState(); + } ); SceneManager::instance()->add( mUISceneNode ); @@ -3692,7 +3709,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe ); mMenuIconSize = mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ); - IconManager::init( mUISceneNode, iconFont, mimeIconFont, codIconFont ); + IconManager::init( mUISceneNode, mIconFont, mMimeIconFont, mCodIconFont ); UIWidgetCreator::registerWidget( "searchbar", UISearchBar::New ); UIWidgetCreator::registerWidget( "locatebar", UILocateBar::New ); @@ -3724,12 +3741,6 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe if ( !mConfig.ui.showSidePanel ) showSidePanel( mConfig.ui.showSidePanel ); - if ( !mAsyncResourcesLoaded ) { - std::unique_lock syntaxLanguagesLock( mAsyncResourcesLoadMutex ); - mAsyncResourcesLoadCond.wait( syntaxLanguagesLock, - [this]() { return mAsyncResourcesLoaded; } ); - } - mSplitter = UICodeEditorSplitter::New( this, mUISceneNode, mThreadPool, mColorSchemes, mInitColorScheme ); mSplitter->setHideTabBarOnSingleTab( mConfig.editor.hideTabBarOnSingleTab ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index e45d70e2b..43f0237b5 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -533,6 +533,9 @@ class App : public UICodeEditorSplitter::Client { FontTrueType* mFontMono{ nullptr }; FontTrueType* mTerminalFont{ nullptr }; FontTrueType* mFallbackFont{ nullptr }; + FontTrueType* mIconFont{ nullptr }; + FontTrueType* mMimeIconFont{ nullptr }; + FontTrueType* mCodIconFont{ nullptr }; efsw::FileWatcher* mFileWatcher{ nullptr }; FileSystemListener* mFileSystemListener{ nullptr }; Mutex mWatchesLock;