1 /*
2 * Copyright (C) 2007-2009 Torch Mobile, Inc.
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 License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "Path.h"
22
23 #include "AffineTransform.h"
24 #include "FloatRect.h"
25 #include "NotImplemented.h"
26 #include "PlatformPathWinCE.h"
27 #include "PlatformString.h"
28 #include <wtf/OwnPtr.h>
29
30 namespace WebCore {
31
Path()32 Path::Path()
33 : m_path(new PlatformPath())
34 {
35 }
36
Path(const Path & other)37 Path::Path(const Path& other)
38 : m_path(new PlatformPath(*other.m_path))
39 {
40 }
41
~Path()42 Path::~Path()
43 {
44 delete m_path;
45 }
46
operator =(const Path & other)47 Path& Path::operator=(const Path& other)
48 {
49 if (&other != this) {
50 delete m_path;
51 m_path = new PlatformPath(*other.m_path);
52 }
53 return *this;
54 }
55
contains(const FloatPoint & point,WindRule rule) const56 bool Path::contains(const FloatPoint& point, WindRule rule) const
57 {
58 return m_path->contains(point, rule);
59 }
60
translate(const FloatSize & size)61 void Path::translate(const FloatSize& size)
62 {
63 m_path->translate(size);
64 }
65
boundingRect() const66 FloatRect Path::boundingRect() const
67 {
68 return m_path->boundingRect();
69 }
70
moveTo(const FloatPoint & point)71 void Path::moveTo(const FloatPoint& point)
72 {
73 m_path->moveTo(point);
74 }
75
addLineTo(const FloatPoint & point)76 void Path::addLineTo(const FloatPoint& point)
77 {
78 m_path->addLineTo(point);
79 }
80
addQuadCurveTo(const FloatPoint & cp,const FloatPoint & p)81 void Path::addQuadCurveTo(const FloatPoint& cp, const FloatPoint& p)
82 {
83 m_path->addQuadCurveTo(cp, p);
84 }
85
addBezierCurveTo(const FloatPoint & cp1,const FloatPoint & cp2,const FloatPoint & p)86 void Path::addBezierCurveTo(const FloatPoint& cp1, const FloatPoint& cp2, const FloatPoint& p)
87 {
88 m_path->addBezierCurveTo(cp1, cp2, p);
89 }
90
addArcTo(const FloatPoint & p1,const FloatPoint & p2,float radius)91 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
92 {
93 m_path->addArcTo(p1, p2, radius);
94 }
95
closeSubpath()96 void Path::closeSubpath()
97 {
98 m_path->closeSubpath();
99 }
100
addArc(const FloatPoint & p,float r,float sar,float ear,bool anticlockwise)101 void Path::addArc(const FloatPoint& p, float r, float sar, float ear, bool anticlockwise)
102 {
103 m_path->addEllipse(p, r, r, sar, ear, anticlockwise);
104 }
105
addRect(const FloatRect & r)106 void Path::addRect(const FloatRect& r)
107 {
108 m_path->addRect(r);
109 }
110
addEllipse(const FloatRect & r)111 void Path::addEllipse(const FloatRect& r)
112 {
113 m_path->addEllipse(r);
114 }
115
clear()116 void Path::clear()
117 {
118 m_path->clear();
119 }
120
isEmpty() const121 bool Path::isEmpty() const
122 {
123 return m_path->isEmpty();
124 }
125
apply(void * info,PathApplierFunction function) const126 void Path::apply(void* info, PathApplierFunction function) const
127 {
128 m_path->apply(info, function);
129 }
130
transform(const AffineTransform & t)131 void Path::transform(const AffineTransform& t)
132 {
133 m_path->transform(t);
134 }
135
strokeBoundingRect(StrokeStyleApplier *) const136 FloatRect Path::strokeBoundingRect(StrokeStyleApplier*) const
137 {
138 notImplemented();
139 return FloatRect();
140 }
141
strokeContains(StrokeStyleApplier *,const FloatPoint &) const142 bool Path::strokeContains(StrokeStyleApplier*, const FloatPoint&) const
143 {
144 notImplemented();
145 return false;
146 }
147
hasCurrentPoint() const148 bool Path::hasCurrentPoint() const
149 {
150 // Not sure if this is correct. At the meantime, we do what other ports
151 // do.
152 // See https://bugs.webkit.org/show_bug.cgi?id=27266,
153 // https://bugs.webkit.org/show_bug.cgi?id=27187, and
154 // http://trac.webkit.org/changeset/45873
155 return !isEmpty();
156 }
157
currentPoint() const158 FloatPoint Path::currentPoint() const
159 {
160 return m_path->lastPoint();
161 }
162
163 } // namespace WebCore
164