characterIndex(for:in:fractionOfDistanceBetweenInsertionPoints:)
Returns the index of the character that lies beneath the specified point using the specified container’s coordinate system.
Declaration
func characterIndex(for point: NSPoint, in container: NSTextContainer, fractionOfDistanceBetweenInsertionPoints partialFraction: UnsafeMutablePointer<CGFloat>?) -> IntParameters
- point:
The point to test.
- container:
The text container within which the point is tested.
- partialFraction:
A fraction of the distance from the insertion point, logically before the given character to the next one.
Return Value
The index of the character falling under point.
Discussion
Analogous to glyphIndex(for:in:fractionOfDistanceThroughGlyph:), but expressed in character index terms. The method returns the index of the character falling under point, expressed in coordinate system of container; if no character is under the point, the nearest character is returned, where nearest is defined according to the requirements of selection by mouse. However, this is not simply equivalent to taking the result of the corresponding glyph index method and converting it to a character index, because in some cases a single glyph represents more than one selectable character, for example an fi ligature glyph. In that case, there is an insertion point within the glyph, and this method returns one character or the other, depending on whether the specified point lies to the left or the right of that insertion point.
In general, this method returns only character indexes for which there is an insertion point. The partialFraction is a fraction of the distance from the insertion point, logically before the given character to the next one, which may be either to the right or to the left depending on directionality.
See Also
Performing advanced layout queries
boundingRect(forGlyphRange:in:)characterRange(forGlyphRange:actualGlyphRange:)enumerateEnclosingRects(forGlyphRange:withinSelectedGlyphRange:in:using:)enumerateLineFragments(forGlyphRange:using:)fractionOfDistanceThroughGlyph(for:in:)getLineFragmentInsertionPoints(forCharacterAt:alternatePositions:inDisplayOrder:positions:characterIndexes:)glyphIndex(for:in:)glyphIndex(for:in:fractionOfDistanceThroughGlyph:)glyphRange(forBoundingRect:in:)glyphRange(forBoundingRectWithoutAdditionalLayout:in:)glyphRange(for:)glyphRange(forCharacterRange:actualCharacterRange:)range(ofNominallySpacedGlyphsContaining:)