Cotton code
29 lines · 1.3 KB · SwiftRaw
// A specimen rendered to an image: `SpecimenCard` at a card's size with the// room its sheets under take beside it, in Cotton's one look at one text size,// on the ground the face declares (`FaceGround`: the page ground Cotton's deck// stands on, or a ground of its own), so a face is seen against what is drawn// round it. A specimen that draws nothing comes// back nil, which is what its tests fail on.import CottonFacesimport CottonPaperimport SwiftUIpublic enum SpecimenShot {    /// `specimen` of `face` drawn at `size` and `textSize`, at    /// `scale` pixels to the point; nil when it drew nothing.    @MainActor public static func image(        _ face: Face, _ specimen: Specimen, size: CGSize,        textSize: DynamicTypeSize = .large, scale: CGFloat = 2    ) -> CGImage? {        let room = CardPaperKnobs.underRoom(width: size.width)        let renderer = ImageRenderer(content: SpecimenCard(face, specimen)            .dynamicTypeSize(textSize)            .frame(width: size.width, height: size.height)            .frame(width: size.width + room.width, height: size.height + room.height, alignment: .topLeading)            .background(FaceGroundSurface(SpecimenCard.ground(of: face))))        renderer.scale = scale        return renderer.cgImage    }}