Re: boundingRectForGlyphRange oddness - what on earth?
Re: boundingRectForGlyphRange oddness - what on earth?
- Subject: Re: boundingRectForGlyphRange oddness - what on earth?
- From: Keith Blount <email@hidden>
- Date: Wed, 30 Mar 2005 15:30:08 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks for your reply, Douglas, you have been
incredibly helpful with every question I have had
about tracking text co-ordinates over the past few
months. Also many thanks to Serge and Marcus who
pointed out that I had overlooked ligatures - my
earlier reply to the list thanking them seems to have
gone missing.
After Marcus's reply, I did see that the problem
disappeared if I turned ligatures off via the Format
menu in my app, though this seems a rather brute force
solution.
Following your suggestion and checking the layout
manager docs again, I updated my method as follows:
- (NSRect)rectForCharacterIndex:(int)charIndex
{
NSLayoutManager *layoutManager = [self
layoutManager];
NSTextContainer *textContainer = [self
textContainer];
unsigned rectCount;
NSRectArray rectArray = [layoutManager
rectArrayForCharacterRange:NSMakeRange(charIndex,1)
withinSelectedCharacterRange:NSMakeRange(NSNotFound,0)
inTextContainer:textContainer
rectCount:&rectCount];
if (rectCount)
return rectArray[0];
return NSZeroRect;
}
Unfortunately, this has made no difference - the rect
returned is still for the whole ligature ("fi" for the
"i", "fl" for the "l" etc). I am using this code to
custom highlight text that is attached to an
associated note, so it needs to be accurate - so it
seems that I will have to take the brute force
approach after all and turn off ligatures. I don't
quite understand why this method isn't working for me
if it is responsible for drawing text selection,
though, which clearly doesn't have a problem with
ligatures. Am I missing something?
Many thanks again,
Keith
--- Douglas Davidson <email@hidden> wrote:
>
> On Mar 30, 2005, at 6:00 AM, Keith Blount wrote:
>
> > 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.
> >
>
> What you are seeing here is a ligature. In the font
> you are using,
> the two characters 'f' and 'i' in combination are
> represented by a
> single 'fi' glyph. Common ligatures in Latin text
> are 'fi', 'ff',
> 'fl', 'ffi', and 'ffl'. Some fonts will make use of
> some of these,
> some will not.
>
> You can prevent the use of ligatures by adding the
> attribute
> NSLigatureAttributeName to your text, with the value
> [NSNumber
> numberWithInt:0]. However, before you try that, I
> would suggest that
> you try using NSLayoutManager's
>
rectArrayForCharacterRange:withinSelectedCharacterRange:inTextContainer:
>
> rectCount: method instead. This (along with its
> glyph-based
> companion) is the most specific and sophisticated
> means of
> determining rects for portions of text; it is the
> method used for
> selection rectangles, for example.
>
> As the header notes suggest, you can pass
> {NSNotFound, 0} for the
> selCharRange argument. If you want a rect for a
> single character,
> look at the returned-by-reference rectCount to make
> sure it is
> nonzero, and if so look at the first rect in the
> returned C array.
>
> Douglas Davidson
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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