rectArray(forGlyphRange:withinSelectedGlyphRange:in:rectCount:)
Returns an array of rectangles and, by reference, the number of such rectangles, that define the region in the given container enclosing the given glyph range.
Declaration
func rectArray(forGlyphRange glyphRange: NSRange, withinSelectedGlyphRange selGlyphRange: NSRange, in container: NSTextContainer, rectCount: UnsafeMutablePointer<Int>) -> NSRectArray?Parameters
- glyphRange:
The glyph range for which to return rectangles.
- selGlyphRange:
Selected glyphs within
glyphRange, which can affect the size of the rectangles; it must be equal to or containglyphRange. If the caller is interested in this more from an enclosing point of view rather than a selection point of view, pass{NSNotFound, 0}as the selected range. - container:
The text container in which the text is laid out.
- rectCount:
The number of rectangles returned.
Return Value
The array of rectangles enclosing the given range.
Discussion
These rectangles can be used to draw the text background or highlight for the given range of characters. If a selected range is given in selGlyphRange, the rectangles returned are correct for drawing the selection. Selection rectangles are generally more complicated than enclosing rectangles and supplying a selected range is the clue this method uses to determine whether to go to the trouble of doing this special work.
The number of rectangles returned isn’t necessarily the number of lines enclosing the specified range. Contiguous lines can share an enclosing rectangle, and lines broken into several fragments have a separate enclosing rectangle for each fragment.
This method will do the minimum amount of work required to answer the question. The resulting array is owned by the layout manager and will be reused when this method, rectArray(forCharacterRange:withinSelectedCharacterRange:in:rectCount:), or boundingRect(forGlyphRange:in:) is called. One of these methods may be called indirectly. If you aren’t going to use the rectangles right away, you should copy them to another location. These rectangles are always in container coordinates.
The purpose of this method is to calculate line rectangles for drawing the text background and highlighting. These 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.
Performs glyph generation and layout if needed.
See Also
Methods
showCGGlyphs(_:positions:count:font:matrix:attributes:in:)invalidateGlyphs(onLayoutInvalidationForGlyphRange:)invalidateLayout(forCharacterRange:isSoft:actualCharacterRange:)textStorage(_:edited:range:changeInLength:invalidatedRange:)insertGlyph(_:atGlyphIndex:characterIndex:)insertGlyphs(_:length:forStartingGlyphAt:characterIndex:)glyph(at:)glyph(at:isValidIndex:)replaceGlyph(at:withGlyph:)getGlyphs(_:range:)getGlyphs(in:glyphs:characterIndexes:glyphInscriptions:elasticBits:)getGlyphs(in:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:)deleteGlyphs(in:)setCharacterIndex(_:forGlyphAt:)intAttribute(_:forGlyphAt:)