diff --git a/.gitignore b/.gitignore index 96785c63..46d91daf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ rcc lib bin plugins +fontconfig qvg *.swp diff --git a/support/SkinnyFont.cpp b/support/SkinnyFont.cpp index 4018e768..0bcddaac 100644 --- a/support/SkinnyFont.cpp +++ b/support/SkinnyFont.cpp @@ -4,44 +4,35 @@ *****************************************************************************/ #include "SkinnyFont.h" -#include + #include -#include -#include #include +#include +#include -static void foolFontconfig() -{ - // as the examples are always using the same fonts, we can disable - // everything, that has to do with system fonts - - static QTemporaryDir dir; - - QString fontConfig = - "\n" - "\n" - "\n" - "\t%1\n" - "\t%2/cache\n" - "\n"; - fontConfig = fontConfig.arg( dir.path(), dir.path() ); - - QFile f( dir.path() + "/fonts.conf" ); - f.open( QIODevice::WriteOnly ); - f.write( fontConfig.toUtf8() ); - f.close(); - - qputenv( "FONTCONFIG_FILE", f.fileName().toUtf8() ); - - QFontDatabase(); -} +#define STRINGIFY(x) #x +#define STRING(x) STRINGIFY(x) void SkinnyFont::init( QGuiApplication* ) { - foolFontconfig(); +#ifdef FONTCONFIG_FILE + const char env[] = "FONTCONFIG_FILE"; + if ( !qEnvironmentVariableIsSet( env ) ) + qputenv( env, STRING( FONTCONFIG_FILE ) ); +#endif - QFontDatabase::addApplicationFont( ":/fonts/Roboto-Regular.ttf" ); - QFontDatabase::addApplicationFont( ":/fonts/DejaVuSans.ttf" ); + QElapsedTimer timer; + timer.start(); + + QFontDatabase(); + + const auto elapsed = timer.elapsed(); + + if ( elapsed > 20 ) + { + qWarning() << "Loading fonts needed" << elapsed << "ms."; + qWarning() << "Probably because of creating a font cache."; + } /* The default initialization in QskSkin sets up its font table diff --git a/support/fonts.conf.in b/support/fonts.conf.in new file mode 100644 index 00000000..ac65f704 --- /dev/null +++ b/support/fonts.conf.in @@ -0,0 +1,9 @@ + + + + + + FONTDIR + FONTCACHEDIR/cache + + diff --git a/support/fonts.qrc b/support/fonts.qrc deleted file mode 100644 index 1dbfeb54..00000000 --- a/support/fonts.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - fonts/DejaVuSans.ttf - fonts/Roboto-Regular.ttf - - diff --git a/support/fonts/NotoSansCJKsc-Regular.otf b/support/fonts/NotoSansCJKsc-Regular.otf new file mode 100644 index 00000000..741201b0 Binary files /dev/null and b/support/fonts/NotoSansCJKsc-Regular.otf differ diff --git a/support/support.pro b/support/support.pro index 93db3bd9..70d4a834 100644 --- a/support/support.pro +++ b/support/support.pro @@ -10,7 +10,9 @@ TARGET = qsktestsupport DESTDIR = $${QSK_OUT_ROOT}/lib QT += quick + CONFIG += ensure_skins +CONFIG += fontconfig contains(QSK_CONFIG, QskDll) { @@ -43,9 +45,6 @@ SOURCES += \ SkinnyShapeProvider.cpp \ SkinnyShortcut.cpp -RESOURCES += \ - fonts.qrc - DEFINES += PLUGIN_PATH=$$clean_path( $$QSK_PLUGIN_DIR ) ensure_skins { @@ -62,3 +61,26 @@ ensure_skins { LIBS *= -L$${QSK_PLUGIN_DIR}/skins -lsquiekskin -lmaterialskin } +fontconfig { + + QSK_FONTDIR=$${PWD}/fonts + QSK_FONTCACHEDIR=$${OUT_PWD}/fontconfig + QSK_FONTCONF_FILE=$${QSK_FONTCACHEDIR}/fonts.conf + + QSK_FONTCONF_DATA = "$$cat( $${PWD}/fonts.conf.in, false )" + QSK_FONTCONF_DATA = $$replace(QSK_FONTCONF_DATA, FONTCACHEDIR, $${QSK_FONTCACHEDIR} ) + QSK_FONTCONF_DATA = $$replace(QSK_FONTCONF_DATA, FONTDIR, $${QSK_FONTDIR} ) + write_file( $${QSK_FONTCONF_FILE}, QSK_FONTCONF_DATA ) + + DEFINES += FONTCONFIG_FILE=$$clean_path( $$QSK_FONTCONF_FILE ) + + linux { + + fontcache.target = $${QSK_FONTCACHEDIR}/cache + fontcache.depends = $${QSK_FONTCONF_FILE} + fontcache.commands = FONTCONFIG_FILE=$${QSK_FONTCONF_FILE} fc-cache -v + + QMAKE_EXTRA_TARGETS += fontcache + PRE_TARGETDEPS += $${QSK_FONTCACHEDIR}/cache + } +}