Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Application::loadFonts( LanguageInfo::Language newLang )
- {
- bool needLoadingDialog = m_bFontsLoaded;
- // Retrieve path for installed fonts
- auto fontsPath = QString::fromStdString( PathsProvider::instance().path( PathType::FontsPath ) );
- QFontDatabase fontDB;
- if ( !m_bFontsLoaded )
- {
- int nsr = fontDB.addApplicationFont( QString{ "%1/NotoSans-Regular.ttf" }.arg( fontsPath ) );
- int nsb = fontDB.addApplicationFont( QString{ "%1/NotoSans-Bold.ttf" }.arg( fontsPath ) );
- int nsi = fontDB.addApplicationFont( QString{ "%1/NotoSans-Italic.ttf" }.arg( fontsPath ) );
- int nsbi = fontDB.addApplicationFont( QString{ "%1/NotoSans-BoldItalic.ttf" }.arg( fontsPath ) );
- if ( -1 != nsr && -1 != nsb && -1 != nsi && -1 != nsbi )
- {
- m_bFontsLoaded = true;
- }
- }
- std::function<void()> loadCJKFonts = [=]()
- {
- int nsr = fontDB.addApplicationFont( QString{ "%1/NotoSansCJK-Regular.ttc" }.arg( fontsPath ) );
- int nsb = fontDB.addApplicationFont( QString{ "%1/NotoSansCJK-Bold.ttc" }.arg( fontsPath ) );
- if ( -1 != nsr && -1 != nsb )
- {
- m_bCJKFontsLoaded = true;
- }
- };
- // load CJK font only if language is Chinese or Japanese, cause it takes about 3.5 seconds to load on device
- // and about 18 on PC
- if ( !m_bCJKFontsLoaded && ( LanguageInfo::Japanese == newLang || LanguageInfo::ChineseTraditional == newLang
- || LanguageInfo::ChineseSimplified == newLang) )
- {
- if ( needLoadingDialog )
- {
- //! \todo: revert commented code when LoadingDialog will be implemented
- loadCJKFonts();
- // LoadingDialog* pDialog = new LoadingDialog{
- // //% "Language"
- // qtTrId( "id-application-language" ),
- // //% "Loading fonts"
- // qtTrId( "id-application-loading_fonts" ), loadCJKFonts };
- // connect( pDialog, &LoadingDialog::finished, pDialog, &LoadingDialog::deleteLater );
- // pDialog->show();
- }
- else
- {
- loadCJKFonts();
- }
- }
- /*!
- * Setting up default application font.
- */
- QGuiApplication::setFont( QFont{ "Noto Sans" } );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement