diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 584636fea..67d505718 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -518,6 +518,21 @@ void Application::switchTestMode() { App::restart(); } +void Application::switchFreeType() { + if (cUseFreeType()) { + QFile(cWorkingDir() + qsl("tdata/withfreetype")).remove(); + cSetUseFreeType(false); + } else { + QFile f(cWorkingDir() + qsl("tdata/withfreetype")); + if (f.open(QIODevice::WriteOnly)) { + f.write("1"); + f.close(); + } + cSetUseFreeType(true); + } + App::restart(); +} + void Application::writeInstallBetaVersionsSetting() { _launcher->writeInstallBetaVersionsSetting(); } diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index f2643fcbe..b4cf4c11d 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -215,6 +215,7 @@ public: void switchDebugMode(); void switchTestMode(); + void switchFreeType(); void writeInstallBetaVersionsSetting(); void call_handleUnreadCounterUpdate(); diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 19d9c3bbf..1d04386ee 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -34,26 +34,47 @@ private: static constexpr auto kForwardArgumentCount = 1; int _count = 0; - char *_arguments[kForwardArgumentCount + 1] = { nullptr }; + std::vector _owned; + std::vector _arguments; + + void pushArgument(const char *text); }; FilteredCommandLineArguments::FilteredCommandLineArguments( int argc, - char **argv) -: _count(std::clamp(argc, 0, kForwardArgumentCount)) { + char **argv) { // For now just pass only the first argument, the executable path. - for (auto i = 0; i != _count; ++i) { - _arguments[i] = argv[i]; + for (auto i = 0; i != kForwardArgumentCount; ++i) { + pushArgument(argv[i]); } + +#if defined Q_OS_WIN || defined Q_OS_MAC + if (cUseFreeType()) { + pushArgument("-platform"); +#ifdef Q_OS_WIN + pushArgument("windows:fontengine=freetype"); +#else // Q_OS_WIN + pushArgument("cocoa:fontengine=freetype"); +#endif // !Q_OS_WIN + } +#endif // Q_OS_WIN || Q_OS_MAC + + pushArgument(nullptr); } int &FilteredCommandLineArguments::count() { + _count = _arguments.size() - 1; return _count; } char **FilteredCommandLineArguments::values() { - return _arguments; + return _arguments.data(); +} + +void FilteredCommandLineArguments::pushArgument(const char *text) { + _owned.emplace_back(text); + _arguments.push_back(_owned.back().data()); } QString DebugModeSettingPath() { @@ -82,6 +103,12 @@ void ComputeTestMode() { } } +void ComputeFreeType() { + if (QFile(cWorkingDir() + qsl("tdata/withfreetype")).exists()) { + cSetUseFreeType(true); + } +} + QString InstallBetaVersionsSettingPath() { return cWorkingDir() + qsl("tdata/devversion"); } @@ -301,6 +328,7 @@ void Launcher::workingFolderReady() { ComputeTestMode(); ComputeDebugMode(); + ComputeFreeType(); ComputeInstallBetaVersions(); ComputeInstallationTag(); } @@ -382,6 +410,7 @@ void Launcher::processArguments() { auto parseMap = std::map { { "-testmode" , KeyFormat::NoValues }, { "-debug" , KeyFormat::NoValues }, + { "-freetype" , KeyFormat::NoValues }, { "-many" , KeyFormat::NoValues }, { "-key" , KeyFormat::OneValue }, { "-autostart" , KeyFormat::NoValues }, @@ -423,6 +452,7 @@ void Launcher::processArguments() { SetUpdaterDisabledAtStartup(); } gTestMode = parseResult.contains("-testmode"); + gUseFreeType = parseResult.contains("-freetype"); Logs::SetDebugEnabled(parseResult.contains("-debug")); gManyInstance = parseResult.contains("-many"); gKeyFile = parseResult.value("-key", {}).join(QString()).toLower(); diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 1052fc7d1..3eddc2f80 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -39,6 +39,7 @@ bool gStartInTray = false; bool gAutoStart = false; bool gSendToMenu = false; bool gUseExternalVideoPlayer = false; +bool gUseFreeType = false; bool gAutoUpdate = true; TWindowPos gWindowPos; LaunchMode gLaunchMode = LaunchModeNormal; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index b33e80119..940752d79 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -42,6 +42,7 @@ DeclareSetting(bool, StartMinimized); DeclareSetting(bool, StartInTray); DeclareSetting(bool, SendToMenu); DeclareSetting(bool, UseExternalVideoPlayer); +DeclareSetting(bool, UseFreeType); enum LaunchMode { LaunchModeNormal = 0, LaunchModeAutoStart, diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index bb965a89d..c4f20a7b1 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -126,6 +126,21 @@ auto GenerateCodes() { codes.emplace(qsl("export"), [](SessionController *window) { window->session().data().startExport(); }); +#if defined Q_OS_WIN || defined Q_OS_MAC + codes.emplace(qsl("freetype"), [](SessionController *window) { + auto text = cUseFreeType() +#ifdef Q_OS_WIN + ? qsl("Switch font engine to GDI?") +#else // Q_OS_WIN + ? qsl("Switch font engine to Cocoa?") +#endif // !Q_OS_WIN + : qsl("Switch font engine to FreeType?"); + + Ui::show(Box(text, [] { + Core::App().switchFreeType(); + })); + }); +#endif // Q_OS_WIN || Q_OS_MAC auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter(); auto audioKeys = {