NSLayoutManager -boundingRectForGlyphRange:inTextContainer: returned glyph rect is incorrect
Originator: | jlmendezbonini | ||
Number: | rdar://17237078 | Date Originated: | 6/9/2014 |
Status: | Open | Resolved: | |
Product: | iOS | Product Version: | iOS SDK |
Classification: | Reproducible: | Yes |
Summary: There's no reliable way to get the bounding rect for a given glyph with TextKit. Invoking -boundingRectForGlyphRange:inTextContainer returns a rect that doesn't fully enclose the actual drawn glyph. Additionally, the documentation for -enumerateEnclosingRectsForGlyphRange:withinSelectedGlyphRange:inTextContainer:usingBlock: states: "...The rectangles don’t necessarily enclose glyphs that draw outside their line fragment rectangles; use boundingRectForGlyphRange:inTextContainer: to determine the area that contains all drawing performed for a range of glyphs..." It's clearly indicated that boundingRectForGlyphRange should return the actual drawings glyphs, however, this is clearly not the case. Ideally we would have another instance method to get the actual boundingRect for the drawn rect just like CTFontGetBoundingRectsForGlyphs allow us to do in Core Text. Steps to Reproduce: 1. Create a UITextView 2. Add the letter "f" using font "Zapfino". 3. Access the NSLayoutManager object of the UITextView and invoke -boundingRectForGlyphRange:inTextContainer. The returned rectangle doesn't fully enclose the drawn glyph. See the attached project for an example. Expected Results: The bounding rect should fully enclose the drawn glyph. Actual Results: The bounding rect doesn't enclose the actual drawn glyph and clipping occurs. E.g. in the example project the "f" gets clipped if aligned to the right or left. Version: iOS 7.0 and up Notes: Configuration: iPhone, Simulator, etc. Attachments: 'RadarSample.zip' was successfully uploaded.
Comments
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!
Sample code
See: https://github.com/jlmendezbonini/bug_NSLayoutManager-GlyphFrames for sample code.