Merge remote branch 'origin/master' into refactor
[profile/ivi/qtbase.git] / src / gui / painting / qcosmeticstroker_p.h
1 #ifndef QCOSMETICSTROKER_P_H
2 #define QCOSMETICSTROKER_P_H
3
4 #include <private/qdrawhelper_p.h>
5 #include <private/qvectorpath_p.h>
6 #include <private/qpaintengine_raster_p.h>
7 #include <qpen.h>
8
9 QT_BEGIN_HEADER
10
11 QT_BEGIN_NAMESPACE
12
13 QT_MODULE(Gui)
14
15 class QCosmeticStroker;
16
17
18 typedef void (*StrokeLine)(QCosmeticStroker *stroker, qreal x1, qreal y1, qreal x2, qreal y2, int caps);
19
20 class QCosmeticStroker
21 {
22 public:
23     struct Point {
24         int x;
25         int y;
26     };
27     struct PointF {
28         qreal x;
29         qreal y;
30     };
31
32     enum Caps {
33         NoCaps = 0,
34         CapBegin = 0x1,
35         CapEnd = 0x2,
36     };
37
38     // used to avoid drop outs or duplicated points
39     enum Direction {
40         TopToBottom,
41         BottomToTop,
42         LeftToRight,
43         RightToLeft
44     };
45
46     QCosmeticStroker(QRasterPaintEngineState *s, const QRect &dr)
47         : state(s),
48           clip(dr),
49           pattern(0),
50           reversePattern(0),
51           patternSize(0),
52           patternLength(0),
53           patternOffset(0),
54           current_span(0),
55           lastDir(LeftToRight),
56           lastAxisAligned(false)
57     { setup(); }
58     ~QCosmeticStroker() { free(pattern); free(reversePattern); }
59     void drawLine(const QPointF &p1, const QPointF &p2);
60     void drawPath(const QVectorPath &path);
61     void drawPoints(const QPoint *points, int num);
62     void drawPoints(const QPointF *points, int num);
63
64
65     QRasterPaintEngineState *state;
66     QRect clip;
67     // clip bounds in real
68     qreal xmin, xmax;
69     qreal ymin, ymax;
70
71     StrokeLine stroke;
72     bool drawCaps;
73
74     int *pattern;
75     int *reversePattern;
76     int patternSize;
77     int patternLength;
78     int patternOffset;
79
80     enum { NSPANS = 255 };
81     QT_FT_Span spans[NSPANS];
82     int current_span;
83     ProcessSpans blend;
84
85     int opacity;
86
87     uint color;
88     uint *pixels;
89     int ppl;
90
91     Direction lastDir;
92     Point lastPixel;
93     bool lastAxisAligned;
94
95 private:
96     void setup();
97
98     void renderCubic(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, int caps);
99     void renderCubicSubdivision(PointF *points, int level, int caps);
100     // used for closed subpaths
101     void calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal ry2);
102
103 public:
104     bool clipLine(qreal &x1, qreal &y1, qreal &x2, qreal &y2);
105 };
106
107 QT_END_NAMESPACE
108
109 QT_END_HEADER
110
111 #endif // QCOSMETICLINE_H