Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
svg-path-parser.h
Go to the documentation of this file.
1
33#ifndef LIB2GEOM_SEEN_SVG_PATH_PARSER_H
34#define LIB2GEOM_SEEN_SVG_PATH_PARSER_H
35
36#include <iostream>
37#include <iterator>
38#include <stdexcept>
39#include <vector>
40#include <cstdio>
41#include <2geom/exception.h>
42#include <2geom/point.h>
43#include <2geom/path-sink.h>
44#include <2geom/forward.h>
45
46namespace Geom {
47
63public:
66
71 void reset();
72
79 void parse(char const *str, int len = -1);
81 void parse(std::string const &s);
82
90 void feed(char const *str, int len = -1);
92 void feed(std::string const &s);
93
98 void finish();
99
108 void setZSnapThreshold(Coord threshold) { _z_snap_threshold = threshold; }
110
111private:
118 std::vector<Coord> _params;
122
123 int cs;
124 std::string _number_part;
125
126 void _push(Coord value);
127 Coord _pop();
128 bool _pop_flag();
131 void _moveTo(Point const &p);
132 void _lineTo(Point const &p);
133 void _curveTo(Point const &c0, Point const &c1, Point const &p);
134 void _quadTo(Point const &c, Point const &p);
135 void _arcTo(double rx, double ry, double angle,
136 bool large_arc, bool sweep, Point const &p);
137 void _closePath();
138 void _pushCurve(Curve *c);
139
140 void _parse(char const *str, char const *strend, bool finish);
141};
142
145void parse_svg_path(char const *str, PathSink &sink);
148inline void parse_svg_path(std::string const &str, PathSink &sink) {
149 parse_svg_path(str.c_str(), sink);
150}
153void parse_svg_path_file(FILE *fi, PathSink &sink);
154
157inline PathVector parse_svg_path(char const *str) {
158 PathVector ret;
159 SubpathInserter iter(ret);
160 PathIteratorSink<SubpathInserter> generator(iter);
161
162 parse_svg_path(str, generator);
163 return ret;
164}
165
168inline PathVector read_svgd_f(FILE * fi) {
169 PathVector ret;
170 SubpathInserter iter(ret);
171 PathIteratorSink<SubpathInserter> generator(iter);
172
173 parse_svg_path_file(fi, generator);
174 return ret;
175}
176
179inline PathVector read_svgd(char const *filename) {
180 FILE* fi = fopen(filename, "r");
181 if(fi == NULL) throw(std::runtime_error("Error opening file"));
182 PathVector out = read_svgd_f(fi);
183 fclose(fi);
184 return out;
185}
186
187} // end namespace Geom
188
189#endif
190/*
191 Local Variables:
192 mode:c++
193 c-file-style:"stroustrup"
194 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
195 indent-tabs-mode:nil
196 fill-column:99
197 End:
198*/
199// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Defines the different types of exceptions that 2geom can throw.
Cartesian point / 2D vector and related operations.
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
Store paths to an output iterator.
Definition path-sink.h:116
Callback interface for processing path data.
Definition path-sink.h:56
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
Read SVG path data and feed it to a PathSink.
void finish()
Finalize parsing.
void setZSnapThreshold(Coord threshold)
Set the threshold for considering the closing segment degenerate.
Coord _pop_coord(Geom::Dim2 axis)
void _parse(char const *str, char const *strend, bool finish)
void feed(char const *str, int len=-1)
Parse a part of path data stored in a C-style string.
std::vector< Coord > _params
void _quadTo(Point const &c, Point const &p)
Coord zSnapThreshold() const
void parse(char const *str, int len=-1)
Parse a C-style string.
void _curveTo(Point const &c0, Point const &c1, Point const &p)
void _moveTo(Point const &p)
void _lineTo(Point const &p)
void _arcTo(double rx, double ry, double angle, bool large_arc, bool sweep, Point const &p)
void _push(Coord value)
void reset()
Reset internal state.
double c[8][4]
Contains forward declarations of 2geom types.
void parse_svg_path(char const *str, PathSink &sink)
Feed SVG path data to the specified sink.
PathVector read_svgd_f(FILE *fi)
Create path vector from a C stream with SVG path data.
PathVector read_svgd(char const *filename)
Create path vector from SVG path data stored in a file.
void parse_svg_path_file(FILE *fi, PathSink &sink)
Feed SVG path data from a C stream to the specified sink.
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
Various utility functions.
Definition affine.h:22
std::back_insert_iterator< PathVector > SubpathInserter
Definition path-sink.h:222
callback interface for SVG path data
auto len
Definition safe-printf.h:21