Inkscape
Vector Graphics Editor
|
Serialize paths to SVG path data strings. More...
#include <svg-path-writer.h>
Public Member Functions | |
SVGPathWriter () | |
~SVGPathWriter () override | |
void | moveTo (Point const &p) override |
Move to a different point without creating a segment. | |
void | lineTo (Point const &p) override |
Output a line segment. | |
void | quadTo (Point const &c, Point const &p) override |
Output a cubic Bezier segment. | |
void | curveTo (Point const &c0, Point const &c1, Point const &p) override |
Output a quadratic Bezier segment. | |
void | arcTo (double rx, double ry, double angle, bool large_arc, bool sweep, Point const &p) override |
Output an elliptical arc segment. | |
void | closePath () override |
Close the current path with a line segment. | |
void | flush () override |
Flush any internal state of the generator. | |
void | clear () |
Clear any path data written so far. | |
void | setPrecision (int prec) |
Set output precision. | |
void | setOptimize (bool opt) |
Enable or disable length optimization. | |
void | setUseShorthands (bool use) |
Enable or disable the use of V, H, T and S commands where possible. | |
std::string | str () const |
Retrieve the generated path data string. | |
![]() | |
virtual bool | backspace () |
Undo the last segment. | |
virtual void | feed (Curve const &c, bool moveto_initial=true) |
virtual void | feed (Path const &p) |
Output a subpath. | |
virtual void | feed (PathVector const &v) |
Output a path. | |
virtual void | feed (Rect const &) |
Output an axis-aligned rectangle, using moveTo, lineTo and closePath. | |
virtual void | feed (Circle const &e) |
Output a circle as two elliptical arcs. | |
virtual void | feed (Ellipse const &e) |
Output an ellipse as two elliptical arcs. | |
virtual | ~PathSink () |
Private Member Functions | |
void | _setCommand (char cmd) |
std::string | _formatCoord (Coord par) |
Private Attributes | |
std::ostringstream | _s |
std::ostringstream | _ns |
std::vector< Coord > | _current_pars |
Point | _subpath_start |
Point | _current |
Point | _quad_tangent |
Point | _cubic_tangent |
Coord | _epsilon |
int | _precision |
bool | _optimize |
bool | _use_shorthands |
char | _command |
Serialize paths to SVG path data strings.
You can access the generated string by calling the str() method.
Definition at line 45 of file svg-path-writer.h.
Geom::SVGPathWriter::SVGPathWriter | ( | ) |
Definition at line 45 of file svg-path-writer.cpp.
References _ns.
|
inlineoverride |
Definition at line 50 of file svg-path-writer.h.
|
private |
Definition at line 259 of file svg-path-writer.cpp.
References _ns, _precision, and Geom::format_coord_shortest().
Referenced by flush().
|
private |
|
overridevirtual |
Output an elliptical arc segment.
See the EllipticalArc class for the documentation of parameters.
Implements Geom::PathSink.
Definition at line 147 of file svg-path-writer.cpp.
References _cubic_tangent, _current, _current_pars, _optimize, _quad_tangent, _setCommand(), flush(), Geom::X, and Geom::Y.
void Geom::SVGPathWriter::clear | ( | ) |
Clear any path data written so far.
Definition at line 228 of file svg-path-writer.cpp.
References _command, _current, _current_pars, _ns, _s, and _subpath_start.
Referenced by TEST_F().
|
overridevirtual |
Close the current path with a line segment.
Implements Geom::PathSink.
Definition at line 165 of file svg-path-writer.cpp.
References _cubic_tangent, _current, _optimize, _quad_tangent, _s, _subpath_start, and flush().
|
overridevirtual |
Output a quadratic Bezier segment.
Implements Geom::PathSink.
Definition at line 126 of file svg-path-writer.cpp.
References _cubic_tangent, _current, _current_pars, _epsilon, _optimize, _quad_tangent, _setCommand(), _use_shorthands, Geom::are_near(), flush(), Geom::X, and Geom::Y.
|
overridevirtual |
Flush any internal state of the generator.
This call should implicitly finish the current subpath. Calling this method should be idempotent, because the default implementations of path() and pathvector() will call it multiple times in a row.
Implements Geom::PathSink.
Definition at line 176 of file svg-path-writer.cpp.
References _command, _current_pars, _formatCoord(), _optimize, _s, and Geom::is_digit().
Referenced by _setCommand(), arcTo(), closePath(), curveTo(), lineTo(), moveTo(), and quadTo().
|
overridevirtual |
Output a line segment.
Implements Geom::PathSink.
Definition at line 69 of file svg-path-writer.cpp.
References _command, _cubic_tangent, _current, _current_pars, _epsilon, _optimize, _quad_tangent, _setCommand(), _use_shorthands, Geom::are_near(), flush(), Geom::X, and Geom::Y.
|
overridevirtual |
Move to a different point without creating a segment.
Usually starts a new subpath.
Implements Geom::PathSink.
Definition at line 57 of file svg-path-writer.cpp.
References _cubic_tangent, _current, _current_pars, _optimize, _quad_tangent, _setCommand(), _subpath_start, flush(), Geom::X, and Geom::Y.
Output a cubic Bezier segment.
Implements Geom::PathSink.
Definition at line 107 of file svg-path-writer.cpp.
References _cubic_tangent, _current, _current_pars, _epsilon, _optimize, _quad_tangent, _setCommand(), _use_shorthands, Geom::are_near(), c, flush(), Geom::X, and Geom::Y.
|
inline |
Enable or disable length optimization.
When set to true, the path writer will optimize the generated path data for minimum length. However, this will make the data less readable, because spaces between commands and coordinates will be omitted where unnecessary for correct parsing.
When set to false, the string will be a straightforward, partially redundant representation of the passed commands, optimized for readability. Commands and coordinates will always be separated by spaces and the command symbol will not be omitted for multiple consecutive commands of the same type.
Length optimization is turned off by default.
Definition at line 82 of file svg-path-writer.h.
References _optimize.
Referenced by TEST_F(), and Geom::write_svg_path().
void Geom::SVGPathWriter::setPrecision | ( | int | prec | ) |
Set output precision.
When the parameter is negative, the path writer enters a verbatim mode which preserves all values exactly.
Definition at line 240 of file svg-path-writer.cpp.
References _epsilon, _ns, and _precision.
Referenced by Geom::write_svg_path().
|
inline |
Enable or disable the use of V, H, T and S commands where possible.
Shorthands are turned on by default.
Definition at line 86 of file svg-path-writer.h.
References _use_shorthands.
Referenced by TEST_F(), and Geom::write_svg_path().
|
inline |
Retrieve the generated path data string.
Definition at line 89 of file svg-path-writer.h.
References _s.
Referenced by Geom::operator<<(), Geom::operator<<(), TEST_F(), and Geom::write_svg_path().
|
private |
Definition at line 105 of file svg-path-writer.h.
Referenced by _setCommand(), clear(), flush(), and lineTo().
|
private |
Definition at line 100 of file svg-path-writer.h.
Referenced by arcTo(), closePath(), curveTo(), lineTo(), moveTo(), and quadTo().
|
private |
Definition at line 98 of file svg-path-writer.h.
Referenced by arcTo(), clear(), closePath(), curveTo(), lineTo(), moveTo(), and quadTo().
|
private |
|
private |
Definition at line 101 of file svg-path-writer.h.
Referenced by curveTo(), lineTo(), quadTo(), and setPrecision().
|
private |
Definition at line 95 of file svg-path-writer.h.
Referenced by _formatCoord(), clear(), setPrecision(), and SVGPathWriter().
|
private |
Definition at line 103 of file svg-path-writer.h.
Referenced by arcTo(), closePath(), curveTo(), flush(), lineTo(), moveTo(), quadTo(), and setOptimize().
|
private |
Definition at line 102 of file svg-path-writer.h.
Referenced by _formatCoord(), and setPrecision().
|
private |
Definition at line 99 of file svg-path-writer.h.
Referenced by arcTo(), closePath(), curveTo(), lineTo(), moveTo(), and quadTo().
|
private |
Definition at line 95 of file svg-path-writer.h.
Referenced by clear(), closePath(), flush(), and str().
|
private |
Definition at line 97 of file svg-path-writer.h.
Referenced by clear(), closePath(), and moveTo().
|
private |
Definition at line 104 of file svg-path-writer.h.
Referenced by curveTo(), lineTo(), quadTo(), and setUseShorthands().