yeet
This commit is contained in:
24
node_modules/expo-font/ios/EXFont.podspec
generated
vendored
Normal file
24
node_modules/expo-font/ios/EXFont.podspec
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
require 'json'
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'EXFont'
|
||||
s.version = package['version']
|
||||
s.summary = package['description']
|
||||
s.description = package['description']
|
||||
s.license = package['license']
|
||||
s.author = package['author']
|
||||
s.homepage = package['homepage']
|
||||
s.platform = :ios, '10.0'
|
||||
s.source = { git: 'https://github.com/expo/expo.git' }
|
||||
s.source_files = 'EXFont/**/*.{h,m}'
|
||||
s.preserve_paths = 'EXFont/**/*.{h,m}'
|
||||
s.requires_arc = true
|
||||
|
||||
s.dependency 'UMCore'
|
||||
s.dependency 'UMFontInterface'
|
||||
|
||||
end
|
||||
|
||||
|
12
node_modules/expo-font/ios/EXFont/EXFont.h
generated
vendored
Normal file
12
node_modules/expo-font/ios/EXFont/EXFont.h
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
static const char *EXFontAssocKey = "EXFont";
|
||||
|
||||
@interface EXFont : NSObject
|
||||
|
||||
- (instancetype)initWithCGFont:(CGFontRef)cgFont;
|
||||
- (UIFont *)UIFontWithSize:(CGFloat)fsize;
|
||||
|
||||
@end
|
43
node_modules/expo-font/ios/EXFont/EXFont.m
generated
vendored
Normal file
43
node_modules/expo-font/ios/EXFont/EXFont.m
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// 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
|
10
node_modules/expo-font/ios/EXFont/EXFontLoader.h
generated
vendored
Normal file
10
node_modules/expo-font/ios/EXFont/EXFontLoader.h
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <UMCore/UMExportedModule.h>
|
||||
#import <UMCore/UMModuleRegistryConsumer.h>
|
||||
|
||||
@interface EXFontLoader : UMExportedModule <UMModuleRegistryConsumer>
|
||||
|
||||
- (instancetype)initWithFontFamilyPrefix:(NSString *)prefix;
|
||||
|
||||
@end
|
93
node_modules/expo-font/ios/EXFont/EXFontLoader.m
generated
vendored
Normal file
93
node_modules/expo-font/ios/EXFont/EXFontLoader.m
generated
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <EXFont/EXFontLoader.h>
|
||||
#import <EXFont/EXFontLoaderProcessor.h>
|
||||
#import <UMFontInterface/UMFontManagerInterface.h>
|
||||
#import <EXFont/EXFontScaler.h>
|
||||
#import <EXFont/EXFont.h>
|
||||
#import <objc/runtime.h>
|
||||
#import <EXFont/EXFontManager.h>
|
||||
#import <EXFont/EXFontScalersManager.h>
|
||||
|
||||
@interface EXFontLoader ()
|
||||
|
||||
@property (nonatomic, strong) EXFontScaler *scaler;
|
||||
@property (nonatomic, strong) EXFontLoaderProcessor *processor;
|
||||
@property (nonatomic, strong) EXFontManager *manager;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EXFontLoader
|
||||
|
||||
UM_EXPORT_MODULE(ExpoFontLoader);
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_scaler = [[EXFontScaler alloc] init];
|
||||
_manager = [[EXFontManager alloc] init];
|
||||
_processor = [[EXFontLoaderProcessor alloc] initWithManager:_manager];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFontFamilyPrefix:(NSString *)prefix
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_scaler = [[EXFontScaler alloc] init];
|
||||
_manager = [[EXFontManager alloc] init];
|
||||
_processor = [[EXFontLoaderProcessor alloc] initWithFontFamilyPrefix:prefix manager:_manager];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
|
||||
{
|
||||
if (moduleRegistry) {
|
||||
id<UMFontManagerInterface> manager = [moduleRegistry getModuleImplementingProtocol:@protocol(UMFontManagerInterface)];
|
||||
[manager addFontProcessor:_processor];
|
||||
|
||||
id<UMFontScalersManagerInterface> scalersManager = [moduleRegistry getSingletonModuleForName:@"FontScalersManager"];
|
||||
[scalersManager registerFontScaler:_scaler];
|
||||
}
|
||||
}
|
||||
|
||||
UM_EXPORT_METHOD_AS(loadAsync,
|
||||
loadAsyncWithFontFamilyName:(NSString *)fontFamilyName
|
||||
withLocalUri:(NSString *)path
|
||||
resolver:(UMPromiseResolveBlock)resolve
|
||||
rejecter:(UMPromiseRejectBlock)reject)
|
||||
{
|
||||
if ([_manager fontForName:fontFamilyName]) {
|
||||
reject(@"E_FONT_ALREADY_EXISTS",
|
||||
[NSString stringWithFormat:@"Font with family name '%@' already loaded", fontFamilyName],
|
||||
nil);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(nikki): make sure path is in experience's scope
|
||||
NSURL *uriString = [[NSURL alloc] initWithString:path];
|
||||
NSData *data = [[NSFileManager defaultManager] contentsAtPath:[uriString path]];
|
||||
if (!data) {
|
||||
reject(@"E_FONT_FILE_NOT_FOUND",
|
||||
[NSString stringWithFormat:@"File '%@' for font '%@' doesn't exist", path, fontFamilyName],
|
||||
nil);
|
||||
return;
|
||||
}
|
||||
|
||||
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
|
||||
CGFontRef font = CGFontCreateWithDataProvider(provider);
|
||||
CGDataProviderRelease(provider);
|
||||
if (!font) {
|
||||
reject(@"E_FONT_CREATION_FAILED",
|
||||
[NSString stringWithFormat:@"Could not create font from loaded data for '%@'", fontFamilyName],
|
||||
nil);
|
||||
return;
|
||||
}
|
||||
|
||||
[_manager setFont:[[EXFont alloc] initWithCGFont:font] forName:fontFamilyName];
|
||||
resolve(nil);
|
||||
}
|
||||
|
||||
@end
|
14
node_modules/expo-font/ios/EXFont/EXFontLoaderProcessor.h
generated
vendored
Normal file
14
node_modules/expo-font/ios/EXFont/EXFontLoaderProcessor.h
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UMFontInterface/UMFontProcessorInterface.h>
|
||||
#import <EXFont/EXFontManager.h>
|
||||
|
||||
@interface EXFontLoaderProcessor : NSObject <UMFontProcessorInterface>
|
||||
|
||||
- (instancetype)initWithFontFamilyPrefix:(NSString *)prefix
|
||||
manager:(EXFontManager *)manager;
|
||||
|
||||
- (instancetype)initWithManager:(EXFontManager *)manager;
|
||||
|
||||
@end
|
69
node_modules/expo-font/ios/EXFont/EXFontLoaderProcessor.m
generated
vendored
Normal file
69
node_modules/expo-font/ios/EXFont/EXFontLoaderProcessor.m
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <EXFont/EXFontLoaderProcessor.h>
|
||||
#import <EXFont/EXFontLoader.h>
|
||||
#import <EXFont/EXFont.h>
|
||||
#import <EXFont/EXFontManager.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@interface EXFontLoaderProcessor ()
|
||||
|
||||
@property (nonatomic, copy) NSString *fontFamilyPrefix;
|
||||
@property (nonatomic, strong) EXFontManager *manager;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EXFontLoaderProcessor
|
||||
|
||||
- (instancetype)initWithFontFamilyPrefix:(NSString *)prefix
|
||||
manager:(EXFontManager *)manager
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_fontFamilyPrefix = prefix;
|
||||
_manager = manager;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithManager:(EXFontManager *)manager
|
||||
{
|
||||
return [self initWithFontFamilyPrefix:nil manager:manager];
|
||||
}
|
||||
|
||||
- (UIFont *)updateFont:(UIFont *)uiFont
|
||||
withFamily:(NSString *)family
|
||||
size:(NSNumber *)size
|
||||
weight:(NSString *)weight
|
||||
style:(NSString *)style
|
||||
variant:(NSArray<NSDictionary *> *)variant
|
||||
scaleMultiplier:(CGFloat)scaleMultiplier
|
||||
{
|
||||
const CGFloat defaultFontSize = 14;
|
||||
EXFont *exFont = nil;
|
||||
|
||||
// Did we get a new family, and if so, is it associated with an EXFont?
|
||||
if (_fontFamilyPrefix && [family hasPrefix:_fontFamilyPrefix]) {
|
||||
NSString *suffix = [family substringFromIndex:_fontFamilyPrefix.length];
|
||||
exFont = [_manager fontForName:suffix];
|
||||
} else if (!_fontFamilyPrefix) {
|
||||
exFont = [_manager fontForName:family];
|
||||
}
|
||||
|
||||
// Did the passed-in UIFont come from an EXFont?
|
||||
if (!exFont && uiFont) {
|
||||
exFont = objc_getAssociatedObject(uiFont, EXFontAssocKey);
|
||||
}
|
||||
|
||||
// If it's an EXFont, generate the corresponding UIFont, else fallback to React Native's built-in method
|
||||
if (exFont) {
|
||||
CGFloat computedSize = [size doubleValue] ?: uiFont.pointSize ?: defaultFontSize;
|
||||
if (scaleMultiplier > 0.0 && scaleMultiplier != 1.0) {
|
||||
computedSize = round(computedSize * scaleMultiplier);
|
||||
}
|
||||
return [exFont UIFontWithSize:computedSize];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
12
node_modules/expo-font/ios/EXFont/EXFontManager.h
generated
vendored
Normal file
12
node_modules/expo-font/ios/EXFont/EXFontManager.h
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <EXFont/EXFont.h>
|
||||
|
||||
@interface EXFontManager : NSObject
|
||||
|
||||
- (instancetype)init;
|
||||
- (EXFont *)fontForName:(NSString *)name;
|
||||
- (void)setFont:(EXFont *)font forName:(NSString *)name;
|
||||
|
||||
@end
|
31
node_modules/expo-font/ios/EXFont/EXFontManager.m
generated
vendored
Normal file
31
node_modules/expo-font/ios/EXFont/EXFontManager.m
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <EXFont/EXFontManager.h>
|
||||
|
||||
@interface EXFontManager ()
|
||||
|
||||
@property (nonatomic, strong, readonly) NSMutableDictionary *registry;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EXFontManager
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_registry = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (EXFont *)fontForName:(NSString *)name
|
||||
{
|
||||
return _registry[name];
|
||||
}
|
||||
|
||||
- (void)setFont:(EXFont *)font forName:(NSString *)name
|
||||
{
|
||||
_registry[name] = font;
|
||||
}
|
||||
|
||||
@end
|
8
node_modules/expo-font/ios/EXFont/EXFontScaler.h
generated
vendored
Normal file
8
node_modules/expo-font/ios/EXFont/EXFontScaler.h
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UMFontInterface/UMFontScalerInterface.h>
|
||||
|
||||
@interface EXFontScaler : NSObject <UMFontScalerInterface>
|
||||
|
||||
@end
|
16
node_modules/expo-font/ios/EXFont/EXFontScaler.m
generated
vendored
Normal file
16
node_modules/expo-font/ios/EXFont/EXFontScaler.m
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2015-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <EXFont/EXFontScaler.h>
|
||||
|
||||
#import <EXFont/EXFont.h>
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@implementation EXFontScaler
|
||||
|
||||
- (UIFont *)scaledFont:(UIFont *)font toSize:(CGFloat)fontSize
|
||||
{
|
||||
EXFont *exFont = objc_getAssociatedObject(font, EXFontAssocKey);
|
||||
return [exFont UIFontWithSize:fontSize];
|
||||
}
|
||||
|
||||
@end
|
8
node_modules/expo-font/ios/EXFont/Singletons/EXFontScalersManager.h
generated
vendored
Normal file
8
node_modules/expo-font/ios/EXFont/Singletons/EXFontScalersManager.h
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright 2018-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <UMCore/UMSingletonModule.h>
|
||||
#import <UMFontInterface/UMFontScalersManagerInterface.h>
|
||||
|
||||
@interface EXFontScalersManager : UMSingletonModule <UMFontScalersManagerInterface>
|
||||
|
||||
@end
|
61
node_modules/expo-font/ios/EXFont/Singletons/EXFontScalersManager.m
generated
vendored
Normal file
61
node_modules/expo-font/ios/EXFont/Singletons/EXFontScalersManager.m
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright 2018-present 650 Industries. All rights reserved.
|
||||
|
||||
#import <EXFont/EXFontScalersManager.h>
|
||||
|
||||
#import <UMCore/UMDefines.h>
|
||||
#import <EXFont/EXFont.h>
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
static NSPointerArray *currentFontScalers;
|
||||
|
||||
@implementation UIFont (EXFontLoader)
|
||||
|
||||
- (UIFont *)EXFontWithSize:(CGFloat)fontSize
|
||||
{
|
||||
for (id<UMFontScalerInterface> fontScaler in currentFontScalers) {
|
||||
UIFont *scaledFont = [fontScaler scaledFont:self toSize:fontSize];
|
||||
if (scaledFont) {
|
||||
return scaledFont;
|
||||
}
|
||||
}
|
||||
|
||||
return [self EXFontWithSize:fontSize];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* A singleton module responsible for overriding UIFont's
|
||||
* fontWithSize: method which is used for scaling fonts.
|
||||
* We need this one, central place to store the scalers
|
||||
* as for now to get rid of timing problems when backgrounding/
|
||||
* foregrounding apps.
|
||||
*/
|
||||
|
||||
@implementation EXFontScalersManager
|
||||
|
||||
UM_REGISTER_SINGLETON_MODULE(FontScalersManager);
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
static dispatch_once_t initializeCurrentFontScalersOnce;
|
||||
dispatch_once(&initializeCurrentFontScalersOnce, ^{
|
||||
currentFontScalers = [NSPointerArray weakObjectsPointerArray];
|
||||
|
||||
Class uiFont = [UIFont class];
|
||||
SEL uiUpdate = @selector(fontWithSize:);
|
||||
SEL exUpdate = @selector(EXFontWithSize:);
|
||||
|
||||
method_exchangeImplementations(class_getInstanceMethod(uiFont, uiUpdate),
|
||||
class_getInstanceMethod(uiFont, exUpdate));
|
||||
});
|
||||
}
|
||||
|
||||
- (void)registerFontScaler:(id<UMFontScalerInterface>)fontScaler
|
||||
{
|
||||
[currentFontScalers compact];
|
||||
[currentFontScalers addPointer:(__bridge void * _Nullable)(fontScaler)];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user