Skip to content

Commit

Permalink
Sharper chord diagrams on export
Browse files Browse the repository at this point in the history
  • Loading branch information
Desbeers committed Sep 7, 2023
1 parent f349c8a commit bf69726
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Chord Provider/Export/ExportSong+render.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ extension ExportSong {
/// - Returns: The header as CGImage
@MainActor
static func renderChords(song: Song) -> CGImage? {
/// Size of the chord diagram
let frame = CGRect(x: 0, y: 0, width: 60, height: 80)
/// Size of the chord diagrams
let frame = CGRect(x: 0, y: 0, width: 180, height: 240)
/// The grid items
let gridItems = Array(repeating: GridItem(.fixed(60), spacing: 0), count: 10)
/// Render the chords
let renderer = ImageRenderer(
content:
LazyVGrid(
columns: [GridItem(.adaptive(minimum: frame.width ))],
columns: gridItems,
alignment: .center,
spacing: 4,
pinnedViews: [.sectionHeaders, .sectionFooters]
spacing: 4
) {
ForEach(song.chords.sorted(using: KeyPathComparator(\.name))) { chord in
ChordDiagramView(chord: chord, frame: frame)
.scaledToFit()
.frame(width: 60)
}
}
.padding()
Expand Down
3 changes: 2 additions & 1 deletion Chord Provider/Export/ExportSong.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ enum ExportSong {
pages.append(finalA4)
#else
let finalA4: SWIFTImage = UIGraphicsImageRenderer(size: pageSize).image { _ in
SWIFTImage(ciImage: page).draw(in: .init(origin: .zero, size: .init(width: rectToDrawIn.width, height: rectToDrawIn.height)))
SWIFTImage(ciImage: page)
.draw(in: .init(origin: .zero, size: .init(width: rectToDrawIn.width, height: rectToDrawIn.height)))
}
pages.append(finalA4)
#endif
Expand Down
2 changes: 2 additions & 0 deletions Chord Provider/Views/ChordDiagramView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct ChordDiagramView: View {
)
if let image = layer.image() {
Image(swiftImage: image)
.resizable()
.aspectRatio(contentMode: .fit)
}
}
/// The warning if we can't show a diagram
Expand Down

0 comments on commit bf69726

Please sign in to comment.