On Mar 6, 2017, at 3:41 AM, Gerriet M. Denkmann <gerri...@icloud.com> wrote: > > I am trying to get bounding rects in a TextView: > > NSRange glyphRange = [ layoutManager glyphRangeForCharacterRange: > someCharRange > > actualCharacterRange: NULL > ]; > NSTextContainer *container = [ layoutManager textContainerForGlyphAtIndex: > glyphRange.location > > effectiveRange: NULL > ]; > CGRect rect = [ layoutManager boundingRectForGlyphRange: glyphRange > inTextContainer: container ]; > > The problem: > > using the ruler of the TextView I know the actual x-range of someCharRange. > But the rect is much bigger on both sides. > E.g. selecting a string which occupies 1 cm from 19 cm to 20 cm on the ruler > I get a rect : 18.16 + 3.63 = 21.79 > > The error (not very surprisingly) depends on the font used. > > How can I get a rectangle from my string which closely resembles what is seen > on the screen?
Try using -enumerateEnclosingRectsForGlyphRange:withinSelectedGlyphRange:inTextContainer:usingBlock:. In particular, if you want rectangles which match how selection looks, pass a valid range for selectedRange. Regards, Ken _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com