2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Fixed font changing

This commit is contained in:
RadRussianRus
2019-10-02 01:52:18 +03:00
parent 1c0f75bbf7
commit 52dfebcc8e
5 changed files with 46 additions and 7 deletions

View File

@@ -161,6 +161,18 @@ Application::~Application() {
}
void Application::run() {
if (!cMainFont().isEmpty()) {
style::internal::SetMainFont(cMainFont());
}
if (!cSemiboldFont().isEmpty()) {
style::internal::SetSemiboldFont(cSemiboldFont());
}
if (cSemiboldFontIsBold()) {
style::internal::SetSemiboldIsBold(cSemiboldFontIsBold());
}
if (!cMonospaceFont().isEmpty()) {
style::internal::SetMonospaceFont(cMonospaceFont());
}
style::internal::StartFonts();
ThirdParty::start();

View File

@@ -30,6 +30,7 @@ auto PaletteChanges = rpl::event_stream<>();
auto ShortAnimationRunning = rpl::variable<bool>(false);
auto RunningShortAnimations = 0;
auto ResolvedMonospaceFont = style::font();
QString CustomMonospaceFont;
std::vector<internal::ModuleBase*> &StyleModules() {
static auto result = std::vector<internal::ModuleBase*>();
@@ -52,8 +53,8 @@ void ResolveMonospaceFont() {
family = attempt;
}
};
if (!cMonospaceFont().isEmpty()) {
tryFont(cMonospaceFont());
if (!CustomMonospaceFont.isEmpty()) {
tryFont(CustomMonospaceFont);
}
tryFont("Consolas");
tryFont("Liberation Mono");
@@ -69,6 +70,10 @@ void ResolveMonospaceFont() {
} // namespace
void SetMonospaceFont(const QString &familyName) {
CustomMonospaceFont = familyName;
}
void registerModule(ModuleBase *module) {
StyleModules().push_back(module);
}

View File

@@ -26,6 +26,8 @@ public:
};
void SetMonospaceFont(const QString &familyName);
void registerModule(ModuleBase *module);
[[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under);

View File

@@ -76,8 +76,24 @@ bool Started = false;
QString OpenSansOverride;
QString OpenSansSemiboldOverride;
QString CustomMainFont;
QString CustomSemiboldFont;
bool CustomSemiboldIsBold = false;
} // namespace
void SetMainFont(const QString &familyName) {
CustomMainFont = familyName;
}
void SetSemiboldFont(const QString &familyName) {
CustomSemiboldFont = familyName;
}
void SetSemiboldIsBold(bool isBold) {
CustomSemiboldIsBold = isBold;
}
void StartFonts() {
if (Started) {
return;
@@ -119,11 +135,11 @@ void StartFonts() {
QFont::insertSubstitutions("Open Sans Semibold", list);
#endif // Q_OS_WIN || Q_OS_MAC
if (!cMainFont().isEmpty() && ValidateFont(cMainFont())) {
OpenSansOverride = cMainFont();
if (!CustomMainFont.isEmpty() && ValidateFont(CustomMainFont)) {
OpenSansOverride = CustomMainFont;
}
if (!cSemiboldFont().isEmpty() && ValidateFont(cSemiboldFont())) {
OpenSansSemiboldOverride = cSemiboldFont();
if (!CustomSemiboldFont.isEmpty() && ValidateFont(CustomSemiboldFont)) {
OpenSansSemiboldOverride = CustomSemiboldFont;
}
}
@@ -169,7 +185,7 @@ FontData::FontData(int size, uint32 flags, int family, Font *other)
f.setPixelSize(size);
if (_flags & FontBold) {
f.setBold(true);
} else if (fontFamilies[family] == "Open Sans Semibold" && cSemiboldFontIsBold()) {
} else if (fontFamilies[family] == "Open Sans Semibold" && CustomSemiboldIsBold) {
f.setBold(true);
}
f.setItalic(_flags & FontItalic);

View File

@@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace style {
namespace internal {
void SetMainFont(const QString &familyName);
void SetSemiboldFont(const QString &familyName);
void SetSemiboldIsBold(bool isBold);
void StartFonts();
[[nodiscard]] QString GetFontOverride(const QString &familyName);