Assume that fonts which CT won't give the OS/2 table for are Regular

This commit is contained in:
Thomas Goyne 2015-12-12 11:45:17 -08:00
parent f2b3b69b3f
commit 278b7621cf
1 changed files with 8 additions and 6 deletions

View File

@ -35,6 +35,9 @@ void process_descriptor(NSFontDescriptor *font, std::vector<FontMatch>& out) {
return; return;
NSFont *nsfont = [NSFont fontWithDescriptor:font size:10]; NSFont *nsfont = [NSFont fontWithDescriptor:font size:10];
int weight = 400;
int width = 5;
auto traits = CTFontGetSymbolicTraits((__bridge CTFontRef)nsfont); auto traits = CTFontGetSymbolicTraits((__bridge CTFontRef)nsfont);
bool italic = !!(traits & kCTFontItalicTrait); bool italic = !!(traits & kCTFontItalicTrait);
@ -49,12 +52,11 @@ void process_descriptor(NSFontDescriptor *font, std::vector<FontMatch>& out) {
} }
auto data = (__bridge_transfer NSData *)CTFontCopyTable((__bridge CTFontRef)nsfont, kCTFontTableOS2, 0); auto data = (__bridge_transfer NSData *)CTFontCopyTable((__bridge CTFontRef)nsfont, kCTFontTableOS2, 0);
if (data.length < 6) if (data.length > 7) {
return; auto bytes = static_cast<const uint8_t *>(data.bytes);
weight = (bytes[4] << 8) + bytes[5];
auto bytes = static_cast<const uint8_t *>(data.bytes); width = (bytes[6] << 8) + bytes[7];
int weight = (bytes[4] << 8) + bytes[5]; }
int width = (bytes[6] << 8) + bytes[7];
out.push_back({url, [font objectForKey:NSFontCharacterSetAttribute], weight, width, italic}); out.push_back({url, [font objectForKey:NSFontCharacterSetAttribute], weight, width, italic});
} }