[iOS] Simplify dynamically loading fonts

This commit is contained in:
Saúl Ibarra Corretgé 2018-10-16 12:17:15 +02:00 committed by Zoltan Bettenbuk
parent 011a46ce2d
commit 9407f562f6
4 changed files with 7 additions and 39 deletions

View File

@ -14,7 +14,6 @@
0B49424520AD8DBD00BD2DE0 /* outgoingStart.wav in Resources */ = {isa = PBXBuildFile; fileRef = 0B49424320AD8DBD00BD2DE0 /* outgoingStart.wav */; };
0B49424620AD8DBD00BD2DE0 /* outgoingRinging.wav in Resources */ = {isa = PBXBuildFile; fileRef = 0B49424420AD8DBD00BD2DE0 /* outgoingRinging.wav */; };
0B7C2CFD200F51D60060D076 /* LaunchOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B7C2CFC200F51D60060D076 /* LaunchOptions.m */; };
0B93EF7B1EC608550030D24D /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B93EF7A1EC608550030D24D /* CoreText.framework */; };
0B93EF7E1EC9DDCD0030D24D /* RCTBridgeWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B93EF7C1EC9DDCD0030D24D /* RCTBridgeWrapper.h */; };
0B93EF7F1EC9DDCD0030D24D /* RCTBridgeWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 0B93EF7D1EC9DDCD0030D24D /* RCTBridgeWrapper.m */; };
0BA13D311EE83FF8007BEF7F /* ExternalAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */; };
@ -114,7 +113,6 @@
files = (
0BB9AD791F5EC6D7001C08DB /* Intents.framework in Frameworks */,
0BB9AD771F5EC6CE001C08DB /* CallKit.framework in Frameworks */,
0B93EF7B1EC608550030D24D /* CoreText.framework in Frameworks */,
0F65EECE1D95DA94561BB47E /* libPods-JitsiMeet.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -18,10 +18,6 @@
<string>1.9.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>JitsiMeetFonts</key>
<array>
<string>jitsi.ttf</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-2</string>

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
#import <CoreText/CoreText.h>
#import <Intents/Intents.h>
#include <mach/mach_time.h>
@ -53,35 +52,6 @@ RCTFatalHandler _RCTFatal = ^(NSError *error) {
}
};
/**
* Helper function to dynamically load custom fonts. The `UIAppFonts` key in the
* plist file doesn't work for frameworks, so fonts have to be manually loaded.
*/
void loadCustomFonts(Class clazz) {
NSBundle *bundle = [NSBundle bundleForClass:clazz];
NSArray *fonts = [bundle objectForInfoDictionaryKey:@"JitsiMeetFonts"];
for (NSString *item in fonts) {
NSString *fontName = [item stringByDeletingPathExtension];
NSString *fontExt = [item pathExtension];
NSString *fontPath = [bundle pathForResource:fontName ofType:fontExt];
NSData *inData = [NSData dataWithContentsOfFile:fontPath];
CFErrorRef error;
CGDataProviderRef provider
= CGDataProviderCreateWithCFData((__bridge CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (!CTFontManagerRegisterGraphicsFont(font, &error)) {
CFStringRef errorDescription = CFErrorCopyDescription(error);
NSLog(@"Failed to load font: %@", errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
}
}
/**
* Helper function to register a fatal error handler for React. Our handler
* won't kill the process, it will swallow JS errors and print stack traces
@ -410,9 +380,6 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
= [[RCTBridgeWrapper alloc] initWithLaunchOptions:_launchOptions];
views = [NSMapTable strongToWeakObjectsMapTable];
// Dynamically load custom bundled fonts.
loadCustomFonts(self.class);
// Register a fatal error handler for React.
registerFatalErrorHandler();
});

View File

@ -1,3 +1,5 @@
import { Platform } from 'react-native';
// FIXME The import of react-native-vector-icons makes the file native-specific
// but the file's name and/or location (within the directory structure) don't
// reflect that, it suggests the file is platform-independent.
@ -10,3 +12,8 @@ import icoMoonConfig from './jitsi.json';
* Creates the Jitsi icon set from the ico moon project config file.
*/
export const Icon = createIconSetFromIcoMoon(icoMoonConfig);
// Dynamically load font on iOS
if (Platform.OS === 'ios') {
Icon.loadFont('jitsi.ttf');
}