Handle fonts that are marked as bold but have the same weight as the normal variant

This commit is contained in:
Thomas Goyne 2016-01-01 15:41:58 -08:00
parent 761a121452
commit 3c381b6c55

View file

@ -25,6 +25,7 @@ struct FontMatch {
NSCharacterSet *codepoints = nil; NSCharacterSet *codepoints = nil;
int weight = 400; int weight = 400;
int width = 5; int width = 5;
bool bold = false;
bool italic = false; bool italic = false;
bool family_match = false; bool family_match = false;
}; };
@ -44,6 +45,7 @@ FontMatch process_descriptor(NSFontDescriptor *desc, NSString *name) {
// that // that
auto traits = CTFontGetSymbolicTraits((__bridge CTFontRef)font); auto traits = CTFontGetSymbolicTraits((__bridge CTFontRef)font);
ret.italic = !!(traits & kCTFontItalicTrait); ret.italic = !!(traits & kCTFontItalicTrait);
ret.bold = !!(traits & kCTFontBoldTrait);
if (!ret.italic) { if (!ret.italic) {
auto data = (__bridge_transfer NSData *)CTFontCopyTable((__bridge CTFontRef)font, kCTFontTableHead, 0); auto data = (__bridge_transfer NSData *)CTFontCopyTable((__bridge CTFontRef)font, kCTFontTableHead, 0);
if (data.length > 45) { if (data.length > 45) {
@ -143,6 +145,9 @@ CollectionResult CoreTextFontFileLister::GetFontPaths(std::string const& facenam
if (m.weight != best.weight) { if (m.weight != best.weight) {
return weight_penalty(bold, m.weight) < weight_penalty(bold, best.weight); return weight_penalty(bold, m.weight) < weight_penalty(bold, best.weight);
} }
else if (m.bold != best.bold) {
return m.bold == bold > 550;
}
if (m.italic != best.italic) { if (m.italic != best.italic) {
return (m.italic != italic) < (best.italic != italic); return (m.italic != italic) < (best.italic != italic);
} }