Skip to content

Commit

Permalink
don't change gutter font implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Aug 23, 2024
1 parent 8a4b08c commit f61e63a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
7 changes: 3 additions & 4 deletions Sources/STTextViewAppKit/Gutter/STGutterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]] = [
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion Sources/STTextViewAppKit/STTextView+Gutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions Sources/STTextViewUIKit/Gutter/STGutterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]] = [
Expand Down Expand Up @@ -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)
}
1 change: 0 additions & 1 deletion Sources/STTextViewUIKit/STTextView+Gutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion TextEdit/Mac/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TextEdit/iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f61e63a

Please sign in to comment.