1231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block/*
2231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  Copyright (C) 2007-2009 Torch Mobile, Inc.
3231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
4231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  This library is free software; you can redistribute it and/or
5231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  modify it under the terms of the GNU Library General Public
6231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  License as published by the Free Software Foundation; either
7231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  version 2 of the License, or (at your option) any later version.
8231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
9231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  This library is distributed in the hope that it will be useful,
10231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  Library General Public License for more details.
13231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
14231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  You should have received a copy of the GNU Library General Public License
15231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  along with this library; see the file COPYING.LIB.  If not, write to
16231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *  Boston, MA 02110-1301, USA.
18231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block */
19231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
2068513a70bcd92384395513322f1b801e7bf9c729Steve Block#ifndef PlatformPathWinCE_h
2168513a70bcd92384395513322f1b801e7bf9c729Steve Block#define PlatformPathWinCE_h
22231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
23dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "FloatPoint.h"
24dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "FloatRect.h"
25dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "Path.h"
26dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include <wtf/Vector.h>
27dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blocknamespace WebCore {
29231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
30231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class GraphicsContext;
31231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
32231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    struct PathPoint {
33231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        float m_x;
34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        float m_y;
35231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const float& x() const { return m_x; }
36231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const float& y() const { return m_y; }
37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void set(float x, float y)
38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        {
39231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            m_x = x;
40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            m_y = y;
41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        operator FloatPoint() const { return FloatPoint(m_x, m_y); }
43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void move(const FloatSize& offset)
44231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        {
45231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            m_x += offset.width();
46231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            m_y += offset.height();
47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        }
48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PathPoint& operator=(const FloatPoint& p)
49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        {
50231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            m_x = p.x();
51231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            m_y = p.y();
52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            return *this;
53231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        }
54231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void clear() { m_x = m_y = 0; }
55231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    };
56231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
57231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    struct PathPolygon: public Vector<PathPoint> {
58231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void move(const FloatSize& offset);
598a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        void transform(const AffineTransform& t);
60231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        bool contains(const FloatPoint& point) const;
61231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    };
62231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
63231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class PlatformPathElement {
64231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    public:
65231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        enum PlaformPathElementType {
66231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathMoveTo,
67231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathLineTo,
68231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathArcTo,
69231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathQuadCurveTo,
70231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathBezierCurveTo,
71231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathCloseSubpath,
72231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
73231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        struct MoveTo {
75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_end;
76231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
77231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
78231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        struct LineTo {
79231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_end;
80231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
81231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        struct ArcTo {
83231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_end;
84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_center;
85231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_radius;
86231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            bool m_clockwise;
87231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
88231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
89231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        struct QuadCurveTo {
90231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_point0;
91231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_point1;
92231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
93231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
94231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        struct BezierCurveTo {
95231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_point0;
96231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_point1;
97231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_point2;
98231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        };
99231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
100231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElement(): m_type(PathCloseSubpath) { m_data.m_points[0].set(0, 0);    }
101231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElement(const MoveTo& data): m_type(PathMoveTo) { m_data.m_moveToData = data; }
102231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElement(const LineTo& data): m_type(PathLineTo) { m_data.m_lineToData = data; }
103231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElement(const ArcTo& data): m_type(PathArcTo) { m_data.m_arcToData = data; }
104231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElement(const QuadCurveTo& data): m_type(PathQuadCurveTo) { m_data.m_quadCurveToData = data; }
105231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElement(const BezierCurveTo& data): m_type(PathBezierCurveTo) { m_data.m_bezierCurveToData = data; }
106231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
107231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const MoveTo& moveTo() const { return m_data.m_moveToData; }
108231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const LineTo& lineTo() const { return m_data.m_lineToData; }
109231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const ArcTo& arcTo() const { return m_data.m_arcToData; }
110231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const QuadCurveTo& quadCurveTo() const { return m_data.m_quadCurveToData; }
111231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const BezierCurveTo& bezierCurveTo() const { return m_data.m_bezierCurveToData; }
112231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const PathPoint& lastPoint() const
113231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        {
114231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            int n = numPoints();
115231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            return n > 1 ? m_data.m_points[n - 1] : m_data.m_points[0];
116231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        }
117231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const PathPoint& pointAt(int index) const { return m_data.m_points[index]; }
118231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        int numPoints() const;
119231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        int numControlPoints() const;
120231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void move(const FloatSize& offset);
1218a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        void transform(const AffineTransform& t);
122231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PathElementType type() const;
123231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlaformPathElementType platformType() const { return m_type; }
124231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void inflateRectToContainMe(FloatRect& r, const FloatPoint& lastPoint) const;
125231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
126231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    private:
127231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlaformPathElementType m_type;
128231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        union {
129231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            MoveTo m_moveToData;
130231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            LineTo m_lineToData;
131231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            ArcTo m_arcToData;
132231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            QuadCurveTo m_quadCurveToData;
133231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            BezierCurveTo m_bezierCurveToData;
134231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            PathPoint m_points[4];
135231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        } m_data;
136231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    };
137231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
138231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    typedef Vector<PlatformPathElement> PlatformPathElements;
139231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
140231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class PlatformPath {
141231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    public:
142231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPath();
143231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const PlatformPathElements& elements() const { return m_elements; }
144231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void append(const PlatformPathElement& e);
145231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void append(const PlatformPath& p);
146231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void clear();
147231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        bool isEmpty() const { return m_elements.isEmpty(); }
148231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
1498a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        void strokePath(HDC, const AffineTransform* tr) const;
1508a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        void fillPath(HDC, const AffineTransform* tr) const;
151231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        FloatPoint lastPoint() const { return m_elements.isEmpty() ? FloatPoint(0, 0) : m_elements.last().lastPoint(); }
152231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
153231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        const FloatRect& boundingRect() const { return m_boundingRect; }
154231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        bool contains(const FloatPoint& point, WindRule rule) const;
155231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void translate(const FloatSize& size);
1568a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block        void transform(const AffineTransform& t);
157231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
158231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void moveTo(const FloatPoint&);
159231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addLineTo(const FloatPoint&);
160231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
161231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
162231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
163231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void closeSubpath();
164231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addEllipse(const FloatPoint& p, float a, float b, float sar, float ear, bool anticlockwise);
165231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addRect(const FloatRect& r);
166231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addEllipse(const FloatRect& r);
167231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void apply(void* info, PathApplierFunction function) const;
168231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
169231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    private:
170231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void ensureSubpath();
171231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        void addToSubpath(const PlatformPathElement& e);
172231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
173231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PlatformPathElements m_elements;
174231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        FloatRect m_boundingRect;
175231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        Vector<PathPolygon> m_subpaths;
176231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        PathPoint m_currentPoint;
177231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        bool m_penLifted;
178231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    };
179231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
180231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
181231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
18268513a70bcd92384395513322f1b801e7bf9c729Steve Block#endif // PlatformPathWinCE_h
183