1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_PATHCAPTURE_H_ 8 #define MOZILLA_GFX_PATHCAPTURE_H_ 9 10 #include "2D.h" 11 #include <vector> 12 #include <ostream> 13 14 #include "PathHelpers.h" 15 16 namespace mozilla { 17 namespace gfx { 18 19 class PathCapture; 20 21 class PathBuilderCapture : public PathBuilder { 22 public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCapture,override)23 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCapture, override) 24 25 PathBuilderCapture(FillRule aFillRule, DrawTarget* aDT) 26 : mFillRule(aFillRule), mDT(aDT) {} 27 28 /* Move the current point in the path, any figure currently being drawn will 29 * be considered closed during fill operations, however when stroking the 30 * closing line segment will not be drawn. 31 */ 32 virtual void MoveTo(const Point& aPoint) override; 33 /* Add a linesegment to the current figure */ 34 virtual void LineTo(const Point& aPoint) override; 35 /* Add a cubic bezier curve to the current figure */ 36 virtual void BezierTo(const Point& aCP1, const Point& aCP2, 37 const Point& aCP3) override; 38 /* Add a quadratic bezier curve to the current figure */ 39 virtual void QuadraticBezierTo(const Point& aCP1, const Point& aCP2) override; 40 /* Add an arc to the current figure */ 41 virtual void Arc(const Point& aOrigin, float aRadius, float aStartAngle, 42 float aEndAngle, bool aAntiClockwise) override; 43 /* Close the current figure, this will essentially generate a line segment 44 * from the current point to the starting point for the current figure 45 */ 46 virtual void Close() override; 47 48 virtual already_AddRefed<Path> Finish() override; 49 GetBackendType()50 virtual BackendType GetBackendType() const override { 51 return BackendType::CAPTURE; 52 } 53 54 private: 55 friend class PathCapture; 56 57 FillRule mFillRule; 58 std::vector<PathOp> mPathOps; 59 RefPtr<DrawTarget> mDT; 60 }; 61 62 class PathCapture : public Path { 63 public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCapture,override)64 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCapture, override) 65 66 PathCapture(const std::vector<PathOp> aOps, FillRule aFillRule, 67 DrawTarget* aDT, const Point& aCurrentPoint, 68 const Point& aBeginPoint) 69 : mPathOps(aOps), 70 mFillRule(aFillRule), 71 mDT(aDT), 72 mCurrentPoint(aCurrentPoint), 73 mBeginPoint(aBeginPoint) {} 74 GetBackendType()75 virtual BackendType GetBackendType() const override { 76 return BackendType::CAPTURE; 77 } 78 virtual already_AddRefed<PathBuilder> CopyToBuilder( 79 FillRule aFillRule) const override; 80 virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder( 81 const Matrix& aTransform, FillRule aFillRule) const override; 82 virtual bool ContainsPoint(const Point& aPoint, 83 const Matrix& aTransform) const override; 84 virtual bool StrokeContainsPoint(const StrokeOptions& aStrokeOptions, 85 const Point& aPoint, 86 const Matrix& aTransform) const override; 87 88 virtual Rect GetBounds(const Matrix& aTransform = Matrix()) const override; 89 90 virtual Rect GetStrokedBounds( 91 const StrokeOptions& aStrokeOptions, 92 const Matrix& aTransform = Matrix()) const override; 93 94 virtual void StreamToSink(PathSink* aSink) const override; 95 GetFillRule()96 virtual FillRule GetFillRule() const override { return mFillRule; } 97 98 Path* GetRealizedPath() const; 99 100 private: 101 bool EnsureRealizedPath() const; 102 103 mutable RefPtr<Path> mRealizedPath; 104 std::vector<PathOp> mPathOps; 105 FillRule mFillRule; 106 RefPtr<DrawTarget> mDT; 107 Point mCurrentPoint; 108 Point mBeginPoint; 109 }; 110 111 } // namespace gfx 112 } // namespace mozilla 113 114 #endif /* MOZILLA_GFX_PATHCAPTURE_H_ */ 115