|
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_PATH_CAIRO_H_ |
|
7 #define MOZILLA_GFX_PATH_CAIRO_H_ |
|
8 |
|
9 #include "2D.h" |
|
10 #include "cairo.h" |
|
11 #include <vector> |
|
12 |
|
13 namespace mozilla { |
|
14 namespace gfx { |
|
15 |
|
16 class DrawTargetCairo; |
|
17 class PathCairo; |
|
18 |
|
19 class PathBuilderCairo : public PathBuilder |
|
20 { |
|
21 public: |
|
22 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo) |
|
23 PathBuilderCairo(FillRule aFillRule); |
|
24 |
|
25 virtual void MoveTo(const Point &aPoint); |
|
26 virtual void LineTo(const Point &aPoint); |
|
27 virtual void BezierTo(const Point &aCP1, |
|
28 const Point &aCP2, |
|
29 const Point &aCP3); |
|
30 virtual void QuadraticBezierTo(const Point &aCP1, |
|
31 const Point &aCP2); |
|
32 virtual void Close(); |
|
33 virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle, |
|
34 float aEndAngle, bool aAntiClockwise = false); |
|
35 virtual Point CurrentPoint() const; |
|
36 virtual TemporaryRef<Path> Finish(); |
|
37 |
|
38 private: // data |
|
39 friend class PathCairo; |
|
40 |
|
41 FillRule mFillRule; |
|
42 std::vector<cairo_path_data_t> mPathData; |
|
43 // It's easiest to track this here, parsing the path data to find the current |
|
44 // point is a little tricky. |
|
45 Point mCurrentPoint; |
|
46 Point mBeginPoint; |
|
47 }; |
|
48 |
|
49 class PathCairo : public Path |
|
50 { |
|
51 public: |
|
52 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo) |
|
53 PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t> &aPathData, const Point &aCurrentPoint); |
|
54 PathCairo(cairo_t *aContext); |
|
55 ~PathCairo(); |
|
56 |
|
57 virtual BackendType GetBackendType() const { return BackendType::CAIRO; } |
|
58 |
|
59 virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; |
|
60 virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform, |
|
61 FillRule aFillRule = FillRule::FILL_WINDING) const; |
|
62 |
|
63 virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const; |
|
64 |
|
65 virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, |
|
66 const Point &aPoint, |
|
67 const Matrix &aTransform) const; |
|
68 |
|
69 virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const; |
|
70 |
|
71 virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, |
|
72 const Matrix &aTransform = Matrix()) const; |
|
73 |
|
74 virtual void StreamToSink(PathSink *aSink) const; |
|
75 |
|
76 virtual FillRule GetFillRule() const { return mFillRule; } |
|
77 |
|
78 void SetPathOnContext(cairo_t *aContext) const; |
|
79 |
|
80 void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const; |
|
81 private: |
|
82 void EnsureContainingContext() const; |
|
83 |
|
84 FillRule mFillRule; |
|
85 std::vector<cairo_path_data_t> mPathData; |
|
86 mutable cairo_t *mContainingContext; |
|
87 Point mCurrentPoint; |
|
88 }; |
|
89 |
|
90 } |
|
91 } |
|
92 |
|
93 #endif /* MOZILLA_GFX_PATH_CAIRO_H_ */ |