Cotton code
89 lines · 2.6 KB · SwiftRaw
// What a face prints on its stock, on every kind of card: the heavy title// struck twice on the typewriter, a run of the hand given room for its last// glyph, a quick stroke of the pen, the faint printed hairline, and Card// design's pictures multiplied into the stock.import CottonPaperimport SwiftUI/// The hand's last glyph reaches past the run's box (a script "i" leans out/// of it) and a Text draws only inside its box: a thin space after the words/// gives that glyph its room.public enum HandRun {    public static func tail(_ words: String) -> String { words + "\u{2009}" }}/// A quick pen stroke rising left to right, thinning at its end.public struct PenSwash: Shape {    public init() {}    public func path(in rect: CGRect) -> Path {        var path = Path()        path.move(to: CGPoint(x: rect.minX, y: rect.maxY))        path.addQuadCurve(to: CGPoint(x: rect.maxX, y: rect.minY), control: CGPoint(x: rect.midX, y: rect.maxY * 0.7))        return path    }}/// Typing struck twice, a hair apart: the heavy title of the references.public struct HeavyType: View {    let words: String    let size: CGFloat    public init(words: String, size: CGFloat) {        self.words = words        self.size = size    }    public var body: some View {        Text(words)            .font(CottonFonts.type(size))            .faceInk(.ink)            .overlay(alignment: .topLeading) {                Text(words)                    .font(CottonFonts.type(size))                    .faceInk(.ink)                    .offset(x: size * 0.025)                    .accessibilityHidden(true)            }            .fixedSize(horizontal: false, vertical: true)            .accessibilityAddTraits(.isHeader)    }}/// One of Card design's pictures printed on a face, at the width it is/// given, multiplied into the stock.public struct FaceArt: View {    let name: String    @Environment(\.theme) private var theme    public init(name: String) {        self.name = name    }    public var body: some View {        if let image = CottonMedia.image(name) {            image                .resizable()                .interpolation(.high)                .scaledToFit()                .blendMode(theme.printBlend)                .accessibilityHidden(true)        }    }}/// The faint printed hairline across a card.public struct FaceHairline: View {    @Environment(\.theme) private var theme    public init() {}    public var body: some View {        Rectangle()            .fill(theme.print(.pencil).opacity(0.35))            .frame(height: 0.75)            .blendMode(theme.printBlend)            .accessibilityHidden(true)    }}