2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-01-10 02:15:10 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_PATH_CAIRO_H_
|
|
|
|
#define MOZILLA_GFX_PATH_CAIRO_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include "cairo.h"
|
2013-09-28 18:20:24 +04:00
|
|
|
#include <vector>
|
2012-01-10 02:15:10 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2013-09-28 18:20:24 +04:00
|
|
|
class PathCairo;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
|
|
|
class PathBuilderCairo : public PathBuilder
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo)
|
2014-08-08 05:17:30 +04:00
|
|
|
explicit PathBuilderCairo(FillRule aFillRule);
|
2012-01-10 02:15:10 +04:00
|
|
|
|
|
|
|
virtual void MoveTo(const Point &aPoint);
|
|
|
|
virtual void LineTo(const Point &aPoint);
|
|
|
|
virtual void BezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2,
|
|
|
|
const Point &aCP3);
|
|
|
|
virtual void QuadraticBezierTo(const Point &aCP1,
|
|
|
|
const Point &aCP2);
|
|
|
|
virtual void Close();
|
|
|
|
virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
|
|
|
|
float aEndAngle, bool aAntiClockwise = false);
|
|
|
|
virtual Point CurrentPoint() const;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<Path> Finish();
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2014-10-04 15:13:29 +04:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
|
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
private: // data
|
2013-09-28 18:20:24 +04:00
|
|
|
friend class PathCairo;
|
2012-09-04 01:48:04 +04:00
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
FillRule mFillRule;
|
2013-09-28 18:20:24 +04:00
|
|
|
std::vector<cairo_path_data_t> mPathData;
|
|
|
|
// It's easiest to track this here, parsing the path data to find the current
|
|
|
|
// point is a little tricky.
|
|
|
|
Point mCurrentPoint;
|
|
|
|
Point mBeginPoint;
|
2012-01-10 02:15:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class PathCairo : public Path
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 17:23:37 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo)
|
2013-09-28 18:20:24 +04:00
|
|
|
PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t> &aPathData, const Point &aCurrentPoint);
|
2014-08-08 05:17:30 +04:00
|
|
|
explicit PathCairo(cairo_t *aContext);
|
2013-09-28 18:20:24 +04:00
|
|
|
~PathCairo();
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2014-01-10 23:06:16 +04:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2016-02-08 05:15:54 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const;
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
|
2016-02-08 05:15:54 +03:00
|
|
|
FillRule aFillRule) const;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
|
|
|
virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
|
|
|
|
|
2012-10-29 19:54:53 +04:00
|
|
|
virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Point &aPoint,
|
|
|
|
const Matrix &aTransform) const;
|
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
|
|
|
|
|
|
|
|
virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Matrix &aTransform = Matrix()) const;
|
|
|
|
|
2013-11-07 13:11:26 +04:00
|
|
|
virtual void StreamToSink(PathSink *aSink) const;
|
2013-11-07 13:10:12 +04:00
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
virtual FillRule GetFillRule() const { return mFillRule; }
|
|
|
|
|
2013-09-28 18:20:24 +04:00
|
|
|
void SetPathOnContext(cairo_t *aContext) const;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2013-09-28 18:20:24 +04:00
|
|
|
void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const;
|
2012-01-10 02:15:10 +04:00
|
|
|
private:
|
2015-09-21 20:33:06 +03:00
|
|
|
void EnsureContainingContext(const Matrix &aTransform) const;
|
2013-09-28 18:20:24 +04:00
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
FillRule mFillRule;
|
2013-09-28 18:20:24 +04:00
|
|
|
std::vector<cairo_path_data_t> mPathData;
|
|
|
|
mutable cairo_t *mContainingContext;
|
2015-09-21 20:33:06 +03:00
|
|
|
mutable Matrix mContainingTransform;
|
2013-09-28 18:20:24 +04:00
|
|
|
Point mCurrentPoint;
|
2012-01-10 02:15:10 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-01-10 02:15:10 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_PATH_CAIRO_H_ */
|