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_PATHCG_H_ michael@0: #define MOZILLA_GFX_PATHCG_H_ michael@0: michael@0: #include michael@0: #include "2D.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class PathCG; michael@0: michael@0: class PathBuilderCG : public PathBuilder michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCG) michael@0: // absorbs a reference of aPath michael@0: PathBuilderCG(CGMutablePathRef aPath, FillRule aFillRule) michael@0: : mFillRule(aFillRule) michael@0: { michael@0: mCGPath = aPath; michael@0: } michael@0: michael@0: PathBuilderCG(FillRule aFillRule) michael@0: : mFillRule(aFillRule) michael@0: { michael@0: mCGPath = CGPathCreateMutable(); michael@0: } michael@0: michael@0: virtual ~PathBuilderCG(); 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: michael@0: virtual TemporaryRef Finish(); michael@0: michael@0: private: michael@0: friend class PathCG; michael@0: friend class ScaledFontMac; michael@0: michael@0: void EnsureActive(const Point &aPoint); michael@0: michael@0: CGMutablePathRef mCGPath; michael@0: Point mCurrentPoint; michael@0: Point mBeginPoint; michael@0: FillRule mFillRule; michael@0: }; michael@0: michael@0: class PathCG : public Path michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCG) michael@0: PathCG(CGMutablePathRef aPath, FillRule aFillRule) michael@0: : mPath(aPath) michael@0: , mFillRule(aFillRule) michael@0: { michael@0: CGPathRetain(mPath); michael@0: } michael@0: virtual ~PathCG() { CGPathRelease(mPath); } michael@0: michael@0: // Paths will always return BackendType::COREGRAPHICS, but note that they michael@0: // are compatible with BackendType::COREGRAPHICS_ACCELERATED backend. michael@0: virtual BackendType GetBackendType() const { return BackendType::COREGRAPHICS; } 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: virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, michael@0: const Point &aPoint, michael@0: const Matrix &aTransform) const; michael@0: virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const; 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: CGMutablePathRef GetPath() const { return mPath; } michael@0: michael@0: private: michael@0: friend class DrawTargetCG; michael@0: michael@0: CGMutablePathRef mPath; michael@0: Point mEndPoint; michael@0: FillRule mFillRule; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif