diff --git a/Sources/STTextViewAppKit/Gutter/STGutterView.swift b/Sources/STTextViewAppKit/Gutter/STGutterView.swift index 1d62d86..d37e122 100644 --- a/Sources/STTextViewAppKit/Gutter/STGutterView.swift +++ b/Sources/STTextViewAppKit/Gutter/STGutterView.swift @@ -13,7 +13,7 @@ public final class STGutterView: NSView { /// Initialized with a textView font value and does not update automatically when /// text view font changes. @Invalidating(.display) - public var font: NSFont = adjustGutterFont(NSFont(descriptor: NSFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular).fontDescriptor.withSymbolicTraits(.condensed), size: 0)!) + public var font = adjustGutterFont(NSFont(descriptor: NSFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular).fontDescriptor.withSymbolicTraits(.condensed), size: 0)!) /// The insets of the ruler view. @Invalidating(.display) @@ -113,7 +113,7 @@ public final class STGutterView: NSView { } } -internal func adjustGutterFont(_ font: NSFont) -> NSFont { +private func adjustGutterFont(_ font: NSFont) -> NSFont { // https://useyourloaf.com/blog/ios-9-proportional-numbers/ // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html let features: [[NSFontDescriptor.FeatureKey: Int]] = [ @@ -143,6 +143,5 @@ internal func adjustGutterFont(_ font: NSFont) -> NSFont { ] ] - let adjustedFont = NSFont(descriptor: font.fontDescriptor.addingAttributes([.featureSettings: features]), size: max(font.pointSize * 0.9, NSFont.smallSystemFontSize)) - return adjustedFont ?? font + return NSFont(descriptor: font.fontDescriptor.addingAttributes([.featureSettings: features]), size: 0) ?? font } diff --git a/Sources/STTextViewAppKit/STTextView+Gutter.swift b/Sources/STTextViewAppKit/STTextView+Gutter.swift index 9f138d5..d58924d 100644 --- a/Sources/STTextViewAppKit/STTextView+Gutter.swift +++ b/Sources/STTextViewAppKit/STTextView+Gutter.swift @@ -17,7 +17,6 @@ extension STTextView { set { if gutterView == nil, newValue == true { let gutterView = STGutterView() - gutterView.font = adjustGutterFont(font) gutterView.frame.size.width = gutterView.minimumThickness gutterView.selectedLineTextColor = textColor gutterView.highlightSelectedLine = highlightSelectedLine diff --git a/Sources/STTextViewUIKit/Gutter/STGutterView.swift b/Sources/STTextViewUIKit/Gutter/STGutterView.swift index 78a3971..8cbd5be 100644 --- a/Sources/STTextViewUIKit/Gutter/STGutterView.swift +++ b/Sources/STTextViewUIKit/Gutter/STGutterView.swift @@ -14,7 +14,7 @@ public final class STGutterView: UIView { /// Initialized with a textView font value and does not update automatically when /// text view font changes. @Invalidating(.display) - public var font: UIFont = adjustGutterFont(UIFont(descriptor: UIFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular).fontDescriptor.withSymbolicTraits(.traitCondensed)!, size: 0)) + public var font = adjustGutterFont(UIFont(descriptor: UIFont.monospacedDigitSystemFont(ofSize: 0, weight: .regular).fontDescriptor.withSymbolicTraits(.traitCondensed)!, size: 0)) /// The insets of the ruler view. @Invalidating(.display) @@ -95,7 +95,7 @@ public final class STGutterView: UIView { } } -func adjustGutterFont(_ font: UIFont) -> UIFont { +private func adjustGutterFont(_ font: UIFont) -> UIFont { // https://useyourloaf.com/blog/ios-9-proportional-numbers/ // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html let features: [[UIFontDescriptor.FeatureKey: Int]] = [ @@ -125,6 +125,5 @@ func adjustGutterFont(_ font: UIFont) -> UIFont { ] ] - let adjustedFont = UIFont(descriptor: font.fontDescriptor.addingAttributes([.featureSettings: features]), size: max(font.pointSize * 0.9, UIFont.smallSystemFontSize)) - return adjustedFont + return UIFont(descriptor: font.fontDescriptor.addingAttributes([.featureSettings: features]), size: 0) } diff --git a/Sources/STTextViewUIKit/STTextView+Gutter.swift b/Sources/STTextViewUIKit/STTextView+Gutter.swift index 322a5fe..149be7f 100644 --- a/Sources/STTextViewUIKit/STTextView+Gutter.swift +++ b/Sources/STTextViewUIKit/STTextView+Gutter.swift @@ -12,7 +12,6 @@ extension STTextView { set { if gutterView == nil, newValue == true { let gutterView = STGutterView() - gutterView.font = adjustGutterFont(font) gutterView.frame.size.width = gutterView.minimumThickness gutterView.selectedLineTextColor = textColor gutterView.highlightSelectedLine = highlightSelectedLine diff --git a/TextEdit/Mac/ViewController.swift b/TextEdit/Mac/ViewController.swift index 322ff9f..597d3c6 100644 --- a/TextEdit/Mac/ViewController.swift +++ b/TextEdit/Mac/ViewController.swift @@ -25,7 +25,8 @@ final class ViewController: NSViewController { paragraph.lineHeightMultiple = 1.2 textView.defaultParagraphStyle = paragraph - textView.font = NSFont.monospacedSystemFont(ofSize: 14, weight: .regular) + + textView.font = NSFont.monospacedSystemFont(ofSize: 0, weight: .regular) textView.text = try! String(contentsOf: Bundle.main.url(forResource: "content", withExtension: "txt")!) textView.isHorizontallyResizable = false // wrap textView.highlightSelectedLine = true diff --git a/TextEdit/iOS/ViewController.swift b/TextEdit/iOS/ViewController.swift index d3c847b..939b3ca 100644 --- a/TextEdit/iOS/ViewController.swift +++ b/TextEdit/iOS/ViewController.swift @@ -21,7 +21,7 @@ class ViewController: UIViewController { paragraph.lineHeightMultiple = 1.2 textView.defaultParagraphStyle = paragraph - textView.font = UIFont.monospacedSystemFont(ofSize: 14, weight: .regular) + textView.font = UIFont.monospacedSystemFont(ofSize: 0, weight: .regular) textView.text = try! String(contentsOf: Bundle.main.url(forResource: "content", withExtension: "txt")!) textView.showsLineNumbers = true textView.showsInvisibleCharacters = false