Minimize amount of code to rebuild when switching options

This commit is contained in:
Ilya Fedin 2023-09-22 04:22:15 +04:00 committed by John Preston
parent a33bd4e0a5
commit 68b43db05d
3 changed files with 14 additions and 12 deletions

View file

@ -33,6 +33,7 @@ PRIVATE
ui/colors.palette ui/colors.palette
emoji_suggestions/emoji_autocomplete.json emoji_suggestions/emoji_autocomplete.json
fonts/fonts.qrc
qt_conf/win.qrc qt_conf/win.qrc
ui/dpr/dpr_icon.cpp ui/dpr/dpr_icon.cpp
@ -298,8 +299,9 @@ PRIVATE
emoji_suggestions/emoji_suggestions_helper.h emoji_suggestions/emoji_suggestions_helper.h
) )
if (NOT DESKTOP_APP_USE_PACKAGED_FONTS) if (DESKTOP_APP_USE_PACKAGED_FONTS)
nice_target_sources(lib_ui ${src_loc} PRIVATE fonts/fonts.qrc) target_compile_definitions(lib_ui PRIVATE LIB_UI_USE_PACKAGED_FONTS)
remove_target_sources(lib_ui ${src_loc} fonts/fonts.qrc)
endif() endif()
if (WIN32) if (WIN32)

View file

@ -52,11 +52,11 @@ QFont ResolveFont(const QString &familyOverride, uint32 flags, int size) {
} else { } else {
result.setFamily(GetFontOverride(flags)); result.setFamily(GetFontOverride(flags));
if (bold) { if (bold) {
#ifdef DESKTOP_APP_USE_PACKAGED_FONTS #ifdef LIB_UI_USE_PACKAGED_FONTS
result.setWeight(QFont::DemiBold); result.setWeight(QFont::DemiBold);
#else // DESKTOP_APP_USE_PACKAGED_FONTS #else // LIB_UI_USE_PACKAGED_FONTS
result.setBold(true); result.setBold(true);
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS #endif // !LIB_UI_USE_PACKAGED_FONTS
if (flags & FontItalic) { if (flags & FontItalic) {
result.setStyleName("Semibold Italic"); result.setStyleName("Semibold Italic");

View file

@ -29,9 +29,9 @@ void style_InitFontsResource() {
#else // Q_OS_MAC #else // Q_OS_MAC
#ifndef DESKTOP_APP_USE_PACKAGED_FONTS #ifndef LIB_UI_USE_PACKAGED_FONTS
Q_INIT_RESOURCE(fonts); Q_INIT_RESOURCE(fonts);
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS #endif // !LIB_UI_USE_PACKAGED_FONTS
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
Q_INIT_RESOURCE(win); Q_INIT_RESOURCE(win);
#endif // Q_OS_WIN #endif // Q_OS_WIN
@ -127,7 +127,7 @@ enum {
FontTypesCount, FontTypesCount,
}; };
#ifndef DESKTOP_APP_USE_PACKAGED_FONTS #ifndef LIB_UI_USE_PACKAGED_FONTS
QString FontTypeFiles[FontTypesCount] = { QString FontTypeFiles[FontTypesCount] = {
"DAOpenSansRegular", "DAOpenSansRegular",
"DAOpenSansRegularItalic", "DAOpenSansRegularItalic",
@ -160,7 +160,7 @@ QString FontTypePersianFallback[FontTypesCount] = {
"DAVazirMedium", "DAVazirMedium",
"DAVazirMedium", "DAVazirMedium",
}; };
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS #endif // !LIB_UI_USE_PACKAGED_FONTS
int32 FontTypeFlags[FontTypesCount] = { int32 FontTypeFlags[FontTypesCount] = {
0, 0,
FontItalic, FontItalic,
@ -183,7 +183,7 @@ void StartFonts() {
style_InitFontsResource(); style_InitFontsResource();
#ifndef DESKTOP_APP_USE_PACKAGED_FONTS #ifndef LIB_UI_USE_PACKAGED_FONTS
[[maybe_unused]] bool areGood[FontTypesCount] = { false }; [[maybe_unused]] bool areGood[FontTypesCount] = { false };
for (auto i = 0; i != FontTypesCount; ++i) { for (auto i = 0; i != FontTypesCount; ++i) {
const auto file = FontTypeFiles[i]; const auto file = FontTypeFiles[i];
@ -227,11 +227,11 @@ void StartFonts() {
QFont::insertSubstitutions(name, list); QFont::insertSubstitutions(name, list);
} }
#endif // Q_OS_MAC #endif // Q_OS_MAC
#elif __has_include(<glib.h>) // !DESKTOP_APP_USE_PACKAGED_FONTS #elif __has_include(<glib.h>) // !LIB_UI_USE_PACKAGED_FONTS
g_warning( g_warning(
"Unable to load patched fonts with Qt workarounds, " "Unable to load patched fonts with Qt workarounds, "
"expect font issues."); "expect font issues.");
#endif // DESKTOP_APP_USE_PACKAGED_FONTS #endif // LIB_UI_USE_PACKAGED_FONTS
auto appFont = QApplication::font(); auto appFont = QApplication::font();
appFont.setStyleStrategy(QFont::PreferQuality); appFont.setStyleStrategy(QFont::PreferQuality);