boundingRectForGlyphRange oddness - what on earth?
boundingRectForGlyphRange oddness - what on earth?
- Subject: boundingRectForGlyphRange oddness - what on earth?
- From: Keith Blount <email@hidden>
- Date: Wed, 30 Mar 2005 06:00:01 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello
I have a text view subclass and I want to draw certain
marks behind and above certain characters. To do this,
I am overriding drawRect: and
drawViewBackgroundInRect:, and calculating the areas I
want to custom draw. The method I am using to find the
rect of any given character is this:
- (NSRect)rectForCharacterIndex:(int)charIndex
{
/*
NSLayoutManager *layoutManager = [self
layoutManager];
NSTextContainer *textContainer = [self
textContainer];
NSRange glyphRange = [layoutManager
glyphRangeForCharacterRange:NSMakeRange(charIndex,1)
actualCharacterRange:NULL];
return [layoutManager
boundingRectForGlyphRange:glyphRange
inTextContainer:textContainer];
*/
NSRect rect = [self
firstRectForCharacterRange:NSMakeRange(charIndex,1)];
rect.origin = [[self window]
convertScreenToBase:rect.origin];
rect = [self convertRect:rect fromView:nil];
if (!rect.size.width) rect.size.width = 6.0;
return rect;
}
As you can see, I was using NSLayoutManager's
boundingRectForGlyphRange and then opted for
NSTextView's firstRectForCharacterRange method to
achieve this. However, both have exactly the same,
very weird, problem:
If the charIndex being passed in is a small "i",
everything works fine - it gets the bounding box for
that "i" character. But then, if you type in a small
"f" directly before the "i", so that you have an "fi"
combination, and then you pass in the charIndex for
the "i" that follows the "fi", the rect returned from
my method is for *both* letters - if I want to draw a
circle around the letter "i", for instance, it gets
drawn around both the "f" and the "i". What on earth
is going on here? I have as yet come across no other
letter combination that does this to me.
This is such an abstract problem that I don't hold out
much hope, but if anyone out there knows the problem,
or how I can accurately get the rect of a single
character without fail, I would be very grateful.
Many thanks,
Keith
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden