1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00
Files
svgo/docs/03-plugins/convert-path-data.mdx
2023-11-07 23:43:09 +00:00

78 lines
2.7 KiB
Plaintext

---
title: Convert Path Commands
svgo:
pluginId: convertPathData
defaultPlugin: true
parameters:
applyTransforms:
description: If to apply transforms.
default: true
applyTransformsStroked:
description: If to apply transforms to paths with a stroke.
default: true
makeArcs:
description: If to convert from curves to arcs when possible. This is an object with two properties, <code>threshold</code> and <code>tolerance</code>.
straightCurves:
description: If to convert curve commands that are effectively straight lines to line commands.
default: true
lineShorthands:
description: If to convert regular lines to an explicit horizontal or vertical line where possible.
default: true
curveSmoothShorthands:
description: If to convert curves to smooth curves where possible.
default: true
floatPrecision:
description: Number of decimal places to round to, using conventional rounding rules.
default: 3
transformPrecision:
description: Number of decimal places to round to, using conventional rounding rules.
default: 5
removeUseless:
description: Remove redundant path commands that don't draw anything.
default: true
collapseRepeated:
description: Collapse repeated commands when they can be merged into one.
default: true
utilizeAbsolute:
description: If to convert between absolute or relative coordinates, whichever is shortest.
default: true
negativeExtraSpace:
default: true
forceAbsolutePath:
description: If to always convert to absolute coordinates, even if it adds more bytes.
default: false
---
Optimize path commands found in `<path>`, `<glyph>`, and `<missing-glyph>` elements. Path commands are the syntax used in the `d` attribute, each character represents an instruction to draw paths.
:::info
You can get more context on path commands on [MDN Web Docs](https://developer.mozilla.org/docs/Web/SVG/Attribute/d#path_commands).
:::
This plugin uses multiple techniques to either reduce the number of instructions or reduce the attribute length:
* Convert between relative or absolute coordinates, whichever is shortest.
* Convert between commands. For example, a bézier curve that behaves like a straight line might as well use a line instruction.
* Trim redundant delimiters and leading zeros.
* Round numeric values using conventional rounding rules.
You can read more about the plugins capabilities by going through the individual parameters.
## Usage
<PluginUsage/>
### Parameters
<PluginParams/>
## Demo
<PluginDemo/>
## Implementation
* https://github.com/svg/svgo/blob/main/plugins/convertPathData.js