This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

44 lines
898 B
Mathematica
Raw Normal View History

2021-04-02 02:24:13 +03:00
// Copyright 2015-present 650 Industries. All rights reserved.
#import <EXFont/EXFont.h>
#import <objc/runtime.h>
#import <CoreText/CoreText.h>
@interface EXFont ()
@property (nonatomic, assign) CGFontRef cgFont;
@property (nonatomic, strong) NSMutableDictionary *sizes;
@end
@implementation EXFont
- (instancetype)initWithCGFont:(CGFontRef)cgFont
{
if (self = [super init]) {
_cgFont = cgFont;
_sizes = [NSMutableDictionary dictionary];
}
return self;
}
- (UIFont *)UIFontWithSize:(CGFloat)fsize
{
NSNumber *size = @(fsize);
UIFont *uiFont = _sizes[size];
if (uiFont) {
return uiFont;
}
uiFont = (__bridge_transfer UIFont *)CTFontCreateWithGraphicsFont(_cgFont, fsize, NULL, NULL);
_sizes[size] = uiFont;
objc_setAssociatedObject(uiFont, EXFontAssocKey, self, OBJC_ASSOCIATION_ASSIGN);
return uiFont;
}
- (void)dealloc
{
CGFontRelease(_cgFont);
}
@end