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