From d079a7d0c7d8687312ba40f9d0e4e55e4f1f424b Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:55:01 -0400 Subject: [PATCH] Only init paragraph style once. --- .../Preferences/Menu Bar/StatusContainerView.swift | 12 +++++++++++- Clocker/Preferences/Menu Bar/StatusItemView.swift | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Clocker/Preferences/Menu Bar/StatusContainerView.swift b/Clocker/Preferences/Menu Bar/StatusContainerView.swift index 0c8984f..3821276 100644 --- a/Clocker/Preferences/Menu Bar/StatusContainerView.swift +++ b/Clocker/Preferences/Menu Bar/StatusContainerView.swift @@ -57,6 +57,16 @@ protocol StatusItemViewConforming { class StatusContainerView: NSView { private var previousX: Int = 0 private let store: DataStore + private lazy var paragraphStyle: NSMutableParagraphStyle = { + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + paragraphStyle.lineBreakMode = .byTruncatingTail + // Better readability for p,q,y,g in the status bar. + let userPreferredLanguage = Locale.preferredLanguages.first ?? "en-US" + let lineHeight = userPreferredLanguage.contains("en") ? 0.92 : 1 + paragraphStyle.lineHeightMultiple = CGFloat(lineHeight) + return paragraphStyle + }() override func awakeFromNib() { super.awakeFromNib() @@ -167,7 +177,7 @@ class StatusContainerView: NSView { NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.backgroundColor: NSColor.clear, - NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, + NSAttributedString.Key.paragraphStyle: paragraphStyle, ] let operation = TimezoneDataOperations(with: timezone, store: store) diff --git a/Clocker/Preferences/Menu Bar/StatusItemView.swift b/Clocker/Preferences/Menu Bar/StatusItemView.swift index 4c687bb..b90dca3 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemView.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemView.swift @@ -53,6 +53,16 @@ class StatusItemView: NSView { private var operationsObject: TimezoneDataOperations { return TimezoneDataOperations(with: dataObject, store: DataStore.shared()) } + private lazy var paragraphStyle: NSMutableParagraphStyle = { + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + paragraphStyle.lineBreakMode = .byTruncatingTail + // Better readability for p,q,y,g in the status bar. + let userPreferredLanguage = Locale.preferredLanguages.first ?? "en-US" + let lineHeight = userPreferredLanguage.contains("en") ? 0.92 : 1 + paragraphStyle.lineHeightMultiple = CGFloat(lineHeight) + return paragraphStyle + }() private var timeAttributes: [NSAttributedString.Key: AnyObject] { let textColor = hasDarkAppearance ? NSColor.white : NSColor.black @@ -61,7 +71,7 @@ class StatusItemView: NSView { NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.backgroundColor: NSColor.clear, - NSAttributedString.Key.paragraphStyle: defaultTimeParagraphStyle, + NSAttributedString.Key.paragraphStyle: paragraphStyle, ] return attributes } @@ -73,7 +83,7 @@ class StatusItemView: NSView { NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.backgroundColor: NSColor.clear, - NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, + NSAttributedString.Key.paragraphStyle: paragraphStyle, ] return textFontAttributes }