#ifndef Path_h
#define Path_h
#include "platform/PlatformExport.h"
#include "platform/geometry/RoundedRect.h"
#include "platform/graphics/WindRule.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPathMeasure.h"
#include "wtf/FastAllocBase.h"
#include "wtf/Forward.h"
class SkPath;
namespace WebCore {
class AffineTransform;
class FloatPoint;
class FloatRect;
class FloatSize;
class GraphicsContext;
class StrokeData;
enum PathElementType {
PathElementMoveToPoint,
PathElementAddLineToPoint,
PathElementAddQuadCurveToPoint,
PathElementAddCurveToPoint,
PathElementCloseSubpath
};
struct PathElement {
PathElementType type;
FloatPoint* points;
};
typedef void (*PathApplierFunction)(void* info, const PathElement*);
class PLATFORM_EXPORT Path {
WTF_MAKE_FAST_ALLOCATED;
public:
Path();
~Path();
Path(const Path&);
Path& operator=(const Path&);
bool operator==(const Path&) const;
bool contains(const FloatPoint&, WindRule = RULE_NONZERO) const;
bool strokeContains(const FloatPoint&, const StrokeData&) const;
FloatRect boundingRect() const;
FloatRect strokeBoundingRect(const StrokeData&) const;
float length() const;
FloatPoint pointAtLength(float length, bool& ok) const;
float normalAngleAtLength(float length, bool& ok) const;
bool pointAndNormalAtLength(float length, FloatPoint&, float&) const;
class PLATFORM_EXPORT PositionCalculator {
WTF_MAKE_NONCOPYABLE(PositionCalculator);
public:
explicit PositionCalculator(const Path&);
bool pointAndNormalAtLength(float length, FloatPoint&, float&);
private:
SkPath m_path;
SkPathMeasure m_pathMeasure;
SkScalar m_accumulatedLength;
};
void clear();
bool isEmpty() const;
bool hasCurrentPoint() const;
FloatPoint currentPoint() const;
WindRule windRule() const;
void setWindRule(const WindRule);
void moveTo(const FloatPoint&);
void addLineTo(const FloatPoint&);
void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& endPoint);
void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& endPoint);
void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
void closeSubpath();
void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise);
void addRect(const FloatRect&);
void addEllipse(const FloatPoint&, float radiusX, float radiusY, float rotation, float startAngle, float endAngle, bool anticlockwise);
void addEllipse(const FloatRect&);
void addRoundedRect(const FloatRect&, const FloatSize& roundingRadii);
void addRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
void addRoundedRect(const RoundedRect&);
void addPath(const Path&, const AffineTransform&);
void translate(const FloatSize&);
const SkPath& skPath() const { return m_path; }
void apply(void* info, PathApplierFunction) const;
void transform(const AffineTransform&);
void addPathForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
void addBeziersForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
bool unionPath(const Path& other);
private:
void addEllipse(const FloatPoint&, float radiusX, float radiusY, float startAngle, float endAngle, bool anticlockwise);
SkPath m_path;
};
#if !ASSERT_DISABLED
PLATFORM_EXPORT bool ellipseIsRenderable(float startAngle, float endAngle);
#endif
}
#endif