updates plug with all sorts of awesome improvements
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import CoreText
|
||||
import Foundation
|
||||
|
||||
/// Registers the bundled OpenDyslexic and OpenDyslexic Mono faces for this process.
|
||||
/// Registers the bundled IBM Plex faces for this process. CoreText reads WOFF2 directly.
|
||||
public enum FontRegistry {
|
||||
public static let resourceBundleName = "Plak_PlakUI.bundle"
|
||||
|
||||
@@ -38,7 +38,7 @@ public enum FontRegistry {
|
||||
registered = names
|
||||
return names
|
||||
}
|
||||
for url in files where ["otf", "ttf"].contains(url.pathExtension.lowercased()) {
|
||||
for url in files where ["woff2", "woff", "ttf", "otf"].contains(url.pathExtension.lowercased()) {
|
||||
var error: Unmanaged<CFError>?
|
||||
let ok = CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error)
|
||||
let already = (error?.takeRetainedValue()).map { CFErrorGetCode($0) == CTFontManagerError.alreadyRegistered.rawValue } ?? false
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import AppKit
|
||||
|
||||
/// OpenDyslexic for text, OpenDyslexic Mono for code and tables; a system font when a bundled face is missing.
|
||||
/// IBM Plex Mono for the page, code, tables and bookmarks, IBM Plex Sans for the banner; the system fonts when Plex is missing.
|
||||
public enum PlakFonts {
|
||||
public static let regular = "OpenDyslexic-Regular"
|
||||
public static let monoRegular = "OpenDyslexicMono-Regular"
|
||||
|
||||
public static func body(_ size: CGFloat) -> NSFont {
|
||||
FontRegistry.registerBundledFonts()
|
||||
return NSFont(name: regular, size: size) ?? .systemFont(ofSize: size)
|
||||
return NSFont(name: "IBMPlexSans-Regular", size: size) ?? NSFont.systemFont(ofSize: size)
|
||||
}
|
||||
|
||||
public static func mono(_ size: CGFloat) -> NSFont {
|
||||
FontRegistry.registerBundledFonts()
|
||||
return NSFont(name: monoRegular, size: size) ?? .monospacedSystemFont(ofSize: size, weight: .regular)
|
||||
return NSFont(name: "IBMPlexMono-Regular", size: size) ?? NSFont.monospacedSystemFont(ofSize: size, weight: .regular)
|
||||
}
|
||||
|
||||
/// The height of one line of this font with no paragraph style.
|
||||
|
||||
@@ -1,33 +1,39 @@
|
||||
import AppKit
|
||||
|
||||
/// The colour tokens of the paper look.
|
||||
/// The colour tokens of the Kade dark slate look, the same as Helder.
|
||||
public enum Theme {
|
||||
/// Window and page background.
|
||||
public static let paper = NSColor(hex: 0xD8D0C0)
|
||||
/// Text.
|
||||
public static let ink = NSColor(hex: 0x2B2621)
|
||||
/// Dates, `image missing`.
|
||||
public static let inkMuted = NSColor(hex: 0x6E655A)
|
||||
/// The caret.
|
||||
public static let accent = NSColor(hex: 0x8A4B2A)
|
||||
/// Selected text, the save error message, and the lines of a table.
|
||||
public static let selection = NSColor(hex: 0xB9AE98)
|
||||
public static let paper = NSColor(hex: 0x101720)
|
||||
/// Text, also on the save error banner.
|
||||
public static let ink = NSColor(hex: 0xE4E7E6)
|
||||
/// Bookmark labels, the bookmark index, `image missing`.
|
||||
public static let inkMuted = NSColor(hex: 0x6C7783)
|
||||
/// The caret, the drop caret and the frame of the selected table cell.
|
||||
public static let accent = NSColor(hex: 0xE8913A)
|
||||
/// The tint behind selected text.
|
||||
public static let selection = NSColor(hex: 0xE8913A, alpha: 0.22)
|
||||
/// The grid lines of a table.
|
||||
public static let rule = NSColor(hex: 0x3A424C)
|
||||
/// The hairline from a bookmark to its label.
|
||||
public static let bookmarkRule = NSColor(hex: 0x6C7783)
|
||||
/// The background of the save error banner.
|
||||
public static let panel = NSColor(hex: 0x18202B)
|
||||
/// The tint behind a code block.
|
||||
public static let codePaper = NSColor(hex: 0xCBC2B0)
|
||||
public static let codePaper = NSColor(hex: 0x18202B)
|
||||
/// Code keywords, and true, false and null.
|
||||
public static let codeKeyword = NSColor(hex: 0x7A2E14)
|
||||
public static let codeKeyword = NSColor(hex: 0xC3A6CE)
|
||||
/// Code strings and heredocs, XML attribute values and CDATA.
|
||||
public static let codeString = NSColor(hex: 0x385218)
|
||||
/// Code comments: muted, yet readable on the code paper.
|
||||
public static let codeComment = NSColor(hex: 0x564E44)
|
||||
public static let codeString = NSColor(hex: 0x8FBFB4)
|
||||
/// Code comments.
|
||||
public static let codeComment = NSColor(hex: 0x6C7783)
|
||||
/// Code numbers.
|
||||
public static let codeNumber = NSColor(hex: 0x2E4A7A)
|
||||
public static let codeNumber = NSColor(hex: 0xF0B476)
|
||||
/// PHP `$variables`.
|
||||
public static let codeVariable = NSColor(hex: 0x0E5064)
|
||||
public static let codeVariable = NSColor(hex: 0xBAC0C0)
|
||||
/// XML tags and the PHP open and close tags.
|
||||
public static let codeTag = NSColor(hex: 0x7A3B12)
|
||||
public static let codeTag = NSColor(hex: 0xC3A6CE)
|
||||
/// XML attribute names and JSON keys.
|
||||
public static let codeAttribute = NSColor(hex: 0x5E4A12)
|
||||
public static let codeAttribute = NSColor(hex: 0xBAC0C0)
|
||||
}
|
||||
|
||||
public extension NSColor {
|
||||
@@ -43,7 +49,7 @@ public extension NSColor {
|
||||
|
||||
/// The body text size that ⌘+ / ⌘− / ⌘0 change.
|
||||
public struct TextSize: Equatable, Sendable {
|
||||
public static let standard: CGFloat = 16
|
||||
public static let standard: CGFloat = 13
|
||||
public static let range: ClosedRange<CGFloat> = 10...32
|
||||
public static let step: CGFloat = 2
|
||||
|
||||
@@ -58,35 +64,67 @@ public struct TextSize: Equatable, Sendable {
|
||||
public mutating func reset() { self = TextSize() }
|
||||
}
|
||||
|
||||
/// The width of the reading column in characters, that ⌘. / ⌘, change.
|
||||
public struct ColumnWidth: Equatable, Sendable {
|
||||
public static let standard = 68
|
||||
public static let range: ClosedRange<Int> = 40...160
|
||||
public static let step = 8
|
||||
|
||||
public private(set) var characters: Int
|
||||
|
||||
public init(characters: Int = ColumnWidth.standard) {
|
||||
self.characters = min(max(characters, ColumnWidth.range.lowerBound), ColumnWidth.range.upperBound)
|
||||
}
|
||||
|
||||
public mutating func wider() { self = ColumnWidth(characters: characters + ColumnWidth.step) }
|
||||
public mutating func narrower() { self = ColumnWidth(characters: characters - ColumnWidth.step) }
|
||||
public mutating func reset() { self = ColumnWidth() }
|
||||
}
|
||||
|
||||
/// Sizes of the page layout that follow the body size.
|
||||
public enum PageMetrics {
|
||||
public static let columnCharacters = 68
|
||||
public static let lineHeightMultiple: CGFloat = 1.6
|
||||
public static let lineHeightMultiple: CGFloat = 20.0 / 13.0
|
||||
public static let dateScale: CGFloat = 0.75
|
||||
/// Room under the transparent title bar.
|
||||
public static let topInset: CGFloat = 52
|
||||
public static let sideMargin: CGFloat = 28
|
||||
/// The narrowest left margin that shows created dates.
|
||||
public static let dateMarginMinimum: CGFloat = 120
|
||||
/// Room between a margin date and the column.
|
||||
public static let dateSpacing: CGFloat = 16
|
||||
/// The size of code and tables against the body size.
|
||||
public static let codeScale: CGFloat = 0.875
|
||||
/// Room between the left edge of the window and the bookmark index.
|
||||
public static let bookmarkIndexInset: CGFloat = 8
|
||||
/// The bookmark index shows only the last bookmarks of the page.
|
||||
public static let bookmarkIndexCount = 10
|
||||
/// Room between the column, a bookmark rule and a bookmark label.
|
||||
public static let bookmarkGap: CGFloat = 8
|
||||
/// The rule right of a bookmark label.
|
||||
public static let bookmarkTail: CGFloat = 16
|
||||
/// The shortest rule between the column and a bookmark label.
|
||||
public static let bookmarkRuleMinimum: CGFloat = 24
|
||||
/// Below this side space bookmarks are always narrow.
|
||||
public static let bookmarkSideMinimum: CGFloat = 160
|
||||
/// A label longer than this many characters never keeps bookmarks narrow; it is cut off with an ellipsis instead.
|
||||
public static let bookmarkLabelCharacters = 40
|
||||
/// The size of code and tables against the body size; the same as the page text.
|
||||
public static let codeScale: CGFloat = 1
|
||||
/// Room around the code inside a code block.
|
||||
public static let codePadding: CGFloat = 8
|
||||
public static let codeCornerRadius: CGFloat = 4
|
||||
public static let codeCornerRadius: CGFloat = 2
|
||||
/// The widest a table column shows; a longer value is cut off with an ellipsis.
|
||||
public static let tableColumnMaximum: CGFloat = 240
|
||||
public static let tableCellPadding = NSSize(width: 6, height: 3)
|
||||
|
||||
/// The width of about 68 characters of body text.
|
||||
public static func columnWidth(bodySize: CGFloat) -> CGFloat {
|
||||
let sample = String(String(repeating: "the quick brown fox jumps over a lazy dog ", count: 2).prefix(columnCharacters))
|
||||
let width = NSAttributedString(string: sample, attributes: [.font: PlakFonts.body(bodySize)]).size().width
|
||||
/// The side space from which bookmarks are wide: room for the widest label, at most `reasonableLabel`, with its rules.
|
||||
public static func bookmarkWideSide(widestLabel: CGFloat, reasonableLabel: CGFloat) -> CGFloat {
|
||||
let label = ceil(min(widestLabel, reasonableLabel))
|
||||
return max(bookmarkGap + bookmarkRuleMinimum + bookmarkGap + label + bookmarkGap + bookmarkTail, bookmarkSideMinimum)
|
||||
}
|
||||
|
||||
/// The width of about `characters` characters of body text.
|
||||
public static func columnWidth(bodySize: CGFloat, characters: Int) -> CGFloat {
|
||||
let sample = String(String(repeating: "the quick brown fox jumps over a lazy dog ", count: 4).prefix(characters))
|
||||
let width = NSAttributedString(string: sample, attributes: [.font: PlakFonts.mono(bodySize)]).size().width
|
||||
return ceil(width)
|
||||
}
|
||||
|
||||
/// The height of one text line: 1.6 times the size, or more when the font needs it.
|
||||
/// The height of one text line: 20/13 of the size, Helder's code line, or more when the font needs it.
|
||||
public static func lineHeight(_ font: NSFont) -> CGFloat {
|
||||
max(round(font.pointSize * lineHeightMultiple), PlakFonts.naturalLineHeight(font))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user