Skip to content

Commit

Permalink
Chante to select font preference from three choices
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 31, 2023
1 parent 65e3942 commit 9ff4670
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 72 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Change Log
4.6.0-beta.2 (unreleased)
--------------------------

### Improvements

- [beta] Change the font to prefer for the editor to select from the standard, monospaced, and automatic.


### Known Issues

- User interface is not localized yet.
Expand Down
76 changes: 48 additions & 28 deletions CotEditor/Base.lproj/AppearancePane.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ <h1>Change Appearance settings in CotEditor</h1>

<tbody>
<tr>
<th>Font</th>
<td>The text font for the editor. Accoding to the kind of the document’s syntax, you can prioritize the monopaced font specified below.
<th>Prefer font using</th>
<td>Select whether to use the standard or monospaced font in the editors when opening a document. If you select “Automatic,” font will be automatically selected from the standard and monospaced depending on the document’s syntax kind.</td>

<th>Standard font</th>
<td>The standard font to display text in the editors.

<dl>
<dt>Font</dt>
Expand All @@ -40,12 +43,7 @@ <h1>Change Appearance settings in CotEditor</h1>

<tr>
<th>Monospaced font</th>
<td>The monospaced font for the editor such as when the kind of the document’s syntax is “code.”

<dl>
<dt>Always use monospaced font</dt>
<dd>Use the monospaced font for the editor regardless the document’s syntax.</dd>
</dl></td>
<td>The monospaced font to display text in the editors.</td>
</tr>

<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ <h1>CotEditorで「表示」設定を変更する</h1>

<tbody>
<tr>
<th>フォント</th>
<td>エディタのテキスト表示に使うフォントを設定します。ただし、シンタックススタイルの種類によっては下記の「等幅フォント」が優先されます。
<th>優先するフォント</th>
<td>書類を開いたときに、標準フォントと等幅フォントのどちら使用するか設定します。「自動」を選択すると、書類のシンタックスの種類によって標準か等幅かを自動で選択します。</td>

<th>標準フォント</th>
<td>エディタのテキスト表示に使う標準的なフォントを設定します。

<dl>
<dt>フォント</dt>
Expand All @@ -40,12 +43,7 @@ <h1>CotEditorで「表示」設定を変更する</h1>

<tr>
<th>等幅フォント</th>
<td>シンタックスの種類が「コード」のときなどにエディタに使う等幅のフォントを設定します。

<dl>
<dt>常に等幅フォントを使用</dt>
<dd>シンタックスの種類に関わらず常にエディタに等幅のフォントを使用します。</dd>
</dl></td>
<td>エディタのテキスト表示に使う等幅のフォントを設定します。</td>
</tr>

