• 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
boundingRectForGlyphRange is very inaccurate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

boundingRectForGlyphRange is very inaccurate


  • Subject: boundingRectForGlyphRange is very inaccurate
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Mon, 06 Mar 2017 16:41:31 +0700

macOS 12.3, Xcode Version 8.2.1 (8C1002).

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?

Gerriet.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: boundingRectForGlyphRange is very inaccurate
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Enforcing Editor vs. Viewer (was: Which way should my document class handle an older format?)
  • Next by Date: Re: Issue with addTitlebarAccessoryViewController on 10.10
  • Previous by thread: Overriding the automatic-save type
  • Next by thread: Re: boundingRectForGlyphRange is very inaccurate
  • Index(es):
    • Date
    • Thread