/SVGPathKotlin

Simple library for drawing Path from svg path data written in Kotlin.

Primary LanguageKotlin

SVGPathKotlin

Simple library for drawing Path from svg path data written in Kotlin

Image

About

SVGPathKotlin is simple library that generate commands that are used for creating Path with applied curves, that can later be drawn to Canvas on any View. Commands are extracted from raw path data string that is passed as argument to the constructor of the SvgPath class. If you want to learn more about the library and how it works you check the official wiki page.

Platform API Download

Add to your project

Add the jitpack maven repository

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Add the dependency

dependencies { 
  implementation 'com.github.slaviboy:SVGPathKotlin:0.3.0'
}

How to use

Create SvgPath object and pass you svg path data as string. To apply any of the available transformations: rotation, scale, skew or translate to the path, use the matrix variable. To change properties for the Paint object such as: strokeWidth, strokeColor, fillColor, opacity when the path is being drawn to the canvas use the renderProperties variable.

// create SvgPath object using raw path data as string
val svgPath = SvgPath("M 10 80 Q 52.5 10, 95 80 T 180 80")

// change stroke color and width for the path
svgPath.renderProperties.apply { 
     strokeWidth = 5.0f
     strokeColor = Color.GREEN
}
        
// apply transformation to the path using its matrix
svgPath.matrix.apply {
     postRotate(45.0f)
     postSkew(0.5f, 0.0f)
}

To check the available example on creating SvgPath and SvgPathGroup check the classes in the views package.