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}); }