Files
ElyOffice/packaging/icons/icon.swift
T
ZacharyZhang-NY b7fca0146d Ely Office: six offline-first desktop apps in Rust and GPUI
ElyDoc, ElyTable, ElyShow (LibreOfficeKit), ElyPDF (MuPDF), ElyTree (Git),
ElyMark (Milkdown and CodeMirror in CEF). ElyMail and ElyAgent follow.
2026-10-08 21:20:08 -04:00

23 lines
1.1 KiB
Swift

// Renders SVGs to transparent PNGs. Usage: icon <px> <in.svg> <out.png>...
import AppKit
let args = CommandLine.arguments
guard args.count >= 4, args.count % 2 == 0, let size = Int(args[1]) else {
FileHandle.standardError.write("usage: icon <px> <in.svg> <out.png>...\n".data(using: .utf8)!)
exit(2)
}
for pair in stride(from: 2, to: args.count, by: 2) {
guard let svg = NSImage(contentsOfFile: args[pair]) else {
FileHandle.standardError.write("icon: cannot read \(args[pair])\n".data(using: .utf8)!)
exit(1)
}
let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: size, pixelsHigh: size,
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false,
colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep)
svg.draw(in: NSRect(x: 0, y: 0, width: size, height: size))
NSGraphicsContext.restoreGraphicsState()
try rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: args[pair + 1]))
}