]>
Commit | Line | Data |
---|---|---|
a90939db JF |
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(WX) && USE(WXGC) | |
41 | class wxGraphicsPath; | |
42 | typedef wxGraphicsPath PlatformPath; | |
43 | #elif PLATFORM(CAIRO) | |
44 | namespace WebCore { | |
45 | struct CairoPath; | |
46 | } | |
47 | typedef WebCore::CairoPath PlatformPath; | |
48 | #elif PLATFORM(SKIA) | |
49 | class SkPath; | |
50 | typedef SkPath PlatformPath; | |
51 | #else | |
52 | typedef void PlatformPath; | |
53 | #endif | |
54 | ||
55 | namespace WebCore { | |
56 | ||
57 | class FloatPoint; | |
58 | class FloatRect; | |
59 | class FloatSize; | |
60 | class GraphicsContext; | |
61 | class String; | |
62 | class StrokeStyleApplier; | |
63 | class TransformationMatrix; | |
64 | ||
65 | enum WindRule { | |
66 | RULE_NONZERO = 0, | |
67 | RULE_EVENODD = 1 | |
68 | }; | |
69 | ||
70 | enum PathElementType { | |
71 | PathElementMoveToPoint, | |
72 | PathElementAddLineToPoint, | |
73 | PathElementAddQuadCurveToPoint, | |
74 | PathElementAddCurveToPoint, | |
75 | PathElementCloseSubpath | |
76 | }; | |
77 | ||
78 | struct PathElement { | |
79 | PathElementType type; | |
80 | FloatPoint* points; | |
81 | }; | |
82 | ||
83 | typedef void (*PathApplierFunction)(void* info, const PathElement*); | |
84 | ||
85 | class Path { | |
86 | public: | |
87 | Path(); | |
88 | ~Path(); | |
89 | ||
90 | Path(const Path&); | |
91 | Path& operator=(const Path&); | |
92 | ||
93 | void swap(Path& other) { std::swap(m_path, other.m_path); } | |
94 | ||
95 | bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const; | |
96 | bool strokeContains(StrokeStyleApplier*, const FloatPoint&) const; | |
97 | FloatRect boundingRect() const; | |
98 | FloatRect strokeBoundingRect(StrokeStyleApplier* = 0); | |
99 | ||
100 | float length(); | |
101 | FloatPoint pointAtLength(float length, bool& ok); | |
102 | float normalAngleAtLength(float length, bool& ok); | |
103 | ||
104 | void clear(); | |
105 | bool isEmpty() const; | |
106 | ||
107 | void moveTo(const FloatPoint&); | |
108 | void addLineTo(const FloatPoint&); | |
109 | void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& endPoint); | |
110 | void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& endPoint); | |
111 | void addArcTo(const FloatPoint&, const FloatPoint&, float radius); | |
112 | void closeSubpath(); | |
113 | ||
114 | void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise); | |
115 | void addRect(const FloatRect&); | |
116 | void addEllipse(const FloatRect&); | |
117 | ||
118 | void translate(const FloatSize&); | |
119 | ||
120 | String debugString() const; | |
121 | ||
122 | PlatformPath* platformPath() const { return m_path; } | |
123 | ||
124 | static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii); | |
125 | static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius); | |
126 | static Path createRectangle(const FloatRect&); | |
127 | static Path createEllipse(const FloatPoint& center, float rx, float ry); | |
128 | static Path createCircle(const FloatPoint& center, float r); | |
129 | static Path createLine(const FloatPoint&, const FloatPoint&); | |
130 | ||
131 | void apply(void* info, PathApplierFunction) const; | |
132 | void transform(const TransformationMatrix&); | |
133 | ||
134 | private: | |
135 | PlatformPath* m_path; | |
136 | }; | |
137 | ||
138 | } | |
139 | ||
140 | #endif |