https://github.com/piaschilling/svgpathmapper
Simple program to create material icons from svg files by mapping xml code to kotlin code
https://github.com/piaschilling/svgpathmapper
kotlin xml
Last synced: 3 months ago
JSON representation
Simple program to create material icons from svg files by mapping xml code to kotlin code
- Host: GitHub
- URL: https://github.com/piaschilling/svgpathmapper
- Owner: PiaSchilling
- Created: 2022-02-25T14:31:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-28T23:10:15.000Z (over 4 years ago)
- Last Synced: 2024-12-27T06:15:36.307Z (over 1 year ago)
- Topics: kotlin, xml
- Language: Java
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SvgPathMapper
Simple program to create material icons from svg files by mapping xml code to kotlin code
### What it can do - Example
The following svg code is used as the input: (the icon looks like this )
```xml
```
The kotlin code created by the program then looks like this:
```kotlin
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.materialIcon
import androidx.compose.material.icons.materialPath
import androidx.compose.ui.graphics.vector.ImageVector
public val Icons.Filled.Android: ImageVector
get() {
if (_android != null) {
return _android!!
}
_android = materialIcon(name = "Filled.Android") {
materialPath {
moveTo(17.532f,20.58f)
curveTo(16.98f,20.58f,16.524f,20.136f,16.524f,19.584f)
curveTo(16.524f,19.032f,16.98f,18.6f,17.532f,18.6f)
curveTo(18.084f,18.6f,18.54f,19.032f,18.54f,19.584f)
curveTo(18.54f,20.136f,18.084f,20.58f,17.532f,20.58f)
moveTo(6.492f,20.58f)
curveTo(5.94f,20.58f,5.484f,20.136f,5.484f,19.584f)
curveTo(5.484f,19.032f,5.94f,18.6f,6.492f,18.6f)
curveTo(7.044f,18.6f,7.488f,19.032f,7.488f,19.584f)
curveTo(7.488f,20.136f,7.044f,20.58f,6.492f,20.58f)
moveTo(17.892f,14.568f)
lineTo(19.896f,11.112f)
curveTo(20.004f,10.908f,19.932f,10.656f,19.74f,10.548f)
curveTo(19.536f,10.428f,19.284f,10.5f,19.2f,10.704f)
lineTo(17.148f,14.196f)
curveTo(15.54f,13.464f,13.8f,13.08f,12f,13.092f)
curveTo(10.164f,13.092f,8.4f,13.488f,6.876f,14.184f)
lineTo(4.848f,10.692f)
curveTo(4.74f,10.488f,4.488f,10.416f,4.284f,10.536f)
curveTo(4.08f,10.644f,4.02f,10.896f,4.128f,11.1f)
lineTo(6.12f,14.556f)
curveTo(2.7f,16.428f,0.348f,19.896f,-0f,24f)
lineTo(24f,24f)
curveTo(23.664f,19.908f,21.324f,16.44f,17.892f,14.568f)
close()
}
}
return _android!!
}
private var _android: ImageVector? = null
```
A kotlin file is created, which contains the generated code to be able to include it easily into the project. The output file is saved to the same directory as the input svg file.
Possibly existing matrix transformations are flattened/removed by calculating the path coordinates new based on the matrix values. Translate and other transformations are currently not taken care of.
### How it works
There are two programm arguments required:
1. the path to the input svg file
2. the name the material icon should have (will be used to name the variables and the kotlin file)
Just set both of them in the given order as arguments for the main method: e.g. `/Desktop/android_black_24dp.svg Android`