Skip to content

Commit

Permalink
fix: color of CTRubyAnnotation. fix #409
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddxxx committed Aug 3, 2020
1 parent 11c584f commit 6f5e187
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions LyricsX/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<key>CFBundleShortVersionString</key>
<string>1.5.4</string>
<key>CFBundleVersion</key>
<string>2305</string>
<string>2306</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand All @@ -58,7 +58,7 @@
<key>LSUIElement</key>
<true/>
<key>LX_BUILD_TIME</key>
<integer>1594983759</integer>
<integer>1596440587</integer>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
Expand Down
12 changes: 7 additions & 5 deletions LyricsX/View/KaraokeLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ class KaraokeLabel: NSTextField {
}
guard shouldDrawFurigana else { continue }
if let (furigana, range) = tokenizer.currentFuriganaAnnotation(in: string) {
var attr: [CFAttributedString.Key: Any] = [.rubySizeFactor: 0.5]
attr[.foregroundColor] = textColor
var attr: [CFAttributedString.Key: Any] = [.ctRubySizeFactor: 0.5]
attr[.ctForegroundColor] = textColor
let annotation = CTRubyAnnotation.create(furigana, attributes: attr)
attrString.addAttribute(.rubyAnnotation, value: annotation, range: range)
attrString.addAttribute(.ctRubyAnnotation, value: annotation, range: range)
}
}
textColor?.do { attrString.addAttributes([.foregroundColor: $0], range: attrString.fullRange) }
Expand Down Expand Up @@ -168,7 +168,7 @@ class KaraokeLabel: NSTextField {
progressLayer.mask = mask

guard let index = progress.firstIndex(where: { $0.0 > 0 }) else { return }
var map = progress.map { ($0.0, line.offset(charIndex: $0.1)) }
var map = progress.map { ($0.0, line.offset(charIndex: $0.1).primary) }
if index > 0 {
let progress = map[index - 1].1 + CGFloat(map[index - 1].0) * (map[index].1 - map[index - 1].1) / CGFloat(map[index].0 - map[index - 1].0)
map.replaceSubrange(..<index, with: [(0, progress)])
Expand Down Expand Up @@ -209,6 +209,8 @@ class KaraokeLabel: NSTextField {
}
}

import CoreText

extension CFAttributedString.Key {
static let rubyAnnotation = kCTRubyAnnotationAttributeName as CFAttributedString.Key
static let ctForegroundColor = kCTForegroundColorAttributeName as CFAttributedString.Key
}

0 comments on commit 6f5e187

Please sign in to comment.