Skip to content

Commit

Permalink
version 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amao committed Nov 29, 2018
1 parent f9c95cf commit afd49b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion M80AttributedLabel.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'M80AttributedLabel'
s.version = '1.7.2'
s.version = '1.8.0'
s.authors = {'Xiang Wangfeng' => '[email protected]'}
s.homepage = 'https://github.com/xiangwangfeng/M80AttributedLabel/'
s.summary = 'Another attributed label using CoreText'
Expand Down
12 changes: 5 additions & 7 deletions M80AttributedLabel/M80AttributedLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ - (CGRect)rectForRange:(NSRange)range
CFArrayRef runs = CTLineGetGlyphRuns(line);
CFIndex runCount = CFArrayGetCount(runs);

// Iterate through each of the "runs" (i.e. a chunk of text) and find the runs that
// intersect with the range.
for (CFIndex k = 0; k < runCount; k++)
{
CTRunRef run = CFArrayGetValueAtIndex(runs, k);
Expand All @@ -473,20 +471,18 @@ - (CGRect)rectForRange:(NSRange)range

if (intersectedRunRange.length == 0)
{
// This run doesn't intersect the range, so skip it.
continue;
}

CGFloat ascent = 0.0f;
CGFloat descent = 0.0f;
CGFloat leading = 0.0f;

// Use of 'leading' doesn't properly highlight Japanese-character link.
CGFloat width = (CGFloat)CTRunGetTypographicBounds(run,
CFRangeMake(0, 0),
&ascent,
&descent,
NULL); //&leading);
NULL);
CGFloat height = ascent + descent;

CGFloat xOffset = CTLineGetOffsetForStringIndex(line, CTRunGetStringRange(run).location, nil);
Expand Down Expand Up @@ -768,6 +764,7 @@ - (void)drawHighlightWithRect:(CGRect)rect
CGRect highlightRect = [self rectForRange:linkRange
inLine:line
lineOrigin:lineOrigins[i]];

highlightRect = CGRectOffset(highlightRect, 0, -rect.origin.y);
if (!CGRectIsEmpty(highlightRect))
{
Expand Down Expand Up @@ -844,7 +841,8 @@ - (void)drawText:(NSAttributedString *)attributedString

if (lastLineRange.length > 0)
{
//移除掉最后一个对象...(其实这个地方有点问题,也有可能需要移除最后 2 个对象,因为 attachment 宽度的关系)
//移除掉最后一个对象...
//其实这个地方有点问题,也有可能需要移除最后 2 个对象,因为 attachment 宽度的关系
[truncationString deleteCharactersInRange:NSMakeRange(lastLineRange.length - 1, 1)];
}
[truncationString appendAttributedString:tokenString];
Expand Down Expand Up @@ -909,7 +907,7 @@ - (void)drawAttachments
CGFloat lineHeight = lineAscent + lineDescent;
CGFloat lineBottomY = lineOrigin.y - lineDescent;

//遍历以找到对应的 attachment 进行绘制
//遍历找到对应的 attachment 进行绘制
for (CFIndex k = 0; k < runCount; k++)
{
CTRunRef run = CFArrayGetValueAtIndex(runs, k);
Expand Down
6 changes: 4 additions & 2 deletions M80AttributedLabel/M80AttributedLabelURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ + (NSDataDetector *)linkDetector
NSDataDetector *detector = dict[M80LinkDetectorKey];
if (detector == nil)
{

detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber
error:nil];
dict[M80LinkDetectorKey] = detector;
if (detector)
{
dict[M80LinkDetectorKey] = detector;
}
}
return detector;
}
Expand Down

0 comments on commit afd49b4

Please sign in to comment.