Slide 45
Slide 45 text
macOS native 5FYU,JUͰͷγϯλοΫεϋΠϥΠτߴԽ
©2022 1024jp
5FYU,JUʁ
func apply(highlights: [Highlight], range highlightRange: NSRange, theme: Theme) {
if let location = layoutManager.location(layoutManager.documentRange.location,
offsetBy: highlightRange.location),
let end = layoutManager.location(location, offsetBy: highlightRange.length),
let textRange = NSTextRange(location: location, end: end)
{
layoutManager.removeRenderingAttribute(.foregroundColor, for: textRange)
}
for highlight in highlights {
guard
let location = layoutManager.location(layoutManager.documentRange.location,
offsetBy: highlight.range.location),
let end = layoutManager.location(location, offsetBy: highlight.range.length),
let textRange = NSTextRange(location: location, end: end)
else { continue }
let color = theme.style(for: highlight.type).color
layoutManager.addRenderingAttribute(.foregroundColor, value: highlight.color, for: textRange)
}
}
0.39 s
TextKit 2 NSTextLayoutManager