diff --git a/Packages/Fuziki_NSAttributedTextView/Package.swift b/Packages/Fuziki_NSAttributedTextView/Package.swift index db2951e7..5a574d6e 100644 --- a/Packages/Fuziki_NSAttributedTextView/Package.swift +++ b/Packages/Fuziki_NSAttributedTextView/Package.swift @@ -12,11 +12,15 @@ let package = Package( targets: ["NSAttributedTextView"] ), ], - dependencies: [], + dependencies: [ + .package(path: "../vChewing_CocoaExtension"), + ], targets: [ .target( name: "NSAttributedTextView", - dependencies: [] + dependencies: [ + .product(name: "CocoaExtension", package: "vChewing_CocoaExtension"), + ] ), ] ) diff --git a/Packages/Fuziki_NSAttributedTextView/Sources/NSAttributedTextView/NSAttributedTextView.swift b/Packages/Fuziki_NSAttributedTextView/Sources/NSAttributedTextView/NSAttributedTextView.swift index ac32cf85..6afdd087 100644 --- a/Packages/Fuziki_NSAttributedTextView/Sources/NSAttributedTextView/NSAttributedTextView.swift +++ b/Packages/Fuziki_NSAttributedTextView/Sources/NSAttributedTextView/NSAttributedTextView.swift @@ -6,6 +6,7 @@ // Modified by The vChewing Project in order to use it with AppKit. import Cocoa +import CocoaExtension import SwiftUI @available(macOS 10.15, *) @@ -107,20 +108,14 @@ public class NSAttributedTextView: NSView { default: return attributedStringValue(areaCalculation: true) } }() - var rect = attrString.boundingRect( - with: NSSize(width: 1600.0, height: 1600.0), - options: [.usesLineFragmentOrigin, .usesFontLeading, .usesDeviceMetrics] - ) - rect.size.height *= 1.03 - rect.size.height = max(rect.size.height, NSFont.systemFontSize * 1.1) - rect.size.height = ceil(rect.size.height) - rect.size.width *= 1.03 - rect.size.width = max(rect.size.width, NSFont.systemFontSize * 1.05) - rect.size.width = ceil(rect.size.width) + var textWH = attrString.boundingDimension if direction != .horizontal { - rect = .init(x: rect.minX, y: rect.minY, width: rect.height, height: rect.width) + textWH.height *= 1.03 + textWH.height = max(textWH.height, NSFont.systemFontSize * 1.1) + textWH.height = ceil(textWH.height) + textWH = .init(width: textWH.height, height: textWH.width) } - return rect + return .init(origin: .zero, size: textWH) } override public func draw(_ rect: CGRect) { diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData.swift index f6356142..9f68b8dc 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData.swift @@ -58,11 +58,7 @@ public class CandidateCellData: Hashable { public var cellLength: Int { if displayedText.count <= 2 { return Int(ceil(size * 3)) } - let rect = attributedStringForLengthCalculation.boundingRect( - with: NSSize(width: 1600.0, height: 1600.0), options: [.usesLineFragmentOrigin] - ) - let rawResult = ceil(rect.width) - return Int(rawResult) + return Int(ceil(attributedStringForLengthCalculation.boundingDimension.width)) } public var attributedStringHeader: NSAttributedString { diff --git a/Packages/vChewing_NotifierUI/Package.swift b/Packages/vChewing_NotifierUI/Package.swift index 2f604b11..f78707cf 100644 --- a/Packages/vChewing_NotifierUI/Package.swift +++ b/Packages/vChewing_NotifierUI/Package.swift @@ -12,11 +12,15 @@ let package = Package( targets: ["NotifierUI"] ), ], - dependencies: [], + dependencies: [ + .package(path: "../vChewing_CocoaExtension"), + ], targets: [ .target( name: "NotifierUI", - dependencies: [] + dependencies: [ + .product(name: "CocoaExtension", package: "vChewing_CocoaExtension"), + ] ), ] ) diff --git a/Packages/vChewing_NotifierUI/Sources/NotifierUI/NotifierUI.swift b/Packages/vChewing_NotifierUI/Sources/NotifierUI/NotifierUI.swift index 9ec1d883..a7feb62f 100644 --- a/Packages/vChewing_NotifierUI/Sources/NotifierUI/NotifierUI.swift +++ b/Packages/vChewing_NotifierUI/Sources/NotifierUI/NotifierUI.swift @@ -7,6 +7,7 @@ // requirements defined in MIT License. import Cocoa +import CocoaExtension public class Notifier: NSWindowController { public static func notify(message: String) { @@ -78,10 +79,8 @@ public class Notifier: NSWindowController { let attrStringAlt = NSMutableAttributedString(string: additionalString, attributes: attrAlt) attrString.insert(attrStringAlt, at: attrString.length) - let textRect: NSRect = attrString.boundingRect( - with: NSSize(width: 1600.0, height: 1600.0), options: [.usesLineFragmentOrigin] - ) - let windowWidth = Double(4) * kLargeFontSize + textRect.width + let textWH = attrString.boundingDimension + let windowWidth = Double(4) * kLargeFontSize + textWH.width let contentRect = NSRect(x: 0, y: 0, width: windowWidth, height: 60.0) var windowRect = contentRect windowRect.origin.x = screenRect.maxX - windowRect.width - 10 @@ -123,8 +122,8 @@ public class Notifier: NSWindowController { theWindow.contentView?.addSubview(lblMessage) let x = lblMessage.frame.origin.x - let y = ((theWindow.frame.height) - textRect.height) / 1.9 - let newFrame = NSRect(x: x, y: y, width: theWindow.frame.width, height: textRect.height) + let y = ((theWindow.frame.height) - textWH.height) / 1.9 + let newFrame = NSRect(x: x, y: y, width: theWindow.frame.width, height: textWH.height) lblMessage.frame = newFrame super.init(window: theWindow) diff --git a/Packages/vChewing_PopupCompositionBuffer/Sources/PopupCompositionBuffer/PopupCompositionBuffer.swift b/Packages/vChewing_PopupCompositionBuffer/Sources/PopupCompositionBuffer/PopupCompositionBuffer.swift index 9ddb7a36..f01933bd 100644 --- a/Packages/vChewing_PopupCompositionBuffer/Sources/PopupCompositionBuffer/PopupCompositionBuffer.swift +++ b/Packages/vChewing_PopupCompositionBuffer/Sources/PopupCompositionBuffer/PopupCompositionBuffer.swift @@ -164,13 +164,10 @@ public class PopupCompositionBuffer: NSWindowController { private func adjustSize() { let attrString = messageTextField.attributedStringValue - var rect = attrString.boundingRect( - with: NSSize(width: 1600.0, height: 1600.0), - options: [.usesLineFragmentOrigin, .usesFontLeading] - ) - rect.size.width = max(rect.size.width, 20 * Double(attrString.string.count)) + 2 + var rect = NSRect(origin: .zero, size: attrString.boundingDimension) rect.size.height *= 1.2 rect.size.height = max(22, rect.size.height) + rect.size.width = max(rect.size.width, 20 * Double(attrString.string.count)) + 2 if isTypingDirectionVertical { rect = .init(x: rect.minX, y: rect.minY, width: rect.height, height: rect.width) } diff --git a/Source/Modules/InputHandler_Core.swift b/Source/Modules/InputHandler_Core.swift index be72b709..aaf94bab 100644 --- a/Source/Modules/InputHandler_Core.swift +++ b/Source/Modules/InputHandler_Core.swift @@ -119,7 +119,7 @@ public class InputHandler: InputHandlerProtocol { var isHaninKeyboardSymbolMode = false - static let tooltipHaninKeyboardSymbolMode: String = "\("Hanin Keyboard Symbol Input.".localized)  " + static let tooltipHaninKeyboardSymbolMode: String = "\("Hanin Keyboard Symbol Input.".localized)" // MARK: - Codepoint Input Buffer. @@ -134,12 +134,13 @@ public class InputHandler: InputHandlerProtocol { var tooltipCodePointInputMode: String { let commonTerm = NSMutableString() commonTerm.insert("Code Point Input.".localized, at: 0) - switch IMEApp.currentInputMode { - case .imeModeCHS: commonTerm.insert("[GB] ", at: 0) - case .imeModeCHT: commonTerm.insert("[Big5] ", at: 0) - default: break + if !(delegate?.isVerticalTyping ?? false) { + switch IMEApp.currentInputMode { + case .imeModeCHS: commonTerm.insert("[GB] ", at: 0) + case .imeModeCHT: commonTerm.insert("[Big5] ", at: 0) + default: break + } } - commonTerm.append("  ") return commonTerm.description } diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index 9bf50818..a82e3eb9 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -204,7 +204,7 @@ extension InputHandler { if calligrapher.isEmpty, isWildcardKeyInput { delegate.callError("3606B9C0") var newEmptyState = compositor.isEmpty ? IMEState.ofEmpty() : generateStateOfInputting() - newEmptyState.tooltip = NSLocalizedString("Wildcard key cannot be the initial key.", comment: "") + "  " + newEmptyState.tooltip = NSLocalizedString("Wildcard key cannot be the initial key.", comment: "") newEmptyState.data.tooltipColorState = .redAlert newEmptyState.tooltipDuration = 1.0 delegate.switchState(newEmptyState) @@ -345,7 +345,7 @@ extension InputHandler { delegate.callError("D220B880:輸入的字碼沒有對應的字元。") var updatedState = IMEState.ofAbortion() updatedState.tooltipDuration = 0 - updatedState.tooltip = "Invalid Code Point.".localized + "  " + updatedState.tooltip = "Invalid Code Point.".localized delegate.switchState(updatedState) isCodePointInputMode = true return true diff --git a/Source/Modules/InputHandler_HandleStates.swift b/Source/Modules/InputHandler_HandleStates.swift index c9962f54..b5fc3a9d 100644 --- a/Source/Modules/InputHandler_HandleStates.swift +++ b/Source/Modules/InputHandler_HandleStates.swift @@ -166,7 +166,7 @@ extension InputHandler { return true } var newState = generateStateOfInputting() - newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") + "  " + newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") newState.data.tooltipColorState = tooltipColorState newState.tooltipDuration = 1.85 delegate.switchState(newState) @@ -185,7 +185,7 @@ extension InputHandler { return true } var newState = generateStateOfInputting() - newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") + "  " + newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") newState.data.tooltipColorState = .warning newState.tooltipDuration = 1.85 delegate.switchState(newState) @@ -808,7 +808,6 @@ extension InputHandler { } else { newTooltip.insert((newIndex + 1).description + " / " + candidates.count.description, at: 0) } - newTooltip.append("  ") newState.tooltip = newTooltip.description vCLog(newState.tooltip) newState.tooltipDuration = 0 diff --git a/Source/Modules/SessionCtl_Delegates.swift b/Source/Modules/SessionCtl_Delegates.swift index 155e698b..37305b5c 100644 --- a/Source/Modules/SessionCtl_Delegates.swift +++ b/Source/Modules/SessionCtl_Delegates.swift @@ -233,7 +233,7 @@ extension SessionCtl: CtlCandidateDelegate { tooltipMessage = succeeded ? "! Succeeded in filtering a candidate." : "⚠︎ Failed from filtering a candidate." } if !succeeded { newState.data.tooltipColorState = .redAlert } - newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") + "  " + newState.tooltip = NSLocalizedString(tooltipMessage, comment: "") switchState(newState) } } diff --git a/Source/Modules/SessionCtl_HandleEvent.swift b/Source/Modules/SessionCtl_HandleEvent.swift index ba1948e7..dd8f732e 100644 --- a/Source/Modules/SessionCtl_HandleEvent.swift +++ b/Source/Modules/SessionCtl_HandleEvent.swift @@ -99,7 +99,7 @@ public extension SessionCtl { if !LMMgr.currentLM.isCoreLMLoaded { if (event as InputSignalProtocol).isReservedKey { return false } var newState: IMEStateProtocol = IMEState.ofEmpty() - newState.tooltip = NSLocalizedString("Factory dictionary not loaded yet.", comment: "") + "  " + newState.tooltip = NSLocalizedString("Factory dictionary not loaded yet.", comment: "") newState.tooltipDuration = 1.85 newState.data.tooltipColorState = .redAlert switchState(newState)