-[NSLayoutManager boundingRectForGlyphRange:inTextContainer:] does not return the glyph bouning rect

Originator:mrjohnniewalker
Number:rdar://24257941 Date Originated:20-Jan-2016 03:13 PM
Status:Open Resolved:
Product:OS X Product Version:10.11.2
Classification:Serious Bug Reproducible:Always
 
Summary:

-[NSLayoutManager boundingRectForGlyphRange:inTextContainer:] should return the rectangle used to contain the glyphs, but this is not true in all circumstances, for example with calligraphic fonts such as Zapfino or Snell Roundhand

From the NSLayoutManager documentation
- (NSRect)boundingRectForGlyphRange:(NSRange)glyphRange inTextContainer:(NSTextContainer *)container

“This method can be used to translate glyph ranges into display rectangles for invalidation and redrawing when a range of glyphs changes.”

Steps to Reproduce:
Typeset a line using the string “Oh Zapfino!” in Zapfino 100pt, and use -[NSLayoutManager boundingRectForGlyphRange:inTextContainer:] to query the glyph bounds.

Expected Results:
The returned rectangle should contain the glyphs.

Actual Results:
The returned rectangle is too small to contain the glyphs by some margin.

Regression:
I have not seen this succeed in any configuration.

Notes:
I recognise APIs do exist at the CoreText level to accurately measure the bounds, but this problematic when used with a custom NSTypesetter subclass.

Comments

Response from Apple Developer Relations

This issue behaves as intended based on the following:

The method is designed to work in the typographic bounds, not image bounds.

Please update your bug report to let us know if this is still an issue for you.

By mrjohnniewalker at Feb. 11, 2016, 9:24 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!