Allow to set custom font before starting
This commit is contained in:
parent
c68dceb189
commit
b445c55444
4 changed files with 43 additions and 2 deletions
|
|
@ -29,6 +29,7 @@ auto PaletteChanges = rpl::event_stream<>();
|
||||||
auto ShortAnimationRunning = rpl::variable<bool>(false);
|
auto ShortAnimationRunning = rpl::variable<bool>(false);
|
||||||
auto RunningShortAnimations = 0;
|
auto RunningShortAnimations = 0;
|
||||||
auto ResolvedMonospaceFont = style::font();
|
auto ResolvedMonospaceFont = style::font();
|
||||||
|
QString CustomMonospaceFont;
|
||||||
|
|
||||||
std::vector<internal::ModuleBase*> &StyleModules() {
|
std::vector<internal::ModuleBase*> &StyleModules() {
|
||||||
static auto result = std::vector<internal::ModuleBase*>();
|
static auto result = std::vector<internal::ModuleBase*>();
|
||||||
|
|
@ -51,6 +52,9 @@ void ResolveMonospaceFont() {
|
||||||
family = attempt;
|
family = attempt;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (!CustomMonospaceFont.isEmpty()) {
|
||||||
|
tryFont(CustomMonospaceFont);
|
||||||
|
}
|
||||||
tryFont("Consolas");
|
tryFont("Consolas");
|
||||||
tryFont("Liberation Mono");
|
tryFont("Liberation Mono");
|
||||||
tryFont("Menlo");
|
tryFont("Menlo");
|
||||||
|
|
@ -65,6 +69,10 @@ void ResolveMonospaceFont() {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void SetMonospaceFont(const QString &familyName) {
|
||||||
|
CustomMonospaceFont = familyName;
|
||||||
|
}
|
||||||
|
|
||||||
void registerModule(ModuleBase *module) {
|
void registerModule(ModuleBase *module) {
|
||||||
StyleModules().push_back(module);
|
StyleModules().push_back(module);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SetMonospaceFont(const QString &familyName);
|
||||||
|
|
||||||
void registerModule(ModuleBase *module);
|
void registerModule(ModuleBase *module);
|
||||||
|
|
||||||
[[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under);
|
[[nodiscard]] QColor EnsureContrast(const QColor &over, const QColor &under);
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,24 @@ QString FontTypeWindowsFallback[FontTypesCount] = {
|
||||||
bool Started = false;
|
bool Started = false;
|
||||||
QString Overrides[FontTypesCount];
|
QString Overrides[FontTypesCount];
|
||||||
|
|
||||||
|
QString CustomMainFont;
|
||||||
|
QString CustomSemiboldFont;
|
||||||
|
bool CustomSemiboldIsBold = false;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void SetMainFont(const QString &familyName) {
|
||||||
|
CustomMainFont = familyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetSemiboldFont(const QString &familyName) {
|
||||||
|
CustomSemiboldFont = familyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetSemiboldIsBold(bool isBold) {
|
||||||
|
CustomSemiboldIsBold = isBold;
|
||||||
|
}
|
||||||
|
|
||||||
void StartFonts() {
|
void StartFonts() {
|
||||||
if (Started) {
|
if (Started) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -164,6 +180,17 @@ void StartFonts() {
|
||||||
QFont::insertSubstitutions(name, list);
|
QFont::insertSubstitutions(name, list);
|
||||||
}
|
}
|
||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
|
if (!CustomMainFont.isEmpty() && ValidateFont(CustomMainFont)) {
|
||||||
|
Overrides[FontTypeRegular] = CustomMainFont;
|
||||||
|
Overrides[FontTypeRegularItalic] = CustomMainFont;
|
||||||
|
Overrides[FontTypeBold] = CustomMainFont;
|
||||||
|
Overrides[FontTypeBoldItalic] = CustomMainFont;
|
||||||
|
}
|
||||||
|
if (!CustomSemiboldFont.isEmpty() && ValidateFont(CustomSemiboldFont)) {
|
||||||
|
Overrides[FontTypeSemibold] = CustomSemiboldFont;
|
||||||
|
Overrides[FontTypeSemiboldItalic] = CustomSemiboldFont;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetPossibleEmptyOverride(const QString &familyName, int32 flags) {
|
QString GetPossibleEmptyOverride(const QString &familyName, int32 flags) {
|
||||||
|
|
@ -226,8 +253,8 @@ FontData::FontData(int size, uint32 flags, int family, Font *other)
|
||||||
f.setPixelSize(size);
|
f.setPixelSize(size);
|
||||||
if (_flags & FontBold) {
|
if (_flags & FontBold) {
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
//} else if (fontFamilies[family] == "Open Sans Semibold") {
|
} else if (fontFamilies[family] == "Open Sans Semibold" && CustomSemiboldIsBold) {
|
||||||
// f.setWeight(QFont::DemiBold);
|
f.setBold(true);
|
||||||
}
|
}
|
||||||
f.setItalic(_flags & FontItalic);
|
f.setItalic(_flags & FontItalic);
|
||||||
f.setUnderline(_flags & FontUnderline);
|
f.setUnderline(_flags & FontUnderline);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@
|
||||||
namespace style {
|
namespace style {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
void SetMainFont(const QString &familyName);
|
||||||
|
void SetSemiboldFont(const QString &familyName);
|
||||||
|
void SetSemiboldIsBold(bool isBold);
|
||||||
|
|
||||||
void StartFonts();
|
void StartFonts();
|
||||||
[[nodiscard]] QString GetFontOverride(const QString &familyName, int32 flags = 0);
|
[[nodiscard]] QString GetFontOverride(const QString &familyName, int32 flags = 0);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue