mvm_core_ui/MVMCoreUI/Utility/MFFonts.m
Pfeil, Scott Robert 252beb311a dynamic type
2019-10-22 11:40:50 -04:00

66 lines
2.2 KiB
Objective-C

//
// MFFonts.m
// myverizon
//
// Created by Scott Pfeil on 11/17/14.
// Copyright (c) 2014 Verizon Wireless. All rights reserved.
//
#import "MFFonts.h"
#import <CoreText/CoreText.h>
#import "MVMCoreUIUtility.h"
@import MVMCore.MVMCoreLoggingHandler;
@implementation MFFonts
+ (void)loadMVMFonts {
static dispatch_once_t once;
dispatch_once(&once, ^{
[MFFonts loadFont:@"NHaasGroteskDSStd-75Bd" type:@"otf"];
[MFFonts loadFont:@"NHaasGroteskDSStd-55Rg" type:@"otf"];
[MFFonts loadFont:@"OCRAExtended" type:@"ttf"];
});
}
+ (void)loadFont:(NSString *)fontName type:(NSString *)type{
NSString *fontPath = [[MVMCoreUIUtility bundleForMVMCoreUI] pathForResource:fontName ofType:type];
NSData *inData = [NSData dataWithContentsOfFile:fontPath];
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
[UIFont familyNames];//fixing weird app freeze after launch app issue
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (!CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
MVMCoreLog(@"Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
}
+ (nullable UIFont *)mfFont75Bd:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size];
UIFontMetrics *metrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleHeadline];
return [metrics scaledFontForFont:font];
}
+ (nullable UIFont *)mfFont55Rg:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size];;
UIFontMetrics *metrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody];
return [metrics scaledFontForFont:font];
}
+ (nullable UIFont *)mfFontOcratxt:(CGFloat)size {
[self loadMVMFonts];
return [UIFont fontWithName:@"OCRAExtended" size:size];
}
+ (nullable UIFont *)mfFontWithName:(nonnull NSString *)name size:(CGFloat)size {
return [UIFont fontWithName:name size:size] ?: [self mfFont55Rg:size];
}
@end