# 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)

*** ** * ** ***


```
public final class PathParser
```

<br />

*** ** * ** ***

Parses SVG path strings.

## Summary

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

| ### Public methods |
|---|---|
| `static boolean` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#canMorph(androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html PathParser.PathDataNode[] nodesFrom, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html PathParser.PathDataNode[] nodesTo )` |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[]` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#createNodesFromPathData(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html pathData)` |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Path.html` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#createPathFromPathData(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html pathData)` Takes a string representation of an SVG path and converts it to a `https://developer.android.com/reference/android/graphics/Path.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[]` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#deepCopyNodes(androidx.core.graphics.PathParser.PathDataNode[])(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] source)` |
| `static void` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#interpolatePathDataNodes(androidx.core.graphics.PathParser.PathDataNode[],float,androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] target, float fraction, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] from, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] to )` Interpolate between two arrays of PathDataNodes with the given fraction, and store the results in the first parameter. |
| `static void` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#nodesToPath(androidx.core.graphics.PathParser.PathDataNode[],android.graphics.Path)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] node, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Path.html path)` Convert an array of PathDataNode to Path. |
| `static void` | `https://developer.android.com/reference/androidx/core/graphics/PathParser#updateNodes(androidx.core.graphics.PathParser.PathDataNode[],androidx.core.graphics.PathParser.PathDataNode[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] target, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] source )` Update the target's data to match the source. |

## Public methods

### canMorph

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

```
public static boolean canMorph(
    @Nullable PathParser.PathDataNode[] nodesFrom,
    @Nullable PathParser.PathDataNode[] nodesTo
)
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html PathParser.PathDataNode[] nodesFrom` | The source path represented in an array of PathDataNode |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html PathParser.PathDataNode[] nodesTo` | The target path represented in an array of PathDataNode |

| Returns |
|---|---|
| `boolean` | whether the `nodesFrom` can morph into `nodesTo` |

### createNodesFromPathData

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

```
public static @NonNull PathParser.PathDataNode[] createNodesFromPathData(@NonNull String pathData)
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html pathData` | The string representing a path, the same as "d" string in svg file. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[]` | an array of the PathDataNode. |

### createPathFromPathData

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

```
public static @NonNull Path createPathFromPathData(@NonNull String pathData)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html pathData` | The string representing a path, the same as "d" string in svg file. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html 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)

```
public static @NonNull PathParser.PathDataNode[] deepCopyNodes(@NonNull PathParser.PathDataNode[] source)
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] source` | The array of PathDataNode to be duplicated. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html 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)

```
public static void interpolatePathDataNodes(
    @NonNull PathParser.PathDataNode[] target,
    float fraction,
    @NonNull PathParser.PathDataNode[] from,
    @NonNull PathParser.PathDataNode[] to
)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] target` | The resulting array of `https://developer.android.com/reference/androidx/core/graphics/PathParser.PathDataNode` for the interpolation |
| `float fraction` | A float fraction value in the range of 0 to 1 |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] from` | The array of `https://developer.android.com/reference/androidx/core/graphics/PathParser.PathDataNode` when fraction is 0 |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] to` | The array of `https://developer.android.com/reference/androidx/core/graphics/PathParser.PathDataNode` when the fraction is 1 |

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

| See also |
|---|---|
| `https://developer.android.com/reference/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)

```
public static void nodesToPath(@NonNull PathParser.PathDataNode[] node, @NonNull Path path)
```

Convert an array of PathDataNode to Path.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] node` | The source array of PathDataNode. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Path.html path` | The target Path object. |

### updateNodes

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

```
public static void updateNodes(
    @NonNull PathParser.PathDataNode[] target,
    @NonNull PathParser.PathDataNode[] source
)
```

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] target` | The target path represented in an array of PathDataNode |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PathParser.PathDataNode[] source` | The source path represented in an array of PathDataNode |