michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_PATH_CAIRO_H_ michael@0: #define MOZILLA_GFX_PATH_CAIRO_H_ michael@0: michael@0: #include "2D.h" michael@0: #include "cairo.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class DrawTargetCairo; michael@0: class PathCairo; michael@0: michael@0: class PathBuilderCairo : public PathBuilder michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo) michael@0: PathBuilderCairo(FillRule aFillRule); michael@0: michael@0: virtual void MoveTo(const Point &aPoint); michael@0: virtual void LineTo(const Point &aPoint); michael@0: virtual void BezierTo(const Point &aCP1, michael@0: const Point &aCP2, michael@0: const Point &aCP3); michael@0: virtual void QuadraticBezierTo(const Point &aCP1, michael@0: const Point &aCP2); michael@0: virtual void Close(); michael@0: virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle, michael@0: float aEndAngle, bool aAntiClockwise = false); michael@0: virtual Point CurrentPoint() const; michael@0: virtual TemporaryRef Finish(); michael@0: michael@0: private: // data michael@0: friend class PathCairo; michael@0: michael@0: FillRule mFillRule; michael@0: std::vector mPathData; michael@0: // It's easiest to track this here, parsing the path data to find the current michael@0: // point is a little tricky. michael@0: Point mCurrentPoint; michael@0: Point mBeginPoint; michael@0: }; michael@0: michael@0: class PathCairo : public Path michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo) michael@0: PathCairo(FillRule aFillRule, std::vector &aPathData, const Point &aCurrentPoint); michael@0: PathCairo(cairo_t *aContext); michael@0: ~PathCairo(); michael@0: michael@0: virtual BackendType GetBackendType() const { return BackendType::CAIRO; } michael@0: michael@0: virtual TemporaryRef CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; michael@0: virtual TemporaryRef TransformedCopyToBuilder(const Matrix &aTransform, michael@0: FillRule aFillRule = FillRule::FILL_WINDING) const; michael@0: michael@0: virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const; michael@0: michael@0: virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, michael@0: const Point &aPoint, michael@0: const Matrix &aTransform) const; michael@0: michael@0: virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const; michael@0: michael@0: virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, michael@0: const Matrix &aTransform = Matrix()) const; michael@0: michael@0: virtual void StreamToSink(PathSink *aSink) const; michael@0: michael@0: virtual FillRule GetFillRule() const { return mFillRule; } michael@0: michael@0: void SetPathOnContext(cairo_t *aContext) const; michael@0: michael@0: void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const; michael@0: private: michael@0: void EnsureContainingContext() const; michael@0: michael@0: FillRule mFillRule; michael@0: std::vector mPathData; michael@0: mutable cairo_t *mContainingContext; michael@0: Point mCurrentPoint; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_PATH_CAIRO_H_ */