2017-10-27 23:10:06 +00: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 11:12:37 +00: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-09 22:15:10 +00:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_PATH_CAIRO_H_
|
|
|
|
#define MOZILLA_GFX_PATH_CAIRO_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include "cairo.h"
|
2013-09-28 14:20:24 +00:00
|
|
|
#include <vector>
|
2012-01-09 22:15:10 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2013-09-28 14:20:24 +00:00
|
|
|
class PathCairo;
|
2012-01-09 22:15:10 +00:00
|
|
|
|
|
|
|
class PathBuilderCairo : public PathBuilder
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 13:23:37 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo)
|
2014-08-08 01:17:30 +00:00
|
|
|
explicit PathBuilderCairo(FillRule aFillRule);
|
2012-01-09 22:15:10 +00: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 14:00:52 +00:00
|
|
|
virtual already_AddRefed<Path> Finish();
|
2012-01-09 22:15:10 +00:00
|
|
|
|
2014-10-04 11:13:29 +00:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
|
|
|
|
|
2012-01-09 22:15:10 +00:00
|
|
|
private: // data
|
2013-09-28 14:20:24 +00:00
|
|
|
friend class PathCairo;
|
2012-09-03 21:48:04 +00:00
|
|
|
|
2012-01-09 22:15:10 +00:00
|
|
|
FillRule mFillRule;
|
2013-09-28 14:20:24 +00: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-09 22:15:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PathCairo : public Path
|
|
|
|
{
|
|
|
|
public:
|
2014-02-24 13:23:37 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo)
|
2013-09-28 14:20:24 +00:00
|
|
|
PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t> &aPathData, const Point &aCurrentPoint);
|
2014-08-08 01:17:30 +00:00
|
|
|
explicit PathCairo(cairo_t *aContext);
|
2013-09-28 14:20:24 +00:00
|
|
|
~PathCairo();
|
2012-01-09 22:15:10 +00:00
|
|
|
|
2014-01-10 19:06:16 +00:00
|
|
|
virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
|
2012-01-09 22:15:10 +00:00
|
|
|
|
2016-02-08 02:15:54 +00:00
|
|
|
virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const;
|
2015-06-17 14:00:52 +00:00
|
|
|
virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
|
2016-02-08 02:15:54 +00:00
|
|
|
FillRule aFillRule) const;
|
2012-01-09 22:15:10 +00:00
|
|
|
|
|
|
|
virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
|
|
|
|
|
2012-10-29 15:54:53 +00:00
|
|
|
virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Point &aPoint,
|
|
|
|
const Matrix &aTransform) const;
|
|
|
|
|
2012-01-09 22:15:10 +00:00
|
|
|
virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
|
|
|
|
|
|
|
|
virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
|
|
|
|
const Matrix &aTransform = Matrix()) const;
|
|
|
|
|
2013-11-07 09:11:26 +00:00
|
|
|
virtual void StreamToSink(PathSink *aSink) const;
|
2013-11-07 09:10:12 +00:00
|
|
|
|
2012-01-09 22:15:10 +00:00
|
|
|
virtual FillRule GetFillRule() const { return mFillRule; }
|
|
|
|
|
2013-09-28 14:20:24 +00:00
|
|
|
void SetPathOnContext(cairo_t *aContext) const;
|
2012-01-09 22:15:10 +00:00
|
|
|
|
2013-09-28 14:20:24 +00:00
|
|
|
void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const;
|
2012-01-09 22:15:10 +00:00
|
|
|
private:
|
2015-09-21 17:33:06 +00:00
|
|
|
void EnsureContainingContext(const Matrix &aTransform) const;
|
2013-09-28 14:20:24 +00:00
|
|
|
|
2012-01-09 22:15:10 +00:00
|
|
|
FillRule mFillRule;
|
2013-09-28 14:20:24 +00:00
|
|
|
std::vector<cairo_path_data_t> mPathData;
|
|
|
|
mutable cairo_t *mContainingContext;
|
2015-09-21 17:33:06 +00:00
|
|
|
mutable Matrix mContainingTransform;
|
2013-09-28 14:20:24 +00:00
|
|
|
Point mCurrentPoint;
|
2012-01-09 22:15:10 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-01-09 22:15:10 +00:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_PATH_CAIRO_H_ */
|