wqyfavor closed pull request #1306: [WEEX-449][iOS] Fix issue that iconfont may 
randomly display as '?'.
URL: https://github.com/apache/incubator-weex/pull/1306
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m 
b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 952b446bbb..a2ab434ede 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -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];
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h 
b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
index aee32c2e20..53d1308aa9 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
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m 
b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
index 567ba9a261..f2e325efa1 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 @@ + (BOOL)threadSafeCollectionUsingLock
     return threadSafeCollectionUsingLock;
 }
 
++ (void)setUnregisterFontWhenCollision:(BOOL)value
+{
+    unregisterFontWhenCollision = value;
+}
+
 + (void)performBlock:(void (^)(void))block onThread:(NSThread *)thread
 {
     if (!thread || !block) return;
@@ -486,14 +492,18 @@ + (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);
@@ -501,12 +511,16 @@ + (UIFont *)fontWithSize:(CGFloat)size 
textWeight:(CGFloat)textWeight textStyle:
                         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);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to