mvm_core_ui/MVMCoreUI/Utility/MFFonts.m
Matt Bruce 30b2eb150a remove the duplication of the same fonts that are available within the VDS Framework Library.
we are now calling the registration() funtion in VDS on the launch of MVMCoreUI

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-06-04 14:25:56 -05:00

114 lines
3.7 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/MVMCoreLoggingHandlerHelper.h>
@import MVMCore.Swift;
@import MVMCore.MVMCoreErrorConstants;
@import MVMCore.MVMCoreLoadHandler;
@import MVMCore.MVMCoreErrorObject;
NSString * const DSBold = @"VerizonNHGeDS-Bold";
NSString * const DSRegular = @"VerizonNHGeDS-Regular";
NSString * const TXBold = @"VerizonNHGeTX-Bold";
NSString * const TXRegular = @"VerizonNHGeTX-Regular";
@implementation MFFonts
+ (void)loadMVMFonts {
static dispatch_once_t once;
dispatch_once(&once, ^{
[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 %@: %@", fontName, errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
}
+ (nonnull UIFont *)mfFontDSBold:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:DSBold size:size];
[self validFont:font fontName:DSBold];
return font ?: [UIFont boldSystemFontOfSize:size];
}
+ (nonnull UIFont *)mfFontDSRegular:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:DSRegular size:size];
[self validFont:font fontName:DSRegular];
return font ?: [UIFont systemFontOfSize:size];
}
+ (nonnull UIFont *)mfFontTXBold:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:TXBold size:size];
[self validFont:font fontName:TXBold];
return font ?: [UIFont boldSystemFontOfSize:size];
}
+ (nonnull UIFont *)mfFontTXRegular:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:TXRegular size:size];
[self validFont:font fontName:TXRegular];
return font ?: [UIFont systemFontOfSize:size];
}
+ (nonnull UIFont *)mfFont75Bd:(CGFloat)size {
if (size >= 15) {
return [MFFonts mfFontDSBold:size];
} else {
return [MFFonts mfFontTXBold:size];
}
}
+ (nonnull UIFont *)mfFont55Rg:(CGFloat)size {
if (size >= 15) {
return [MFFonts mfFontDSRegular:size];
} else {
return [MFFonts mfFontTXRegular:size];
}
}
+ (nullable UIFont *)mfFontOcratxt:(CGFloat)size {
[self loadMVMFonts];
UIFont *font = [UIFont fontWithName:@"OCRAExtended" size:size];
[self validFont:font fontName:@"OCRAExtended"];
return font;
}
+ (UIFont *)mfFontWithName:(nonnull NSString *)name size:(CGFloat)size {
UIFont *font = [UIFont fontWithName:name size:size];
[self validFont:font fontName:name];
return font ?: [self mfFont55Rg:size];
}
+ (void)validFont:(UIFont *)font fontName:(NSString *)fontName {
if (font == nil) {
MVMCoreErrorObject *errorObject = [[MVMCoreErrorObject alloc] initWithTitle:@"font can not load" message:[NSString stringWithFormat:@"missing font name is %@", fontName] code:ErrorCodeFontNotFound domain:ErrorDomainNative location:@"MFStyler"];
[[MVMCoreLoggingHandler sharedLoggingHandler]addErrorToLog:errorObject];
}
}
@end