|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef MOZILLA_GFX_PATHCG_H_ |
|
7 #define MOZILLA_GFX_PATHCG_H_ |
|
8 |
|
9 #include <ApplicationServices/ApplicationServices.h> |
|
10 #include "2D.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace gfx { |
|
14 |
|
15 class PathCG; |
|
16 |
|
17 class PathBuilderCG : public PathBuilder |
|
18 { |
|
19 public: |
|
20 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCG) |
|
21 // absorbs a reference of aPath |
|
22 PathBuilderCG(CGMutablePathRef aPath, FillRule aFillRule) |
|
23 : mFillRule(aFillRule) |
|
24 { |
|
25 mCGPath = aPath; |
|
26 } |
|
27 |
|
28 PathBuilderCG(FillRule aFillRule) |
|
29 : mFillRule(aFillRule) |
|
30 { |
|
31 mCGPath = CGPathCreateMutable(); |
|
32 } |
|
33 |
|
34 virtual ~PathBuilderCG(); |
|
35 |
|
36 virtual void MoveTo(const Point &aPoint); |
|
37 virtual void LineTo(const Point &aPoint); |
|
38 virtual void BezierTo(const Point &aCP1, |
|
39 const Point &aCP2, |
|
40 const Point &aCP3); |
|
41 virtual void QuadraticBezierTo(const Point &aCP1, |
|
42 const Point &aCP2); |
|
43 virtual void Close(); |
|
44 virtual void Arc(const Point &aOrigin, Float aRadius, Float aStartAngle, |
|
45 Float aEndAngle, bool aAntiClockwise = false); |
|
46 virtual Point CurrentPoint() const; |
|
47 |
|
48 virtual TemporaryRef<Path> Finish(); |
|
49 |
|
50 private: |
|
51 friend class PathCG; |
|
52 friend class ScaledFontMac; |
|
53 |
|
54 void EnsureActive(const Point &aPoint); |
|
55 |
|
56 CGMutablePathRef mCGPath; |
|
57 Point mCurrentPoint; |
|
58 Point mBeginPoint; |
|
59 FillRule mFillRule; |
|
60 }; |
|
61 |
|
62 class PathCG : public Path |
|
63 { |
|
64 public: |
|
65 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCG) |
|
66 PathCG(CGMutablePathRef aPath, FillRule aFillRule) |
|
67 : mPath(aPath) |
|
68 , mFillRule(aFillRule) |
|
69 { |
|
70 CGPathRetain(mPath); |
|
71 } |
|
72 virtual ~PathCG() { CGPathRelease(mPath); } |
|
73 |
|
74 // Paths will always return BackendType::COREGRAPHICS, but note that they |
|
75 // are compatible with BackendType::COREGRAPHICS_ACCELERATED backend. |
|
76 virtual BackendType GetBackendType() const { return BackendType::COREGRAPHICS; } |
|
77 |
|
78 virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; |
|
79 virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform, |
|
80 FillRule aFillRule = FillRule::FILL_WINDING) const; |
|
81 |
|
82 virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const; |
|
83 virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, |
|
84 const Point &aPoint, |
|
85 const Matrix &aTransform) const; |
|
86 virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const; |
|
87 virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, |
|
88 const Matrix &aTransform = Matrix()) const; |
|
89 |
|
90 virtual void StreamToSink(PathSink *aSink) const; |
|
91 |
|
92 virtual FillRule GetFillRule() const { return mFillRule; } |
|
93 |
|
94 CGMutablePathRef GetPath() const { return mPath; } |
|
95 |
|
96 private: |
|
97 friend class DrawTargetCG; |
|
98 |
|
99 CGMutablePathRef mPath; |
|
100 Point mEndPoint; |
|
101 FillRule mFillRule; |
|
102 }; |
|
103 |
|
104 } |
|
105 } |
|
106 |
|
107 #endif |