1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCOSMETICSTROKER_P_H
5#define QCOSMETICSTROKER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include <private/qdrawhelper_p.h>
20#include <private/qvectorpath_p.h>
21#include <private/qpaintengine_raster_p.h>
22#include <qpen.h>
23
24QT_BEGIN_NAMESPACE
25
26
27class QCosmeticStroker;
28
29
30typedef bool (*StrokeLine)(QCosmeticStroker *stroker, qreal x1, qreal y1, qreal x2, qreal y2, int caps);
31
32class QCosmeticStroker
33{
34public:
35 struct Point {
36 int x;
37 int y;
38 };
39 struct PointF {
40 qreal x;
41 qreal y;
42 };
43
44 enum Caps {
45 NoCaps = 0,
46 CapBegin = 0x1,
47 CapEnd = 0x2
48 };
49
50 // used to avoid drop outs or duplicated points
51 enum Direction {
52 NoDirection = 0,
53 TopToBottom = 0x1,
54 BottomToTop = 0x2,
55 LeftToRight = 0x4,
56 RightToLeft = 0x8,
57 VerticalMask = 0x3,
58 HorizontalMask = 0xc
59 };
60
61 QCosmeticStroker(QRasterPaintEngineState *s, const QRect &dr, const QRect &dr_unclipped)
62 : state(s),
63 deviceRect(dr_unclipped),
64 clip(dr),
65 pattern(nullptr),
66 reversePattern(nullptr),
67 patternSize(0),
68 patternLength(0),
69 patternOffset(0),
70 current_span(0),
71 lastDir(NoDirection),
72 lastAxisAligned(false)
73 { setup(); }
74
75 ~QCosmeticStroker() { free(ptr: pattern); free(ptr: reversePattern); }
76
77 void drawLine(const QPointF &p1, const QPointF &p2);
78 void drawPath(const QVectorPath &path);
79 void drawPoints(const QPoint *points, int num);
80 void drawPoints(const QPointF *points, int num);
81
82
83 QRasterPaintEngineState *state;
84 QRect deviceRect;
85 QRect clip;
86 // clip bounds in real
87 qreal xmin, xmax;
88 qreal ymin, ymax;
89
90 StrokeLine stroke;
91 bool drawCaps;
92
93 int *pattern;
94 int *reversePattern;
95 int patternSize;
96 int patternLength;
97 int patternOffset;
98
99 enum { NSPANS = 255 };
100 QT_FT_Span spans[NSPANS];
101 int current_span;
102 ProcessSpans blend;
103
104 int opacity;
105
106 uint color;
107 uint *pixels;
108 int ppl;
109
110 Direction lastDir;
111 Point lastPixel;
112 bool lastAxisAligned;
113
114private:
115 void setup();
116
117 void renderCubic(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, int caps);
118 void renderCubicSubdivision(PointF *points, int level, int caps);
119 // used for closed subpaths
120 void calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal ry2);
121
122public:
123 bool clipLine(qreal &x1, qreal &y1, qreal &x2, qreal &y2);
124};
125
126QT_END_NAMESPACE
127
128#endif // QCOSMETICLINE_H
129

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