Skip to content

Commit

Permalink
feat: Define ImageRenderer and separate build logic and render logic …
Browse files Browse the repository at this point in the history
…in generating image.
  • Loading branch information
fummicc1 committed Oct 16, 2024
1 parent c4a3acd commit f9fc8e7
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 274 deletions.

This file was deleted.

29 changes: 8 additions & 21 deletions Sources/Csv2ImgCore/Csv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -507,45 +507,32 @@ extension Csv {
}
if let maker = maker as? ImageMaker {
if let fontSize = fontSize {
maker.set(
fontSize: fontSize
)
maker.set(fontSize: fontSize)
}
let exportable: any CsvExportable = try await withCheckedThrowingContinuation {
let image: CGImage = try await withCheckedThrowingContinuation {
continuation in
queue.async { [weak self] in
guard let self = self else {
continuation.resume(
throwing: Csv.Error.underlying(
nil
)
)
continuation.resume(throwing: Csv.Error.underlying(nil))
return
}
Task {
do {
let img = try maker.make(
let image = try maker.make(
columns: await self.columns,
rows: await self.rows
) { progress in
self.progressSubject.value = progress

Check warning on line 525 in Sources/Csv2ImgCore/Csv.swift

View workflow job for this annotation

GitHub Actions / Build Csv2ImgCmd

actor-isolated property 'progressSubject' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode
}
continuation.resume(
returning: img
)
continuation.resume(returning: image)
} catch {
continuation.resume(
throwing: Csv.Error.underlying(
error
)
)
continuation.resume(throwing: Csv.Error.underlying(error))
}
}
}
}
return AnyCsvExportable(
exportable
)

return AnyCsvExportable(image)
} else if let maker = maker as? PdfMaker {
if let fontSize = fontSize {
maker.set(
Expand Down
2 changes: 2 additions & 0 deletions Sources/Csv2ImgCore/CsvError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extension Csv {
case emptyData
/// Csv denied execution because it is generating another contents.
case workInProgress
/// Failed to render image from `CsvImageRepresentation`.
case failedToRenderImage
case underlying(
Swift.Error?
)
Expand Down
22 changes: 22 additions & 0 deletions Sources/Csv2ImgCore/CsvImageRepresentation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import CoreGraphics
import Foundation

public struct CsvImageRepresentation: Equatable {
let width: Int
let height: Int
let backgroundColor: CGColor
let fontSize: CGFloat
let columns: [ColumnRepresentation]
let rows: [RowRepresentation]

struct ColumnRepresentation: Equatable {
let name: String
let style: Csv.Column.Style
let frame: CGRect
}

struct RowRepresentation: Equatable {
let values: [String]
let frames: [CGRect]
}
}
Loading

0 comments on commit f9fc8e7

Please sign in to comment.