Instance Method

enumerateEnclosingRects(forGlyphRange:withinSelectedGlyphRange:in:using:)

Enumerates enclosing rectangles for the given glyph range in the given text container.

Declaration

iOS, Mac Catalyst, tvOS
func enumerateEnclosingRects(forGlyphRange glyphRange: NSRange, withinSelectedGlyphRange selectedRange: NSRange, in textContainer: NSTextContainer, using block: @escaping (CGRect, UnsafeMutablePointer<ObjCBool>) -> Void)
macOS
func enumerateEnclosingRects(forGlyphRange glyphRange: NSRange, withinSelectedGlyphRange selectedRange: NSRange, in textContainer: NSTextContainer, using block: @escaping (NSRect, UnsafeMutablePointer<ObjCBool>) -> Void)

Parameters

glyphRange

The glyph range for which to return enclosing rectangles.

selectedRange

Selected glyphs within glyphRange, which can affect the size of the rectangles. If not interested in selection rectangles, pass {NSNotFound, 0} as the selected range.

textContainer

The text container in which the glyphs are laid out.

block

The block to apply to the glyph range. The block has two arguments:

rect

The current enclosing rectangle.

stop

A reference to a Boolean value. The block can set the value to true to stop further processing of the array. The stop argument is an out-only argument. You should only set this Boolean to true within the block.

Discussion

These rectangles are always in container coordinates. They can be used to draw the text background or highlight for the given range of characters. The rectangles don’t necessarily enclose glyphs that draw outside their line fragment rectangles; use boundingRect(forGlyphRange:in:) to determine the area that contains all drawing performed for a range of glyphs.

If a selected range is given in the second argument, the rectangles returned are correct for drawing the selection. Selection rectangles are generally more complicated than enclosing rectangles, and supplying a selected range determines whether the method does this extra work. This method does the minimum amount of work required to answer the question.

Performs glyph generation and layout if needed.

See Also

Performing Advanced Layout Queries

func boundingRect(forGlyphRange: NSRange, in: NSTextContainer) -> CGRect

Returns a single bounding rectangle (in container coordinates) enclosing all glyphs and other marks drawn in the given text container for the given glyph range, including glyphs that draw outside their line fragment rectangles and text attributes such as underlining.

func characterIndex(for: CGPoint, in: NSTextContainer, fractionOfDistanceBetweenInsertionPoints: UnsafeMutablePointer<CGFloat>?) -> Int

Returns the index of the character falling under the given point, expressed in the given container's coordinate system.

func characterRange(forGlyphRange: NSRange, actualGlyphRange: NSRangePointer?) -> NSRange

Returns the range of characters that generated the glyphs in the given glyph range.

func fractionOfDistanceThroughGlyph(for: CGPoint, in: NSTextContainer) -> CGFloat

This method is a primitive for glyphIndex(for:in:fractionOfDistanceThroughGlyph:). You should always call the main method, not the primitives.

func glyphIndex(for: CGPoint, in: NSTextContainer) -> Int

This method is a primitive for glyphIndex(for:in:fractionOfDistanceThroughGlyph:). You should always call the main method, not the primitives.

func glyphIndex(for: CGPoint, in: NSTextContainer, fractionOfDistanceThroughGlyph: UnsafeMutablePointer<CGFloat>?) -> Int

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

func glyphRange(forBoundingRect: CGRect, in: NSTextContainer) -> NSRange

Returns the smallest contiguous range for glyphs that are laid out wholly or partially within the given rectangle in the given text container.

func glyphRange(forBoundingRectWithoutAdditionalLayout: CGRect, in: NSTextContainer) -> NSRange

Returns the smallest contiguous range for glyphs that are laid out wholly or partially within the given rectangle in the given text container.

func glyphRange(for: NSTextContainer) -> NSRange

Returns the range of glyphs laid out within the given text container.

func glyphRange(forCharacterRange: NSRange, actualCharacterRange: NSRangePointer?) -> NSRange

Returns the range of glyphs that are generated from the characters in the given character range.

func range(ofNominallySpacedGlyphsContaining: Int) -> NSRange

Returns the range for the glyphs around the given glyph that can be displayed using only their advancements from the font, without pairwise kerning or other adjustments to spacing.