1 /* libwpg
2 * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02111-1301 USA
18 *
19 * For further information visit http://libwpg.sourceforge.net
20 */
22 /* "This product is not manufactured, approved, or supported by
23 * Corel Corporation or Corel Corporation Limited."
24 */
26 #include "WPGPath.h"
27 #include "WPGPoint.h"
29 #include <vector>
31 namespace libwpg
32 {
34 class WPGPathPrivate
35 {
36 public:
37 std::vector<WPGPathElement> elements;
38 };
40 } // namespace libwpg
42 using namespace libwpg;
44 WPGPath::WPGPath()
45 {
46 d = new WPGPathPrivate;
47 closed = true;
48 }
50 WPGPath::~WPGPath()
51 {
52 delete d;
53 }
55 WPGPath::WPGPath(const WPGPath& path)
56 {
57 d = new WPGPathPrivate;
58 d->elements = path.d->elements;
59 }
61 WPGPath& WPGPath::operator=(const WPGPath& path)
62 {
63 d->elements = path.d->elements;
64 return *this;
65 }
67 unsigned WPGPath::count() const
68 {
69 return d->elements.size();
70 }
72 WPGPathElement WPGPath::element(unsigned index) const
73 {
74 return d->elements[index];
75 }
77 void WPGPath::moveTo(const WPGPoint& point)
78 {
79 WPGPathElement element;
80 element.type = WPGPathElement::MoveToElement;
81 element.point = point;
82 addElement(element);
83 }
85 void WPGPath::lineTo(const WPGPoint& point)
86 {
87 WPGPathElement element;
88 element.type = WPGPathElement::LineToElement;
89 element.point = point;
90 addElement(element);
91 }
93 void WPGPath::curveTo(const WPGPoint& c1, const WPGPoint& c2, const WPGPoint& endPoint)
94 {
95 WPGPathElement element;
96 element.type = WPGPathElement::CurveToElement;
97 element.point = endPoint;
98 element.extra1 = c1;
99 element.extra2 = c2;
100 addElement(element);
101 }
103 void WPGPath::addElement(const WPGPathElement& element)
104 {
105 d->elements.push_back(element);
106 }
108 void WPGPath::append(const WPGPath& path)
109 {
110 for(unsigned i = 0; i < path.count(); i++)
111 addElement(path.element(i));
112 }