• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
3  *               2006 Rob Buis <buis@kde.org>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef Path_h
28 #define Path_h
29 
30 #include <algorithm>
31 
32 #if PLATFORM(CG)
33 typedef struct CGPath PlatformPath;
34 #elif PLATFORM(QT)
35 #include <qglobal.h>
36 QT_BEGIN_NAMESPACE
37 class QPainterPath;
38 QT_END_NAMESPACE
39 typedef QPainterPath PlatformPath;
40 #elif PLATFORM(SGL)
41 class SkPath;
42 typedef SkPath PlatformPath;
43 #elif PLATFORM(WX) && USE(WXGC)
44 class wxGraphicsPath;
45 typedef wxGraphicsPath PlatformPath;
46 #elif PLATFORM(CAIRO)
47 namespace WebCore {
48     struct CairoPath;
49 }
50 typedef WebCore::CairoPath PlatformPath;
51 #elif PLATFORM(SKIA)
52 class SkPath;
53 typedef SkPath PlatformPath;
54 #else
55 typedef void PlatformPath;
56 #endif
57 
58 namespace WebCore {
59 
60     class FloatPoint;
61     class FloatRect;
62     class FloatSize;
63     class GraphicsContext;
64     class String;
65     class StrokeStyleApplier;
66     class TransformationMatrix;
67 
68     enum WindRule {
69         RULE_NONZERO = 0,
70         RULE_EVENODD = 1
71     };
72 
73     enum PathElementType {
74         PathElementMoveToPoint,
75         PathElementAddLineToPoint,
76         PathElementAddQuadCurveToPoint,
77         PathElementAddCurveToPoint,
78         PathElementCloseSubpath
79     };
80 
81     struct PathElement {
82         PathElementType type;
83         FloatPoint* points;
84     };
85 
86     typedef void (*PathApplierFunction)(void* info, const PathElement*);
87 
88     class Path {
89     public:
90         Path();
91         ~Path();
92 
93         Path(const Path&);
94         Path& operator=(const Path&);
95 
swap(Path & other)96         void swap(Path& other) { std::swap(m_path, other.m_path); }
97 
98         bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const;
99         bool strokeContains(StrokeStyleApplier*, const FloatPoint&) const;
100         FloatRect boundingRect() const;
101         FloatRect strokeBoundingRect(StrokeStyleApplier* = 0);
102 
103         float length();
104         FloatPoint pointAtLength(float length, bool& ok);
105         float normalAngleAtLength(float length, bool& ok);
106 
107         void clear();
108         bool isEmpty() const;
109 
110         void moveTo(const FloatPoint&);
111         void addLineTo(const FloatPoint&);
112         void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& endPoint);
113         void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& endPoint);
114         void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
115         void closeSubpath();
116 
117         void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise);
118         void addRect(const FloatRect&);
119         void addEllipse(const FloatRect&);
120 
121         void translate(const FloatSize&);
122 
123         String debugString() const;
124 
platformPath()125         PlatformPath* platformPath() const { return m_path; }
126 
127         static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii);
128         static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
129         static Path createRectangle(const FloatRect&);
130         static Path createEllipse(const FloatPoint& center, float rx, float ry);
131         static Path createCircle(const FloatPoint& center, float r);
132         static Path createLine(const FloatPoint&, const FloatPoint&);
133 
134         void apply(void* info, PathApplierFunction) const;
135         void transform(const TransformationMatrix&);
136 
137     private:
138         PlatformPath* m_path;
139     };
140 
141 }
142 
143 #endif
144