You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/10/09 03:55:12 UTC

[GitHub] Hanks10100 closed pull request #1319: [WEEX-496][iOS] In CoreText mode, origin of first line is incorret un…

Hanks10100 closed pull request #1319: [WEEX-496][iOS] In CoreText mode, origin of first line is incorret un…
URL: https://github.com/apache/incubator-weex/pull/1319
 
 
   

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/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index 3dcc827d07..d714b87abb 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -124,6 +124,8 @@ @implementation WXTextComponent
     NSString *_textOverflow;
     CGFloat _lineHeight;
     CGFloat _letterSpacing;
+    CGFloat _fontDescender;
+    CGFloat _fontAscender;
     BOOL _truncationLine; // support trunk tail
     
     NSAttributedString * _ctAttributedString;
@@ -430,6 +432,9 @@ - (NSMutableAttributedString *)buildCTAttributeString
     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 @@ - (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:
         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 @@ - (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:
             }
             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


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services