Skip to content

DesignPipe/swift-svgkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVGKit

CI License: MIT

SVG parsing and Android-native format generation in Swift.

Converts SVG files to:

  • ImageVector (Jetpack Compose Kotlin code)
  • VectorDrawable (Android XML resource)

Features

  • Full SVG path parsing (d attribute) with arc, cubic/quadratic bezier support
  • Gradient support (linear, radial) with transform matrices
  • SVG group hierarchy preservation
  • Stroke dash patterns
  • CSS inline styles
  • <use>/<symbol> element expansion
  • Path data validation and normalization
  • Cross-platform: macOS, Linux, Windows

Installation

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/DesignPipe/swift-svgkit.git", from: "0.1.0"),
]

Then add SVGKit to your target's dependencies:

.target(
    name: "MyTarget",
    dependencies: [
        .product(name: "SVGKit", package: "swift-svgkit"),
    ]
)

Usage

Parse SVG and generate ImageVector (Kotlin)

import SVGKit

let svgContent = "<svg>...</svg>"
let parsed = try SVGParser.parse(content: svgContent, iconName: "MyIcon")
let kotlin = ImageVectorGenerator.generate(from: parsed, iconName: "MyIcon")
print(kotlin)

Parse SVG and generate VectorDrawable (XML)

import SVGKit

let svgContent = "<svg>...</svg>"
let parsed = try SVGParser.parse(content: svgContent, iconName: "MyIcon")
let xml = VectorDrawableXMLGenerator.generate(from: parsed, iconName: "MyIcon")
print(xml)

Convert SVG to native VectorDrawable (via resvg)

import SVGKit

let svgContent = "<svg>...</svg>"
let xml = try NativeVectorDrawableConverter.convert(svgContent: svgContent, iconName: "MyIcon")
print(xml)

Requirements

  • Swift 6.2+
  • macOS 13+ / Linux (Ubuntu 22.04+) / Windows

Dependencies

Package Purpose
swift-log Structured logging
swift-resvg SVG tree parsing via resvg

License

MIT

About

SVG parsing and Android-native format generation (ImageVector Kotlin, VectorDrawable XML) in Swift

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages