Skip to content

Commit

Permalink
Simplify signature UIImage export (#66)
Browse files Browse the repository at this point in the history
# Simplify signature `UIImage` export

## ♻️ Current situation & Problem
The current signature export logic manually reads all strokes from the
drawing and sets them to black before converting to an UI image. This
can be done simpler via
`.withRenderingMode(.alwaysTemplate).withTintColor(.black)`


## ⚙️ Release Notes 
- Simplify signature `UIImage` export
- Fixed LFS consent document files in unit tests


## 📚 Documentation
Updated doc


## ✅ Testing
Tested locally


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
philippzagar authored Jan 30, 2025
1 parent a7cc789 commit c06991b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,18 @@ extension ConsentDocument {

#if !os(macOS)
private var signatureImage: UIImage {
var updatedDrawing = PKDrawing()

for stroke in signature.strokes {
// As the `PKDrawing.image()` function automatically converts the ink color dependent on the used color scheme (light or dark mode),
// force the ink used in the `UIImage` of the `PKDrawing` to always be black by adjusting the signature ink according to the color scheme.
let blackStroke = PKStroke(
ink: PKInk(stroke.ink.inkType, color: colorScheme == .light ? .black : .white),
path: stroke.path,
transform: stroke.transform,
mask: stroke.mask
)

updatedDrawing.strokes.append(blackStroke)
}

#if os(iOS)
let scale = UIScreen.main.scale
#else
let scale = 3.0 // retina scale is default
#endif

return updatedDrawing.image(
// As the `PKDrawing.image()` function automatically converts the ink color dependent on the used color scheme (light or dark mode),
// force the tint color used in the `UIImage` to `black`.
return signature.image(
from: .init(x: 0, y: 0, width: signatureSize.width, height: signatureSize.height),
scale: scale
)
).withRenderingMode(.alwaysTemplate).withTintColor(.black)
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ extension ConsentDocumentExportRepresentation {
markdown: markdown,
options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)
)) ?? AttributedString(String(localized: "MARKDOWN_LOADING_ERROR", bundle: .module))

markdownString.font = configuration.fontSettings.documentContentFont

// Indirection needed to hide `Sendable` warnings of `NSFont` on macOS
markdownString.mergeAttributes(.init([.font: configuration.fontSettings.documentContentFont]))

return PDFAttributedText(text: NSAttributedString(markdownString))
}
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit c06991b

Please sign in to comment.