Repository: incubator-weex
Updated Branches:
  refs/heads/master df0eb7d11 -> 0557cf69f


[WEEX-449][iOS] Fix issue that iconfont may randomly display as '?'.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/0557cf69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/0557cf69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/0557cf69

Branch: refs/heads/master
Commit: 0557cf69f59a95e063f96379dea4be6c09f6b743
Parents: df0eb7d
Author: 神漠 <[email protected]>
Authored: Mon Jul 2 18:01:09 2018 +0800
Committer: Adam Feng <[email protected]>
Committed: Mon Jul 2 19:24:18 2018 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m |  3 ++
 ios/sdk/WeexSDK/Sources/Utility/WXUtility.h   |  2 ++
 ios/sdk/WeexSDK/Sources/Utility/WXUtility.m   | 40 +++++++++++++++-------
 3 files changed, 32 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0557cf69/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m 
b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 952b446..a2ab434 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -322,6 +322,9 @@ typedef enum : NSUInteger {
         [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];

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0557cf69/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h 
b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
index aee32c2..53d1308 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
@@ -487,4 +487,6 @@ BOOL WXFloatGreaterThanWithPrecision(CGFloat a,CGFloat 
b,double precision);
 
 + (BOOL)threadSafeCollectionUsingLock;
 
++ (void)setUnregisterFontWhenCollision:(BOOL)value;
+
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0557cf69/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m 
b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
index 567ba9a..f2e325e 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
@@ -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))
 {
@@ -147,6 +148,11 @@ CGFloat WXFloorPixelValue(CGFloat value)
     return threadSafeCollectionUsingLock;
 }
 
++ (void)setUnregisterFontWhenCollision:(BOOL)value
+{
+    unregisterFontWhenCollision = value;
+}
+
 + (void)performBlock:(void (^)(void))block onThread:(NSThread *)thread
 {
     if (!thread || !block) return;
@@ -486,14 +492,18 @@ CGFloat WXFloorPixelValue(CGFloat value)
                     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);
@@ -501,12 +511,16 @@ CGFloat WXFloorPixelValue(CGFloat value)
                         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);

Reply via email to