Get font settings via Ui Integration
This commit is contained in:
parent
0710f40dd1
commit
505c1bea18
7 changed files with 52 additions and 36 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
//
|
//
|
||||||
#include "ui/integration.h"
|
#include "ui/integration.h"
|
||||||
|
|
||||||
|
#include "ui/style/style_core_custom_font.h"
|
||||||
#include "ui/text/text_entity.h"
|
#include "ui/text/text_entity.h"
|
||||||
#include "ui/basic_click_handlers.h"
|
#include "ui/basic_click_handlers.h"
|
||||||
|
|
||||||
|
|
@ -36,6 +37,10 @@ void Integration::textActionsUpdated() {
|
||||||
void Integration::activationFromTopPanel() {
|
void Integration::activationFromTopPanel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
style::CustomFontSettings Integration::fontSettings() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool Integration::screenIsLocked() {
|
bool Integration::screenIsLocked() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ struct TextParseOptions;
|
||||||
class ClickHandler;
|
class ClickHandler;
|
||||||
struct EntityLinkData;
|
struct EntityLinkData;
|
||||||
|
|
||||||
|
namespace style {
|
||||||
|
struct CustomFontSettings;
|
||||||
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace Emoji {
|
namespace Emoji {
|
||||||
class One;
|
class One;
|
||||||
|
|
@ -40,6 +44,8 @@ public:
|
||||||
virtual void textActionsUpdated();
|
virtual void textActionsUpdated();
|
||||||
virtual void activationFromTopPanel();
|
virtual void activationFromTopPanel();
|
||||||
|
|
||||||
|
virtual style::CustomFontSettings fontSettings();
|
||||||
|
|
||||||
[[nodiscard]] virtual bool screenIsLocked();
|
[[nodiscard]] virtual bool screenIsLocked();
|
||||||
[[nodiscard]] virtual QString timeFormat();
|
[[nodiscard]] virtual QString timeFormat();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "ui/style/style_core_custom_font.h"
|
#include "ui/style/style_core_custom_font.h"
|
||||||
|
|
||||||
#include "ui/style/style_core_font.h"
|
#include "ui/style/style_core_font.h"
|
||||||
|
#include "ui/integration.h"
|
||||||
|
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
|
||||||
|
|
@ -46,24 +47,25 @@ QFont ResolveFont(uint32 flags, int size) {
|
||||||
const auto point = good.isEmpty() ? size : good.front();
|
const auto point = good.isEmpty() ? size : good.front();
|
||||||
result = Database.font(custom.family, custom.style, point);
|
result = Database.font(custom.family, custom.style, point);
|
||||||
} else {
|
} else {
|
||||||
if (!UseSystemFont || !overrideIsEmpty) {
|
const auto fontSettings = Ui::Integration::Instance().fontSettings();
|
||||||
|
if (!fontSettings.useSystemFont || !overrideIsEmpty) {
|
||||||
result.setFamily(GetFontOverride(flags));
|
result.setFamily(GetFontOverride(flags));
|
||||||
}
|
}
|
||||||
if (bold) {
|
if (bold) {
|
||||||
if (CustomSemiboldIsBold) {
|
if (fontSettings.semiboldIsBold) {
|
||||||
result.setBold(true);
|
result.setBold(true);
|
||||||
#ifdef DESKTOP_APP_USE_PACKAGED_FONTS
|
#ifdef DESKTOP_APP_USE_PACKAGED_FONTS
|
||||||
} else {
|
} else {
|
||||||
result.setWeight(QFont::DemiBold);
|
result.setWeight(QFont::DemiBold);
|
||||||
#else // DESKTOP_APP_USE_PACKAGED_FONTS
|
#else // DESKTOP_APP_USE_PACKAGED_FONTS
|
||||||
} else if (UseSystemFont) {
|
} else if (fontSettings.useSystemFont) {
|
||||||
result.setWeight(QFont::DemiBold);
|
result.setWeight(QFont::DemiBold);
|
||||||
} else {
|
} else {
|
||||||
result.setBold(true);
|
result.setBold(true);
|
||||||
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS
|
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CustomSemiboldIsBold) {
|
if (!fontSettings.semiboldIsBold) {
|
||||||
if (flags & FontItalic) {
|
if (flags & FontItalic) {
|
||||||
result.setStyleName("Semibold Italic");
|
result.setStyleName("Semibold Italic");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,15 @@ struct CustomFont {
|
||||||
QString style;
|
QString style;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CustomFontSettings {
|
||||||
|
QString mainFont;
|
||||||
|
QString semiboldFont;
|
||||||
|
QString monospaceFont;
|
||||||
|
bool semiboldIsBold = false;
|
||||||
|
bool useSystemFont = false;
|
||||||
|
bool useOriginalMetrics = false;
|
||||||
|
};
|
||||||
|
|
||||||
inline bool operator==(const CustomFont &a, const CustomFont &b) {
|
inline bool operator==(const CustomFont &a, const CustomFont &b) {
|
||||||
return (a.family == b.family) && (a.style == b.style);
|
return (a.family == b.family) && (a.style == b.style);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,13 +179,6 @@ QString Overrides[FontTypesCount];
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
QString CustomMainFont;
|
|
||||||
QString CustomSemiboldFont;
|
|
||||||
QString CustomMonospaceFont;
|
|
||||||
bool CustomSemiboldIsBold = false;
|
|
||||||
bool UseSystemFont = false;
|
|
||||||
bool UseOriginalMetrics = false;
|
|
||||||
|
|
||||||
void StartFonts() {
|
void StartFonts() {
|
||||||
if (Started) {
|
if (Started) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -194,8 +187,10 @@ void StartFonts() {
|
||||||
|
|
||||||
style_InitFontsResource();
|
style_InitFontsResource();
|
||||||
|
|
||||||
|
const auto fontSettings = Ui::Integration::Instance().fontSettings();
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_USE_PACKAGED_FONTS
|
#ifndef DESKTOP_APP_USE_PACKAGED_FONTS
|
||||||
if (!UseSystemFont) {
|
if (!fontSettings.useSystemFont) {
|
||||||
bool areGood[FontTypesCount] = { false };
|
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];
|
||||||
|
|
@ -242,18 +237,18 @@ void StartFonts() {
|
||||||
}
|
}
|
||||||
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS
|
#endif // !DESKTOP_APP_USE_PACKAGED_FONTS
|
||||||
|
|
||||||
if (!CustomMainFont.isEmpty() && ValidateFont(CustomMainFont)) {
|
if (!fontSettings.mainFont.isEmpty() && ValidateFont(fontSettings.mainFont)) {
|
||||||
Overrides[FontTypeRegular] = CustomMainFont;
|
Overrides[FontTypeRegular] = fontSettings.mainFont;
|
||||||
Overrides[FontTypeRegularItalic] = CustomMainFont;
|
Overrides[FontTypeRegularItalic] = fontSettings.mainFont;
|
||||||
Overrides[FontTypeBold] = CustomMainFont;
|
Overrides[FontTypeBold] = fontSettings.mainFont;
|
||||||
Overrides[FontTypeBoldItalic] = CustomMainFont;
|
Overrides[FontTypeBoldItalic] = fontSettings.mainFont;
|
||||||
}
|
}
|
||||||
if (!CustomSemiboldFont.isEmpty() && ValidateFont(CustomSemiboldFont)) {
|
if (!fontSettings.semiboldFont.isEmpty() && ValidateFont(fontSettings.semiboldFont)) {
|
||||||
Overrides[FontTypeSemibold] = CustomSemiboldFont;
|
Overrides[FontTypeSemibold] = fontSettings.semiboldFont;
|
||||||
Overrides[FontTypeSemiboldItalic] = CustomSemiboldFont;
|
Overrides[FontTypeSemiboldItalic] = fontSettings.semiboldFont;
|
||||||
} else if (!CustomMainFont.isEmpty() && ValidateFont(CustomMainFont)) {
|
} else if (fontSettings.mainFont.isEmpty() && ValidateFont(fontSettings.mainFont)) {
|
||||||
Overrides[FontTypeSemibold] = CustomMainFont;
|
Overrides[FontTypeSemibold] = fontSettings.mainFont;
|
||||||
Overrides[FontTypeSemiboldItalic] = CustomMainFont;
|
Overrides[FontTypeSemiboldItalic] = fontSettings.mainFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto appFont = QApplication::font();
|
auto appFont = QApplication::font();
|
||||||
|
|
@ -288,8 +283,10 @@ QString GetFontOverride(int32 flags) {
|
||||||
|
|
||||||
QString MonospaceFont() {
|
QString MonospaceFont() {
|
||||||
static const auto family = [&]() -> QString {
|
static const auto family = [&]() -> QString {
|
||||||
if (TryFont(CustomMonospaceFont)) {
|
const auto fontSettings = Ui::Integration::Instance().fontSettings();
|
||||||
return CustomMonospaceFont;
|
|
||||||
|
if (TryFont(fontSettings.monospaceFont)) {
|
||||||
|
return fontSettings.monospaceFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto manual = ManualMonospaceFont();
|
const auto manual = ManualMonospaceFont();
|
||||||
|
|
@ -304,7 +301,7 @@ QString MonospaceFont() {
|
||||||
const auto useSystem = manual.isEmpty()
|
const auto useSystem = manual.isEmpty()
|
||||||
|| (metrics.horizontalAdvance(QChar('i')) == metrics.horizontalAdvance(QChar('W')));
|
|| (metrics.horizontalAdvance(QChar('i')) == metrics.horizontalAdvance(QChar('W')));
|
||||||
#endif // Q_OS_WIN || Q_OS_MAC
|
#endif // Q_OS_WIN || Q_OS_MAC
|
||||||
return (useSystem || UseSystemFont) ? system : manual;
|
return (useSystem || fontSettings.useSystemFont) ? system : manual;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
return family;
|
return family;
|
||||||
|
|
@ -340,7 +337,8 @@ FontData::FontData(int size, uint32 flags, int family, Font *other)
|
||||||
}
|
}
|
||||||
modified[_flags] = Font(this);
|
modified[_flags] = Font(this);
|
||||||
|
|
||||||
if (UseOriginalMetrics && !(_flags & FontMonospace)) {
|
const auto fontSettings = Ui::Integration::Instance().fontSettings();
|
||||||
|
if (fontSettings.useOriginalMetrics && !(_flags & FontMonospace)) {
|
||||||
const auto mOrig = GetFontMetrics(size);
|
const auto mOrig = GetFontMetrics(size);
|
||||||
|
|
||||||
height = mOrig.height();
|
height = mOrig.height();
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,6 @@
|
||||||
namespace style {
|
namespace style {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
extern QString CustomMainFont;
|
|
||||||
extern QString CustomSemiboldFont;
|
|
||||||
extern QString CustomMonospaceFont;
|
|
||||||
extern bool CustomSemiboldIsBold;
|
|
||||||
extern bool UseSystemFont;
|
|
||||||
extern bool UseOriginalMetrics;
|
|
||||||
|
|
||||||
void StartFonts();
|
void StartFonts();
|
||||||
[[nodiscard]] QString GetPossibleEmptyOverride(int32 flags = 0);
|
[[nodiscard]] QString GetPossibleEmptyOverride(int32 flags = 0);
|
||||||
[[nodiscard]] QString GetFontOverride(int32 flags = 0);
|
[[nodiscard]] QString GetFontOverride(int32 flags = 0);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "ui/text/text.h"
|
#include "ui/text/text.h"
|
||||||
#include "ui/emoji_config.h"
|
#include "ui/emoji_config.h"
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
|
#include "ui/style/style_core_custom_font.h"
|
||||||
#include "base/openssl_help.h"
|
#include "base/openssl_help.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "emoji_suggestions_helper.h"
|
#include "emoji_suggestions_helper.h"
|
||||||
|
|
@ -1306,7 +1307,8 @@ InputField::InputField(
|
||||||
_inner->viewport()->setAutoFillBackground(false);
|
_inner->viewport()->setAutoFillBackground(false);
|
||||||
|
|
||||||
_inner->setContentsMargins(0, 0, 0, 0);
|
_inner->setContentsMargins(0, 0, 0, 0);
|
||||||
if (style::internal::UseOriginalMetrics) {
|
const auto fontSettings = Integration::Instance().fontSettings();
|
||||||
|
if (fontSettings.useOriginalMetrics) {
|
||||||
const auto heightDelta = (_st.font->height - _st.font->m.height());
|
const auto heightDelta = (_st.font->height - _st.font->m.height());
|
||||||
const auto topMargin = (_st.font->ascent - _st.font->m.ascent())
|
const auto topMargin = (_st.font->ascent - _st.font->m.ascent())
|
||||||
+ (heightDelta ? heightDelta / 2 : 0);
|
+ (heightDelta ? heightDelta / 2 : 0);
|
||||||
|
|
@ -1721,7 +1723,8 @@ void InputField::paintEvent(QPaintEvent *e) {
|
||||||
auto r = rect().marginsRemoved(_st.textMargins + _st.placeholderMargins);
|
auto r = rect().marginsRemoved(_st.textMargins + _st.placeholderMargins);
|
||||||
r.moveLeft(r.left() + placeholderLeft);
|
r.moveLeft(r.left() + placeholderLeft);
|
||||||
if (style::RightToLeft()) r.moveLeft(width() - r.left() - r.width());
|
if (style::RightToLeft()) r.moveLeft(width() - r.left() - r.width());
|
||||||
if (style::internal::UseOriginalMetrics) {
|
const auto fontSettings = Integration::Instance().fontSettings();
|
||||||
|
if (fontSettings.useOriginalMetrics) {
|
||||||
if (_mode == Mode::SingleLine) {
|
if (_mode == Mode::SingleLine) {
|
||||||
const auto heightDelta = (_st.placeholderFont->height - _st.placeholderFont->m.height());
|
const auto heightDelta = (_st.placeholderFont->height - _st.placeholderFont->m.height());
|
||||||
const auto topMargin = (_st.placeholderFont->ascent - _st.placeholderFont->m.ascent())
|
const auto topMargin = (_st.placeholderFont->ascent - _st.placeholderFont->m.ascent())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue