From c6545b4bfb6e245b2b020a3e31ca67d59017c4fb Mon Sep 17 00:00:00 2001 From: Rick Vogel Date: Mon, 19 Feb 2024 20:20:52 +0100 Subject: [PATCH 1/5] add fontconfig asserting and path --- src/controls/QskSkin.cpp | 10 ++++++++- support/CMakeLists.txt | 5 ++++- support/SkinnyNamespace.cpp | 41 +++++++++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/controls/QskSkin.cpp b/src/controls/QskSkin.cpp index 416f7a0a2..a3a2c700f 100644 --- a/src/controls/QskSkin.cpp +++ b/src/controls/QskSkin.cpp @@ -344,8 +344,16 @@ void QskSkin::completeFontTable() continue; } + #define QFONT_WEIGHT_MIN 1 + #if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + #define QFONT_WEIGHT_MAX 99 + #else + // https://codebrowser.dev/qt6/qtbase/src/gui/text/qfont_p.h.html#34 + #define QFONT_WEIGHT_MAX 1000 + #endif + int weight = normalFont.weight() + ( j - 2 ) * 100; - weight = qBound( 0, weight, 900 ); + weight = qBound( 0, weight, 99 ); auto font = normalFont; font.setWeight( static_cast< QFont::Weight >( weight ) ); diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 7d0054446..3b3a5a14e 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -55,7 +55,10 @@ if(HIDE_SYSTEM_FONTS) @ONLY NEWLINE_STYLE LF) target_compile_definitions(${target} - PRIVATE FONTCONFIG_FILE=${QSK_FONTCONF_FILE}) + PRIVATE + FONTCONFIG_FILE=${QSK_FONTCONF_FILE} + FONTCONFIG_PATH=${QSK_FONTCACHEDIR} + QSK_FONTCONFIG_ASSERT) endif() set_target_properties(${target} PROPERTIES FOLDER libs) diff --git a/support/SkinnyNamespace.cpp b/support/SkinnyNamespace.cpp index ec0d95bc4..56b6484f5 100644 --- a/support/SkinnyNamespace.cpp +++ b/support/SkinnyNamespace.cpp @@ -84,6 +84,8 @@ static bool pluginPath = initPluginPath(); #if defined( ENSURE_FONTS ) + #include + #if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) #include #include @@ -112,22 +114,43 @@ static bool pluginPath = initPluginPath(); if ( !qobject_cast< QGuiApplication* >( qApp ) ) return; // no fonts needed - #ifdef FONTCONFIG_FILE +#ifdef FONTCONFIG_FILE + { const char env[] = "FONTCONFIG_FILE"; if ( !qEnvironmentVariableIsSet( env ) ) qputenv( env, STRING( FONTCONFIG_FILE ) ); - #endif - - preloadFonts(); + } +#endif - /* - The default initialization in QskSkin sets up its font table - with using the application font for the default font role. - */ - QGuiApplication::setFont( QFont( "DejaVuSans", 12 ) ); +#ifdef FONTCONFIG_PATH + { + const char env[] = "FONTCONFIG_PATH"; + if ( !qEnvironmentVariableIsSet( env ) ) + qputenv( env, STRING( FONTCONFIG_PATH ) ); } #endif + preloadFonts(); + + /* + The default initialization in QskSkin sets up its font table + with using the application font for the default font role. + */ + QGuiApplication::setFont( QFont( "DejaVuSans", 12 ) ); + +#if ( defined( FONTCONFIG_FILE ) || defined( FONTCONFIG_PATH ) ) && defined( QSK_FONTCONFIG_ASSERT ) + const std::string expected = "Roboto"; + const std::string actual = QFontInfo( QFont( "Roboto" ) ).family().toStdString(); + const std::string message = QString( "Expected '%1' font to be available but instead got '%2'" ) + .arg( expected.c_str() ) + .arg( actual.c_str() ) + .toStdString(); + + Q_ASSERT_X( actual == expected, __func__, message.c_str() ); +#endif +} +#endif + Q_COREAPP_STARTUP_FUNCTION( initFonts ) void Skinny::changeSkin() From 0fcdc7fa3f8e7b46d9c655091492f0b40fd392d1 Mon Sep 17 00:00:00 2001 From: Rick Vogel Date: Mon, 19 Feb 2024 20:32:26 +0100 Subject: [PATCH 2/5] use qt version specific font weight boundaries --- src/controls/QskSkin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controls/QskSkin.cpp b/src/controls/QskSkin.cpp index a3a2c700f..aab355dbc 100644 --- a/src/controls/QskSkin.cpp +++ b/src/controls/QskSkin.cpp @@ -353,7 +353,7 @@ void QskSkin::completeFontTable() #endif int weight = normalFont.weight() + ( j - 2 ) * 100; - weight = qBound( 0, weight, 99 ); + weight = qBound( QFONT_WEIGHT_MIN, weight, QFONT_WEIGHT_MAX ); auto font = normalFont; font.setWeight( static_cast< QFont::Weight >( weight ) ); From 3f6006ec5fcf427d7b89e5b6b728b1f2a24c4dd9 Mon Sep 17 00:00:00 2001 From: Rick Vogel Date: Mon, 19 Feb 2024 20:49:24 +0100 Subject: [PATCH 3/5] simplify assertion --- support/SkinnyNamespace.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/support/SkinnyNamespace.cpp b/support/SkinnyNamespace.cpp index 56b6484f5..b6c27251d 100644 --- a/support/SkinnyNamespace.cpp +++ b/support/SkinnyNamespace.cpp @@ -139,14 +139,13 @@ static bool pluginPath = initPluginPath(); QGuiApplication::setFont( QFont( "DejaVuSans", 12 ) ); #if ( defined( FONTCONFIG_FILE ) || defined( FONTCONFIG_PATH ) ) && defined( QSK_FONTCONFIG_ASSERT ) - const std::string expected = "Roboto"; - const std::string actual = QFontInfo( QFont( "Roboto" ) ).family().toStdString(); - const std::string message = QString( "Expected '%1' font to be available but instead got '%2'" ) - .arg( expected.c_str() ) - .arg( actual.c_str() ) - .toStdString(); - - Q_ASSERT_X( actual == expected, __func__, message.c_str() ); + const QString expected = "Roboto"; + const QString actual = QFontInfo( QFont( expected ) ).family(); + const QString message = QString( "Expected '%1' font to be available but instead got '%2'" ) + .arg( expected ) + .arg( actual ); + + Q_ASSERT_X( actual == expected, __func__, message.toStdString().c_str() ); #endif } #endif From 0f8964fcfc26ee9b211a64ce6b9b4aa6d2021bae Mon Sep 17 00:00:00 2001 From: Rick Vogel Date: Mon, 19 Feb 2024 21:00:21 +0100 Subject: [PATCH 4/5] add support library to iot smoketest --- .github/workflows/cmake.yml | 4 ++-- support/SkinnyNamespace.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 7d0217442..7e3e68064 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -380,7 +380,7 @@ jobs: QT_DEBUG_PLUGINS: "1" run: | echo "starting iotdashboard" - DYLD_LIBRARY_PATH=./qskinny_install/lib:./qskinny_install/plugins/skins ./qskinny_build/examples/bin/iotdashboard.app/Contents/MacOS/iotdashboard -qwindowgeometry 1024x600+75+100 --screenshot ${{ matrix.config.screenshot_filename }} & + DYLD_LIBRARY_PATH=./qskinny_install/lib:./qskinny_install/plugins/skins:./qskinny_build/support ./qskinny_build/examples/bin/iotdashboard.app/Contents/MacOS/iotdashboard -qwindowgeometry 1024x600+75+100 --screenshot ${{ matrix.config.screenshot_filename }} & sleep 10 # TODO remove 'qskinny_build\skins\material3\Release' when skin install is fixed @@ -389,7 +389,7 @@ jobs: env: QT_DEBUG_PLUGINS: "1" run: | - $env:Path += ";./qskinny_install/bin;./qskinny_install/lib;./qskinny_install/plugins/skins;./qskinny_build/skins/material3/Release;./qskinny_build/skins/windows/Release;./qskinny_build/skins/squiek/Release" + $env:Path += ";./qskinny_install/bin;./qskinny_install/lib;./qskinny_install/plugins/skins;./qskinny_build/skins/material3/Release;./qskinny_build/skins/windows/Release;./qskinny_build/skins/squiek/Release;./qskinny_build/support" echo "starting iotdashboard" Start-Process qskinny_build\examples\bin\Release\iotdashboard.exe -ArgumentList "-qwindowgeometry 1024x600+0+0 --screenshot ${{ matrix.config.screenshot_filename }}" Start-Sleep -Seconds 10 diff --git a/support/SkinnyNamespace.cpp b/support/SkinnyNamespace.cpp index b6c27251d..546f87008 100644 --- a/support/SkinnyNamespace.cpp +++ b/support/SkinnyNamespace.cpp @@ -85,6 +85,7 @@ static bool pluginPath = initPluginPath(); #if defined( ENSURE_FONTS ) #include + #include #if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) #include @@ -119,6 +120,8 @@ static bool pluginPath = initPluginPath(); const char env[] = "FONTCONFIG_FILE"; if ( !qEnvironmentVariableIsSet( env ) ) qputenv( env, STRING( FONTCONFIG_FILE ) ); + + std::cout << "FONTCONFIG_FILE: " << qgetenv(env).toStdString() <<'\n'; } #endif @@ -127,6 +130,8 @@ static bool pluginPath = initPluginPath(); const char env[] = "FONTCONFIG_PATH"; if ( !qEnvironmentVariableIsSet( env ) ) qputenv( env, STRING( FONTCONFIG_PATH ) ); + + std::cout << "FONTCONFIG_PATH: " << qgetenv(env).toStdString() <<'\n'; } #endif From 247dbaa6c8777656a82d22668d1095a8d07268ba Mon Sep 17 00:00:00 2001 From: Rick Vogel Date: Mon, 19 Feb 2024 21:22:29 +0100 Subject: [PATCH 5/5] force assertion --- support/SkinnyNamespace.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support/SkinnyNamespace.cpp b/support/SkinnyNamespace.cpp index 546f87008..77976289c 100644 --- a/support/SkinnyNamespace.cpp +++ b/support/SkinnyNamespace.cpp @@ -143,7 +143,7 @@ static bool pluginPath = initPluginPath(); */ QGuiApplication::setFont( QFont( "DejaVuSans", 12 ) ); -#if ( defined( FONTCONFIG_FILE ) || defined( FONTCONFIG_PATH ) ) && defined( QSK_FONTCONFIG_ASSERT ) +// #if ( defined( FONTCONFIG_FILE ) || defined( FONTCONFIG_PATH ) ) && defined( QSK_FONTCONFIG_ASSERT ) const QString expected = "Roboto"; const QString actual = QFontInfo( QFont( expected ) ).family(); const QString message = QString( "Expected '%1' font to be available but instead got '%2'" ) @@ -151,7 +151,7 @@ static bool pluginPath = initPluginPath(); .arg( actual ); Q_ASSERT_X( actual == expected, __func__, message.toStdString().c_str() ); -#endif +// #endif } #endif