gfx/2d/PathCairo.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/PathCairo.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_GFX_PATH_CAIRO_H_
    1.10 +#define MOZILLA_GFX_PATH_CAIRO_H_
    1.11 +
    1.12 +#include "2D.h"
    1.13 +#include "cairo.h"
    1.14 +#include <vector>
    1.15 +
    1.16 +namespace mozilla {
    1.17 +namespace gfx {
    1.18 +
    1.19 +class DrawTargetCairo;
    1.20 +class PathCairo;
    1.21 +
    1.22 +class PathBuilderCairo : public PathBuilder
    1.23 +{
    1.24 +public:
    1.25 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCairo)
    1.26 +  PathBuilderCairo(FillRule aFillRule);
    1.27 +
    1.28 +  virtual void MoveTo(const Point &aPoint);
    1.29 +  virtual void LineTo(const Point &aPoint);
    1.30 +  virtual void BezierTo(const Point &aCP1,
    1.31 +                        const Point &aCP2,
    1.32 +                        const Point &aCP3);
    1.33 +  virtual void QuadraticBezierTo(const Point &aCP1,
    1.34 +                                 const Point &aCP2);
    1.35 +  virtual void Close();
    1.36 +  virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
    1.37 +                   float aEndAngle, bool aAntiClockwise = false);
    1.38 +  virtual Point CurrentPoint() const;
    1.39 +  virtual TemporaryRef<Path> Finish();
    1.40 +
    1.41 +private: // data
    1.42 +  friend class PathCairo;
    1.43 +
    1.44 +  FillRule mFillRule;
    1.45 +  std::vector<cairo_path_data_t> mPathData;
    1.46 +  // It's easiest to track this here, parsing the path data to find the current
    1.47 +  // point is a little tricky.
    1.48 +  Point mCurrentPoint;
    1.49 +  Point mBeginPoint;
    1.50 +};
    1.51 +
    1.52 +class PathCairo : public Path
    1.53 +{
    1.54 +public:
    1.55 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCairo)
    1.56 +  PathCairo(FillRule aFillRule, std::vector<cairo_path_data_t> &aPathData, const Point &aCurrentPoint);
    1.57 +  PathCairo(cairo_t *aContext);
    1.58 +  ~PathCairo();
    1.59 +
    1.60 +  virtual BackendType GetBackendType() const { return BackendType::CAIRO; }
    1.61 +
    1.62 +  virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
    1.63 +  virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
    1.64 +                                                             FillRule aFillRule = FillRule::FILL_WINDING) const;
    1.65 +
    1.66 +  virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
    1.67 +
    1.68 +  virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
    1.69 +                                   const Point &aPoint,
    1.70 +                                   const Matrix &aTransform) const;
    1.71 +
    1.72 +  virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
    1.73 +
    1.74 +  virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
    1.75 +                                const Matrix &aTransform = Matrix()) const;
    1.76 +
    1.77 +  virtual void StreamToSink(PathSink *aSink) const;
    1.78 +
    1.79 +  virtual FillRule GetFillRule() const { return mFillRule; }
    1.80 +
    1.81 +  void SetPathOnContext(cairo_t *aContext) const;
    1.82 +
    1.83 +  void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const;
    1.84 +private:
    1.85 +  void EnsureContainingContext() const;
    1.86 +
    1.87 +  FillRule mFillRule;
    1.88 +  std::vector<cairo_path_data_t> mPathData;
    1.89 +  mutable cairo_t *mContainingContext;
    1.90 +  Point mCurrentPoint;
    1.91 +};
    1.92 +
    1.93 +}
    1.94 +}
    1.95 +
    1.96 +#endif /* MOZILLA_GFX_PATH_CAIRO_H_ */

mercurial