Open fwcd opened 4 months ago
I got interested in this myself, and started trying to understand the Text class, as well as its property theRuns
. As you may already be aware, I the NXRun
class is akin to NSRange
, but contains the attributes being applied to a section of text.
I looked at CoreText documentation, and some vestiges of this may be present:
from the documentation of CTRunDelegate
A run delegate is assigned to a run (attribute range) to control typographic traits such glyph ascent, glyph descent, and glyph width.
https://developer.apple.com/documentation/coretext/ctrundelegate?language=objc
update:
more to the point is the CTRun
class https://developer.apple.com/documentation/coretext/ctrun?language=objc
update further:
There are likely many good examples, but this project on GH implements a TextView markup in CoreText based in relevant parts on CTRun: https://github.com/LiveUI/FTCoreText/tree/master
While the legacy NeXTStep API has substantial similarities to the modern AppKit, there are a number of differences, most notably including the change of the
NX
prefix toNS
(but lots of other things have changed too over the last 30 years).Discoveries
Text
is probably best migrated toNSTextView
(rather thanNSText
), which provides access to text layouting internalsNXRun
can probably be migrated toNSTextStorage
which inherits fromNSMutableAttributedString
, sinceNSTextView
exposes its text storageHyperText
relies quite heavily on storing references toAnchor
instances in theinfo
field. SinceNSTextStorage
is an attributed string under the hood, the easiest way to store custom data is probably to declare a custom attribute, so we do just that (AnchorAttributeName
inHyperText
)Useful resources
attributeRuns
orparagraphs
might be close to NeXTStep'stheRuns
NXRun
etc): https://developer.apple.com/documentation/appkit/textkit