From 719d85e78f0ff69b4b53c359384d3d19d876dcde Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Wed, 16 Oct 2024 17:03:02 -0700 Subject: [PATCH] improve --- .../ConsentView/ConsentDocument+Export.swift | 4 +- .../ConsentDocument+ExportConfiguration.swift | 50 +++++++++++-------- Sources/SpeziConsent/SignatureView.swift | 4 +- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Sources/SpeziConsent/ConsentView/ConsentDocument+Export.swift b/Sources/SpeziConsent/ConsentView/ConsentDocument+Export.swift index 918be63..38a47c1 100644 --- a/Sources/SpeziConsent/ConsentView/ConsentDocument+Export.swift +++ b/Sources/SpeziConsent/ConsentView/ConsentDocument+Export.swift @@ -112,8 +112,8 @@ extension ConsentDocument { let renderer = ImageRenderer(content: exportBody(markdown: markdownString)) let paperSize = CGSize( - width: exportConfiguration.paperSize.dimensions.width, - height: exportConfiguration.paperSize.dimensions.height + width: exportConfiguration.paperSize.width, + height: exportConfiguration.paperSize.height ) renderer.proposedSize = .init(paperSize) diff --git a/Sources/SpeziConsent/ConsentView/ConsentDocument+ExportConfiguration.swift b/Sources/SpeziConsent/ConsentView/ConsentDocument+ExportConfiguration.swift index 02ff8cf..bf4892b 100644 --- a/Sources/SpeziConsent/ConsentView/ConsentDocument+ExportConfiguration.swift +++ b/Sources/SpeziConsent/ConsentView/ConsentDocument+ExportConfiguration.swift @@ -17,29 +17,39 @@ extension ConsentDocument { /// You can use the `dimensions` property to get the width and height of each paper size in points. /// /// - Note: The dimensions are calculated based on the standard DPI (dots per inch) of 72 for print. - public enum PaperSize { + public struct PaperSize { + let width: CGFloat + let height: CGFloat + /// Standard US Letter paper size. - case usLetter + public static var usLetter: PaperSize { usLetter() } /// Standard DIN A4 paper size. - case dinA4 - + public static var dinA4: PaperSize { dinA4() } - /// Provides the dimensions of the paper in points. - /// - /// - Returns: A tuple containing the width and height of the paper in points. - var dimensions: (width: CGFloat, height: CGFloat) { - let pointsPerInch: CGFloat = 72.0 - - switch self { - case .usLetter: - let widthInInches: CGFloat = 8.5 - let heightInInches: CGFloat = 11.0 - return (widthInInches * pointsPerInch, heightInInches * pointsPerInch) - case .dinA4: - let widthInInches: CGFloat = 8.3 - let heightInInches: CGFloat = 11.7 - return (widthInInches * pointsPerInch, heightInInches * pointsPerInch) - } + /// Standard US Letter paper size with variable resolution. + public static func usLetter(pointsPerInch: CGFloat = 72) -> PaperSize { + let widthInInches: CGFloat = 8.5 + let heightInInches: CGFloat = 11.0 + return .init( + width: widthInInches * pointsPerInch, + height: heightInInches * pointsPerInch + ) + } + + /// Standard DIN A4 paper size with variable resolution. + public static func dinA4(pointsPerInch: CGFloat = 72) -> PaperSize { + let widthInInches: CGFloat = 8.3 + let heightInInches: CGFloat = 11.7 + return .init( + width: widthInInches * pointsPerInch, + height: heightInInches * pointsPerInch + ) + } + + /// Create a custom paper size in points by points. + public init(width: CGFloat, height: CGFloat) { + self.width = width + self.height = height } } diff --git a/Sources/SpeziConsent/SignatureView.swift b/Sources/SpeziConsent/SignatureView.swift index c98f99a..974b28f 100644 --- a/Sources/SpeziConsent/SignatureView.swift +++ b/Sources/SpeziConsent/SignatureView.swift @@ -107,7 +107,7 @@ public struct SignatureView: View { /// - canvasSize: The size of the canvas as a Binding. /// - name: The name that is displayed under the signature line. /// - lineOffset: Defines the distance of the signature line from the bottom of the view. The default value is 30. - init( + public init( signature: Binding = .constant(PKDrawing()), isSigning: Binding = .constant(false), canvasSize: Binding = .constant(.zero), @@ -126,7 +126,7 @@ public struct SignatureView: View { /// - signature: A `Binding` containing the current text-based signature as a `String`. /// - name: The name that is displayed under the signature line. /// - lineOffset: Defines the distance of the signature line from the bottom of the view. The default value is 30. - init( + public init( signature: Binding = .constant(String()), name: PersonNameComponents = PersonNameComponents(), lineOffset: CGFloat = 30