Repository: incubator-weex
Updated Branches:
  refs/heads/0.18.0-hotfix 282e5cb35 -> 793a4e219


[WEEX-496][iOS] In CoreText mode, origin of first line is incorret under iOS9 
or lower.


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

Branch: refs/heads/0.18.0-hotfix
Commit: 793a4e219a7cdee66e3eba30f1a652e4215cd9a8
Parents: 282e5cb
Author: 神漠 <qianyuan....@alipay.com>
Authored: Wed Jul 11 19:56:59 2018 +0800
Committer: Adam Feng <cxfe...@gmail.com>
Committed: Wed Jul 11 20:34:15 2018 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/793a4e21/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 3dcc827..d714b87 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -124,6 +124,8 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
     NSString *_textOverflow;
     CGFloat _lineHeight;
     CGFloat _letterSpacing;
+    CGFloat _fontDescender;
+    CGFloat _fontAscender;
     BOOL _truncationLine; // support trunk tail
     
     NSAttributedString * _ctAttributedString;
@@ -430,6 +432,9 @@ do {\
     CTFontRef ctFont = CTFontCreateWithName((__bridge 
CFStringRef)font.fontName,
                                            font.pointSize,
                                            NULL);
+    _fontAscender = font.ascender;
+    _fontDescender = font.descender;
+    
     if (ctFont) {
         [attributedString addAttribute:(id)kCTFontAttributeName 
value:(__bridge id)(ctFont) range:NSMakeRange(0, string.length)];
         CFRelease(ctFont);
@@ -720,6 +725,15 @@ do {\
         BOOL needTruncation = NO;
         CTLineRef ctTruncatedLine = NULL;
         CTFrameGetLineOrigins(_coreTextFrameRef, CFRangeMake(0, 0), 
lineOrigins);
+        
+        CGFloat fixDescent = 0;
+        if (lineCount > 0 && _lineHeight && WX_SYS_VERSION_LESS_THAN(@"10.0")) 
{
+            CGFloat ascent, descent, leading;
+            CTLineRef line1 = (CTLineRef)CFArrayGetValueAtIndex(ctLines, 0);
+            CTLineGetTypographicBounds(line1, &ascent, &descent, &leading);
+            fixDescent = (descent + _fontDescender) + (ascent - _fontAscender);
+        }
+        
         for (CFIndex lineIndex = 0;(!_lines || _lines > lineIndex) && 
lineIndex < lineCount; lineIndex ++) {
             CTLineRef lineRef = NULL;
             lineRef = CFArrayGetValueAtIndex(ctLines, lineIndex);
@@ -728,7 +742,7 @@ do {\
             }
             CGPoint lineOrigin = lineOrigins[lineIndex];
             lineOrigin.x += padding.left;
-            lineOrigin.y -= padding.top;
+            lineOrigin.y -= padding.top + fixDescent;
             CFArrayRef runs = CTLineGetGlyphRuns(lineRef);
             [mutableLines addObject:(__bridge id _Nonnull)(lineRef)];
             // lineIndex base 0

Reply via email to