diff --git a/Museion/ProsePresenter.swift b/Museion/ProsePresenter.swift index 46bfcec..6ad9838 100644 --- a/Museion/ProsePresenter.swift +++ b/Museion/ProsePresenter.swift @@ -42,10 +42,12 @@ nonisolated enum ProsePresenter { /// as body anyway; dedicated quote spacing waits for #20's polish pass. static func paragraph(_ kind: LineKind) -> NSParagraphStyle { let style = NSMutableParagraphStyle() + style.lineHeightMultiple = ProseTypography.lineHeightMultiple + let line = ProseTypography.linePoints switch kind { - case .heading1: style.paragraphSpacing = 18; style.paragraphSpacingBefore = 26 - case .heading2: style.paragraphSpacing = 12; style.paragraphSpacingBefore = 20 - case .quote, .syntaxOnly, .body: style.paragraphSpacing = 10 + case .heading1: style.paragraphSpacing = 2 * line; style.paragraphSpacingBefore = 26 + case .heading2: style.paragraphSpacing = 2 * line; style.paragraphSpacingBefore = 1 * line + case .quote, .syntaxOnly, .body: style.paragraphSpacing = 1 * line } return style } diff --git a/Museion/ProseTypography.swift b/Museion/ProseTypography.swift index 569554b..5538b2e 100644 --- a/Museion/ProseTypography.swift +++ b/Museion/ProseTypography.swift @@ -28,6 +28,11 @@ nonisolated enum ProseTypography { static let defaultBodySize: Double = 17 static let defaultHeadingsSize: Double = 26 static let defaultCodeSize: Double = 13 + /// Text flow (#71 polish): line-height multiple + paragraph/heading + /// spacing measured in body lines — different faces need different flow. + static let defaultLineHeight: Double = 1.25 + static let defaultParagraphSpacingLines: Double = 1 + static let defaultHeadingSpacingLines: Double = 2 /// Register the six defaults once at app start. static func registerDefaults() { @@ -38,6 +43,9 @@ nonisolated enum ProseTypography { "proseHeadingsSize": defaultHeadingsSize, "proseCodeFace": defaultCodeFace, "proseCodeSize": defaultCodeSize, + "proseLineHeight": defaultLineHeight, + "proseParagraphSpacingLines": defaultParagraphSpacingLines, + "proseHeadingSpacingLines": defaultHeadingSpacingLines, ]) } @@ -83,6 +91,35 @@ nonisolated enum ProseTypography { bolded(bodyFont) } + // MARK: Text flow (#71 polish) + + /// Line-height multiple (clamped 1…2; 0/absent → default). + static var lineHeightMultiple: CGFloat { + clamped("proseLineHeight", default: defaultLineHeight, 1 ... 2) + } + + /// Spacing after body paragraphs, in body lines. + static var paragraphSpacingLines: CGFloat { + clamped("proseParagraphSpacingLines", default: defaultParagraphSpacingLines, 0 ... 4) + } + + /// Spacing after headings, in body lines. + static var headingSpacingLines: CGFloat { + clamped("proseHeadingSpacingLines", default: defaultHeadingSpacingLines, 0 ... 6) + } + + /// One body line at the configured flow, in points. + static var linePoints: CGFloat { + let f = bodyFont + return (f.ascender - f.descender + f.leading) * lineHeightMultiple + } + + private static func clamped(_ key: String, default def: Double, _ range: ClosedRange) -> CGFloat { + let stored = UserDefaults.standard.double(forKey: key) + let value = stored == 0 ? def : stored + return CGFloat(min(max(value, range.lowerBound), range.upperBound)) + } + // MARK: Attribute stacks (reading + editing share them) static var foregroundColor: NSColor { diff --git a/Museion/ReadingPresenter.swift b/Museion/ReadingPresenter.swift index a1744cf..020d12f 100644 --- a/Museion/ReadingPresenter.swift +++ b/Museion/ReadingPresenter.swift @@ -146,7 +146,8 @@ enum ReadingPresenter { /// paragraph when the file can't load. private static func imageBlockContent(url: URL, alt: String) -> NSAttributedString { let ps = NSMutableParagraphStyle() - ps.paragraphSpacing = 10 + ps.lineHeightMultiple = lineHeightMultiple + ps.paragraphSpacing = paragraphSpacingAfter ps.paragraphSpacingBefore = 8 guard let image = NSImage(contentsOf: url), image.size.width > 0 else { return inlineParse(alt.isEmpty ? "![missing](\(url.lastPathComponent))" : alt) @@ -201,7 +202,13 @@ enum ReadingPresenter { .map { $0.trimmingCharacters(in: .whitespaces) } .filter { !$0.isEmpty } .joined(separator: " ") - return inlineParse(joined) + let para = inlineParse(joined) + let ps = NSMutableParagraphStyle() + ps.lineHeightMultiple = lineHeightMultiple + ps.paragraphSpacing = paragraphSpacingAfter + let styled = NSMutableAttributedString(attributedString: para) + styled.addAttribute(.paragraphStyle, value: ps, range: NSRange(location: 0, length: styled.length)) + return styled } private static func headingContent(_ text: String, level: Int) -> NSAttributedString { diff --git a/Museion/SettingsPaneView.swift b/Museion/SettingsPaneView.swift index ec5c8e5..cc8b41c 100644 --- a/Museion/SettingsPaneView.swift +++ b/Museion/SettingsPaneView.swift @@ -35,6 +35,7 @@ struct SettingsPaneView: View { VStack(alignment: .leading, spacing: 24) { contentSection typographySection + flowSection } .padding(24) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) @@ -65,6 +66,23 @@ struct SettingsPaneView: View { } } + // MARK: Text flow (#71 polish) + + private var flowSection: some View { + VStack(alignment: .leading, spacing: 12) { + Text("Text Flow") + .font(.system(size: 13, weight: .semibold)) + Text( + "Reading rhythm. Line height scales the leading; the spacings are measured in body lines — tune them when a face change tightens or loosens the page.", + ) + .font(.callout) + .foregroundStyle(DesignTokens.muted) + FlowRow(label: "Line height", key: "proseLineHeight", range: 1 ... 2, step: 0.05) + FlowRow(label: "Space after ¶", key: "proseParagraphSpacingLines", range: 0 ... 4, step: 0.25) + FlowRow(label: "Space after headings", key: "proseHeadingSpacingLines", range: 0 ... 6, step: 0.25) + } + } + // MARK: Typography (#70) private var typographySection: some View { @@ -146,6 +164,35 @@ private struct SlotRow: View { } } +/// One flow knob: label + numeric field (UserDefaults-backed). +private struct FlowRow: View { + let label: String + let key: String + let range: ClosedRange + let step: Double + + var body: some View { + HStack(spacing: 10) { + Text(label) + .font(.system(size: 12, weight: .semibold)) + .frame(width: 150, alignment: .leading) + TextField("", value: binding, format: .number.precision(.fractionLength(2))) + .textFieldStyle(.roundedBorder) + .frame(width: 64) + Text("× body line") + .font(.system(size: 11, design: DesignTokens.mono)) + .foregroundStyle(DesignTokens.muted) + } + } + + private var binding: Binding { + Binding( + get: { UserDefaults.standard.double(forKey: key) }, + set: { UserDefaults.standard.set(max(range.lowerBound, min(range.upperBound, $0)), forKey: key) }, + ) + } +} + private extension Array { /// Order-preserving dedupe (face lists merge current + installed). func uniqued() -> [Element] where Element: Hashable {