gfx/2d/PathCG.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/PathCG.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     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_PATHCG_H_
    1.10 +#define MOZILLA_GFX_PATHCG_H_
    1.11 +
    1.12 +#include <ApplicationServices/ApplicationServices.h>
    1.13 +#include "2D.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace gfx {
    1.17 +
    1.18 +class PathCG;
    1.19 +
    1.20 +class PathBuilderCG : public PathBuilder
    1.21 +{
    1.22 +public:
    1.23 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderCG)
    1.24 +  // absorbs a reference of aPath
    1.25 +  PathBuilderCG(CGMutablePathRef aPath, FillRule aFillRule)
    1.26 +    : mFillRule(aFillRule)
    1.27 +  {
    1.28 +      mCGPath = aPath;
    1.29 +  }
    1.30 +
    1.31 +  PathBuilderCG(FillRule aFillRule)
    1.32 +    : mFillRule(aFillRule)
    1.33 +  {
    1.34 +      mCGPath = CGPathCreateMutable();
    1.35 +  }
    1.36 +
    1.37 +  virtual ~PathBuilderCG();
    1.38 +
    1.39 +  virtual void MoveTo(const Point &aPoint);
    1.40 +  virtual void LineTo(const Point &aPoint);
    1.41 +  virtual void BezierTo(const Point &aCP1,
    1.42 +                        const Point &aCP2,
    1.43 +                        const Point &aCP3);
    1.44 +  virtual void QuadraticBezierTo(const Point &aCP1,
    1.45 +                                 const Point &aCP2);
    1.46 +  virtual void Close();
    1.47 +  virtual void Arc(const Point &aOrigin, Float aRadius, Float aStartAngle,
    1.48 +                   Float aEndAngle, bool aAntiClockwise = false);
    1.49 +  virtual Point CurrentPoint() const;
    1.50 +
    1.51 +  virtual TemporaryRef<Path> Finish();
    1.52 +
    1.53 +private:
    1.54 +  friend class PathCG;
    1.55 +  friend class ScaledFontMac;
    1.56 +
    1.57 +  void EnsureActive(const Point &aPoint);
    1.58 +
    1.59 +  CGMutablePathRef mCGPath;
    1.60 +  Point mCurrentPoint;
    1.61 +  Point mBeginPoint;
    1.62 +  FillRule mFillRule;
    1.63 +};
    1.64 +
    1.65 +class PathCG : public Path
    1.66 +{
    1.67 +public:
    1.68 +  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathCG)
    1.69 +  PathCG(CGMutablePathRef aPath, FillRule aFillRule)
    1.70 +    : mPath(aPath)
    1.71 +    , mFillRule(aFillRule)
    1.72 +  {
    1.73 +    CGPathRetain(mPath);
    1.74 +  }
    1.75 +  virtual ~PathCG() { CGPathRelease(mPath); }
    1.76 +
    1.77 +  // Paths will always return BackendType::COREGRAPHICS, but note that they
    1.78 +  // are compatible with BackendType::COREGRAPHICS_ACCELERATED backend.
    1.79 +  virtual BackendType GetBackendType() const { return BackendType::COREGRAPHICS; }
    1.80 +
    1.81 +  virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
    1.82 +  virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
    1.83 +                                                             FillRule aFillRule = FillRule::FILL_WINDING) const;
    1.84 +
    1.85 +  virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const;
    1.86 +  virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
    1.87 +                                   const Point &aPoint,
    1.88 +                                   const Matrix &aTransform) const;
    1.89 +  virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const;
    1.90 +  virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
    1.91 +                                const Matrix &aTransform = Matrix()) const;
    1.92 +
    1.93 +  virtual void StreamToSink(PathSink *aSink) const;
    1.94 +
    1.95 +  virtual FillRule GetFillRule() const { return mFillRule; }
    1.96 +
    1.97 +  CGMutablePathRef GetPath() const { return mPath; }
    1.98 +
    1.99 +private:
   1.100 +  friend class DrawTargetCG;
   1.101 +
   1.102 +  CGMutablePathRef mPath;
   1.103 +  Point mEndPoint;
   1.104 +  FillRule mFillRule;
   1.105 +};
   1.106 +
   1.107 +}
   1.108 +}
   1.109 +
   1.110 +#endif

mercurial