Proportional body font with fixed-pitch tables, code and tags !336

merged merged by cmc on 2026-10-14 04:02 UTC · krz/orgstar:prose-font into main

18 files changed, +221 −21

Layout: unified · split

Sources/OrgApp/OrgPreferences.swift +1
@@ -66,6 +66,7 @@ public enum OrgPreferences {
6666 public static func theme(_ colors: ThemeSpec, _ defaults: UserDefaults = .standard) -> ThemeSpec {
6767 var spec = colors
6868 spec.font = string("themeFont", defaults)
69 spec.bodyFont = string("themeBodyFont", defaults)
6970 spec.fontSize = integer("themeFontSize", defaults)
7071 spec.lineSpacing = integer("themeLineSpacing", defaults)
7172 spec.headingSizeStep = integer("themeHeadingStep", defaults)
Sources/OrgApp/UserConfig.swift +2
@@ -295,6 +295,8 @@ public enum UserConfig {
295295 comment: "the grid's times as HHMM, separated by spaces", legacy: ""),
296296 Setting(section: "theme", key: "font", defaultsKey: "themeFont", kind: .string, fallback: .string(""),
297297 comment: "a monospaced font family; \"\" for the system's", legacy: ""),
298 Setting(section: "theme", key: "body-font", defaultsKey: "themeBodyFont", kind: .string, fallback: .string(""),
299 comment: "a font family for prose, or \"system\"; tables, code, dates and tags keep the font above; \"\" for the font above throughout", legacy: ""),
298300 Setting(section: "theme", key: "font-size", defaultsKey: "themeFontSize", kind: .integer, fallback: .integer(13),
299301 comment: "points", legacy: ""),
300302 Setting(section: "theme", key: "line-spacing", defaultsKey: "themeLineSpacing", kind: .integer, fallback: .integer(2),
Sources/OrgEditorAppKit/OrgEditor+Styling.swift +7 −1
@@ -43,6 +43,12 @@ extension OrgEditor {
4343 }
4444 if Presentation.excludesScripts(run.role) { scriptExclusions.append(run.range) }
4545 }
46 if theme.mixedPitch {
47 for prefix in Presentation.fixedPitchPrefixes(storage.string as NSString, in: range) {
48 guard let clipped = clip(prefix, to: range) else { continue }
49 storage.addAttribute(.font, value: theme.fixedPitch(storage, clipped), range: clipped)
50 }
51 }
4652 if !showMarkup, options.prettyEntities { prettify(range, in: storage, revealed: revealed, scriptExclusions: scriptExclusions) }
4753 applyShrunk(range, in: storage)
4854 applyHighlights(range, in: storage)
@@ -70,7 +76,7 @@ extension OrgEditor {
7076 }
7177 let size = theme.font.pointSize
7278 storage.addAttributes([
73 .font: NSFont.monospacedSystemFont(ofSize: size * 0.7, weight: .regular),
79 .font: theme.mixedPitch ? theme.body.withSize(size * 0.7) : NSFont.monospacedSystemFont(ofSize: size * 0.7, weight: .regular),
7480 .baselineOffset: (superscript ? 0.3 : -0.3) * size,
7581 ], range: NSRange(location: lineStart + body.lowerBound, length: body.count))
7682 }
Sources/OrgEditorAppKit/OrgEditor.swift +1 −1
@@ -282,7 +282,7 @@ public final class OrgEditor: NSObject {
282282 private func applyThemeToView() {
283283 Theme.selection = theme.color("selection") ?? .selectedTextBackgroundColor
284284 for view in orgTextViews {
285 view.font = theme.font
285 view.font = theme.body
286286 view.typingAttributes = theme.base
287287 view.drawsBackground = true
288288 view.backgroundColor = theme.color("background") ?? .textBackgroundColor
Sources/OrgEditorAppKit/Theme.swift +25 −4
@@ -6,7 +6,10 @@ import OrgPresentation
66@MainActor
77struct Theme {
88 let spec: ThemeSpec
9 /// The fixed-pitch font: columns, tables, code and the rest of `Presentation.isFixedPitch`.
910 let font: NSFont
11 /// The font for prose; `font` unless the theme names a body font.
12 let body: NSFont
1013
1114 init(_ spec: ThemeSpec = .default) {
1215 self.spec = spec
@@ -14,9 +17,24 @@ struct Theme {
1417 font = spec.font.isEmpty ? NSFont.monospacedSystemFont(ofSize: size, weight: .regular)
1518 : NSFontManager.shared.font(withFamily: spec.font, traits: [], weight: 5, size: size)
1619 ?? NSFont.monospacedSystemFont(ofSize: size, weight: .regular)
20 body = switch spec.bodyFont {
21 case "": font
22 case "system": NSFont.systemFont(ofSize: size)
23 case let family: NSFontManager.shared.font(withFamily: family, traits: [], weight: 5, size: size) ?? font
24 }
1725 Self.blockBackground = color("block-background") ?? .clear
1826 }
1927
28 /// Prose and fixed-pitch text use different fonts.
29 var mixedPitch: Bool { body != font }
30
31 /// The fixed-pitch font at the size and weight the text in `range` has.
32 func fixedPitch(_ storage: NSTextStorage, _ range: NSRange) -> NSFont {
33 let current = currentFont(storage, range)
34 let sized = font.withSize(current.pointSize)
35 return current.fontDescriptor.symbolicTraits.contains(.bold) ? NSFontManager.shared.convert(sized, toHaveTrait: .boldFontMask) : sized
36 }
37
2038 /// A color that follows the appearance, or nil when the theme has none for `key`.
2139 func color(_ key: String) -> NSColor? {
2240 // Editor colors are set for both appearances by the default theme; a key the theme
@@ -43,7 +61,7 @@ struct Theme {
4361 var foreground: NSColor { color("foreground") ?? .textColor }
4462
4563 var base: [NSAttributedString.Key: Any] {
46 [.font: font, .foregroundColor: foreground, .paragraphStyle: paragraphStyle(firstLine: 0, wrapped: 0)]
64 [.font: body, .foregroundColor: foreground, .paragraphStyle: paragraphStyle(firstLine: 0, wrapped: 0)]
4765 }
4866
4967 /// Width of one column of the monospaced font.
@@ -78,10 +96,13 @@ struct Theme {
7896 func fg(_ key: String) {
7997 if let color = color(key) { storage.addAttribute(.foregroundColor, value: color, range: range) }
8098 }
99 if mixedPitch, Presentation.isFixedPitch(role) {
100 storage.addAttribute(.font, value: fixedPitch(storage, range), range: range)
101 }
81102 switch role {
82103 case .heading(let level):
83 let size = font.pointSize + CGFloat(max(0, spec.headingSizeStep) * max(0, 4 - level))
84 let heading = NSFontManager.shared.convert(font.withSize(size), toHaveTrait: .boldFontMask)
104 let size = body.pointSize + CGFloat(max(0, spec.headingSizeStep) * max(0, 4 - level))
105 let heading = NSFontManager.shared.convert(body.withSize(size), toHaveTrait: .boldFontMask)
85106 storage.addAttribute(.font, value: heading, range: range)
86107 fg("heading-\(min(max(level, 1), 8))")
87108 case .leadingStars:
@@ -126,7 +147,7 @@ struct Theme {
126147 }
127148
128149 private func currentFont(_ storage: NSTextStorage, _ range: NSRange) -> NSFont {
129 storage.attribute(.font, at: range.location, effectiveRange: nil) as? NSFont ?? font
150 storage.attribute(.font, at: range.location, effectiveRange: nil) as? NSFont ?? body
130151 }
131152
132153 private func bold(_ storage: NSTextStorage, _ range: NSRange) -> NSFont {
Sources/OrgPresentation/Display.swift +57
@@ -92,6 +92,63 @@ extension Presentation {
9292 return out
9393 }
9494
95 /// Roles drawn in the fixed-pitch font when the body font is proportional, as Emacs's
96 /// mixed-pitch-mode keeps `mixed-pitch-fixed-pitch-faces`: text that lines up by column.
97 public static func isFixedPitch(_ role: StyleRole) -> Bool {
98 switch role {
99 case .table, .rule, .block, .blockDelimiter, .verbatim, .code, .inlineSource, .metadata, .keyword, .tags, .timestamp, .syntax: true
100 default: false
101 }
102 }
103
104 /// The start of each line in `range` that sets where its text begins, for the fixed-pitch
105 /// font under a proportional body: a heading's stars and space, and the leading blanks,
106 /// bullet and checkbox `hangingColumns` counts. org-indent's indentation is in columns of
107 /// the fixed-pitch font, so these keep text lined up under it.
108 public static func fixedPitchPrefixes(_ text: NSString, in range: Range<Int>) -> [Range<Int>] {
109 var out: [Range<Int>] = []
110 var location = range.lowerBound
111 while location < range.upperBound {
112 let line = text.lineRange(for: NSRange(location: location, length: 0))
113 guard line.length > 0 else { break }
114 location = NSMaxRange(line)
115 let content = text.substring(with: line)
116 let stars = content.prefix { $0 == "*" }.count
117 let length: Int
118 if stars > 0, content.dropFirst(stars).first == " " {
119 length = stars + 1
120 } else {
121 length = hangingPrefix(content).utf16.count
122 }
123 if length > 0 { out.append(line.location..<(line.location + length)) }
124 }
125 return out
126 }
127
128 /// The characters `hangingColumns` counts: leading blanks, then a bullet, its space and a
129 /// checkbox.
130 static func hangingPrefix(_ line: String) -> Substring {
131 let blanks = line.prefix { $0 == " " || $0 == "\t" }
132 let rest = line.dropFirst(blanks.count)
133 var bullet = 0
134 if let first = rest.first, first == "-" || first == "+" || (first == "*" && !blanks.isEmpty) {
135 bullet = 1
136 } else {
137 let digits = rest.prefix { $0.isASCII && $0.isNumber }
138 if !digits.isEmpty, let separator = rest.dropFirst(digits.count).first, separator == "." || separator == ")" {
139 bullet = digits.count + 1
140 }
141 }
142 guard bullet > 0, rest.dropFirst(bullet).first == " " else { return blanks }
143 var length = blanks.count + bullet + 1
144 let afterBullet = rest.dropFirst(bullet + 1)
145 if afterBullet.count >= 4, afterBullet.first == "[", "X x-".contains(afterBullet.dropFirst().first!),
146 afterBullet.dropFirst(2).first == "]", afterBullet.dropFirst(3).first == " " {
147 length += 4
148 }
149 return line.prefix(length)
150 }
151
95152 /// Columns a wrapped continuation of `line` should start past the line's own start.
96153 public static func hangingColumns(_ line: String) -> Int {
97154 var columns = 0
Sources/OrgPresentation/ThemeSpec.swift +4 −1
@@ -38,6 +38,9 @@ public struct RGBA: Hashable, Sendable {
3838public struct ThemeSpec: Equatable, Sendable {
3939 /// A font family; empty for the system's monospaced font.
4040 public var font = ""
41 /// The font for prose: a family, `system` for the system's proportional font, or empty for
42 /// `font` throughout. Tables, code and other `Presentation.isFixedPitch` text keep `font`.
43 public var bodyFont = ""
4144 public var fontSize = 13
4245 /// Points between lines.
4346 public var lineSpacing = 2
@@ -182,7 +185,7 @@ public struct ThemeSpec: Equatable, Sendable {
182185 // MARK: - Reading
183186
184187 /// Keys of `[theme]` that aren't colors; config.toml's settings handle them.
185 public static let typeKeys: Set<String> = ["font", "font-size", "line-spacing", "heading-size-step", "theme-file"]
188 public static let typeKeys: Set<String> = ["font", "body-font", "font-size", "line-spacing", "heading-size-step", "theme-file"]
186189
187190 /// Whether a table holds theme colors.
188191 public static func isThemeTable(_ name: String) -> Bool {
Sources/Orgstar/ContentView.swift +2
@@ -92,6 +92,7 @@ struct ContentView: View {
9292 @AppStorage("showHiddenFiles") private var showHiddenFiles = true
9393 @AppStorage("ignoredFolders") private var ignoredFolders = ScanRules.defaultIgnoredFolders.sorted().joined(separator: " ")
9494 @AppStorage("themeFont") private var themeFont = ""
95 @AppStorage("themeBodyFont") private var themeBodyFont = ""
9596 @AppStorage("themeFontSize") private var themeFontSize = 13
9697 @AppStorage("themeLineSpacing") private var themeLineSpacing = 2
9798 @AppStorage("themeHeadingStep") private var themeHeadingStep = 1
@@ -100,6 +101,7 @@ struct ContentView: View {
100101 private var theme: ThemeSpec {
101102 var spec = ConfigSync.shared.theme
102103 spec.font = themeFont
104 spec.bodyFont = themeBodyFont
103105 spec.fontSize = themeFontSize
104106 spec.lineSpacing = themeLineSpacing
105107 spec.headingSizeStep = themeHeadingStep
Sources/Orgstar/OrgstarApp.swift +14 −1
@@ -621,10 +621,16 @@ struct SettingsView: View {
621621 @AppStorage("settingsTab") private var tab = "general"
622622 @AppStorage("showHiddenFiles") private var showHiddenFiles = true
623623 @AppStorage("themeFont") private var themeFont = ""
624 @AppStorage("themeBodyFont") private var themeBodyFont = ""
624625 @AppStorage("themeFontSize") private var themeFontSize = 13
625626 @AppStorage("themeLineSpacing") private var themeLineSpacing = 2
626627 @AppStorage("themeHeadingStep") private var themeHeadingStep = 1
627628
629 /// Installed font families that aren't monospaced, for body text.
630 private static let proportionalFamilies: [String] = NSFontManager.shared.availableFontFamilies.filter { family in
631 NSFontManager.shared.font(withFamily: family, traits: [], weight: 5, size: 13)?.isFixedPitch == false
632 }
633
628634 /// Installed monospaced font families.
629635 private static let monospacedFamilies: [String] = NSFontManager.shared.availableFontFamilies.filter { family in
630636 NSFontManager.shared.font(withFamily: family, traits: [], weight: 5, size: 13)?.isFixedPitch == true
@@ -775,11 +781,18 @@ struct SettingsView: View {
775781 ForEach(Self.monospacedFamilies, id: \.self) { Text($0).tag($0) }
776782 if !themeFont.isEmpty, !Self.monospacedFamilies.contains(themeFont) { Text(themeFont).tag(themeFont) }
777783 }
784 Picker("Body text", selection: $themeBodyFont) {
785 Text("Same as Font").tag("")
786 Text("System").tag("system")
787 Divider()
788 ForEach(Self.proportionalFamilies, id: \.self) { Text($0).tag($0) }
789 if !["", "system"].contains(themeBodyFont), !Self.proportionalFamilies.contains(themeBodyFont) { Text(themeBodyFont).tag(themeBodyFont) }
790 }
778791 Stepper("Size: \(themeFontSize) pt", value: $themeFontSize, in: 8...36)
779792 Stepper("Line spacing: \(themeLineSpacing) pt", value: $themeLineSpacing, in: 0...16)
780793 Stepper("Headings grow by \(themeHeadingStep) pt a level", value: $themeHeadingStep, in: 0...8)
781794 } footer: {
782 Text("Tags and tables line up in columns, so a monospaced font keeps them straight.")
795 Text("Tags and tables line up in columns, so Font should be monospaced. With a Body text font, prose uses it while tables, code, dates, tags and drawers keep Font.")
783796 .settingsFooter()
784797 }
785798 Section {
Sources/OrgstarMobile/MobileEditor+Styling.swift +9 −1
@@ -203,6 +203,14 @@ extension MobileEditor {
203203 }
204204 if Presentation.excludesScripts(run.role) { scriptExclusions.append(run.range) }
205205 }
206 if theme.mixedPitch {
207 for prefix in Presentation.fixedPitchPrefixes(ns, in: whole) {
208 let clipped = NSIntersectionRange(NSRange(prefix), lines)
209 guard clipped.length > 0 else { continue }
210 let current = storage.attribute(.font, at: clipped.location, effectiveRange: nil) as? UIFont ?? theme.body
211 storage.addAttribute(.font, value: theme.fixedPitch(current), range: clipped)
212 }
213 }
206214 if !showMarkup, options.prettyEntities { prettify(whole, in: storage, revealed: revealed, scriptExclusions: scriptExclusions) }
207215 applyShrunk(whole, in: storage)
208216 applyImages(whole, in: storage, revealed: revealed)
@@ -238,7 +246,7 @@ extension MobileEditor {
238246 }
239247 let size = theme.font.pointSize
240248 storage.addAttributes([
241 .font: theme.font.withSize(size * 0.7),
249 .font: theme.body.withSize(size * 0.7),
242250 .baselineOffset: (superscript ? 0.3 : -0.3) * size,
243251 ], range: NSRange(location: lineStart + body.lowerBound, length: body.count))
244252 }
Sources/OrgstarMobile/MobileEditor.swift +1 −1
@@ -32,7 +32,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
3232 get { theme.spec }
3333 set {
3434 let new = MobileTheme(newValue)
35 guard new.spec != theme.spec || new.font != theme.font else { return }
35 guard new.spec != theme.spec || new.font != theme.font || new.body != theme.body else { return }
3636 theme = new
3737 paragraphStyles = [:]
3838 applyThemeToView()
Sources/OrgstarMobile/MobileTheme.swift +29 −5
@@ -7,7 +7,10 @@ import UIKit
77@MainActor
88struct MobileTheme {
99 let spec: ThemeSpec
10 /// The fixed-pitch font: columns, tables, code and the rest of `Presentation.isFixedPitch`.
1011 let font: UIFont
12 /// The font for prose; `font` unless the theme names a body font.
13 let body: UIFont
1114
1215 init(_ spec: ThemeSpec = .default) {
1316 self.spec = spec
@@ -16,7 +19,24 @@ struct MobileTheme {
1619 // theme's size for the default Dynamic Type size, scaled for others.
1720 let chosen = spec.font.isEmpty || UIFont.fontNames(forFamilyName: spec.font).isEmpty ? nil
1821 : UIFont(descriptor: UIFontDescriptor(fontAttributes: [.family: spec.font]), size: size)
19 font = UIFontMetrics(forTextStyle: .body).scaledFont(for: chosen ?? .monospacedSystemFont(ofSize: size, weight: .regular))
22 let metrics = UIFontMetrics(forTextStyle: .body)
23 font = metrics.scaledFont(for: chosen ?? .monospacedSystemFont(ofSize: size, weight: .regular))
24 body = switch spec.bodyFont {
25 case "": font
26 case "system": metrics.scaledFont(for: .systemFont(ofSize: size))
27 case let family where !UIFont.fontNames(forFamilyName: family).isEmpty:
28 metrics.scaledFont(for: UIFont(descriptor: UIFontDescriptor(fontAttributes: [.family: family]), size: size))
29 default: font
30 }
31 }
32
33 /// Prose and fixed-pitch text use different fonts.
34 var mixedPitch: Bool { body != font }
35
36 /// The fixed-pitch font at the size and weight of `current`.
37 func fixedPitch(_ current: UIFont) -> UIFont {
38 let sized = font.withSize(current.pointSize)
39 return current.fontDescriptor.symbolicTraits.contains(.traitBold) ? Self.adding(.traitBold, to: sized) : sized
2040 }
2141
2242 /// A color that follows the appearance, or nil when the theme has none for `key`.
@@ -46,8 +66,8 @@ struct MobileTheme {
4666
4767 /// A heading's font: larger by the heading step for levels 1 to 3, bold.
4868 func headingFont(_ level: Int) -> UIFont {
49 let size = font.pointSize + CGFloat(max(0, spec.headingSizeStep) * max(0, 4 - level))
50 return Self.adding(.traitBold, to: font.withSize(size))
69 let size = body.pointSize + CGFloat(max(0, spec.headingSizeStep) * max(0, 4 - level))
70 return Self.adding(.traitBold, to: body.withSize(size))
5171 }
5272
5373 static func adding(_ traits: UIFontDescriptor.SymbolicTraits, to font: UIFont) -> UIFont {
@@ -56,7 +76,7 @@ struct MobileTheme {
5676 }
5777
5878 var base: [NSAttributedString.Key: Any] {
59 [.font: font, .foregroundColor: foreground, .paragraphStyle: paragraphStyle(firstLine: 0, wrapped: 0)]
79 [.font: body, .foregroundColor: foreground, .paragraphStyle: paragraphStyle(firstLine: 0, wrapped: 0)]
6080 }
6181
6282 /// Markup hidden from view: no width, no color.
@@ -85,9 +105,13 @@ struct MobileTheme {
85105 if let color = color(key) { storage.addAttribute(.foregroundColor, value: color, range: range) }
86106 }
87107 func traits(_ add: UIFontDescriptor.SymbolicTraits) {
88 let current = storage.attribute(.font, at: range.location, effectiveRange: nil) as? UIFont ?? font
108 let current = storage.attribute(.font, at: range.location, effectiveRange: nil) as? UIFont ?? body
89109 storage.addAttribute(.font, value: Self.adding(add, to: current), range: range)
90110 }
111 if mixedPitch, Presentation.isFixedPitch(role) {
112 let current = storage.attribute(.font, at: range.location, effectiveRange: nil) as? UIFont ?? body
113 storage.addAttribute(.font, value: fixedPitch(current), range: range)
114 }
91115 switch role {
92116 case .heading(let level):
93117 storage.addAttribute(.font, value: headingFont(level), range: range)
Sources/OrgstarMobile/ReaderScreen.swift +2 −1
@@ -245,7 +245,8 @@ struct ReaderScreen: View {
245245 var result = AttributedString()
246246 for segment in segments {
247247 var part = AttributedString(segment.text)
248 var font = level.map(theme.headingFont) ?? theme.font
248 var font = level.map(theme.headingFont) ?? theme.body
249 if theme.mixedPitch, segment.roles.contains(where: Presentation.isFixedPitch) { font = theme.fixedPitch(font) }
249250 var color = level.flatMap { theme.color("heading-\(min(max($0, 1), 8))") } ?? theme.foreground
250251 func fg(_ key: String) { if let c = theme.color(key) { color = c } }
251252 // Outer roles first, so inner ones win.
Tests/OrgEditorAppKitTests/EditorTests.swift +26
@@ -244,6 +244,32 @@ struct EditingTests {
244244 h.checkInSync()
245245 }
246246
247 @Test func mixedPitch() throws {
248 let text = "**** Heading :tag:\nProse text.\n- item\n| a | b |\n#+begin_src sh\necho\n#+end_src\n"
249 let h = Harness(text)
250 var spec = ThemeSpec.default
251 spec.bodyFont = "system"
252 h.editor.themeSpec = spec
253 h.drainStyling()
254 let storage = try #require(h.textView.textStorage)
255 let ns = text as NSString
256 func fixed(_ needle: String, offset: Int = 0) -> Bool {
257 let font = storage.attribute(.font, at: ns.range(of: needle).location + offset, effectiveRange: nil) as? NSFont
258 return font?.isFixedPitch == true
259 }
260 #expect(!fixed("Prose"))
261 #expect(!fixed("Heading"))
262 #expect(fixed("****"))
263 #expect(fixed(":tag:"))
264 #expect(fixed("- item") && !fixed("item"))
265 #expect(fixed("| a"))
266 #expect(fixed("echo"))
267 // Body indentation is still counted in columns of the fixed-pitch font.
268 let style = try #require(storage.attribute(.paragraphStyle, at: ns.range(of: "Prose").location, effectiveRange: nil) as? NSParagraphStyle)
269 #expect(style.firstLineHeadIndent == 5 * h.editor.theme.column)
270 #expect(h.editor.theme.font.isFixedPitch)
271 }
272
247273 @Test func styling() throws {
248274 let h = Harness("** b\nbody\n")
249275 let storage = try #require(h.textView.textStorage)
Tests/OrgPresentationTests/MixedPitchTests.swift added +33
@@ -0,0 +1,33 @@
1import Foundation
2import OrgCore
3import Testing
4@testable import OrgPresentation
5
6struct MixedPitchTests {
7 @Test func fixedPitchRoles() {
8 for role: StyleRole in [.table, .rule, .block, .blockDelimiter, .verbatim, .code, .inlineSource, .metadata, .keyword, .tags, .timestamp, .syntax(.keyword)] {
9 #expect(Presentation.isFixedPitch(role), "\(role)")
10 }
11 for role: StyleRole in [.heading(level: 1), .bold, .italic, .link, .comment, .todo, .markup, .footnote] {
12 #expect(!Presentation.isFixedPitch(role), "\(role)")
13 }
14 }
15
16 @Test func prefixesThatSetIndentation() {
17 let text = "** Heading\nProse here.\n indented prose\n- item\n - [ ] box\n12. twelve\n\tTabbed\n*bold* not a heading\n" as NSString
18 let prefixes = Presentation.fixedPitchPrefixes(text, in: 0..<text.length).map { text.substring(with: NSRange($0)) }
19 #expect(prefixes == ["** ", " ", "- ", " - [ ] ", "12. ", "\t"])
20 }
21
22 @Test func prefixesOnlyInRange() {
23 let text = "- a\n- b\n" as NSString
24 #expect(Presentation.fixedPitchPrefixes(text, in: 4..<8) == [4..<6])
25 }
26
27 @Test func bodyFontInSpec() {
28 var spec = ThemeSpec.default
29 #expect(spec.bodyFont.isEmpty)
30 spec.bodyFont = "system"
31 #expect(spec != ThemeSpec.default)
32 }
33}
docs/manual/guide/02-the-editor.org +1 −1
@@ -30,7 +30,7 @@ The two Org options are in Settings ▸ Editing as "Emacs hides emphasis markers
3030- Blocks (=#+BEGIN_…= to =#+END_…=), dynamic blocks and fixed-width lines are drawn on a shaded band across the whole width of the editor, as Emacs extends the =org-block= face. Code in src blocks is highlighted for its language (see [[file:11-code-blocks.org][Code blocks]]).
3131- A folded heading shows an ellipsis after its line.
3232
33Colours come from the theme and follow the system's light or dark appearance. The font, size and line spacing are in Settings ▸ Appearance; colours are set in =config.toml=. See [[file:13-configuration.org][Configuration]]. Use a monospaced font: tags and tables line up by columns.
33Colours come from the theme and follow the system's light or dark appearance. The font, size and line spacing are in Settings ▸ Appearance; colours are set in =config.toml=. See [[file:13-configuration.org][Configuration]]. The font should be monospaced, since tags and tables line up by columns. A body font for prose can be set beside it, as =mixed-pitch-mode= does in Emacs: prose and headings use it, and tables, code, dates, tags, drawers and the start of each line keep the monospaced font.
3434
3535** Indentation and stars
3636
docs/manual/guide/13-configuration.org +6 −3
@@ -103,6 +103,7 @@ orgstar's menus, settings and agenda are in English and German, and follow the l
103103| Control | Range | Default | Key |
104104|---------------------------------+-----------------------------------------------+--------------------+---------------------|
105105| Font | System monospaced, or any installed monospaced family | System monospaced | =font= |
106| Body text | Same as Font, System, or any installed proportional family | Same as Font | =body-font= |
106107| Size | 8 to 36 pt | 13 pt | =font-size= |
107108| Line spacing | 0 to 16 pt | 2 pt | =line-spacing= |
108109| Headings grow by N pt a level | 0 to 8 pt | 1 pt | =heading-size-step= |
@@ -359,6 +360,7 @@ Publishing projects, one table each, as =org-publish-project-alist= has them. Th
359360| Key | Type | Default | Effect |
360361|---------------------+---------+---------+----------------------------------------------------------------------------------------------|
361362| =font= | string | =""= | A font family. =""= uses the system's monospaced font. |
363| =body-font= | string | =""= | A font family for prose, or ="system"= for the system's proportional font. =""= uses =font= throughout. |
362364| =font-size= | integer | =13= | Points. |
363365| =line-spacing= | integer | =2= | Points between lines. |
364366| =heading-size-step= | integer | =1= | Points a heading is larger than the level below. Level 4 and deeper are body size. |
@@ -765,11 +767,12 @@ orgstar follows the system's light or dark appearance (System Settings ▸ Appea
765767
766768* Fonts
767769
768The editor uses one font for everything: body text, headings, code and tables. Choose it in Settings ▸ Appearance or with =font= under =[theme]=.
770By default the editor uses one font for everything: body text, headings, code and tables. Choose it in Settings ▸ Appearance or with =font= under =[theme]=.
769771
770- The Font menu lists installed monospaced families. =config.toml= accepts any family name; a family that isn't installed falls back to the system's monospaced font. Tags and tables line up in columns, so a proportional font misaligns them.
772- The Font menu lists installed monospaced families. =config.toml= accepts any family name; a family that isn't installed falls back to the system's monospaced font. Tags and tables line up in columns, so a proportional font there misaligns them.
773- Body text (=body-font=) sets a second font for prose, as Emacs's =mixed-pitch-mode= does. Paragraphs, list text and headings use it. Tables, source and example blocks, verbatim and code, keyword lines, planning lines, drawers, timestamps and tags keep =font=, and so do a heading's stars and a line's leading blanks, bullet and checkbox, so text still starts under the indentation. Tags after a heading in the body font no longer line up at =org-tags-column=; the file is unchanged. A family that isn't installed falls back to =font=.
771774- =font-size= is the body size, at least 6 points.
772775- Headings are bold. Level 1 is =font-size= plus three times =heading-size-step=, level 2 plus two times, level 3 plus one time; level 4 and deeper are body size. Set =heading-size-step = 0= for one size throughout.
773776- =line-spacing= adds space between lines, in points.
774777
775On iPhone and iPad, the editor and reader use the same theme, read from the synced configuration folder. =font= applies when the family is installed on the device, otherwise the system's monospaced font is used, and =font-size= is the size at the default Dynamic Type setting, scaled with the size chosen on the device. The =selection= color, the =cursor= color and the =syntax-*= colors apply there too. See [[file:14-ios.org][iPhone and iPad]].
778On iPhone and iPad, the editor and reader use the same theme, read from the synced configuration folder. =font= and =body-font= apply when the family is installed on the device, otherwise the system's monospaced font is used, and =font-size= is the size at the default Dynamic Type setting, scaled with the size chosen on the device. The =selection= color, the =cursor= color and the =syntax-*= colors apply there too. See [[file:14-ios.org][iPhone and iPad]].
docs/manual/guide/14-ios.org +1 −1
@@ -82,7 +82,7 @@ Files that aren't valid UTF-8 open read-only; commands that would change them sa
8282
8383The editor and the reader use the theme set in the configuration folder's =config.toml=, stacked as on the Mac: the default theme, then the theme file named by =theme-file=, then the colours in =[theme]=, =[theme.light]=, =[theme.dark]=, =[theme.todo]= and =[theme.category]=. A TODO keyword without a colour in =[theme.todo]= takes its class's colour: =todo-next= for =NEXT= and =STRT=, =todo-waiting= for =WAIT= and =HOLD=, =todo-cancelled= for =KILL= and =CANCELLED=, and so on (see [[file:13-configuration.org][Configuration]] for the lists). Colours follow the system's light or dark appearance. Problems in the theme show in the Settings tab with the other problems. A change to =config.toml= or the theme file applies as it syncs, to open editors too. See [[file:13-configuration.org][Configuration]] for the colour keys.
8484
85- Font :: =font= when that family is installed on the device, otherwise the system's monospaced font.
85- Font :: =font= when that family is installed on the device, otherwise the system's monospaced font. =body-font=, when set, is used for prose as on the Mac.
8686- Size :: =font-size= is the size at the default Dynamic Type setting, 13 pt by default. Text grows and shrinks with the text size chosen in the system Settings app.
8787- Line spacing and headings :: =line-spacing= and =heading-size-step= apply as on the Mac.
8888- Caret and selection :: the selection highlight takes the theme's =selection= colour, over block bands too; the caret and the selection handles take =cursor=.