Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qstroker_p.h
Go to the documentation of this file.
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 QSTROKER_P_H
5#define QSTROKER_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 "QtGui/qpainterpath.h"
20#include "private/qdatabuffer_p.h"
21#include "private/qnumeric_p.h"
22
24
25// #define QFIXED_IS_26_6
26
27#if defined QFIXED_IS_26_6
28typedef int qfixed;
29#define qt_real_to_fixed(real) qfixed(real * 64)
30#define qt_int_to_fixed(real) qfixed(int(real) << 6)
31#define qt_fixed_to_real(fixed) qreal(fixed / qreal(64))
32#define qt_fixed_to_int(fixed) int(fixed >> 6)
33struct qfixed2d
34{
35 qfixed x;
36 qfixed y;
37
38 bool operator==(const qfixed2d &other) const { return x == other.x && y == other.y; }
39};
40#elif defined QFIXED_IS_32_32
41typedef qint64 qfixed;
42#define qt_real_to_fixed(real) qfixed(real * double(qint64(1) << 32))
43#define qt_fixed_to_real(fixed) qreal(fixed / double(qint64(1) << 32))
44struct qfixed2d
45{
46 qfixed x;
47 qfixed y;
48
49 bool operator==(const qfixed2d &other) const { return x == other.x && y == other.y; }
50};
51#elif defined QFIXED_IS_16_16
52typedef int qfixed;
53#define qt_real_to_fixed(real) qfixed(real * qreal(1 << 16))
54#define qt_fixed_to_real(fixed) qreal(fixed / qreal(1 << 16))
55struct qfixed2d
56{
57 qfixed x;
58 qfixed y;
59
60 bool operator==(const qfixed2d &other) const { return x == other.x && y == other.y; }
61};
62#else
63typedef qreal qfixed;
64#define qt_real_to_fixed(real) qfixed(real)
65#define qt_fixed_to_real(fixed) fixed
67{
70
71 bool isFinite() { return qIsFinite(x) && qIsFinite(y); }
72 bool operator==(const qfixed2d &other) const { return qFuzzyCompare(x, other.x)
73 && qFuzzyCompare(y, other.y); }
74};
75#endif
76
77#define QT_PATH_KAPPA 0.5522847498
78
79QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength,
80 QPointF *controlPoints, int *point_count);
81
83
87 qfixed c2x, qfixed c2y,
88 qfixed ex, qfixed ey,
89 void *data);
90
91// qtransform.cpp
92Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
93
94class Q_GUI_EXPORT QStrokerOps
95{
96public:
97 struct Element {
101
102 inline bool isMoveTo() const { return type == QPainterPath::MoveToElement; }
103 inline bool isLineTo() const { return type == QPainterPath::LineToElement; }
104 inline bool isCurveTo() const { return type == QPainterPath::CurveToElement; }
105
106 operator qfixed2d () { qfixed2d pt = { x, y }; return pt; }
107 };
108
109 QStrokerOps();
110 virtual ~QStrokerOps();
111
115
116 virtual void begin(void *customData);
117 virtual void end();
118
119 inline void moveTo(qfixed x, qfixed y);
120 inline void lineTo(qfixed x, qfixed y);
121 inline void cubicTo(qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey);
122
123 void strokePath(const QPainterPath &path, void *data, const QTransform &matrix);
124 void strokePolygon(const QPointF *points, int pointCount, bool implicit_close,
125 void *data, const QTransform &matrix);
126 void strokeEllipse(const QRectF &ellipse, void *data, const QTransform &matrix);
127
128 QRectF clipRect() const { return m_clip_rect; }
129 void setClipRect(const QRectF &clip) { m_clip_rect = clip; }
130
132 {
133 qreal scale;
135 m_dashThreshold = scale == 0 ? qreal(0.5) : (qreal(0.5) / scale);
136 }
137
138 void setCurveThreshold(qfixed threshold) { m_curveThreshold = threshold; }
139 qfixed curveThreshold() const { return m_curveThreshold; }
140
141protected:
142 inline void emitMoveTo(qfixed x, qfixed y);
143 inline void emitLineTo(qfixed x, qfixed y);
144 inline void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey);
145
146 virtual void processCurrentSubpath() = 0;
147 QDataBuffer<Element> m_elements;
148
152
157
158};
159
160class Q_GUI_EXPORT QStroker : public QStrokerOps
161{
162public:
163
172
173 QStroker();
174 ~QStroker();
175
177 {
178 m_strokeWidth = width;
179 m_curveThreshold = qt_real_to_fixed(qBound(0.00025, 1.0 / qt_fixed_to_real(width), 0.25));
180 }
181 qfixed strokeWidth() const { return m_strokeWidth; }
182
183 void setCapStyle(Qt::PenCapStyle capStyle) { m_capStyle = joinModeForCap(capStyle); }
184 Qt::PenCapStyle capStyle() const { return capForJoinMode(m_capStyle); }
185 LineJoinMode capStyleMode() const { return m_capStyle; }
186
187 void setJoinStyle(Qt::PenJoinStyle style) { m_joinStyle = joinModeForJoin(style); }
188 Qt::PenJoinStyle joinStyle() const { return joinForJoinMode(m_joinStyle); }
189 LineJoinMode joinStyleMode() const { return m_joinStyle; }
190
191 void setMiterLimit(qfixed length) { m_miterLimit = length; }
192 qfixed miterLimit() const { return m_miterLimit; }
193
194 void setForceOpen(bool state) { m_forceOpen = state; }
195 bool forceOpen() const { return m_forceOpen; }
196
197 void joinPoints(qfixed x, qfixed y, const QLineF &nextLine, LineJoinMode join);
198 inline void emitMoveTo(qfixed x, qfixed y);
199 inline void emitLineTo(qfixed x, qfixed y);
200 inline void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey);
201
202protected:
203 static Qt::PenCapStyle capForJoinMode(LineJoinMode mode);
204 static LineJoinMode joinModeForCap(Qt::PenCapStyle);
205
206 static Qt::PenJoinStyle joinForJoinMode(LineJoinMode mode);
207 static LineJoinMode joinModeForJoin(Qt::PenJoinStyle joinStyle);
208
209 void processCurrentSubpath() override;
210
213
216
219
222
224};
225
226class Q_GUI_EXPORT QDashStroker : public QStrokerOps
227{
228public:
229 QDashStroker(QStroker *stroker);
231
232 QStroker *stroker() const { return m_stroker; }
233
234 static QList<qfixed> patternForStyle(Qt::PenStyle style);
235 static int repetitionLimit() { return 10000; }
236
237 void setDashPattern(const QList<qfixed> &dashPattern) { m_dashPattern = dashPattern; }
238 QList<qfixed> dashPattern() const { return m_dashPattern; }
239
240 void setDashOffset(qreal offset) { m_dashOffset = offset; }
241 qreal dashOffset() const { return m_dashOffset; }
242
243 void begin(void *data) override;
244 void end() override;
245
246 inline void setStrokeWidth(qreal width) { m_stroke_width = width; }
247 inline void setMiterLimit(qreal limit) { m_miter_limit = limit; }
248
249protected:
250 void processCurrentSubpath() override;
251
253 QList<qfixed> m_dashPattern;
255
258};
259
260
261/*******************************************************************************
262 * QStrokerOps inline membmers
263 */
264
270
276
277inline void QStrokerOps::emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
278{
280 m_cubicTo(c1x, c1y, c2x, c2y, ex, ey, m_customData);
281}
282
284{
285 if (m_elements.size()>1)
287 m_elements.reset();
289 m_elements.add(e);
290}
291
293{
295 m_elements.add(e);
296}
297
307
308/*******************************************************************************
309 * QStroker inline members
310 */
319
328
330 qfixed c2x, qfixed c2y,
331 qfixed ex, qfixed ey)
332{
333 if (c2x == ex && c2y == ey) {
334 if (c1x == ex && c1y == ey) {
337 } else {
338 m_back2X = c1x;
339 m_back2Y = c1y;
340 }
341 } else {
342 m_back2X = c2x;
343 m_back2Y = c2y;
344 }
345 m_back1X = ex;
346 m_back1Y = ey;
347 QStrokerOps::emitCubicTo(c1x, c1y, c2x, c2y, ex, ey);
348}
349
350/*******************************************************************************
351 * QDashStroker inline members
352 */
353inline void QDashStroker::begin(void *data)
354{
355 if (m_stroker)
358}
359
360inline void QDashStroker::end()
361{
363 if (m_stroker)
364 m_stroker->end();
365}
366
368
369#endif // QSTROKER_P_H
qreal m_miter_limit
Definition qstroker_p.h:257
QStroker * stroker() const
Definition qstroker_p.h:232
void begin(void *data) override
Prepares the stroker.
Definition qstroker_p.h:353
void setMiterLimit(qreal limit)
Definition qstroker_p.h:247
void setDashPattern(const QList< qfixed > &dashPattern)
Definition qstroker_p.h:237
QStroker * m_stroker
Definition qstroker_p.h:252
void setStrokeWidth(qreal width)
Definition qstroker_p.h:246
QList< qfixed > m_dashPattern
Definition qstroker_p.h:253
void setDashOffset(qreal offset)
Definition qstroker_p.h:240
qreal dashOffset() const
Definition qstroker_p.h:241
void end() override
Finishes the stroke.
Definition qstroker_p.h:360
static int repetitionLimit()
Definition qstroker_p.h:235
qreal m_dashOffset
Definition qstroker_p.h:254
QList< qfixed > dashPattern() const
Definition qstroker_p.h:238
qreal m_stroke_width
Definition qstroker_p.h:256
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
Definition qline.h:192
\inmodule QtGui
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
Definition qstroker_p.h:277
QRectF clipRect() const
Definition qstroker_p.h:128
virtual void begin(void *customData)
Prepares the stroker.
Definition qstroker.cpp:171
void setCubicToHook(qStrokerCubicToHook cubicToHook)
Definition qstroker_p.h:114
void moveTo(qfixed x, qfixed y)
Definition qstroker_p.h:283
void setMoveToHook(qStrokerMoveToHook moveToHook)
Definition qstroker_p.h:112
void setCurveThresholdFromTransform(const QTransform &transform)
Definition qstroker_p.h:131
void setLineToHook(qStrokerLineToHook lineToHook)
Definition qstroker_p.h:113
QDataBuffer< Element > m_elements
Definition qstroker_p.h:147
void cubicTo(qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey)
Definition qstroker_p.h:298
void setClipRect(const QRectF &clip)
Definition qstroker_p.h:129
void emitLineTo(qfixed x, qfixed y)
Definition qstroker_p.h:271
virtual void end()
Finishes the stroke.
Definition qstroker.cpp:182
qfixed m_curveThreshold
Definition qstroker_p.h:150
qStrokerLineToHook m_lineTo
Definition qstroker_p.h:155
qfixed m_dashThreshold
Definition qstroker_p.h:151
void * m_customData
Definition qstroker_p.h:153
qStrokerCubicToHook m_cubicTo
Definition qstroker_p.h:156
void setCurveThreshold(qfixed threshold)
Definition qstroker_p.h:138
void emitMoveTo(qfixed x, qfixed y)
Definition qstroker_p.h:265
qfixed curveThreshold() const
Definition qstroker_p.h:139
void lineTo(qfixed x, qfixed y)
Definition qstroker_p.h:292
QRectF m_clip_rect
Definition qstroker_p.h:149
virtual void processCurrentSubpath()=0
qStrokerMoveToHook m_moveTo
Definition qstroker_p.h:154
LineJoinMode m_joinStyle
Definition qstroker_p.h:215
void setStrokeWidth(qfixed width)
Definition qstroker_p.h:176
qfixed m_back1Y
Definition qstroker_p.h:218
qfixed strokeWidth() const
Definition qstroker_p.h:181
void emitLineTo(qfixed x, qfixed y)
Definition qstroker_p.h:320
qfixed m_back2Y
Definition qstroker_p.h:221
void setMiterLimit(qfixed length)
Definition qstroker_p.h:191
void setForceOpen(bool state)
Definition qstroker_p.h:194
LineJoinMode capStyleMode() const
Definition qstroker_p.h:185
bool m_forceOpen
Definition qstroker_p.h:223
qfixed miterLimit() const
Definition qstroker_p.h:192
LineJoinMode m_capStyle
Definition qstroker_p.h:214
Qt::PenJoinStyle joinStyle() const
Definition qstroker_p.h:188
void emitMoveTo(qfixed x, qfixed y)
Definition qstroker_p.h:311
qfixed m_back1X
Definition qstroker_p.h:217
qfixed m_strokeWidth
Definition qstroker_p.h:211
qfixed m_miterLimit
Definition qstroker_p.h:212
void setJoinStyle(Qt::PenJoinStyle style)
Definition qstroker_p.h:187
LineJoinMode joinStyleMode() const
Definition qstroker_p.h:189
bool forceOpen() const
Definition qstroker_p.h:195
void setCapStyle(Qt::PenCapStyle capStyle)
Definition qstroker_p.h:183
qfixed m_back2X
Definition qstroker_p.h:220
Qt::PenCapStyle capStyle() const
Definition qstroker_p.h:184
void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
Definition qstroker_p.h:329
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
rect
[4]
else opt state
[0]
Combined button and popup list for selecting options.
PenJoinStyle
PenCapStyle
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
bool qIsFinite(qfloat16 f) noexcept
Definition qfloat16.h:285
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLuint end
GLuint GLfloat GLfloat GLfloat x1
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLenum type
GLfloat angle
GLenum GLuint GLintptr offset
GLint y
GLuint GLenum GLenum transform
GLfixed GLfixed GLint GLint GLfixed points
GLfixed GLfixed GLfixed y2
GLint limit
GLuint GLenum matrix
GLfixed GLfixed x2
GLsizei const GLchar *const * path
GLenum GLenum GLenum GLenum GLenum scale
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
static void lineToHook(qfixed x, qfixed y, void *data)
Definition qpdf.cpp:575
static void moveToHook(qfixed x, qfixed y, void *data)
Definition qpdf.cpp:564
static void cubicToHook(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
Definition qpdf.cpp:583
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
void(* qStrokerCubicToHook)(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
Definition qstroker_p.h:86
void(* qStrokerLineToHook)(qfixed x, qfixed y, void *data)
Definition qstroker_p.h:85
QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength, QPointF *controlPoints, int *point_count)
Definition qstroker.cpp:816
void(* qStrokerMoveToHook)(qfixed x, qfixed y, void *data)
Definition qstroker_p.h:84
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
qreal qt_t_for_arc_angle(qreal angle)
Definition qstroker.cpp:756
#define qt_fixed_to_real(fixed)
Definition qstroker_p.h:65
#define qt_real_to_fixed(real)
Definition qstroker_p.h:64
QT_BEGIN_NAMESPACE typedef qreal qfixed
Definition qstroker_p.h:63
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
MyCustomStruct c2
QSharedPointer< T > other(t)
[5]
QGraphicsEllipseItem * ellipse
bool isMoveTo() const
Definition qstroker_p.h:102
bool isLineTo() const
Definition qstroker_p.h:103
QPainterPath::ElementType type
Definition qstroker_p.h:98
bool isCurveTo() const
Definition qstroker_p.h:104
qfixed x
Definition qstroker_p.h:68
bool operator==(const qfixed2d &other) const
Definition qstroker_p.h:72
bool isFinite()
Definition qstroker_p.h:71
qfixed y
Definition qstroker_p.h:69