2 * Copyright (C) 2007 Kevin Ollivier All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "AffineTransform.h"
30 #include "FloatPoint.h"
31 #include "FloatRect.h"
32 #include "NotImplemented.h"
33 #include "PlatformString.h"
34 #include "StrokeStyleApplier.h"
39 #include <wx/graphics.h>
43 int getWxWindRuleForWindRule(WindRule rule)
45 if (rule == RULE_EVENODD)
46 return wxODDEVEN_RULE;
48 return wxWINDING_RULE;
54 // NB: This only supports the 'default' renderer as determined by wx on
55 // each platform. If an app uses a non-default renderer (e.g. Cairo on Win),
56 // there will be problems, but there's no way we can determine which
57 // renderer an app is using right now with wx API, so we will just handle
60 wxGraphicsRenderer* renderer = 0;
62 renderer = wxGraphicsRenderer::GetCairoRenderer();
64 renderer = wxGraphicsRenderer::GetDefaultRenderer();
67 wxGraphicsPath path = renderer->CreatePath();
68 m_path = new wxGraphicsPath(path);
78 Path::Path(const Path& path)
80 m_path = new wxGraphicsPath(*path.m_path);
83 bool Path::contains(const FloatPoint& point, const WindRule rule) const
87 #if wxCHECK_VERSION(2,9,0)
88 return m_path->Contains(point.x(), point.y(), static_cast<wxPolygonFillMode>(getWxWindRuleForWindRule(rule)));
90 return m_path->Contains(point.x(), point.y(), getWxWindRuleForWindRule(rule));
97 void Path::translate(const FloatSize&)
102 FloatRect Path::boundingRect() const
106 return m_path->GetBox();
113 FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const
119 bool Path::strokeContains(StrokeStyleApplier*, const FloatPoint&) const
125 Path& Path::operator=(const Path& path)
127 *m_path = *path.platformPath();
138 wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetCairoRenderer();
140 wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetDefaultRenderer();
143 wxGraphicsPath path = renderer->CreatePath();
144 m_path = new wxGraphicsPath(path);
149 void Path::moveTo(const FloatPoint& point)
153 m_path->MoveToPoint(point.x(), point.y());
157 void Path::addLineTo(const FloatPoint& point)
161 m_path->AddLineToPoint(point.x(), point.y());
165 void Path::addQuadCurveTo(const FloatPoint& control, const FloatPoint& end)
169 m_path->AddQuadCurveToPoint(control.x(), control.y(), end.x(), end.y());
173 void Path::addBezierCurveTo(const FloatPoint& control1, const FloatPoint& control2, const FloatPoint& end)
177 m_path->AddCurveToPoint(control1.x(), control1.y(), control2.x(), control2.y(), end.x(), end.y());
181 void Path::addArcTo(const FloatPoint& point1, const FloatPoint& point2, float radius)
185 m_path->AddArcToPoint(point1.x(), point1.y(), point2.x(), point2.y(), radius);
189 void Path::closeSubpath()
193 m_path->CloseSubpath();
197 void Path::addArc(const FloatPoint& point, float radius, float startAngle, float endAngle, bool clockwise)
201 m_path->AddArc(point.x(), point.y(), radius, startAngle, endAngle, clockwise);
205 void Path::addRect(const FloatRect& rect)
209 m_path->AddRectangle(rect.x(), rect.y(), rect.width(), rect.height());
213 void Path::addEllipse(const FloatRect& rect)
217 m_path->AddEllipse(rect.x(), rect.y(), rect.width(), rect.height());
221 void Path::transform(const AffineTransform& transform)
225 m_path->Transform(transform);
229 void Path::apply(void* info, PathApplierFunction function) const
234 bool Path::isEmpty() const
238 wxDouble x, y, width, height;
239 m_path->GetBox(&x, &y, &width, &height);
240 return (width == 0 && height == 0);
246 bool Path::hasCurrentPoint() const
251 FloatPoint Path::currentPoint() const
253 // FIXME: return current point of subpath.
254 float quietNaN = std::numeric_limits<float>::quiet_NaN();
255 return FloatPoint(quietNaN, quietNaN);