1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCOSMETICSTROKER_P_H
41#define QCOSMETICSTROKER_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtGui/private/qtguiglobal_p.h>
55#include <private/qdrawhelper_p.h>
56#include <private/qvectorpath_p.h>
57#include <private/qpaintengine_raster_p.h>
58#include <qpen.h>
59
60QT_BEGIN_NAMESPACE
61
62
63class QCosmeticStroker;
64
65
66typedef bool (*StrokeLine)(QCosmeticStroker *stroker, qreal x1, qreal y1, qreal x2, qreal y2, int caps);
67
68class QCosmeticStroker
69{
70public:
71 struct Point {
72 int x;
73 int y;
74 };
75 struct PointF {
76 qreal x;
77 qreal y;
78 };
79
80 enum Caps {
81 NoCaps = 0,
82 CapBegin = 0x1,
83 CapEnd = 0x2
84 };
85
86 // used to avoid drop outs or duplicated points
87 enum Direction {
88 NoDirection = 0,
89 TopToBottom = 0x1,
90 BottomToTop = 0x2,
91 LeftToRight = 0x4,
92 RightToLeft = 0x8,
93 VerticalMask = 0x3,
94 HorizontalMask = 0xc
95 };
96
97 QCosmeticStroker(QRasterPaintEngineState *s, const QRect &dr, const QRect &dr_unclipped)
98 : state(s),
99 deviceRect(dr_unclipped),
100 clip(dr),
101 pattern(nullptr),
102 reversePattern(nullptr),
103 patternSize(0),
104 patternLength(0),
105 patternOffset(0),
106 legacyRounding(false),
107 current_span(0),
108 lastDir(NoDirection),
109 lastAxisAligned(false)
110 { setup(); }
111
112 ~QCosmeticStroker() { free(ptr: pattern); free(ptr: reversePattern); }
113
114 void setLegacyRoundingEnabled(bool legacyRoundingEnabled) { legacyRounding = legacyRoundingEnabled; }
115
116 void drawLine(const QPointF &p1, const QPointF &p2);
117 void drawPath(const QVectorPath &path);
118 void drawPoints(const QPoint *points, int num);
119 void drawPoints(const QPointF *points, int num);
120
121
122 QRasterPaintEngineState *state;
123 QRect deviceRect;
124 QRect clip;
125 // clip bounds in real
126 qreal xmin, xmax;
127 qreal ymin, ymax;
128
129 StrokeLine stroke;
130 bool drawCaps;
131
132 int *pattern;
133 int *reversePattern;
134 int patternSize;
135 int patternLength;
136 int patternOffset;
137
138 bool legacyRounding;
139
140 enum { NSPANS = 255 };
141 QT_FT_Span spans[NSPANS];
142 int current_span;
143 ProcessSpans blend;
144
145 int opacity;
146
147 uint color;
148 uint *pixels;
149 int ppl;
150
151 Direction lastDir;
152 Point lastPixel;
153 bool lastAxisAligned;
154
155private:
156 void setup();
157
158 void renderCubic(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, int caps);
159 void renderCubicSubdivision(PointF *points, int level, int caps);
160 // used for closed subpaths
161 void calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal ry2);
162
163public:
164 bool clipLine(qreal &x1, qreal &y1, qreal &x2, qreal &y2);
165};
166
167QT_END_NAMESPACE
168
169#endif // QCOSMETICLINE_H
170

source code of qtbase/src/gui/painting/qcosmeticstroker_p.h