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