@@ -77,6 +77,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
7777 QString iconTheme = qEnvironmentVariable(" QS_ICON_THEME" );
7878 QHash<QString, QString> envOverrides;
7979 QString appId = qEnvironmentVariable(" QS_APP_ID" );
80+ bool dropExpensiveFonts = false ;
8081 QString dataDir;
8182 QString stateDir;
8283 QString cacheDir;
@@ -92,6 +93,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
9293 else if (pragma == " NativeTextRendering" ) pragmas.nativeTextRendering = true ;
9394 else if (pragma == " IgnoreSystemSettings" ) pragmas.desktopSettingsAware = false ;
9495 else if (pragma == " RespectSystemStyle" ) pragmas.useSystemStyle = true ;
96+ else if (pragma == " DropExpensiveFonts" ) pragmas.dropExpensiveFonts = true ;
9597 else if (pragma.startsWith (" IconTheme " )) pragmas.iconTheme = pragma.sliced (10 );
9698 else if (pragma.startsWith (" Env " )) {
9799 auto envPragma = pragma.sliced (4 );
@@ -116,8 +118,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
116118 } else if (pragma.startsWith (" CacheDir " )) {
117119 pragmas.cacheDir = pragma.sliced (9 ).trimmed ();
118120 } else {
119- qCritical () << " Unrecognized pragma" << pragma;
120- return -1 ;
121+ qWarning () << " Unrecognized pragma" << pragma;
121122 }
122123 } else if (line.startsWith (" import" )) break ;
123124 }
@@ -168,6 +169,46 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
168169
169170 Common::INITIAL_ENVIRONMENT = QProcessEnvironment::systemEnvironment ();
170171
172+ if (pragmas.dropExpensiveFonts ) {
173+ if (auto * runDir = QsPaths::instance ()->instanceRunDir ()) {
174+ auto baseConfigPath = qEnvironmentVariable (" FONTCONFIG_FILE" );
175+ if (baseConfigPath.isEmpty ()) baseConfigPath = " /etc/fonts/fonts.conf" ;
176+
177+ auto filterPath = runDir->filePath (" fonts-override.conf" );
178+ auto filterFile = QFile (filterPath);
179+ if (filterFile.open (QFile::WriteOnly | QFile::Truncate | QFile::Text)) {
180+ auto filterTemplate = QStringLiteral (R"( <?xml version="1.0"?>
181+ <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
182+ <fontconfig>
183+ <include ignore_missing="no">%1</include>
184+ <selectfont>
185+ <rejectfont>
186+ <pattern>
187+ <patelt name="fontwrapper">
188+ <string>woff</string>
189+ </patelt>
190+ </pattern>
191+ <pattern>
192+ <patelt name="fontwrapper">
193+ <string>woff2</string>
194+ </patelt>
195+ </pattern>
196+ </rejectfont>
197+ </selectfont>
198+ </fontconfig>
199+ )" );
200+
201+ QTextStream (&filterFile) << filterTemplate.arg (baseConfigPath);
202+ filterFile.close ();
203+ qputenv (" FONTCONFIG_FILE" , filterPath.toUtf8 ());
204+ } else {
205+ qCritical () << " Could not write fontconfig filter to" << filterPath;
206+ }
207+ } else {
208+ qCritical () << " Could not create fontconfig filter: instance run directory unavailable" ;
209+ }
210+ }
211+
171212 if (!pragmas.useSystemStyle ) {
172213 qunsetenv (" QT_STYLE_OVERRIDE" );
173214 qputenv (" QT_QUICK_CONTROLS_STYLE" , " Fusion" );
0 commit comments