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

Re: boundingRectForGlyphRange is very inaccurate


  • Subject: Re: boundingRectForGlyphRange is very inaccurate
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Tue, 07 Mar 2017 17:17:31 +0700

> On 6 Mar 2017, at 23:26, Ken Thomases <email@hidden> wrote:
>
> On Mar 6, 2017, at 3:41 AM, Gerriet M. Denkmann <email@hidden> 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.

Does return the same results as boundingRectForGlyphRange.

One thing I forgot, was to shift the returned rect by lineFragmentPadding in order to get values compatible with NSTextTab.

Now everything is fine, as long one does not use strange characters, which are defined as Thai, Laos, Burma.
Non-strange chars are Ascii, Khmer, Chinese.

I have a TextView where all lines start at 0 and end at 10.028 cm (because there is a right tab at the end).

Helvetica 北京	 0.000 → 10.028 cm	北0	← this is a line with a correct rect; all following lines are wrong:

Thonburi ม	-0.263 → 10.404 cm	h1
Helvetica  Thonburi ท	-0.402 → 10.397 cm	t6
Helvetica  Thonburi	-0.402 → 10.413 cm	หด
Lao Sangam  ລາວ	-0.428 → 10.400 cm 	12
Myanmar  သမ္မတ	-0.428 → 10.400 cm 	14

One sees that the reported line rectangle is too big on both ends (should be 0.000 → 10.028 cm for all lines).


Kind regards,

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>
References: 
 >boundingRectForGlyphRange is very inaccurate (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: boundingRectForGlyphRange is very inaccurate (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: My method causes DATA LOSS! (was: Can I use the restore/auto-save loading functions for imports?)
  • Next by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Previous by thread: Re: boundingRectForGlyphRange is very inaccurate
  • Next by thread: Re: boundingRectForGlyphRange is very inaccurate
  • Index(es):
    • Date
    • Thread