Skip to content

Commit

Permalink
Merge pull request twitter-archive#46 from joshaber/cursor-size
Browse files Browse the repository at this point in the history
A better attempt at calculating the cursor size
  • Loading branch information
Loren Brichter committed Aug 12, 2011
2 parents 0bdcaf8 + bc086fa commit 413c779
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/UIKit/TUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ - (void)drawRect:(CGRect)rect
renderer.attributedString = fake;
selection = NSMakeRange(0, 0);
}

CGRect r = [renderer firstRectForCharacterRange:ABCFRangeFromNSRange(selection)];
r.size.width = 2.0;
r.size.height = round(r.size.height) - 2; // fudge
r.origin.x = roundf(r.origin.x);
r.origin.y = roundf(r.origin.y);

// Ugh. So this seems to be a decent approximation for the height of the cursor. It doesn't always match the native cursor but what ev.
CGRect r = CGRectIntegral([renderer firstRectForCharacterRange:ABCFRangeFromNSRange(selection)]);
r.size.width = 2.0f;
CGRect fontBoundingBox = CTFontGetBoundingBox(self.font.ctFont);
r.size.height = round(fontBoundingBox.origin.y + fontBoundingBox.size.height);
r.origin.y += floor(self.font.leading);
// NSLog(@"ascent: %f, descent: %f, leading: %f, cap height: %f, x-height: %f, bounding: %@", self.font.ascender, self.font.descender, self.font.leading, self.font.capHeight, self.font.xHeight, NSStringFromRect(CTFontGetBoundingBox(self.font.ctFont)));

[TUIView setAnimationsEnabled:NO block:^{
cursor.frame = r;
Expand Down

0 comments on commit 413c779

Please sign in to comment.