Skip to content

Commit

Permalink
Async load fonts too.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Dec 24, 2024
1 parent a15e461 commit 524ea4d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 47 deletions.
9 changes: 4 additions & 5 deletions include/eepp/graphics/fonttruetype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class EE_API FontTrueType : public Font {

void clearCache();

void updateMonospaceState();

protected:
friend class Text;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -243,8 +244,6 @@ class EE_API FontTrueType : public Font {
void updateFontInternalId();

bool setFontFace( void* face );

void updateMonospaceState();
};

}} // namespace EE::Graphics
Expand Down
2 changes: 2 additions & 0 deletions src/eepp/graphics/fonttruetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==
Expand Down
95 changes: 53 additions & 42 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
Expand Down Expand Up @@ -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<std::mutex> 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<FontTrueType*>( font.second )->updateMonospaceState();
} );

SceneManager::instance()->add( mUISceneNode );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<std::mutex> syntaxLanguagesLock( mAsyncResourcesLoadMutex );
mAsyncResourcesLoadCond.wait( syntaxLanguagesLock,
[this]() { return mAsyncResourcesLoaded; } );
}

mSplitter = UICodeEditorSplitter::New( this, mUISceneNode, mThreadPool, mColorSchemes,
mInitColorScheme );
mSplitter->setHideTabBarOnSingleTab( mConfig.editor.hideTabBarOnSingleTab );
Expand Down
3 changes: 3 additions & 0 deletions src/tools/ecode/ecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 524ea4d

Please sign in to comment.