<!--
{
  "availability" : [
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSLayoutManager/glyphIndex(for:in:fractionOfDistanceThroughGlyph:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSLayoutManager(im)glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:"
  },
  "title" : "glyphIndex(for:in:fractionOfDistanceThroughGlyph:)"
}
-->

# glyphIndex(for:in:fractionOfDistanceThroughGlyph:)

Returns the index of the glyph at the specified point using the container’s coordinate system.

```
func glyphIndex(for point: NSPoint, in container: NSTextContainer, fractionOfDistanceThroughGlyph partialFraction: UnsafeMutablePointer<CGFloat>?) -> Int
```

## Parameters

`point`

The point for which to return the glyph, in coordinates of `container`.

`container`

The container in which the returned glyph is laid out.

`partialFraction`

If not `NULL`, on output, the fraction of the distance between the location of the glyph returned and the location of the next glyph.

## Return Value

The index of the glyph falling under the given point, expressed in the given container’s coordinate system.

## Discussion

If no glyph is under `point`, the nearest glyph is returned, where nearest is defined according to the requirements of selection by mouse. Clients who wish to determine whether the the point actually lies within the bounds of the glyph returned should follow this with a call to [`boundingRect(forGlyphRange:in:)`](/documentation/AppKit/NSLayoutManager/boundingRect(forGlyphRange:in:)) and test whether the point falls in the rectangle returned by that method. If `partialFraction` is non-NULL, it returns by reference the fraction of the distance between the location of the glyph returned and the location of the next glyph.

For purposes such as dragging out a selection or placing the insertion point, a partial percentage less than or equal to 0.5 indicates that `point` should be considered as falling before the glyph index returned; a partial percentage greater than 0.5 indicates that it should be considered as falling after the glyph index returned. If the nearest glyph doesn’t lie under `point` at all (for example, if `point` is beyond the beginning or end of a line), this ratio is 0 or 1.

If the glyph stream contains the glyphs “A” and “b”, with the width of “A” being 13 points, and the user clicks at a location 8 points into “A”, `partialFraction` is 8/13, or 0.615. In this case, the point given should be considered as falling between “A” and “b” for purposes such as dragging out a selection or placing the insertion point.

Performs glyph generation and layout if needed.

As part of its implementation, this method calls [`fractionOfDistanceThroughGlyph(for:in:)`](/documentation/AppKit/NSLayoutManager/fractionOfDistanceThroughGlyph(for:in:)) and [`glyphIndex(for:in:)`](/documentation/AppKit/NSLayoutManager/glyphIndex(for:in:)). To change this method’s behavior, override those two methods instead of this one.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)