From 278b7621cf624771338dad48a83e65d1f6eecc6e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 12 Dec 2015 11:45:17 -0800 Subject: [PATCH] Assume that fonts which CT won't give the OS/2 table for are Regular --- src/font_file_lister_coretext.mm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/font_file_lister_coretext.mm b/src/font_file_lister_coretext.mm index 89ae66fb8..ee41545dc 100644 --- a/src/font_file_lister_coretext.mm +++ b/src/font_file_lister_coretext.mm @@ -35,6 +35,9 @@ void process_descriptor(NSFontDescriptor *font, std::vector& out) { return; NSFont *nsfont = [NSFont fontWithDescriptor:font size:10]; + int weight = 400; + int width = 5; + auto traits = CTFontGetSymbolicTraits((__bridge CTFontRef)nsfont); bool italic = !!(traits & kCTFontItalicTrait); @@ -49,12 +52,11 @@ void process_descriptor(NSFontDescriptor *font, std::vector& out) { } auto data = (__bridge_transfer NSData *)CTFontCopyTable((__bridge CTFontRef)nsfont, kCTFontTableOS2, 0); - if (data.length < 6) - return; - - auto bytes = static_cast(data.bytes); - int weight = (bytes[4] << 8) + bytes[5]; - int width = (bytes[6] << 8) + bytes[7]; + if (data.length > 7) { + auto bytes = static_cast(data.bytes); + weight = (bytes[4] << 8) + bytes[5]; + width = (bytes[6] << 8) + bytes[7]; + } out.push_back({url, [font objectForKey:NSFontCharacterSetAttribute], weight, width, italic}); }