Add support for semibold fonts that don't include "Semibold" in the family name (#1)
In future this solution must be adapted for other font styles, but for now it will work.
This commit is contained in:
parent
b445c55444
commit
55aec1954e
1 changed files with 47 additions and 3 deletions
|
|
@ -37,15 +37,55 @@ uint32 fontKey(int size, uint32 flags, int family) {
|
||||||
return (((uint32(family) << 10) | uint32(size)) << 4) | flags;
|
return (((uint32(family) << 10) | uint32(size)) << 4) | flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString RemoveSemiboldFromName(const QString &familyName) {
|
||||||
|
auto removedSemibold = familyName;
|
||||||
|
removedSemibold.remove("Semibold", Qt::CaseInsensitive);
|
||||||
|
return removedSemibold.trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ValidateFont(const QString &familyName, int flags = 0) {
|
bool ValidateFont(const QString &familyName, int flags = 0) {
|
||||||
QFont checkFont(familyName);
|
const auto parsedFamily = ParseFamilyName(familyName);
|
||||||
|
|
||||||
|
QFont checkFont(parsedFamily);
|
||||||
checkFont.setPixelSize(13);
|
checkFont.setPixelSize(13);
|
||||||
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);
|
||||||
checkFont.setStyleStrategy(QFont::PreferQuality);
|
checkFont.setStyleStrategy(QFont::PreferQuality);
|
||||||
|
|
||||||
|
if (IsRealSemibold(familyName)) {
|
||||||
|
checkFont.setStyleName("Semibold");
|
||||||
|
}
|
||||||
|
|
||||||
auto realFamily = QFontInfo(checkFont).family();
|
auto realFamily = QFontInfo(checkFont).family();
|
||||||
if (realFamily.trimmed().compare(familyName, Qt::CaseInsensitive)) {
|
if (realFamily.trimmed().compare(parsedFamily, 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;
|
||||||
}
|
}
|
||||||
|
|
@ -238,7 +278,7 @@ int registerFontFamily(const QString &family) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FontData::FontData(int size, uint32 flags, int family, Font *other)
|
FontData::FontData(int size, uint32 flags, int family, Font *other)
|
||||||
: f(GetFontOverride(fontFamilies[family], flags))
|
: f(ParseFamilyName(GetFontOverride(fontFamilies[family], flags)))
|
||||||
, m(f)
|
, m(f)
|
||||||
, _size(size)
|
, _size(size)
|
||||||
, _flags(flags)
|
, _flags(flags)
|
||||||
|
|
@ -261,6 +301,10 @@ FontData::FontData(int size, uint32 flags, int family, Font *other)
|
||||||
f.setStrikeOut(_flags & FontStrikeOut);
|
f.setStrikeOut(_flags & FontStrikeOut);
|
||||||
f.setStyleStrategy(QFont::PreferQuality);
|
f.setStyleStrategy(QFont::PreferQuality);
|
||||||
|
|
||||||
|
if (IsRealSemibold(GetFontOverride(fontFamilies[family], flags))) {
|
||||||
|
f.setStyleName("Semibold");
|
||||||
|
}
|
||||||
|
|
||||||
m = QFontMetrics(f);
|
m = QFontMetrics(f);
|
||||||
height = m.height();
|
height = m.height();
|
||||||
ascent = m.ascent();
|
ascent = m.ascent();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue