[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-449][iOS] Fix issue that iconfont may randomly display as '?'.
Browse files Browse the repository at this point in the history
  • Loading branch information
神漠 authored and cxfeng1 committed Jul 2, 2018
1 parent df0eb7d commit 0557cf6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ - (BOOL)_handleConfigCenter
[WXTextComponent setRenderUsingCoreText:useCoreText];
BOOL useThreadSafeLock = [[configCenter configForKey:@"iOS_weex_ext_config.useThreadSafeLock" defaultValue:@YES isDefault:NULL] boolValue];
[WXUtility setThreadSafeCollectionUsingLock:useThreadSafeLock];

BOOL unregisterFontWhenCollision = [[configCenter configForKey:@"iOS_weex_ext_config.unregisterFontWhenCollision" defaultValue:@NO isDefault:NULL] boolValue];
[WXUtility setUnregisterFontWhenCollision:unregisterFontWhenCollision];

//Reading config from orange for Release instance in Main Thread or not
_bReleaseInstanceInMainThread = [[configCenter configForKey:@"iOS_weex_ext_config.releaseInstanceInMainThread" defaultValue:@(YES) isDefault:nil] boolValue];
Expand Down
2 changes: 2 additions & 0 deletions ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,6 @@ BOOL WXFloatGreaterThanWithPrecision(CGFloat a,CGFloat b,double precision);

+ (BOOL)threadSafeCollectionUsingLock;

+ (void)setUnregisterFontWhenCollision:(BOOL)value;

@end
40 changes: 27 additions & 13 deletions ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define KEY_USERNAME_PASSWORD @"com.taobao.Weex.weex123456"

static BOOL threadSafeCollectionUsingLock = YES;
static BOOL unregisterFontWhenCollision = NO;

void WXPerformBlockOnMainThread(void (^ _Nonnull block)(void))
{
Expand Down Expand Up @@ -147,6 +148,11 @@ + (BOOL)threadSafeCollectionUsingLock
return threadSafeCollectionUsingLock;
}

+ (void)setUnregisterFontWhenCollision:(BOOL)value
{
unregisterFontWhenCollision = value;
}

+ (void)performBlock:(void (^)(void))block onThread:(NSThread *)thread
{
if (!thread || !block) return;
Expand Down Expand Up @@ -486,27 +492,35 @@ + (UIFont *)fontWithSize:(CGFloat)size textWeight:(CGFloat)textWeight textStyle:
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL(fontURL);
if (fontDataProvider) {
CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
CFErrorRef error = nil;
CTFontManagerRegisterGraphicsFont(newFont, &error);
// the same font family, remove it and register new one.
if (error) {
CTFontManagerUnregisterGraphicsFont(newFont, NULL);
if (unregisterFontWhenCollision) {
CFErrorRef error = nil;
CTFontManagerRegisterGraphicsFont(newFont, &error);
// the same font family, remove it and register new one.
if (error) {
CTFontManagerUnregisterGraphicsFont(newFont, NULL);
CTFontManagerRegisterGraphicsFont(newFont, NULL);
CFRelease(error);
}
}
else {
CTFontManagerRegisterGraphicsFont(newFont, NULL);
CFRelease(error);
error = nil;
}
fontFamily = (__bridge_transfer NSString*)CGFontCopyPostScriptName(newFont);
CGFontRelease(newFont);
CFRelease(fontURL);
CFRelease(fontDataProvider);
}
} else {
CFErrorRef error = nil;
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error);
if (error) {
CFRelease(error);
error = nil;
CTFontManagerUnregisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
if (unregisterFontWhenCollision) {
CFErrorRef error = nil;
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error);
if (error) {
CTFontManagerUnregisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
CFRelease(error);
}
}
else {
CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
}
NSArray *descriptors = (__bridge_transfer NSArray *)CTFontManagerCreateFontDescriptorsFromURL(fontURL);
Expand Down

0 comments on commit 0557cf6

Please sign in to comment.