Noto fonts added needed for Chinese symbols + fontconfig setup changed

to use a fontconfig cache
This commit is contained in:
Uwe Rathmann 2018-03-13 20:55:42 +01:00
parent ee3ac13e36
commit 5b17788768
6 changed files with 57 additions and 40 deletions

1
.gitignore vendored
View File

@ -6,5 +6,6 @@ rcc
lib lib
bin bin
plugins plugins
fontconfig
qvg qvg
*.swp *.swp

View File

@ -4,44 +4,35 @@
*****************************************************************************/ *****************************************************************************/
#include "SkinnyFont.h" #include "SkinnyFont.h"
#include <QtGlobal>
#include <QFontDatabase> #include <QFontDatabase>
#include <QTemporaryDir>
#include <QFile>
#include <QGuiApplication> #include <QGuiApplication>
#include <QElapsedTimer>
#include <QDebug>
static void foolFontconfig() #define STRINGIFY(x) #x
{ #define STRING(x) STRINGIFY(x)
// 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 =
"<?xml version=\"1.0\"?>\n"
"<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n"
"<fontconfig>\n"
"\t<dir>%1</dir>\n"
"\t<cachedir>%2/cache</cachedir>\n"
"</fontconfig>\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();
}
void SkinnyFont::init( QGuiApplication* ) 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" ); QElapsedTimer timer;
QFontDatabase::addApplicationFont( ":/fonts/DejaVuSans.ttf" ); 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 The default initialization in QskSkin sets up its font table

9
support/fonts.conf.in Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>FONTDIR</dir>
<cachedir>FONTCACHEDIR/cache</cachedir>
</fontconfig>

View File

@ -1,6 +0,0 @@
<RCC>
<qresource prefix="/">
<file>fonts/DejaVuSans.ttf</file>
<file>fonts/Roboto-Regular.ttf</file>
</qresource>
</RCC>

Binary file not shown.

View File

@ -10,7 +10,9 @@ TARGET = qsktestsupport
DESTDIR = $${QSK_OUT_ROOT}/lib DESTDIR = $${QSK_OUT_ROOT}/lib
QT += quick QT += quick
CONFIG += ensure_skins CONFIG += ensure_skins
CONFIG += fontconfig
contains(QSK_CONFIG, QskDll) { contains(QSK_CONFIG, QskDll) {
@ -43,9 +45,6 @@ SOURCES += \
SkinnyShapeProvider.cpp \ SkinnyShapeProvider.cpp \
SkinnyShortcut.cpp SkinnyShortcut.cpp
RESOURCES += \
fonts.qrc
DEFINES += PLUGIN_PATH=$$clean_path( $$QSK_PLUGIN_DIR ) DEFINES += PLUGIN_PATH=$$clean_path( $$QSK_PLUGIN_DIR )
ensure_skins { ensure_skins {
@ -62,3 +61,26 @@ ensure_skins {
LIBS *= -L$${QSK_PLUGIN_DIR}/skins -lsquiekskin -lmaterialskin 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
}
}