[
https://issues.apache.org/jira/browse/WEEX-496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16642761#comment-16642761
]
ASF GitHub Bot commented on WEEX-496:
-------------------------------------
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:
[email protected]
> In CoreText mode, origin of first line is incorret under iOS9 or lower
> ----------------------------------------------------------------------
>
> Key: WEEX-496
> URL: https://issues.apache.org/jira/browse/WEEX-496
> Project: Weex
> Issue Type: Bug
> Components: iOS
> Affects Versions: 0.19
> Reporter: Wang Qianyuan
> Assignee: xingZhang
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)