summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/wince/PlatformPathWinCE.h
blob: 3414b042d7a0e0745e4c5b418baadc6a07f40feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 *  Copyright (C) 2007-2009 Torch Mobile, Inc.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#ifndef PlatformPathWinCE_h
#define PlatformPathWinCE_h

#include "FloatPoint.h"
#include "FloatRect.h"
#include "Path.h"
#include <wtf/Vector.h>

namespace WebCore {

    class GraphicsContext;

    struct PathPoint {
        float m_x;
        float m_y;
        const float& x() const { return m_x; }
        const float& y() const { return m_y; }
        void set(float x, float y)
        {
            m_x = x;
            m_y = y;
        };
        operator FloatPoint() const { return FloatPoint(m_x, m_y); }
        void move(const FloatSize& offset)
        {
            m_x += offset.width();
            m_y += offset.height();
        }
        PathPoint& operator=(const FloatPoint& p)
        {
            m_x = p.x();
            m_y = p.y();
            return *this;
        }
        void clear() { m_x = m_y = 0; }
    };

    struct PathPolygon: public Vector<PathPoint> {
        void move(const FloatSize& offset);
        void transform(const AffineTransform& t);
        bool contains(const FloatPoint& point) const;
    };

    class PlatformPathElement {
    public:
        enum PlaformPathElementType {
            PathMoveTo,
            PathLineTo,
            PathArcTo,
            PathQuadCurveTo,
            PathBezierCurveTo,
            PathCloseSubpath,
        };

        struct MoveTo {
            PathPoint m_end;
        };

        struct LineTo {
            PathPoint m_end;
        };

        struct ArcTo {
            PathPoint m_end;
            PathPoint m_center;
            PathPoint m_radius;
            bool m_clockwise;
        };

        struct QuadCurveTo {
            PathPoint m_point0;
            PathPoint m_point1;
        };

        struct BezierCurveTo {
            PathPoint m_point0;
            PathPoint m_point1;
            PathPoint m_point2;
        };

        PlatformPathElement(): m_type(PathCloseSubpath) { m_data.m_points[0].set(0, 0);    }
        PlatformPathElement(const MoveTo& data): m_type(PathMoveTo) { m_data.m_moveToData = data; }
        PlatformPathElement(const LineTo& data): m_type(PathLineTo) { m_data.m_lineToData = data; }
        PlatformPathElement(const ArcTo& data): m_type(PathArcTo) { m_data.m_arcToData = data; }
        PlatformPathElement(const QuadCurveTo& data): m_type(PathQuadCurveTo) { m_data.m_quadCurveToData = data; }
        PlatformPathElement(const BezierCurveTo& data): m_type(PathBezierCurveTo) { m_data.m_bezierCurveToData = data; }

        const MoveTo& moveTo() const { return m_data.m_moveToData; }
        const LineTo& lineTo() const { return m_data.m_lineToData; }
        const ArcTo& arcTo() const { return m_data.m_arcToData; }
        const QuadCurveTo& quadCurveTo() const { return m_data.m_quadCurveToData; }
        const BezierCurveTo& bezierCurveTo() const { return m_data.m_bezierCurveToData; }
        const PathPoint& lastPoint() const
        {
            int n = numPoints();
            return n > 1 ? m_data.m_points[n - 1] : m_data.m_points[0];
        }
        const PathPoint& pointAt(int index) const { return m_data.m_points[index]; }
        int numPoints() const;
        int numControlPoints() const;
        void move(const FloatSize& offset);
        void transform(const AffineTransform& t);
        PathElementType type() const;
        PlaformPathElementType platformType() const { return m_type; }
        void inflateRectToContainMe(FloatRect& r, const FloatPoint& lastPoint) const;

    private:
        PlaformPathElementType m_type;
        union {
            MoveTo m_moveToData;
            LineTo m_lineToData;
            ArcTo m_arcToData;
            QuadCurveTo m_quadCurveToData;
            BezierCurveTo m_bezierCurveToData;
            PathPoint m_points[4];
        } m_data;
    };

    typedef Vector<PlatformPathElement> PlatformPathElements;

    class PlatformPath {
    public:
        PlatformPath();
        const PlatformPathElements& elements() const { return m_elements; }
        void append(const PlatformPathElement& e);
        void append(const PlatformPath& p);
        void clear();
        bool isEmpty() const { return m_elements.isEmpty(); }

        void strokePath(HDC, const AffineTransform* tr) const;
        void fillPath(HDC, const AffineTransform* tr) const;
        FloatPoint lastPoint() const { return m_elements.isEmpty() ? FloatPoint(0, 0) : m_elements.last().lastPoint(); }

        const FloatRect& boundingRect() const { return m_boundingRect; }
        bool contains(const FloatPoint& point, WindRule rule) const;
        void translate(const FloatSize& size);
        void transform(const AffineTransform& t);

        void moveTo(const FloatPoint&);
        void addLineTo(const FloatPoint&);
        void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
        void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
        void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
        void closeSubpath();
        void addEllipse(const FloatPoint& p, float a, float b, float sar, float ear, bool anticlockwise);
        void addRect(const FloatRect& r);
        void addEllipse(const FloatRect& r);
        String debugString() const;
        void apply(void* info, PathApplierFunction function) const;

    private:
        void ensureSubpath();
        void addToSubpath(const PlatformPathElement& e);

        PlatformPathElements m_elements;
        FloatRect m_boundingRect;
        Vector<PathPolygon> m_subpaths;
        PathPoint m_currentPoint;
        bool m_penLifted;
    };

}

#endif // PlatformPathWinCE_h