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:
|
2017-11-06 06:37:28 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo, override)
|
|
|
|
|
2014-08-08 05:17:30 +04:00
|
|
|
explicit PathBuilderCairo(FillRule aFillRule);
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void MoveTo(const Point& aPoint) override;
|
|
|
|
void LineTo(const Point& aPoint) override;
|
|
|
|
void BezierTo(const Point& aCP1, const Point& aCP2,
|
|
|
|
const Point& aCP3) override;
|
|
|
|
void QuadraticBezierTo(const Point& aCP1, const Point& aCP2) override;
|
2019-04-11 15:36:51 +03:00
|
|
|
void Close() override;
|
2019-05-01 11:47:10 +03:00
|
|
|
void Arc(const Point& aOrigin, float aRadius, float aStartAngle,
|
2019-04-11 15:36:51 +03:00
|
|
|
float aEndAngle, bool aAntiClockwise = false) override;
|
|
|
|
Point CurrentPoint() const override;
|
|
|
|
already_AddRefed<Path> Finish() override;
|
|
|
|
|
|
|
|
BackendType GetBackendType() const override { return BackendType::CAIRO; }
|
2014-10-04 15:13:29 +04:00
|
|
|
|
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:
|
2017-11-06 06:37:28 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo, override)
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t>& aPathData,
|
|
|
|
const Point& aCurrentPoint);
|
|
|
|
explicit PathCairo(cairo_t* aContext);
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~PathCairo();
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
BackendType GetBackendType() const override { return BackendType::CAIRO; }
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
already_AddRefed<PathBuilder> CopyToBuilder(
|
2017-11-06 06:37:28 +03:00
|
|
|
FillRule aFillRule) const override;
|
2019-04-11 15:36:51 +03:00
|
|
|
already_AddRefed<PathBuilder> TransformedCopyToBuilder(
|
2019-05-01 11:47:10 +03:00
|
|
|
const Matrix& aTransform, FillRule aFillRule) const override;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool ContainsPoint(const Point& aPoint,
|
|
|
|
const Matrix& aTransform) const override;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool StrokeContainsPoint(const StrokeOptions& aStrokeOptions,
|
|
|
|
const Point& aPoint,
|
|
|
|
const Matrix& aTransform) const override;
|
2012-10-29 19:54:53 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
Rect GetBounds(const Matrix& aTransform = Matrix()) const override;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
Rect GetStrokedBounds(const StrokeOptions& aStrokeOptions,
|
|
|
|
const Matrix& aTransform = Matrix()) const override;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void StreamToSink(PathSink* aSink) const override;
|
2013-11-07 13:10:12 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
FillRule GetFillRule() const override { return mFillRule; }
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void SetPathOnContext(cairo_t* aContext) const;
|
2012-01-10 02:15:10 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void AppendPathToBuilder(PathBuilderCairo* aBuilder,
|
|
|
|
const Matrix* aTransform = nullptr) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-01-10 02:15:10 +04:00
|
|
|
private:
|
2019-05-01 11:47:10 +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;
|
2019-05-01 11:47:10 +03:00
|
|
|
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_ */
|