SVG Report Renderer

Pure Swift SVG generator for reports using Core Text for text measurement.

API

public enum SVGReportRenderer {
    // Synchronous render without images
    public static func render(_ data: ReportData) -> String

    // Async render with image embedding
    public static func render(
        _ data: ReportData,
        imageProvider: ReportImageProvider
    ) async -> String
}

ReportImageProvider Protocol

For lazy loading record images into the report.

public protocol ReportImageProvider: Sendable {
    func loadImageData(filename: String, for recordId: UUID) async -> Data?
}

Page Dimensions

  • A4 Landscape: 842 x 595 points (72 DPI)
  • Margins: 40 points

Layout Sections

  1. Header (~60pt): Title, date range, total hours
  2. Stacked Bar Chart (~200pt): See 308-stacked-chart
  3. Comments Section (~300pt): See 309-comments-section
  4. Footer (25pt): “Generated by MINUTA.tools”

Text Measurement

Uses Core Text for accurate text width calculation:

  • Font: System font at specified size
  • Measures actual rendered width for layout

Text Wrapping

Comments are wrapped to fit column width:

  • Uses Core Text for measurement
  • 4-line maximum with ”…” truncation
  • Proper word boundary handling

Related