Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qoutlinemapper_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// Qt-Security score:significant reason:default
4
5#ifndef QOUTLINEMAPPER_P_H
6#define QOUTLINEMAPPER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20#include <QtCore/qrect.h>
21
22#include <QtGui/qtransform.h>
23#include <QtGui/qpainterpath.h>
24
25#define QT_FT_BEGIN_HEADER
26#define QT_FT_END_HEADER
27
28#include <private/qrasterdefs_p.h>
29#include <private/qdatabuffer_p.h>
31
33
34// These limitations comes from qrasterizer.cpp, qcosmeticstroker.cpp, and qgrayraster.c.
35// Any higher and rasterization of shapes will produce incorrect results.
36#if Q_PROCESSOR_WORDSIZE == 8
37constexpr int QT_RASTER_COORD_LIMIT = ((1<<23) - 1); // F24dot8 in qgrayraster.c
38#else
39constexpr int QT_RASTER_COORD_LIMIT = ((1<<15) - 1); // F16dot16 in qrasterizer.cpp and qcosmeticstroker.cpp
40#endif
41//#define QT_DEBUG_CONVERT
42
43Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
44
45/********************************************************************************
46 * class QOutlineMapper
47 *
48 * Used to map between QPainterPath and the QT_FT_Outline structure used by the
49 * freetype scanconverter.
50 *
51 * The outline mapper uses a path iterator to get points from the path,
52 * so that it is possible to transform the points as they are converted. The
53 * callback can be a noop, translate or full-fledged xform. (Tests indicated
54 * that using a C callback was low cost).
55 */
57{
58public:
61 m_elements(0),
62 m_points(0),
63 m_tags(0),
64 m_contours(0),
66 {
67 }
68
69 /*!
70 Sets up the matrix to be used for conversion. This also
71 sets up the qt_path_iterator function that is used as a callback
72 to get points.
73 */
74 void setMatrix(const QTransform &m)
75 {
76 m_transform = m;
77
78 qreal scale;
79 qt_scaleForTransform(m, &scale);
80 m_curve_threshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale);
81 }
82
83 void setClipRect(QRect clipRect);
84
85 void beginOutline(Qt::FillRule fillRule)
86 {
87#ifdef QT_DEBUG_CONVERT
88 printf("QOutlineMapper::beginOutline rule=%d\n", fillRule);
89#endif
90 m_valid = true;
91 m_elements.reset();
92 m_element_types.reset();
93 m_points.reset();
94 m_tags.reset();
95 m_contours.reset();
96 m_outline.flags = fillRule == Qt::WindingFill
97 ? QT_FT_OUTLINE_NONE
98 : QT_FT_OUTLINE_EVEN_ODD_FILL;
100 }
101
102 void endOutline();
103
104 void clipElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
105
106 void convertElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
107
108 inline void moveTo(const QPointF &pt) {
109#ifdef QT_DEBUG_CONVERT
110 printf("QOutlineMapper::moveTo() (%f, %f)\n", pt.x(), pt.y());
111#endif
113 m_subpath_start = m_elements.size();
114 m_elements << pt;
115 m_element_types << QPainterPath::MoveToElement;
116 }
117
118 inline void lineTo(const QPointF &pt) {
119#ifdef QT_DEBUG_CONVERT
120 printf("QOutlineMapper::lineTo() (%f, %f)\n", pt.x(), pt.y());
121#endif
122 m_elements.add(pt);
123 m_element_types << QPainterPath::LineToElement;
124 }
125
126 void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep);
127
128 inline void closeSubpath() {
129 int element_count = m_elements.size();
130 if (element_count > 0) {
131 if (m_elements.at(element_count-1) != m_elements.at(m_subpath_start)) {
132#ifdef QT_DEBUG_CONVERT
133 printf(" - implicitly closing\n");
134#endif
135 // Put the object on the stack to avoid the odd case where
136 // lineTo reallocs the databuffer and the QPointF & will
137 // be invalidated.
138 QPointF pt = m_elements.at(m_subpath_start);
139
140 // only do lineTo if we have element_type array...
141 if (m_element_types.size())
142 lineTo(pt);
143 else
144 m_elements << pt;
145
146 }
147 }
148 }
149
151 if (m_valid)
152 return &m_outline;
153 return nullptr;
154 }
155
156 QT_FT_Outline *convertPath(const QPainterPath &path);
157 QT_FT_Outline *convertPath(const QVectorPath &path);
158
159 inline QPainterPath::ElementType *elementTypes() const { return m_element_types.size() == 0 ? nullptr : m_element_types.data(); }
160
161public:
167
170 QRectF controlPointRect; // only valid after endOutline()
171
173
175
177
179
182};
183
184QT_END_NAMESPACE
185
186#endif // QOUTLINEMAPPER_P_H
QTransform m_transform
QT_FT_Outline * outline()
void clipElements(const QPointF *points, const QPainterPath::ElementType *types, int count)
QDataBuffer< QT_FT_Vector > m_points
void convertElements(const QPointF *points, const QPainterPath::ElementType *types, int count)
void setMatrix(const QTransform &m)
Sets up the matrix to be used for conversion.
void moveTo(const QPointF &pt)
void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep)
void setClipRect(QRect clipRect)
QDataBuffer< QPointF > m_elements
QPainterPath::ElementType * elementTypes() const
QDataBuffer< char > m_tags
QDataBuffer< int > m_contours
QDataBuffer< QPainterPath::ElementType > m_element_types
QT_FT_Outline m_outline
QT_FT_Outline * convertPath(const QPainterPath &path)
void beginOutline(Qt::FillRule fillRule)
void lineTo(const QPointF &pt)
Combined button and popup list for selecting options.
#define qreal_to_fixed_26_6(f)
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
QT_BEGIN_NAMESPACE constexpr int QT_RASTER_COORD_LIMIT