tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PathCairo.h (3258B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef MOZILLA_GFX_PATH_CAIRO_H_
      8 #define MOZILLA_GFX_PATH_CAIRO_H_
      9 
     10 #include "2D.h"
     11 #include "cairo.h"
     12 #include <vector>
     13 
     14 namespace mozilla {
     15 namespace gfx {
     16 
     17 class PathCairo;
     18 
     19 class PathBuilderCairo : public PathBuilder {
     20 public:
     21  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo, override)
     22 
     23  explicit PathBuilderCairo(FillRule aFillRule);
     24 
     25  void MoveTo(const Point& aPoint) override;
     26  void LineTo(const Point& aPoint) override;
     27  void BezierTo(const Point& aCP1, const Point& aCP2,
     28                const Point& aCP3) override;
     29  void QuadraticBezierTo(const Point& aCP1, const Point& aCP2) override;
     30  void Close() override;
     31  void Arc(const Point& aOrigin, float aRadius, float aStartAngle,
     32           float aEndAngle, bool aAntiClockwise = false) override;
     33  already_AddRefed<Path> Finish() override;
     34 
     35  BackendType GetBackendType() const override { return BackendType::CAIRO; }
     36 
     37  bool IsActive() const override { return !mPathData.empty(); }
     38 
     39  static already_AddRefed<PathBuilder> Create(FillRule aFillRule);
     40 
     41 private:  // data
     42  friend class PathCairo;
     43 
     44  FillRule mFillRule;
     45  std::vector<cairo_path_data_t> mPathData;
     46 };
     47 
     48 class PathCairo : public Path {
     49 public:
     50  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo, override)
     51 
     52  PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t>& aPathData,
     53            const Point& aCurrentPoint, const Point& aBeginPoint);
     54  explicit PathCairo(cairo_t* aContext);
     55  virtual ~PathCairo();
     56 
     57  BackendType GetBackendType() const override { return BackendType::CAIRO; }
     58 
     59  already_AddRefed<PathBuilder> CopyToBuilder(
     60      FillRule aFillRule) const override;
     61  already_AddRefed<PathBuilder> TransformedCopyToBuilder(
     62      const Matrix& aTransform, FillRule aFillRule) const override;
     63 
     64  bool ContainsPoint(const Point& aPoint,
     65                     const Matrix& aTransform) const override;
     66 
     67  bool StrokeContainsPoint(const StrokeOptions& aStrokeOptions,
     68                           const Point& aPoint,
     69                           const Matrix& aTransform) const override;
     70 
     71  Rect GetBounds(const Matrix& aTransform = Matrix()) const override;
     72 
     73  Rect GetStrokedBounds(const StrokeOptions& aStrokeOptions,
     74                        const Matrix& aTransform = Matrix()) const override;
     75 
     76  void StreamToSink(PathSink* aSink) const override;
     77 
     78  FillRule GetFillRule() const override { return mFillRule; }
     79 
     80  void SetPathOnContext(cairo_t* aContext) const;
     81 
     82  void AppendPathToBuilder(PathBuilderCairo* aBuilder,
     83                           const Matrix* aTransform = nullptr) const;
     84 
     85  bool IsEmpty() const override;
     86 
     87 private:
     88  void EnsureContainingContext(const Matrix& aTransform) const;
     89 
     90  FillRule mFillRule;
     91  std::vector<cairo_path_data_t> mPathData;
     92  mutable cairo_t* mContainingContext;
     93  mutable Matrix mContainingTransform;
     94  Point mCurrentPoint;
     95  Point mBeginPoint;
     96 };
     97 
     98 }  // namespace gfx
     99 }  // namespace mozilla
    100 
    101 #endif /* MOZILLA_GFX_PATH_CAIRO_H_ */