diff --git a/changelog/next.md b/changelog/next.md index b430a27..95de5dc 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -43,6 +43,8 @@ set shell id. - Added `QS_DISABLE_CRASH_HANDLER` environment variable to disable crash handling. - Added `QS_CRASHREPORT_URL` environment variable to allow overriding the crash reporter link. - Added `AppId` pragma and `QS_APP_ID` environment variable to allow overriding the desktop application ID. +- Added `DropExpensiveFonts` pragma which avoids loading fonts which may cause lag and excessive memory usage if many variants are used. +- Unrecognized pragmas are no longer a hard error for future backward compatibility. ## Bug Fixes diff --git a/src/launch/launch.cpp b/src/launch/launch.cpp index 0f5b090..de85956 100644 --- a/src/launch/launch.cpp +++ b/src/launch/launch.cpp @@ -77,6 +77,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio QString iconTheme = qEnvironmentVariable("QS_ICON_THEME"); QHash envOverrides; QString appId = qEnvironmentVariable("QS_APP_ID"); + bool dropExpensiveFonts = false; QString dataDir; QString stateDir; QString cacheDir; @@ -92,6 +93,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio else if (pragma == "NativeTextRendering") pragmas.nativeTextRendering = true; else if (pragma == "IgnoreSystemSettings") pragmas.desktopSettingsAware = false; else if (pragma == "RespectSystemStyle") pragmas.useSystemStyle = true; + else if (pragma == "DropExpensiveFonts") pragmas.dropExpensiveFonts = true; else if (pragma.startsWith("IconTheme ")) pragmas.iconTheme = pragma.sliced(10); else if (pragma.startsWith("Env ")) { auto envPragma = pragma.sliced(4); @@ -116,8 +118,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio } else if (pragma.startsWith("CacheDir ")) { pragmas.cacheDir = pragma.sliced(9).trimmed(); } else { - qCritical() << "Unrecognized pragma" << pragma; - return -1; + qWarning() << "Unrecognized pragma" << pragma; } } else if (line.startsWith("import")) break; } @@ -168,6 +169,46 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio Common::INITIAL_ENVIRONMENT = QProcessEnvironment::systemEnvironment(); + if (pragmas.dropExpensiveFonts) { + if (auto* runDir = QsPaths::instance()->instanceRunDir()) { + auto baseConfigPath = qEnvironmentVariable("FONTCONFIG_FILE"); + if (baseConfigPath.isEmpty()) baseConfigPath = "/etc/fonts/fonts.conf"; + + auto filterPath = runDir->filePath("fonts-override.conf"); + auto filterFile = QFile(filterPath); + if (filterFile.open(QFile::WriteOnly | QFile::Truncate | QFile::Text)) { + auto filterTemplate = QStringLiteral(R"( + + + %1 + + + + + woff + + + + + woff2 + + + + + +)"); + + QTextStream(&filterFile) << filterTemplate.arg(baseConfigPath); + filterFile.close(); + qputenv("FONTCONFIG_FILE", filterPath.toUtf8()); + } else { + qCritical() << "Could not write fontconfig filter to" << filterPath; + } + } else { + qCritical() << "Could not create fontconfig filter: instance run directory unavailable"; + } + } + if (!pragmas.useSystemStyle) { qunsetenv("QT_STYLE_OVERRIDE"); qputenv("QT_QUICK_CONTROLS_STYLE", "Fusion");