GlyphRun
public class GlyphRun
A glyph run is a collection of consecutive glyphs sharing the same attributes and direction.
-
The UTF-16 range of this run in source string.
Declaration
Swift
public var codeUnitRange: Range<Int> { get }
-
The index to the first character of this run in source string.
Declaration
Swift
public var startIndex: String.Index { get }
-
The index after the last character of this run in source string.
Declaration
Swift
public var endIndex: String.Index { get }
-
The extra excluded length at the start of the cluster map.
If the first cluster of this run begins within the extra range, then its rendering will be clipped from the start. The amount of clipping would be equal to the perceived trailing caret position of last excluded character.
For example, consider three characters
f
,i
and anotheri
form a cluster having a single ligature,fii
and the run starts from the secondi
withf
andi
being extra characters. In this case, the ligature would be divided into three equal parts and the first two parts would be clipped.Declaration
Swift
public var startExtraLength: Int { get }
-
The extra excluded length at the end of the cluster map.
If the last cluster of this run finishes within the excluded range, then its rendering will be clipped from the end. The amount of clipping would be equal to the perceived leading caret position of first excluded character.
For example, consider three characters
f
,i
and anotheri
form a cluster having a single ligature,fii
and the run consists of justf
with bothi
being extra characters. In this case, the ligature would be divided into three equal parts and the last two parts would be clipped.Declaration
Swift
public var endExtraLength: Int { get }
-
The bidirectional level of this run.
Declaration
Swift
public var bidiLevel: UInt8 { get }
-
The writing direction of this run.
Declaration
Swift
public var writingDirection: WritingDirection { get }
-
The typeface of this run.
Declaration
Swift
public var typeface: Typeface { get }
-
The type size of this run.
Declaration
Swift
public var typeSize: CGFloat { get }
-
The ascent of this run, which is the distance from the top of the run to the baseline. It is always either positive or zero.
Declaration
Swift
public var ascent: CGFloat { get }
-
The descent of this run, which is the distance from the baseline to the bottom of the run. It is always either positive or zero.
Declaration
Swift
public var descent: CGFloat { get }
-
The leading of this run, which is the distance that should be placed between two lines.
Declaration
Swift
public var leading: CGFloat { get }
-
The origin of this run in parent line.
Declaration
Swift
public internal(set) var origin: CGPoint { get }
-
The typographic width of this run.
Declaration
Swift
public var width: CGFloat { get }
-
The typographic height of this run.
Declaration
Swift
public var height: CGFloat { get }
-
The glyph IDs of this run.
Declaration
Swift
public var glyphIDs: PrimitiveCollection<GlyphID> { get }
-
The glyph offsets of this run.
Declaration
Swift
public var glyphOffsets: PrimitiveCollection<CGPoint> { get }
-
The glyph advances of this run.
Declaration
Swift
public var glyphAdvances: PrimitiveCollection<CGFloat> { get }
-
The indexes, mapping each code unit of this run to corresponding glyph.
Declaration
Swift
public var clusterMap: PrimitiveCollection<Int> { get }
-
Returns the index to the first UTF-16 code unit of specified cluster in source string. In most cases, it would be the same index as the specified one. But if the code unit occurs within a cluster, then a previous index would be returned; whether the run logically flows forward or backward.
Declaration
Swift
public func clusterStart(forCodeUnitAt index: Int) -> Int
Parameters
index
The index of a code unit in source string.
Return Value
The index to the first code unit of specified cluster in source string.
-
Returns the index to the first character of specified cluster in source string. In most cases, it would be the same index as the specified one. But if the character occurs within a cluster, then a previous index would be returned; whether the run logically flows forward or backward.
Declaration
Swift
public func clusterStart(forCharacterAt index: String.Index) -> String.Index
Parameters
index
The index of a character in source string.
Return Value
The index to the first character of specified cluster in source string.
-
Returns the index after the last UTF-16 code unit of specified cluster in source string. In most cases, it would be an index after the specified one. But if the code unit occurs within a cluster, then a farther index would be returned; whether the run logically flows forward or backward.
Declaration
Swift
public func clusterEnd(forCodeUnitAt index: Int) -> Int
Parameters
index
The index of a code unit in source string.
Return Value
The index after the last code unit of specified cluster in source string.
-
Returns the index after the last character of specified cluster in source string. In most cases, it would be an index after the specified one. But if the character occurs within a cluster, then a farther index would be returned; whether the run logically flows forward or backward.
Declaration
Swift
public func clusterEnd(forCharacterAt index: String.Index) -> String.Index
Parameters
index
The index of a character in source string.
Return Value
The index after the last character of specified cluster in source string.
-
Returns the index of leading glyph related to the specified cluster. It will come after the trailing glyph, if the characters of this run logically flow backward.
Declaration
Swift
public func leadingGlyphIndex(forCodeUnitAt index: Int) -> Int
Parameters
index
The index of a UTF-16 code unit in source string.
Return Value
The index of leading glyph related to the specified cluster.
-
Returns the index of leading glyph related to the specified cluster. It will come after the trailing glyph, if the characters of this run logically flow backward.
Declaration
Swift
public func leadingGlyphIndex(forCharacterAt index: String.Index) -> Int
Parameters
index
The index of a character in source string.
Return Value
The index of leading glyph related to the specified cluster.
-
Returns the index of trailing glyph related to the specified cluster. It will come before the leading glyph, if the characters of this run logically flow backward.
Declaration
Swift
public func trailingGlyphIndex(forCodeUnitAt index: Int) -> Int
Parameters
index
The index of a UTF-16 code unit in source string.
Return Value
The index of trailing glyph related to the specified cluster.
-
Returns the index of trailing glyph related to the specified cluster. It will come before the leading glyph, if the characters of this run logically flow backward.
Declaration
Swift
public func trailingGlyphIndex(forCharacterAt index: String.Index) -> Int
Parameters
index
The index of a character in source string.
Return Value
The index of trailing glyph related to the specified cluster.
-
Returns the distance of specified character from the start of the run assumed at zero.
Declaration
Swift
public func distance(forCodeUnitAt index: Int) -> CGFloat
Parameters
index
The index of a UTF-16 code unit in source string.
Return Value
The distance of specified character from the start of the run assumed at zero.
-
Returns the distance of specified character from the start of the run assumed at zero.
Declaration
Swift
public func distance(forCharacterAt index: String.Index) -> CGFloat
Parameters
index
The index of a character in source string.
Return Value
The distance of specified character from the start of the run assumed at zero.
-
Determines the index of a UTF-16 code unit nearest to the specified distance.
The process involves iterating over the clusters of the glyph run. If a cluster consists of multiple characters, its total advance is evenly distributed among the number of characters it contains. The advance of each character is added to track the covered distance. This way leading and trailing characters are determined close to the specified distance. Afterwards, the index of nearer character is returned.
If
distance
is negative, then run’s starting index is returned. If it is beyond run’s extent, then ending index is returned. The indices will be reversed in case of right-to-left run.Declaration
Swift
public func indexOfCodeUnit(at distance: CGFloat) -> Int
Parameters
distance
The distance for which to determine the UTF-16 code unit index. It should be offset from zero origin.
Return Value
The index of UTF-16 code unit in source string, nearest to the specified distance.
-
Determines the index of a character nearest to the specified distance.
The process involves iterating over the clusters of the glyph run. If a cluster consists of multiple characters, its total advance is evenly distributed among the number of characters it contains. The advance of each character is added to track the covered distance. This way leading and trailing characters are determined close to the specified distance. Afterwards, the index of nearer character is returned.
If
distance
is negative, then run’s starting index is returned. If it is beyond run’s extent, then ending index is returned. The indices will be reversed in case of right-to-left run.Declaration
Swift
public func indexOfCharacter(at distance: CGFloat) -> String.Index
Parameters
distance
The distance for which to determine the character index. It should be offset from zero origin.
Return Value
The index of character in source string, nearest to the specified distance.
-
Calculates the bounding box for the specified glyph range in this run. The bounding box is a rectangle that encloses the paths of glyphs, as tightly as possible.
Declaration
Swift
public func computeBoundingBox(forGlyphRange glyphRange: Range<Int>, with renderer: Renderer) -> CGRect
Parameters
glyphRange
The range of glyphs to be measured.
Return Value
A rectangle that tightly encloses the paths of glyphs in the specified range.
-
Draws this run in the
context
with the specifiedrenderer
.Declaration
Swift
public func draw(with renderer: Renderer, in context: CGContext)
Parameters
renderer
The renderer with which to draw this run.
context
The context in which to draw this run.