Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Oct 17, 2024
1 parent 0b34447 commit 719d85e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Sources/SpeziConsent/ConsentView/ConsentDocument+Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/SpeziConsent/SignatureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<PKDrawing> = .constant(PKDrawing()),
isSigning: Binding<Bool> = .constant(false),
canvasSize: Binding<CGSize> = .constant(.zero),
Expand All @@ -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<String> = .constant(String()),
name: PersonNameComponents = PersonNameComponents(),
lineOffset: CGFloat = 30
Expand Down

0 comments on commit 719d85e

Please sign in to comment.