Cotton code
74 lines · 2.8 KB · SwiftRaw
// The reader's faces and its knobs as the core answers them (`shell.reader`'s// `settings`, from the synced `face_settings` row keyed `reader`).//// A face is a whole (the coordinator, 4 Nov 2026): its ground, its ink, its// secondary ink and its hairline, from `BookFaceMaterial`. The page is the// whole screen in the face's ground; every word of the chrome is drawn in// its inks. Which face is worn, what each knob holds, and what a choice// writes are the core's (`phone::reader`); this file only names the// materials a face is drawn in and decodes the knobs Readium is handed.import CottonPaperimport SwiftUI/// One of the reader's three faces, as it is drawn.enum ReaderFace: String, CaseIterable, Sendable, Decodable {    case paper, sepia, night    var ground: SwiftUI.Color { material.ground.colour }    var ink: SwiftUI.Color { material.ink.colour }    var secondary: SwiftUI.Color { material.secondary.colour }    var hairline: SwiftUI.Color { ink.opacity(BookFaceMaterial.hairline(dark: dark)) }    var dark: Bool { self == .night }    var material: (ground: BookFaceMaterial, ink: BookFaceMaterial, secondary: BookFaceMaterial) {        switch self {        case .paper: (.paperGround, .paperInk, .paperSecondary)        case .sepia: (.sepiaGround, .sepiaInk, .sepiaSecondary)        case .night: (.nightGround, .nightInk, .nightSecondary)        }    }}/// A typeface the Typeface knob sets, as Readium is handed it (`ReaderLook.family`).enum ReaderTypeface: String, CaseIterable, Sendable, Decodable {    /// The book's own type.    case publisher    /// Libre Caslon, CottonPaper's book Caslon.    case serif    /// The system's face.    case sans    /// OpenDyslexic.    case dyslexic}/// The reader's settings, as the core answers them.struct ReaderSettings: Equatable, Sendable, Decodable {    /// The face chosen, and the face the page wears now (Night while the    /// phone is dark and the person follows it).    var face: ReaderFace = .paper    var worn: ReaderFace = .paper    var knobs = Knobs()    struct Knobs: Equatable, Sendable, Decodable {        var size: Double = 1.0        var lineHeight: Double?        var margins: Double?        var typeface: ReaderTypeface = .publisher        var layout = "pages"        var follow = false        var weight = "regular"        var justify = false        var publisherStyles = true        var pdfFit = "width"        var scroll: Bool { layout == "scroll" }        var bold: Bool { weight == "bold" }        var pdfWholePage: Bool { pdfFit == "page" }        enum CodingKeys: String, CodingKey {            case size, margins, typeface, layout, follow, weight, justify            case lineHeight = "line_height", publisherStyles = "publisher_styles", pdfFit = "pdf_fit"        }    }}