• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: boundingRectForGlyphRange oddness - what on earth?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: boundingRectForGlyphRange oddness - what on earth?


  • Subject: Re: boundingRectForGlyphRange oddness - what on earth?
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 30 Mar 2005 12:48:52 -0800


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 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

References: 
 >boundingRectForGlyphRange oddness - what on earth? (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: Check for Mac OS Version
  • Next by Date: adding NSView from other application
  • Previous by thread: Re: boundingRectForGlyphRange oddness - what on earth?
  • Next by thread: Re: boundingRectForGlyphRange oddness - what on earth?
  • Index(es):
    • Date
    • Thread