You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2017/04/13 11:21:11 UTC
[21/23] incubator-weex git commit: * [ios] adjust configuation
* [ios] adjust configuation
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/efd56009
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/efd56009
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/efd56009
Branch: refs/heads/0.12-dev
Commit: efd56009158bca5fac3fea41c2c4c80a775d53cd
Parents: e100f8a
Author: acton393 <zh...@gmail.com>
Authored: Thu Apr 13 18:18:46 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Apr 13 18:18:46 2017 +0800
----------------------------------------------------------------------
.../WeexSDK/Sources/Component/WXTextComponent.h | 2 +-
.../WeexSDK/Sources/Component/WXTextComponent.m | 26 ++++++-------
ios/sdk/WeexSDK/Sources/Utility/WXUtility.m | 40 ++++++++++++++------
3 files changed, 43 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/efd56009/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
index 800a909..7fb8f34 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
@@ -22,6 +22,6 @@
@interface WXTextComponent : WXComponent
+ (void)setRenderUsingCoreText:(BOOL)usingCoreText;
-+ (BOOL)textRenderUsingCoreText;
++ (BOOL)useCoreText;
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/efd56009/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index 29f0b24..a6d24d9 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -81,10 +81,7 @@
@end
static BOOL textRenderUsingCoreText = NO;
-
-@interface WXTextComponent()
-@property (nonatomic, assign)BOOL coretext;
-@end
+static BOOL useCoreTextAttr = NO;
@implementation WXTextComponent
{
@@ -127,9 +124,9 @@ static BOOL textRenderUsingCoreText = NO;
if (self) {
// just for coretext and textkit render replacement
if ([attributes objectForKey:@"coretext"]) {
- _coretext = [WXConvert BOOL:attributes[@"coretext"]];
+ useCoreTextAttr = [WXConvert BOOL:attributes[@"coretext"]];
} else {
- _coretext = NO;
+ _useCoreTextAttr = NO;
}
[self fillCSSStyles:styles];
@@ -139,9 +136,15 @@ static BOOL textRenderUsingCoreText = NO;
return self;
}
-- (BOOL)useCoreText
++ (BOOL)useCoreText
{
- return (_coretext || [WXTextComponent textRenderUsingCoreText]);
+ if (useCoreTextAttr) {
+ return YES;
+ }
+ if ([WXTextComponent textRenderUsingCoreText]) {
+ return YES;
+ }
+ return NO;
}
- (void)dealloc
@@ -256,7 +259,7 @@ do {\
return ^CGSize (CGSize constrainedSize) {
CGSize computedSize = CGSizeZero;
NSTextStorage *textStorage = nil;
- if (!(weakSelf.coretext && [WXTextComponent textRenderUsingCoreText]) ) {
+ if (![self useCoreText]) {
textStorage = [weakSelf textStorageWithWidth:constrainedSize.width];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
@@ -318,9 +321,7 @@ do {\
- (NSMutableAttributedString *)buildCTAttributeString {
NSString *string = [self text] ?: @"";
-
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
-
if (_color) {
[attributedString addAttribute:NSForegroundColorAttributeName value:_color range:NSMakeRange(0, string.length)];
}
@@ -552,7 +553,7 @@ do {\
}else {
CGRect textFrame = UIEdgeInsetsInsetRect(bounds, padding);
// sufficient height for text to draw, or frame lines will be empty
- textFrame.size.height = bounds.size.height*2;
+ textFrame.size.height = bounds.size.height * 2;
CGContextSaveGState(context);
//flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
@@ -676,7 +677,6 @@ static void WXTextGetRunsMaxMetric(CFArrayRef runs, CGFloat *xHeight, CGFloat *u
if (attrs) {
CTFontRef font = CFDictionaryGetValue(attrs, kCTFontAttributeName);
if (font) {
-
CGFloat xHeight = CTFontGetXHeight(font);
if (xHeight > maxXHeight) {
maxXHeight = xHeight;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/efd56009/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 466a563..22faf05 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
@@ -33,6 +33,8 @@
#import <CommonCrypto/CommonCrypto.h>
#import <coreText/CoreText.h>
+#import "WXTextComponent.h"
+
#define KEY_PASSWORD @"com.taobao.Weex.123456"
#define KEY_USERNAME_PASSWORD @"com.taobao.Weex.weex123456"
@@ -455,24 +457,40 @@ static BOOL WXNotStat;
// if the font file is not the correct font file. it will crash by singal 9
CFURLRef fontURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (__bridge CFStringRef)fpath, kCFURLPOSIXPathStyle, false);
if (fontURL) {
- CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL(fontURL);
- if (fontDataProvider) {
- CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
+ if ([WXTextComponent useCoreText]) {
+ 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);
+ CTFontManagerRegisterGraphicsFont(newFont, NULL);
+ CFRelease(error);
+ error = nil;
+ }
+ fontFamily = (__bridge_transfer NSString*)CGFontCopyPostScriptName(newFont);
+ CGFontRelease(newFont);
+ CFRelease(fontURL);
+ CFRelease(fontDataProvider);
+ }
+ } else {
CFErrorRef error = nil;
- CTFontManagerRegisterGraphicsFont(newFont, &error);
- // the same font family, remove it and register new one.
+ CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error);
if (error) {
- CTFontManagerUnregisterGraphicsFont(newFont, NULL);
- CTFontManagerRegisterGraphicsFont(newFont, NULL);
CFRelease(error);
error = nil;
+ CTFontManagerUnregisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
+ CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, NULL);
+ }
+ NSArray *descriptors = (__bridge_transfer NSArray *)CTFontManagerCreateFontDescriptorsFromURL(fontURL);
+ // length of descriptors here will be only one.
+ for (UIFontDescriptor *desc in descriptors) {
+ font = [UIFont fontWithDescriptor:desc size:fontSize];
}
- fontFamily = (__bridge_transfer NSString*)CGFontCopyPostScriptName(newFont);
- CGFontRelease(newFont);
CFRelease(fontURL);
- CFRelease(fontDataProvider);
}
-
}
}else {
[[WXRuleManager sharedInstance] removeRule:@"fontFace" rule:@{@"fontFamily": fontFamily}];