<tr>
Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private extension UserDefaults {

if font.isFixedPitch {
self[.monospacedFont] = try? font.archivedData
self[.usesMonospacedFont] = true
self[.fontPreference] = .monospaced
} else {
self[.font] = try? font.archivedData
}
Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/DefaultKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension DefaultKeys {
static let monospacedFont = DefaultKey<Data?>("monospacedFont")
static let monospacedShouldAntialias = DefaultKey<Bool>("monospacedShouldAntialias")
static let monospacedLigature = DefaultKey<Bool>("monospacedLigature")
static let usesMonospacedFont = DefaultKey<Bool>("usesMonospacedFont")
static let fontPreference = DefaultKey<FontPreference>("fontPreference")
static let lineHeight = DefaultKey<CGFloat>("lineHeight")
static let highlightCurrentLine = DefaultKey<Bool>("highlightCurrentLine")
static let documentAppearance = RawRepresentableDefaultKey<AppearanceMode>("appearance")
Expand Down
8 changes: 8 additions & 0 deletions CotEditor/Sources/DefaultOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ enum WritingDirection: Int {
}


enum FontPreference: Int {

case automatic
case monospaced
case standard
}


enum AppearanceMode: Int {

case `default`
Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/DefaultSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct DefaultSettings {
.ligature: true,
.monospacedShouldAntialias: true,
.monospacedLigature: false,
.usesMonospacedFont: false,
.fontPreference: FontPreference.automatic.rawValue,
.lineHeight: 1.2,
.highlightCurrentLine: false,
.documentAppearance: AppearanceMode.default.rawValue,
Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/EditorTextView+Scaling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension EditorTextView {
/// reset scale and font to default
@IBAction func resetFont(_ sender: Any?) {

self.font = UserDefaults.standard.font(for: UserDefaults.standard[.usesMonospacedFont] ? .monospaced : self.syntaxKind.fontType)
self.font = UserDefaults.standard.font(for: self.preferredFontType)
self.setScaleKeepingVisibleArea(1.0)
}
}
25 changes: 21 additions & 4 deletions CotEditor/Sources/EditorTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor

didSet {
guard oldValue != syntaxKind else { return }
self.setFont(type: UserDefaults.standard[.usesMonospacedFont] ? .monospaced : syntaxKind.fontType)
let type: FontType = switch UserDefaults.standard[.fontPreference] {
case .automatic: syntaxKind.fontType
case .standard: .standard
case .monospaced: .monospaced
}
self.setFont(type: type)
}
}

Expand Down Expand Up @@ -211,7 +216,7 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor
self.isContinuousSpellCheckingEnabled = defaults[.checkSpellingAsType]

// set font
let fontType: FontType = defaults[.usesMonospacedFont] ? .monospaced : .standard
let fontType: FontType = (defaults[.fontPreference] == .monospaced) ? .monospaced : .standard
let font = defaults.font(for: fontType)
super.font = font
layoutManager.textFont = font
Expand All @@ -226,8 +231,9 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor

// observe changes in defaults
self.defaultsObservers = [
defaults.publisher(for: .usesMonospacedFont)
.sink { [unowned self] in self.setFont(type: $0 ? .monospaced : self.syntaxKind.fontType) },
defaults.publisher(for: .fontPreference)
.map { [unowned self] _ in self.preferredFontType }
.sink { [unowned self] in self.setFont(type: $0) },

defaults.publisher(for: .balancesBrackets)
.sink { [unowned self] in self.balancesBrackets = $0 },
Expand Down Expand Up @@ -1315,6 +1321,17 @@ class EditorTextView: NSTextView, Themable, CurrentLineHighlighting, MultiCursor
}


/// The font type the user prefers.
var preferredFontType: FontType {

switch UserDefaults.standard[.fontPreference] {
case .automatic: self.syntaxKind.fontType
case .standard: .standard
case .monospaced: .monospaced
}
}


/// Set the font (font, antialias, and ligature) to the given font type.
///
/// - Parameter type: The font type to change.
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/de.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Schrift:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Schrift bevorzugen:";
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Autoamtisch";
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard";
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Nichtproportional";

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standardschrift:";
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Auswählen …";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/en-GB.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Font:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:";
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic";
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard";
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced";

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:";
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Select…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/es.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Tipo de letra:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Seleccionar…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/fr.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Police :";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Choisir…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/it.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Font:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Seleziona…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/ja.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "フォント:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "優先するフォント:";
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "自動";
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "標準";
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "等幅";

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "標準フォント:";
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "選択…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/pt.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Fonte:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Selecionar…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/tr.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Font:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "Seç…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/zh-Hans.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "字体:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "选择…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down
13 changes: 11 additions & 2 deletions CotEditor/zh-Hant.lproj/AppearancePane.strings
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
// limitations under the License.
//

/* Class = "NSTextFieldCell"; title = "Font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "字型:";
/* Class = "NSTextFieldCell"; title = "Prefer font using:"; ObjectID = "XQO-YW-cqZ"; */
"XQO-YW-cqZ.title" = "Prefer font using:"; // FIXME: added
/* Class = "NSMenuItem"; title = "Automatic"; ObjectID = "XcC-5y-bLG"; */
"XcC-5y-bLG.title" = "Automatic"; // FIXME: added
/* Class = "NSMenuItem"; title = "Standard"; ObjectID = "Vla-IY-EYW"; */
"Vla-IY-EYW.title" = "Standard"; // FIXME: added
/* Class = "NSMenuItem"; title = "Monospaced"; ObjectID = "htL-1g-SvR"; */
"htL-1g-SvR.title" = "Monospaced"; // FIXME: added

/* Class = "NSTextFieldCell"; title = "Standard font:"; ObjectID = "Z85-S9-uID"; */
"Z85-S9-uID.title" = "Standard font:"; // FIXME: added
/* Class = "NSButtonCell"; title = "Select…"; ObjectID = "3289"; */
"3289.title" = "選擇…";
/* Class = "NSButtonCell"; title = "Antialias"; ObjectID = "3290"; */
Expand Down

0 comments on commit 9ff4670

Please sign in to comment.