NSAttributedString // Hardcode default kern value in macOS 14.
This commit is contained in:
parent
c5de30a3c3
commit
75cc4aad53
|
@ -99,6 +99,7 @@ public class NSAttributedTextView: NSView {
|
||||||
public var backgroundColor: NSColor = .controlBackgroundColor
|
public var backgroundColor: NSColor = .controlBackgroundColor
|
||||||
|
|
||||||
public var attributes: [NSAttributedString.Key: Any] = [
|
public var attributes: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.verticalGlyphForm: true,
|
.verticalGlyphForm: true,
|
||||||
.font: NSFont.systemFont(ofSize: NSFont.systemFontSize),
|
.font: NSFont.systemFont(ofSize: NSFont.systemFontSize),
|
||||||
.foregroundColor: NSColor.textColor,
|
.foregroundColor: NSColor.textColor,
|
||||||
|
|
|
@ -146,8 +146,9 @@ public class CandidateCellData: Hashable {
|
||||||
public func attributedString(
|
public func attributedString(
|
||||||
noSpacePadding: Bool = true, withHighlight: Bool = false, isMatrix: Bool = false
|
noSpacePadding: Bool = true, withHighlight: Bool = false, isMatrix: Bool = false
|
||||||
) -> NSAttributedString {
|
) -> NSAttributedString {
|
||||||
let attrSpace: [NSAttributedString.Key: AnyObject] = [
|
let attrSpace: [NSAttributedString.Key: Any] = [
|
||||||
.font: phraseFont(size: size),
|
.font: phraseFont(size: size),
|
||||||
|
.kern: 0,
|
||||||
.paragraphStyle: Self.sharedParagraphStyle,
|
.paragraphStyle: Self.sharedParagraphStyle,
|
||||||
]
|
]
|
||||||
let result: NSMutableAttributedString = {
|
let result: NSMutableAttributedString = {
|
||||||
|
@ -172,7 +173,8 @@ public class CandidateCellData: Hashable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public var attributedStringHeader: NSAttributedString {
|
public var attributedStringHeader: NSAttributedString {
|
||||||
let attrKey: [NSAttributedString.Key: AnyObject] = [
|
let attrKey: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: selectionKeyFont(size: fontSizeKey),
|
.font: selectionKeyFont(size: fontSizeKey),
|
||||||
.paragraphStyle: Self.sharedParagraphStyle,
|
.paragraphStyle: Self.sharedParagraphStyle,
|
||||||
.foregroundColor: fontColorKey,
|
.foregroundColor: fontColorKey,
|
||||||
|
@ -182,7 +184,7 @@ public class CandidateCellData: Hashable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func attributedStringPhrase(isMatrix: Bool = false) -> NSAttributedString {
|
public func attributedStringPhrase(isMatrix: Bool = false) -> NSAttributedString {
|
||||||
var attrCandidate: [NSAttributedString.Key: AnyObject] = [
|
var attrCandidate: [NSAttributedString.Key: Any] = [
|
||||||
.font: phraseFont(size: size),
|
.font: phraseFont(size: size),
|
||||||
.paragraphStyle: Self.sharedParagraphStyle,
|
.paragraphStyle: Self.sharedParagraphStyle,
|
||||||
.foregroundColor: fontColorCandidate,
|
.foregroundColor: fontColorCandidate,
|
||||||
|
|
|
@ -158,7 +158,8 @@ extension CandidatePool {
|
||||||
|
|
||||||
private var attributedDescriptionHorizontal: NSAttributedString {
|
private var attributedDescriptionHorizontal: NSAttributedString {
|
||||||
let paragraphStyle = sharedParagraphStyle
|
let paragraphStyle = sharedParagraphStyle
|
||||||
let attrCandidate: [NSAttributedString.Key: AnyObject] = [
|
let attrCandidate: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: Self.blankCell.phraseFont(size: Self.blankCell.size),
|
.font: Self.blankCell.phraseFont(size: Self.blankCell.size),
|
||||||
.paragraphStyle: paragraphStyle,
|
.paragraphStyle: paragraphStyle,
|
||||||
]
|
]
|
||||||
|
@ -197,7 +198,8 @@ extension CandidatePool {
|
||||||
|
|
||||||
private var attributedDescriptionVertical: NSAttributedString {
|
private var attributedDescriptionVertical: NSAttributedString {
|
||||||
let paragraphStyle = sharedParagraphStyle
|
let paragraphStyle = sharedParagraphStyle
|
||||||
let attrCandidate: [NSAttributedString.Key: AnyObject] = [
|
let attrCandidate: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: Self.blankCell.phraseFont(size: Self.blankCell.size),
|
.font: Self.blankCell.phraseFont(size: Self.blankCell.size),
|
||||||
.paragraphStyle: paragraphStyle,
|
.paragraphStyle: paragraphStyle,
|
||||||
]
|
]
|
||||||
|
@ -262,7 +264,8 @@ extension CandidatePool {
|
||||||
: NSColor(white: 0.9, alpha: 0.7)
|
: NSColor(white: 0.9, alpha: 0.7)
|
||||||
let positionCounterColorText = NSColor.controlTextColor
|
let positionCounterColorText = NSColor.controlTextColor
|
||||||
let positionCounterTextSize = max(ceil(CandidateCellData.unifiedSize * 0.7), 11)
|
let positionCounterTextSize = max(ceil(CandidateCellData.unifiedSize * 0.7), 11)
|
||||||
let attrPositionCounter: [NSAttributedString.Key: AnyObject] = [
|
let attrPositionCounter: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: Self.blankCell.phraseFontEmphasized(size: positionCounterTextSize),
|
.font: Self.blankCell.phraseFontEmphasized(size: positionCounterTextSize),
|
||||||
.backgroundColor: positionCounterColorBG,
|
.backgroundColor: positionCounterColorBG,
|
||||||
.foregroundColor: positionCounterColorText,
|
.foregroundColor: positionCounterColorText,
|
||||||
|
@ -275,7 +278,8 @@ extension CandidatePool {
|
||||||
|
|
||||||
private var attributedDescriptionTooltip: NSAttributedString {
|
private var attributedDescriptionTooltip: NSAttributedString {
|
||||||
let positionCounterTextSize = max(ceil(CandidateCellData.unifiedSize * 0.7), 11)
|
let positionCounterTextSize = max(ceil(CandidateCellData.unifiedSize * 0.7), 11)
|
||||||
let attrTooltip: [NSAttributedString.Key: AnyObject] = [
|
let attrTooltip: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: Self.blankCell.phraseFontEmphasized(size: positionCounterTextSize),
|
.font: Self.blankCell.phraseFontEmphasized(size: positionCounterTextSize),
|
||||||
.foregroundColor: NSColor.textColor,
|
.foregroundColor: NSColor.textColor,
|
||||||
]
|
]
|
||||||
|
@ -287,11 +291,13 @@ extension CandidatePool {
|
||||||
|
|
||||||
private var attributedDescriptionReverseLookp: NSAttributedString {
|
private var attributedDescriptionReverseLookp: NSAttributedString {
|
||||||
let reverseLookupTextSize = max(ceil(CandidateCellData.unifiedSize * 0.6), 9)
|
let reverseLookupTextSize = max(ceil(CandidateCellData.unifiedSize * 0.6), 9)
|
||||||
let attrReverseLookup: [NSAttributedString.Key: AnyObject] = [
|
let attrReverseLookup: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: Self.blankCell.phraseFont(size: reverseLookupTextSize),
|
.font: Self.blankCell.phraseFont(size: reverseLookupTextSize),
|
||||||
.foregroundColor: NSColor.textColor,
|
.foregroundColor: NSColor.textColor,
|
||||||
]
|
]
|
||||||
let attrReverseLookupSpacer: [NSAttributedString.Key: AnyObject] = [
|
let attrReverseLookupSpacer: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: Self.blankCell.phraseFont(size: reverseLookupTextSize),
|
.font: Self.blankCell.phraseFont(size: reverseLookupTextSize),
|
||||||
]
|
]
|
||||||
let result = NSMutableAttributedString(string: "", attributes: attrReverseLookupSpacer)
|
let result = NSMutableAttributedString(string: "", attributes: attrReverseLookupSpacer)
|
||||||
|
|
|
@ -211,7 +211,8 @@ extension VwrCandidateTDK {
|
||||||
/// - Returns: 測量出來的字串渲染寬度,經過向上取整之處理。
|
/// - Returns: 測量出來的字串渲染寬度,經過向上取整之處理。
|
||||||
func getTextWidth(text: String, fontSize: CGFloat, isBold: Bool) -> CGFloat? {
|
func getTextWidth(text: String, fontSize: CGFloat, isBold: Bool) -> CGFloat? {
|
||||||
guard !text.isEmpty else { return nil }
|
guard !text.isEmpty else { return nil }
|
||||||
let attributes: [NSAttributedString.Key: AnyObject] = [
|
let attributes: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.font: NSFont.systemFont(ofSize: fontSize, weight: isBold ? .bold : .regular),
|
.font: NSFont.systemFont(ofSize: fontSize, weight: isBold ? .bold : .regular),
|
||||||
.paragraphStyle: CandidateCellData.sharedParagraphStyle,
|
.paragraphStyle: CandidateCellData.sharedParagraphStyle,
|
||||||
]
|
]
|
||||||
|
|
|
@ -64,13 +64,15 @@ public class Notifier: NSWindowController {
|
||||||
let paraStyle = NSMutableParagraphStyle()
|
let paraStyle = NSMutableParagraphStyle()
|
||||||
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
||||||
paraStyle.alignment = .center
|
paraStyle.alignment = .center
|
||||||
let attrTitle: [NSAttributedString.Key: AnyObject] = [
|
let attrTitle: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.foregroundColor: NSColor.controlTextColor,
|
.foregroundColor: NSColor.controlTextColor,
|
||||||
.font: NSFont.boldSystemFont(ofSize: kLargeFontSize),
|
.font: NSFont.boldSystemFont(ofSize: kLargeFontSize),
|
||||||
.paragraphStyle: paraStyle,
|
.paragraphStyle: paraStyle,
|
||||||
]
|
]
|
||||||
let attrString = NSMutableAttributedString(string: messageArray[0], attributes: attrTitle)
|
let attrString = NSMutableAttributedString(string: messageArray[0], attributes: attrTitle)
|
||||||
let attrAlt: [NSAttributedString.Key: AnyObject] = [
|
let attrAlt: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.foregroundColor: NSColor.secondaryLabelColor,
|
.foregroundColor: NSColor.secondaryLabelColor,
|
||||||
.font: NSFont.systemFont(ofSize: kSmallFontSize),
|
.font: NSFont.systemFont(ofSize: kSmallFontSize),
|
||||||
.paragraphStyle: paraStyle,
|
.paragraphStyle: paraStyle,
|
||||||
|
|
|
@ -64,6 +64,7 @@ public class PopupCompositionBuffer: NSWindowController {
|
||||||
let attrString: NSMutableAttributedString = .init(string: state.displayedTextConverted)
|
let attrString: NSMutableAttributedString = .init(string: state.displayedTextConverted)
|
||||||
let attrPCBHeader: NSMutableAttributedString = .init(string: " ")
|
let attrPCBHeader: NSMutableAttributedString = .init(string: " ")
|
||||||
let verticalAttributes: [NSAttributedString.Key: Any] = [
|
let verticalAttributes: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.verticalGlyphForm: true,
|
.verticalGlyphForm: true,
|
||||||
.paragraphStyle: {
|
.paragraphStyle: {
|
||||||
let newStyle = NSMutableParagraphStyle()
|
let newStyle = NSMutableParagraphStyle()
|
||||||
|
@ -88,6 +89,7 @@ public class PopupCompositionBuffer: NSWindowController {
|
||||||
|
|
||||||
let markerAttributes: [NSAttributedString.Key: Any] = {
|
let markerAttributes: [NSAttributedString.Key: Any] = {
|
||||||
var result: [NSAttributedString.Key: Any] = [
|
var result: [NSAttributedString.Key: Any] = [
|
||||||
|
.kern: 0,
|
||||||
.backgroundColor: NSApplication.isDarkMode ? NSColor.systemRed : NSColor.systemYellow,
|
.backgroundColor: NSApplication.isDarkMode ? NSColor.systemRed : NSColor.systemYellow,
|
||||||
.markedClauseSegment: 0,
|
.markedClauseSegment: 0,
|
||||||
]
|
]
|
||||||
|
@ -135,6 +137,10 @@ public class PopupCompositionBuffer: NSWindowController {
|
||||||
attrString.insert(attrPCBHeader, at: 0)
|
attrString.insert(attrPCBHeader, at: 0)
|
||||||
attrString.insert(attrPCBHeader, at: attrString.length)
|
attrString.insert(attrPCBHeader, at: attrString.length)
|
||||||
|
|
||||||
|
attrString.setAttributes(
|
||||||
|
[.kern: 0], range: NSRange(location: 0, length: attrString.length)
|
||||||
|
)
|
||||||
|
|
||||||
textShown = attrString
|
textShown = attrString
|
||||||
messageTextField.maximumNumberOfLines = 1
|
messageTextField.maximumNumberOfLines = 1
|
||||||
if let editor = messageTextField.currentEditor() {
|
if let editor = messageTextField.currentEditor() {
|
||||||
|
|
Loading…
Reference in New Issue