Merge "Merge remote branch 'gerrit/master' into refactor" into refactor
[profile/ivi/qtbase.git] / src / gui / painting / qcosmeticstroker_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QCOSMETICSTROKER_P_H
43 #define QCOSMETICSTROKER_P_H
44
45 #include <private/qdrawhelper_p.h>
46 #include <private/qvectorpath_p.h>
47 #include <private/qpaintengine_raster_p.h>
48 #include <qpen.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Gui)
55
56 class QCosmeticStroker;
57
58
59 typedef void (*StrokeLine)(QCosmeticStroker *stroker, qreal x1, qreal y1, qreal x2, qreal y2, int caps);
60
61 class QCosmeticStroker
62 {
63 public:
64     struct Point {
65         int x;
66         int y;
67     };
68     struct PointF {
69         qreal x;
70         qreal y;
71     };
72
73     enum Caps {
74         NoCaps = 0,
75         CapBegin = 0x1,
76         CapEnd = 0x2,
77     };
78
79     // used to avoid drop outs or duplicated points
80     enum Direction {
81         TopToBottom,
82         BottomToTop,
83         LeftToRight,
84         RightToLeft
85     };
86
87     QCosmeticStroker(QRasterPaintEngineState *s, const QRect &dr)
88         : state(s),
89           clip(dr),
90           pattern(0),
91           reversePattern(0),
92           patternSize(0),
93           patternLength(0),
94           patternOffset(0),
95           current_span(0),
96           lastDir(LeftToRight),
97           lastAxisAligned(false)
98     { setup(); }
99     ~QCosmeticStroker() { free(pattern); free(reversePattern); }
100     void drawLine(const QPointF &p1, const QPointF &p2);
101     void drawPath(const QVectorPath &path);
102     void drawPoints(const QPoint *points, int num);
103     void drawPoints(const QPointF *points, int num);
104
105
106     QRasterPaintEngineState *state;
107     QRect clip;
108     // clip bounds in real
109     qreal xmin, xmax;
110     qreal ymin, ymax;
111
112     StrokeLine stroke;
113     bool drawCaps;
114
115     int *pattern;
116     int *reversePattern;
117     int patternSize;
118     int patternLength;
119     int patternOffset;
120
121     enum { NSPANS = 255 };
122     QT_FT_Span spans[NSPANS];
123     int current_span;
124     ProcessSpans blend;
125
126     int opacity;
127
128     uint color;
129     uint *pixels;
130     int ppl;
131
132     Direction lastDir;
133     Point lastPixel;
134     bool lastAxisAligned;
135
136 private:
137     void setup();
138
139     void renderCubic(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, int caps);
140     void renderCubicSubdivision(PointF *points, int level, int caps);
141     // used for closed subpaths
142     void calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal ry2);
143
144 public:
145     bool clipLine(qreal &x1, qreal &y1, qreal &x2, qreal &y2);
146 };
147
148 QT_END_NAMESPACE
149
150 QT_END_HEADER
151
152 #endif // QCOSMETICLINE_H