Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Fix text line-height property error
Browse files Browse the repository at this point in the history
  • Loading branch information
Txink committed Jul 19, 2019
1 parent f8c3d29 commit 272a393
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,6 @@ - (NSMutableAttributedString *)buildCTAttributeString
[attributedString addAttribute:NSKernAttributeName value:@(_letterSpacing) range:(NSRange){0, attributedString.length}];
}

if ([self adjustLineHeight]) {
if (_lineHeight > font.lineHeight) {
[attributedString addAttribute:NSBaselineOffsetAttributeName
value:@((_lineHeight - font.lineHeight)/ 2)
range:(NSRange){0, attributedString.length}];
}
}

return attributedString;
}

Expand Down Expand Up @@ -638,13 +630,6 @@ - (NSAttributedString *)buildAttributeString
value:paragraphStyle
range:(NSRange){0, attributedString.length}];
}
if ([self adjustLineHeight]) {
if (_lineHeight > font.lineHeight) {
[attributedString addAttribute:NSBaselineOffsetAttributeName
value:@((_lineHeight - font.lineHeight)/ 2)
range:(NSRange){0, attributedString.length}];
}
}

return attributedString;
}
Expand Down Expand Up @@ -800,12 +785,11 @@ - (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:
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);
lineOrigins[0].y += (_lineHeight-(leading+ascent+descent))/2;
}

for (CFIndex lineIndex = 0;(!_lines || _lines > lineIndex) && lineIndex < lineCount; lineIndex ++) {
Expand All @@ -816,7 +800,12 @@ - (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:
}
CGPoint lineOrigin = lineOrigins[lineIndex];
lineOrigin.x += padding.left;
lineOrigin.y -= padding.top + fixDescent;
if(_lineHeight && WX_SYS_VERSION_LESS_THAN(@"10.0")){
lineOrigin.y = lineOrigins[0].y - padding.top - _lineHeight * lineIndex ;
}else{
lineOrigin.y = lineOrigin.y - padding.top ;
}

CFArrayRef runs = CTLineGetGlyphRuns(lineRef);
[mutableLines addObject:(__bridge id _Nonnull)(lineRef)];
// lineIndex base 0
Expand Down Expand Up @@ -869,12 +858,6 @@ - (void)drawTextWithRuns:(CFArrayRef)runs context:(CGContextRef)context lineOrig
run = (CTRunRef)CFArrayGetValueAtIndex(runs, runIndex);
CFDictionaryRef attr = NULL;
attr = CTRunGetAttributes(run);
if (0 == runIndex) {
NSNumber *baselineOffset = (NSNumber*)CFDictionaryGetValue(attr, (__bridge void *)NSBaselineOffsetAttributeName);
if (baselineOffset) {
lineOrigin.y += [baselineOffset doubleValue];
}
}
//To properly draw the glyphs in a run, the fields tx and ty of the CGAffineTransform returned by CTRunGetTextMatrix should be set to the current text position.
CGAffineTransform transform = CTRunGetTextMatrix(run);
transform.tx = lineOrigin.x;
Expand Down

0 comments on commit 272a393

Please sign in to comment.