• 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: Cocoa Text System: How to determine the caret position?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Text System: How to determine the caret position?


  • Subject: Re: Cocoa Text System: How to determine the caret position?
  • From: Graham Cox <email@hidden>
  • Date: Tue, 24 Jun 2008 12:30:59 +1000

Yes, fair enough the problem is more complicated than I realised - I guess I assumed that insertion points were always in between glyphs but of course with ligatures etc. that isn't the case.

Going back to the OP's original reason for this, My feeling is that he's going about it the wrong way. Core Text isn't a text editing framework, it's a text layout framework. I thought that using Cocoa's text system you can get text editing as well as layout for arbitrary text containers including text on a path or vertical text. However it's one thing to say it's possible and another to suggest how to do it, and I don't have the expertise to do that. But reinventing your own text editor from scratch seems like a lot of unnecessary work.

cheers, Graham


On 24 Jun 2008, at 10:52 am, Douglas Davidson wrote:


On Jun 23, 2008, at 5:33 PM, Graham Cox wrote:

[NSLayoutManager_inst characterIndexForGlyphAtIndex:ig];

[NSLayoutManager_inst locationForGlyphAtIndex:ig];



On 24 Jun 2008, at 8:25 am, Yung-Luen Lan wrote:

Is there any way to obtain the position information based on
character, not glyph?


Graham, you're reducing the problem too far. Converting the character index to a glyph index, then getting the location for that glyph index, is probably what the OP is already doing, and as he notes, it won't return an insertion point position within a glyph. In general insertion point positions are not necessarily identical to glyph locations.


The Cocoa text system has a couple of solutions for this: first, you can use rectArrayForCharacterRange:withinSelectedCharacterRange:inTextContainer:rectCount : with a zero-length range to obtain a single insertion point location; second, you can use getLineFragmentInsertionPointsForCharacterAtIndex:alternatePositions:inDisplayOrder:positions:characterIndexes : to obtain insertion points in bulk for an entire line (useful for movement and so on).

However, the OP in the body of the message seems to say that he's using CoreText, while the subject refers to the Cocoa text system. It's not clear which one is intended. In CoreText, I believe the relevant call would be CTLineGetOffsetForStringIndex(), where the index in question is a character index.

Douglas Davidson


_______________________________________________

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: Cocoa Text System: How to determine the caret position?
      • From: Douglas Davidson <email@hidden>
References: 
 >Cocoa Text System: How to determine the caret position? (From: "Yung-Luen Lan" <email@hidden>)
 >Re: Cocoa Text System: How to determine the caret position? (From: Graham Cox <email@hidden>)
 >Re: Cocoa Text System: How to determine the caret position? (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: CoreData pagination
  • Next by Date: How to get a message when RETURN is pressed in a NSTextField
  • Previous by thread: Re: Cocoa Text System: How to determine the caret position?
  • Next by thread: Re: Cocoa Text System: How to determine the caret position?
  • Index(es):
    • Date
    • Thread