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