You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/06/15 06:55:21 UTC
incubator-weex git commit: * [ios] cache attributedString for improve
performance while draw Text
Repository: incubator-weex
Updated Branches:
refs/heads/0.13-dev 005b74a2c -> 24de80e5d
* [ios] cache attributedString for improve performance while draw Text
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/24de80e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/24de80e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/24de80e5
Branch: refs/heads/0.13-dev
Commit: 24de80e5d8481b6b6be9e28dbbc65e72f21ac485
Parents: 005b74a
Author: acton393 <zh...@gmail.com>
Authored: Mon Jun 12 17:43:46 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Jun 15 14:54:52 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/24de80e5/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 721ce44..546ca03 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -118,6 +118,7 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
BOOL _truncationLine; // support trunk tail
BOOL _needsRemoveObserver;
+ NSMutableAttributedString * _ctAttributedString;
}
+ (void)setRenderUsingCoreText:(BOOL)usingCoreText
@@ -241,6 +242,7 @@ do {\
- (void)setNeedsRepaint
{
_textStorage = nil;
+ _ctAttributedString = nil;
}
#pragma mark - Subclass
@@ -335,6 +337,14 @@ do {\
return _text;
}
+- (NSMutableAttributedString *)ctAttributedString
+{
+ if (!_ctAttributedString) {
+ _ctAttributedString = [self buildCTAttributeString];
+ }
+ return _ctAttributedString;
+}
+
- (void)repaintText:(NSNotification *)notification
{
if (![_fontFamily isEqualToString:notification.userInfo[@"fontFamily"]]) {
@@ -605,7 +615,7 @@ do {\
CGContextTranslateCTM(context, 0, textFrame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
- NSMutableAttributedString * attributedStringCopy = [self buildCTAttributeString];
+ NSMutableAttributedString * attributedStringCopy = [self ctAttributedString];
//add path
CGPathRef cgPath = NULL;
cgPath = CGPathCreateWithRect(textFrame, NULL);
@@ -749,7 +759,7 @@ do {\
if (truncationTokenLine) {
// default truncationType is kCTLineTruncationEnd
CTLineTruncationType truncationType = kCTLineTruncationEnd;
- NSAttributedString *attributedString = [self buildCTAttributeString];
+ NSAttributedString *attributedString = [self ctAttributedString];
NSAttributedString * lastLineText = nil;
NSRange lastLineTextRange = WXNSRangeFromCFRange(CTLineGetStringRange(lastLine));
NSRange attributeStringRange = NSMakeRange(0, attributedString.string.length);
@@ -817,7 +827,7 @@ do {\
CGFloat totalHeight = 0;
CGSize suggestSize = CGSizeZero;
- NSAttributedString * attributedStringCpy = [self buildCTAttributeString];
+ NSAttributedString * attributedStringCpy = [self ctAttributedString];
CTFramesetterRef framesetterRef = NULL;
framesetterRef = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedStringCpy);