Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. void Application::loadFonts( LanguageInfo::Language newLang )
  2. {
  3. bool needLoadingDialog = m_bFontsLoaded;
  4.  
  5. // Retrieve path for installed fonts
  6. auto fontsPath = QString::fromStdString( PathsProvider::instance().path( PathType::FontsPath ) );
  7.  
  8. QFontDatabase fontDB;
  9.  
  10. if ( !m_bFontsLoaded )
  11. {
  12. int nsr = fontDB.addApplicationFont( QString{ "%1/NotoSans-Regular.ttf" }.arg( fontsPath ) );
  13. int nsb = fontDB.addApplicationFont( QString{ "%1/NotoSans-Bold.ttf" }.arg( fontsPath ) );
  14. int nsi = fontDB.addApplicationFont( QString{ "%1/NotoSans-Italic.ttf" }.arg( fontsPath ) );
  15. int nsbi = fontDB.addApplicationFont( QString{ "%1/NotoSans-BoldItalic.ttf" }.arg( fontsPath ) );
  16.  
  17. if ( -1 != nsr && -1 != nsb && -1 != nsi && -1 != nsbi )
  18. {
  19. m_bFontsLoaded = true;
  20. }
  21. }
  22.  
  23. std::function<void()> loadCJKFonts = [=]()
  24. {
  25. int nsr = fontDB.addApplicationFont( QString{ "%1/NotoSansCJK-Regular.ttc" }.arg( fontsPath ) );
  26. int nsb = fontDB.addApplicationFont( QString{ "%1/NotoSansCJK-Bold.ttc" }.arg( fontsPath ) );
  27.  
  28. if ( -1 != nsr && -1 != nsb )
  29. {
  30. m_bCJKFontsLoaded = true;
  31. }
  32. };
  33.  
  34. // load CJK font only if language is Chinese or Japanese, cause it takes about 3.5 seconds to load on device
  35. // and about 18 on PC
  36. if ( !m_bCJKFontsLoaded && ( LanguageInfo::Japanese == newLang || LanguageInfo::ChineseTraditional == newLang
  37. || LanguageInfo::ChineseSimplified == newLang) )
  38. {
  39. if ( needLoadingDialog )
  40. {
  41. //! \todo: revert commented code when LoadingDialog will be implemented
  42. loadCJKFonts();
  43. // LoadingDialog* pDialog = new LoadingDialog{
  44. // //% "Language"
  45. // qtTrId( "id-application-language" ),
  46. // //% "Loading fonts"
  47. // qtTrId( "id-application-loading_fonts" ), loadCJKFonts };
  48. // connect( pDialog, &LoadingDialog::finished, pDialog, &LoadingDialog::deleteLater );
  49. // pDialog->show();
  50. }
  51. else
  52. {
  53. loadCJKFonts();
  54. }
  55. }
  56.  
  57. /*!
  58. * Setting up default application font.
  59. */
  60. QGuiApplication::setFont( QFont{ "Noto Sans" } );
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement