Merge pull request #6 from ilya-fedin/fix-bold
This commit is contained in:
commit
b9dab597d8
3 changed files with 6 additions and 55 deletions
|
|
@ -28,7 +28,6 @@ void SetCustomFonts(const CustomFont ®ular, const CustomFont &bold) {
|
||||||
QFont ResolveFont(uint32 flags, int size) {
|
QFont ResolveFont(uint32 flags, int size) {
|
||||||
static auto Database = QFontDatabase();
|
static auto Database = QFontDatabase();
|
||||||
|
|
||||||
const auto fontOverride = ParseFamilyName(GetFontOverride(flags));
|
|
||||||
const auto overrideIsEmpty = GetPossibleEmptyOverride(flags).isEmpty();
|
const auto overrideIsEmpty = GetPossibleEmptyOverride(flags).isEmpty();
|
||||||
|
|
||||||
const auto bold = ((flags & FontBold) || (flags & FontSemibold));
|
const auto bold = ((flags & FontBold) || (flags & FontSemibold));
|
||||||
|
|
@ -46,8 +45,10 @@ QFont ResolveFont(uint32 flags, int size) {
|
||||||
: sizes;
|
: sizes;
|
||||||
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 if (!UseSystemFont || !overrideIsEmpty) {
|
} else {
|
||||||
result.setFamily(fontOverride);
|
if (!UseSystemFont || !overrideIsEmpty) {
|
||||||
|
result.setFamily(GetFontOverride(flags));
|
||||||
|
}
|
||||||
if (bold) {
|
if (bold) {
|
||||||
if (CustomSemiboldIsBold) {
|
if (CustomSemiboldIsBold) {
|
||||||
result.setBold(true);
|
result.setBold(true);
|
||||||
|
|
@ -70,14 +71,6 @@ QFont ResolveFont(uint32 flags, int size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsRealSemibold(fontOverride)) {
|
|
||||||
if (flags & FontItalic) {
|
|
||||||
result.setStyleName("Semibold Italic");
|
|
||||||
} else {
|
|
||||||
result.setStyleName("Semibold");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (italic) {
|
if (italic) {
|
||||||
result.setItalic(true);
|
result.setItalic(true);
|
||||||
|
|
|
||||||
|
|
@ -42,26 +42,13 @@ uint32 fontKey(int size, uint32 flags, int family) {
|
||||||
return (((uint32(family) << 12) | uint32(size)) << 6) | flags;
|
return (((uint32(family) << 12) | uint32(size)) << 6) | flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RemoveSemiboldFromName(const QString &familyName) {
|
|
||||||
auto removedSemibold = familyName;
|
|
||||||
removedSemibold.remove("Semibold", Qt::CaseInsensitive);
|
|
||||||
return removedSemibold.trimmed();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ValidateFont(const QString &familyName, int flags = 0) {
|
bool ValidateFont(const QString &familyName, int flags = 0) {
|
||||||
const auto parsedFamily = ParseFamilyName(familyName);
|
QFont checkFont(familyName);
|
||||||
|
|
||||||
QFont checkFont(parsedFamily);
|
|
||||||
checkFont.setBold(flags & style::internal::FontBold);
|
checkFont.setBold(flags & style::internal::FontBold);
|
||||||
checkFont.setItalic(flags & style::internal::FontItalic);
|
checkFont.setItalic(flags & style::internal::FontItalic);
|
||||||
checkFont.setUnderline(flags & style::internal::FontUnderline);
|
checkFont.setUnderline(flags & style::internal::FontUnderline);
|
||||||
|
|
||||||
if (IsRealSemibold(familyName)) {
|
|
||||||
checkFont.setStyleName("Semibold");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto realFamily = QFontInfo(checkFont).family();
|
auto realFamily = QFontInfo(checkFont).family();
|
||||||
if (realFamily.trimmed().compare(parsedFamily, Qt::CaseInsensitive)) {
|
if (realFamily.trimmed().compare(familyName, Qt::CaseInsensitive)) {
|
||||||
UI_LOG(("Font Error: could not resolve '%1' font, got '%2'.").arg(familyName).arg(realFamily));
|
UI_LOG(("Font Error: could not resolve '%1' font, got '%2'.").arg(familyName).arg(realFamily));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -305,33 +292,6 @@ QString GetFontOverride(int32 flags) {
|
||||||
return result.isEmpty() ? "Open Sans" : result;
|
return result.isEmpty() ? "Open Sans" : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsRealSemibold(const QString &familyName) {
|
|
||||||
const auto removedSemibold = RemoveSemiboldFromName(familyName);
|
|
||||||
|
|
||||||
QFont originalFont(familyName);
|
|
||||||
QFont withoutSemiboldFont(removedSemibold);
|
|
||||||
withoutSemiboldFont.setStyleName("Semibold");
|
|
||||||
|
|
||||||
QFontInfo originalFontInfo(originalFont);
|
|
||||||
QFontInfo withoutSemiboldInfo(withoutSemiboldFont);
|
|
||||||
|
|
||||||
if (originalFontInfo.family().trimmed().compare(familyName, Qt::CaseInsensitive) &&
|
|
||||||
!withoutSemiboldInfo.family().trimmed().compare(removedSemibold, Qt::CaseInsensitive) &&
|
|
||||||
!withoutSemiboldInfo.styleName().trimmed().compare("Semibold", Qt::CaseInsensitive)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ParseFamilyName(const QString &familyName) {
|
|
||||||
if (IsRealSemibold(familyName)) {
|
|
||||||
return RemoveSemiboldFromName(familyName);
|
|
||||||
} else {
|
|
||||||
return familyName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MonospaceFont() {
|
QString MonospaceFont() {
|
||||||
static const auto family = [&]() -> QString {
|
static const auto family = [&]() -> QString {
|
||||||
if (TryFont(CustomMonospaceFont)) {
|
if (TryFont(CustomMonospaceFont)) {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ 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);
|
||||||
[[nodiscard]] bool IsRealSemibold(const QString &familyName);
|
|
||||||
[[nodiscard]] QString ParseFamilyName(const QString &familyName);
|
|
||||||
[[nodiscard]] QString MonospaceFont();
|
[[nodiscard]] QString MonospaceFont();
|
||||||
|
|
||||||
void destroyFonts();
|
void destroyFonts();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue