@@ -61,15 +61,23 @@ extension SwiftDraw.CommandLine {
6161 }
6262
6363 static func process( with config: Configuration ) throws -> Data {
64- guard
65- let svg = SwiftDraw . Image ( fileURL: config. input) ,
66- let data = processImage ( svg, with: config) else {
64+ guard let data = processImage ( config: config) else {
6765 throw Error . invalid
6866 }
69-
67+
7068 return data
7169 }
72-
70+
71+ static func processImage( config: Configuration ) -> Data ? {
72+ switch config. format {
73+ case . swift:
74+ let code = Image . cgCodeText ( fileURL: config. input)
75+ return code? . data ( using: . utf8)
76+ case . jpeg, . pdf, . png:
77+ return SwiftDraw . Image ( fileURL: config. input) . flatMap { processImage ( $0, with: config) }
78+ }
79+ }
80+
7381 static func processImage( _ image: SwiftDraw . Image , with config: Configuration ) -> Data ? {
7482 switch config. format {
7583 case . jpeg:
@@ -78,6 +86,8 @@ extension SwiftDraw.CommandLine {
7886 return try ? Image . pdfData ( fileURL: config. input, size: config. size. cgValue)
7987 case . png:
8088 return image. pngData ( size: config. size. cgValue, scale: config. scale. cgValue)
89+ case . swift:
90+ preconditionFailure ( )
8191 }
8292 }
8393
@@ -87,11 +97,11 @@ extension SwiftDraw.CommandLine {
8797swiftdraw, version 0.7.6
8898copyright (c) 2021 Simon Whitty
8999
90- usage: swiftdraw <file.svg> [--format png | pdf | jpeg] [--size wxh] [--scale 1x | 2x | 3x]
100+ usage: swiftdraw <file.svg> [--format png | pdf | jpeg | swift ] [--size wxh] [--scale 1x | 2x | 3x]
91101
92102<file> svg file to be processed
93103
94- --format format to output image with png | pdf | jpeg
104+ --format format to output image with png | pdf | jpeg | swift
95105--size size of output image e.g. 100x200
96106--scale scale of output image with 1x | 2x | 3x
97107""" )
0 commit comments