What’s the differences between GlyphRange and CharacterRange in NSTextView?
- (NSRectArray)rectArrayForCharacterRange:(NSRange)charRange withinSelectedCharacterRange:(NSRange)selCharRange inTextContainer:(NSTextContainer *)container rectCount:(NSUInteger *)rectCount;
- (NSRectArray)rectArrayForGlyphRange:(NSRange)glyphRange withinSelectedGlyphRange:(NSRange)selGlyphRange inTextContainer:(NSTextContainer *)container rectCount:(NSUInteger *)rectCount;
I think the glyph and char always have same range.
In usage I think glyphRange and charRange are same, because when I use the two method, I give charRange and glyphRange a same range value, the output NSRectArray is the same.
Am I misunderstanding?
There isn’t always a one-to-one correspondence between glyphs and characters. Ligatures are examples of glyphs which represent two characters.
For this reason GlyphRange and CharacterRange may not be the same. The character string “fi” contains two characters, but the layout manager may decide to display it as a single glyph (using the fi ligature), and so the glyph range may have length of 1.
Remember, glyphs are the graphical representations of characters. Think of a character like a as an abstract entity which is the same regardless of typeface or typestyle. As a character, a Times New Roman Italic a is just as much of an a as a Comic Sans Bold a. This distinction in visual appearance is only made at the glyph level.