Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

-isLargeForContrastRatios: relies on font name to determine font weight  #16

@Icycle

Description

@Icycle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions