material-roboto-font-loader-ios
material-roboto-font-loader-ios copied to clipboard
-isLargeForContrastRatios: relies on font name to determine font weight
The UIFont interface doesn't expose any methods to access the weight property of a font. The current implementation of -isLargeForContrastRatios: wants to treat medium weight fonts as bold, and it looks in the font name for the substring "medium". This is somewhat brittle.
The CoreText font interface does expose the weight property, and since this class is toll-free bridged to UIFont, the implementation ought to use CoreText to inspect the true weight attribute, something like this:
CTFontRef coreTextFont = (__bridge CTFontRef)font; CFDictionaryRef coreTextFontTraits = CTFontCopyTraits(coreTextFont); NSDictionary *fontTraits = (__bridge NSDictionary *)coreTextFontTraits; NSNumber *fontWeight = fontTraits[(NSString *)kCTFontWeightTrait]; CFRelease(coreTextFontTraits);
if (fontWeight.floatValue >= (UIFontWeightMedium - FLT_EPSILON)) { return YES; }