Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
path-sink.cpp
Go to the documentation of this file.
1/*
2 * callback interface for SVG path data
3 *
4 * Copyright 2007 MenTaLguY <mental@rydia.net>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it either under the terms of the GNU Lesser General Public
8 * License version 2.1 as published by the Free Software Foundation
9 * (the "LGPL") or, at your option, under the terms of the Mozilla
10 * Public License Version 1.1 (the "MPL"). If you do not alter this
11 * notice, a recipient may use your version of this file under either
12 * the MPL or the LGPL.
13 *
14 * You should have received a copy of the LGPL along with this library
15 * in the file COPYING-LGPL-2.1; if not, output to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * You should have received a copy of the MPL along with this library
18 * in the file COPYING-MPL-1.1
19 *
20 * The contents of this file are subject to the Mozilla Public License
21 * Version 1.1 (the "License"); you may not use this file except in
22 * compliance with the License. You may obtain a copy of the License at
23 * http://www.mozilla.org/MPL/
24 *
25 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27 * the specific language governing rights and limitations.
28 *
29 */
30
32#include <2geom/path-sink.h>
33#include <2geom/exception.h>
34#include <2geom/circle.h>
35#include <2geom/ellipse.h>
36
37namespace Geom {
38
39void PathSink::feed(Curve const &c, bool moveto_initial)
40{
41 c.feed(*this, moveto_initial);
42}
43
44void PathSink::feed(Path const &path) {
45 flush();
46 moveTo(path.front().initialPoint());
47
48 // never output the closing segment to the sink
49 Path::const_iterator iter = path.begin(), last = path.end_open();
50 for (; iter != last; ++iter) {
51 iter->feed(*this, false);
52 }
53 if (path.closed()) {
54 closePath();
55 }
56 flush();
57}
58
59void PathSink::feed(PathVector const &pv) {
60 for (const auto & i : pv) {
61 feed(i);
62 }
63}
64
65void PathSink::feed(Rect const &r) {
66 moveTo(r.corner(0));
67 lineTo(r.corner(1));
68 lineTo(r.corner(2));
69 lineTo(r.corner(3));
70 closePath();
71}
72
73void PathSink::feed(Circle const &e) {
74 Coord r = e.radius();
75 Point c = e.center();
76 Point a = c + Point(0, +r);
77 Point b = c + Point(0, -r);
78
79 moveTo(a);
80 arcTo(r, r, 0, false, false, b);
81 arcTo(r, r, 0, false, false, a);
82 closePath();
83}
84
85void PathSink::feed(Ellipse const &e) {
86 Point s = e.pointAt(0);
87 moveTo(s);
88 arcTo(e.ray(X), e.ray(Y), e.rotationAngle(), false, false, e.pointAt(M_PI));
89 arcTo(e.ray(X), e.ray(Y), e.rotationAngle(), false, false, s);
90 closePath();
91}
92
93}
94
95/*
96 Local Variables:
97 mode:c++
98 c-file-style:"stroustrup"
99 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
100 indent-tabs-mode:nil
101 fill-column:99
102 End:
103*/
104// 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.
Circle shape.
Set of all points at a fixed distance from the center.
Definition circle.h:55
Point center() const
Definition circle.h:75
Coord radius() const
Definition circle.h:77
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
virtual Point initialPoint() const =0
Retrieve the start of the curve.
Set of points with a constant sum of distances from two foci.
Definition ellipse.h:68
Angle rotationAngle() const
Get the angle the X ray makes with the +X axis.
Definition ellipse.h:126
Point pointAt(Coord t) const
Evaluate a point on the ellipse.
Definition ellipse.cpp:358
Coord ray(Dim2 d) const
Get one ray of the ellipse.
Definition ellipse.h:124
CPoint corner(unsigned i) const
Return the n-th corner of the rectangle.
virtual void arcTo(Coord rx, Coord ry, Coord angle, bool large_arc, bool sweep, Point const &p)=0
Output an elliptical arc segment.
virtual void flush()=0
Flush any internal state of the generator.
virtual void lineTo(Point const &p)=0
Output a line segment.
virtual void feed(Curve const &c, bool moveto_initial=true)
Definition path-sink.cpp:39
virtual void closePath()=0
Close the current path with a line segment.
virtual void moveTo(Point const &p)=0
Move to a different point without creating a segment.
Sequence of subpaths.
Definition pathvector.h:122
Sequence of contiguous curves, aka spline.
Definition path.h:353
bool closed() const
Check whether the path is closed.
Definition path.h:503
const_iterator end_open() const
Definition path.h:467
Curve const & front() const
Access the first curve in the path.
Definition path.h:443
const_iterator begin() const
Definition path.h:464
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
double c[8][4]
Ellipse shape.
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
Various utility functions.
Definition affine.h:22
callback interface for SVG path data
Conversion between SBasis and Bezier basis polynomials.