KHTML
Path.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef Path_h
00028 #define Path_h
00029
00030 #include "dom/dom_string.h"
00031 #include "platform/graphics/FloatPoint.h"
00032 #include "platform/graphics/FloatRect.h"
00033 #include <QPainterPath>
00034
00035 typedef QPainterPath PlatformPath;
00036
00037 namespace WebCore {
00038 class AffineTransform;
00039 }
00040
00041 namespace khtml {
00042 using WebCore::AffineTransform;
00043 using WebCore::FloatPoint;
00044 using WebCore::FloatSize;
00045 using WebCore::FloatRect;
00046
00047
00048 enum WindRule {
00049 RULE_NONZERO = 0,
00050 RULE_EVENODD = 1
00051 };
00052
00053 enum PathElementType {
00054 PathElementMoveToPoint,
00055 PathElementAddLineToPoint,
00056 PathElementAddQuadCurveToPoint,
00057 PathElementAddCurveToPoint,
00058 PathElementCloseSubpath
00059 };
00060
00061 struct PathElement {
00062 PathElementType type;
00063 FloatPoint* points;
00064 };
00065
00066 typedef void (*PathApplierFunction) (void* info, const PathElement*);
00067
00068 class Path {
00069 public:
00070 Path();
00071 ~Path();
00072
00073 Path(const Path&);
00074 Path& operator=(const Path&);
00075
00076 bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const;
00077 FloatRect boundingRect() const;
00078
00079 float length();
00080 FloatPoint pointAtLength(float length, bool& ok);
00081 float normalAngleAtLength(float length, bool& ok);
00082
00083 void clear();
00084 bool isEmpty() const;
00085
00086 void moveTo(const FloatPoint&);
00087 void addLineTo(const FloatPoint&);
00088 void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
00089 void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
00090 void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
00091 void closeSubpath();
00092
00093 void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise);
00094 void addRect(const FloatRect&);
00095 void addEllipse(const FloatRect&);
00096
00097 void translate(const FloatSize&);
00098
00099 void setWindingRule(WindRule rule) { m_rule = rule; }
00100 WindRule windingRule() const { return m_rule; }
00101
00102 DOM::DOMString debugString() const;
00103
00104 PlatformPath* platformPath() const { return m_path; }
00105
00106 static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii);
00107 static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
00108 static Path createRectangle(const FloatRect&);
00109 static Path createEllipse(const FloatPoint& center, float rx, float ry);
00110 static Path createCircle(const FloatPoint& center, float r);
00111 static Path createLine(const FloatPoint&, const FloatPoint&);
00112
00113 void apply(void* info, PathApplierFunction) const;
00114 void transform(const AffineTransform&);
00115
00116 private:
00117 PlatformPath* m_path;
00118 WindRule m_rule;
00119 };
00120
00121 }
00122
00123 #endif