# PathParser

# PathParser

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/graphics/PathParser.java+class:androidx.core.graphics.PathParser)  
Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/graphics/PathParser "View this page in Java")

<br />

```
class PathParser
```

<br />

*** ** * ** ***

Parses SVG path strings.

## Summary

|                                                                                                ### Nested types                                                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode) Each PathDataNode represents one command in the "d" attribute of the svg file. |

|                                                                                                     ### Public functions                                                                                                     |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                            | [canMorph](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#canMorph(androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[]))`(` ` nodesFrom: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>?,` ` nodesTo: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>?` `)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `java-static `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | [createNodesFromPathData](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#createNodesFromPathData(java.lang.String))`(pathData: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `java-static `[Path](https://developer.android.com/reference/android/graphics/Path.html)                                                                                                                                     | [createPathFromPathData](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#createPathFromPathData(java.lang.String))`(pathData: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Takes a string representation of an SVG path and converts it to a[Path](https://developer.android.com/reference/android/graphics/Path.html).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `java-static `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | [deepCopyNodes](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#deepCopyNodes(androidx.core.graphics.PathParser.PathDataNode[]))`(source: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                  | [interpolatePathDataNodes](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#interpolatePathDataNodes(androidx.core.graphics.PathParser.PathDataNode[],float,androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[]))`(` ` target: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>,` ` fraction: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`,` ` from: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>,` ` to: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` `)` Interpolate between two arrays of PathDataNodes with the given fraction, and store the results in the first parameter. |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                  | [nodesToPath](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#nodesToPath(androidx.core.graphics.PathParser.PathDataNode[],android.graphics.Path))`(node: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>, path: `[Path](https://developer.android.com/reference/android/graphics/Path.html)`)` Convert an array of PathDataNode to Path.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                  | [updateNodes](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#updateNodes(androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[]))`(` ` target: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>,` ` source: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` `)` Update the target's data to match the source.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

## Public functions

### canMorph

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun canMorph(
    nodesFrom: Array<PathParser.PathDataNode!>?,
    nodesTo: Array<PathParser.PathDataNode!>?
): Boolean
```  

|                                                                                                          Parameters                                                                                                          |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `nodesFrom: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>?` | The source path represented in an array of PathDataNode |
| `nodesTo: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>?`   | The target path represented in an array of PathDataNode |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | whether the`nodesFrom`can morph into`nodesTo` |

### createNodesFromPathData

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun createNodesFromPathData(pathData: String): Array<PathParser.PathDataNode!>
```  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| `pathData: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The string representing a path, the same as "d" string in svg file. |

|                                                                                                    Returns                                                                                                     |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | an array of the PathDataNode. |

### createPathFromPathData

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun createPathFromPathData(pathData: String): Path
```

Takes a string representation of an SVG path and converts it to a[Path](https://developer.android.com/reference/android/graphics/Path.html).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| `pathData: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The string representing a path, the same as "d" string in svg file. |

|                                  Returns                                   |
|----------------------------------------------------------------------------|----------------------------|
| [Path](https://developer.android.com/reference/android/graphics/Path.html) | the generated Path object. |

### deepCopyNodes

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun deepCopyNodes(source: Array<PathParser.PathDataNode!>): Array<PathParser.PathDataNode!>
```  

|                                                                                                        Parameters                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| `source: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | The array of PathDataNode to be duplicated. |

|                                                                                                    Returns                                                                                                     |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | a deep copy of the`source`. |

### interpolatePathDataNodes

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun interpolatePathDataNodes(
    target: Array<PathParser.PathDataNode!>,
    fraction: Float,
    from: Array<PathParser.PathDataNode!>,
    to: Array<PathParser.PathDataNode!>
): Unit
```

Interpolate between two arrays of PathDataNodes with the given fraction, and store the results in the first parameter.  

|                                                                                                        Parameters                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `target: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | The resulting array of[PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)for the interpolation |
| `fraction: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                                                                                                              | A float fraction value in the range of 0 to 1                                                                                                            |
| `from: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>`   | The array of[PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)when fraction is 0              |
| `to: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>`     | The array of[PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)when the fraction is 1          |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | When the arrays of nodes are incompatible for interpolation. |

|                                                                                                 See also                                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [canMorph](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser#canMorph(androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[])) |   |

### nodesToPath

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun nodesToPath(node: Array<PathParser.PathDataNode!>, path: Path): Unit
```

Convert an array of PathDataNode to Path.  

|                                                                                                       Parameters                                                                                                       |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|
| `node: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | The source array of PathDataNode. |
| `path: `[Path](https://developer.android.com/reference/android/graphics/Path.html)                                                                                                                                     | The target Path object.           |

### updateNodes

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
java-static fun updateNodes(
    target: Array<PathParser.PathDataNode!>,
    source: Array<PathParser.PathDataNode!>
): Unit
```

Update the target's data to match the source. Before calling this, make sure canMorph(target, source) is true.  

|                                                                                                        Parameters                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `target: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | The target path represented in an array of PathDataNode |
| `source: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[PathParser.PathDataNode](https://developer.android.com/reference/kotlin/androidx/core/graphics/PathParser.PathDataNode)`!>` | The source path represented in an array of PathDataNode |