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 2018/06/27 07:21:43 UTC

incubator-weex git commit: [WEEX-446, 447][iOS] Fix core text layout bug.

Repository: incubator-weex
Updated Branches:
  refs/heads/master 709d78036 -> aa77c9fa5


[WEEX-446,447][iOS] Fix core text layout bug.


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

Branch: refs/heads/master
Commit: aa77c9fa5e433ce12ed9d77ff370939ef89e1e30
Parents: 709d780
Author: 神漠 <qi...@alipay.com>
Authored: Tue Jun 26 10:38:43 2018 +0800
Committer: Adam Feng <cx...@gmail.com>
Committed: Wed Jun 27 15:21:34 2018 +0800

----------------------------------------------------------------------
 .../WeexSDK/Sources/Component/WXTextComponent.mm  | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/aa77c9fa/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
index 13f470a..714b2ed 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
@@ -971,9 +971,19 @@ do {\
         aWidth = CGFLOAT_MAX;
     }
     aWidth = [attributedStringCpy boundingRectWithSize:CGSizeMake(aWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.width;
+    
+    /* Must get ceil of aWidth. Or core text may not return correct bounds.
+     Maybe aWidth without ceiling triggered some critical conditions. */
+    aWidth = ceil(aWidth);
     CTFramesetterRef ctframesetterRef = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attributedStringCpy));
     suggestSize = CTFramesetterSuggestFrameSizeWithConstraints(ctframesetterRef, CFRangeMake(0, 0), NULL, CGSizeMake(aWidth, MAXFLOAT), NULL);
     
+    if (_lines == 0) {
+        // If not line limit use suggestSize directly.
+        CFRelease(ctframesetterRef);
+        return CGSizeMake(aWidth, suggestSize.height);
+    }
+    
     CGMutablePathRef path = NULL;
     path = CGPathCreateMutable();
         // sufficient height to draw text
@@ -982,15 +992,14 @@ do {\
     CTFrameRef frameRef = NULL;
     frameRef = CTFramesetterCreateFrame(ctframesetterRef, CFRangeMake(0, attributedStringCpy.length), path, NULL);
     CGPathRelease(path);
+    CFRelease(ctframesetterRef);
     
-    CFArrayRef lines = NULL;
     if (NULL == frameRef) {
         //try to protect unexpected crash.
         return suggestSize;
     }
-    CFRelease(ctframesetterRef);
-    ctframesetterRef = NULL;
-    lines = CTFrameGetLines(frameRef);
+    
+    CFArrayRef lines = CTFrameGetLines(frameRef);
     CFIndex lineCount = CFArrayGetCount(lines);
     CGFloat ascent = 0;
     CGFloat descent = 0;
@@ -1010,7 +1019,6 @@ do {\
     
     totalHeight = totalHeight + actualLineCount * leading;
     CFRelease(frameRef);
-    frameRef = NULL;
     
     if (WX_SYS_VERSION_LESS_THAN(@"10.0")) {
         // there is something wrong with coreText drawing text height, trying to fix this with more efficent way.