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
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
4#ifndef QOUTLINEMAPPER_P_H
5#define QOUTLINEMAPPER_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 <QtCore/qrect.h>
20
21#include <QtGui/qtransform.h>
22#include <QtGui/qpainterpath.h>
23
24#define QT_FT_BEGIN_HEADER
25#define QT_FT_END_HEADER
26
27#include <private/qrasterdefs_p.h>
28#include <private/qdatabuffer_p.h>
29#include "qpaintengineex_p.h"
30
32
33// These limitations comes from qrasterizer.cpp, qcosmeticstroker.cpp, and qgrayraster.c.
34// Any higher and rasterization of shapes will produce incorrect results.
35#if Q_PROCESSOR_WORDSIZE == 8
36constexpr int QT_RASTER_COORD_LIMIT = ((1<<23) - 1); // F24dot8 in qgrayraster.c
37#else
38constexpr int QT_RASTER_COORD_LIMIT = ((1<<15) - 1); // F16dot16 in qrasterizer.cpp and qcosmeticstroker.cpp
39#endif
40//#define QT_DEBUG_CONVERT
41
42Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
43
44/********************************************************************************
45 * class QOutlineMapper
46 *
47 * Used to map between QPainterPath and the QT_FT_Outline structure used by the
48 * freetype scanconverter.
49 *
50 * The outline mapper uses a path iterator to get points from the path,
51 * so that it is possible to transform the points as they are converted. The
52 * callback can be a noop, translate or full-fledged xform. (Tests indicated
53 * that using a C callback was low cost).
54 */
56{
57public:
60 m_elements(0),
61 m_points(0),
62 m_tags(0),
63 m_contours(0),
65 {
66 }
67
73 void setMatrix(const QTransform &m)
74 {
75 m_transform = m;
76
79 m_curve_threshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale);
80 }
81
82 void setClipRect(QRect clipRect);
83
85 {
86#ifdef QT_DEBUG_CONVERT
87 printf("QOutlineMapper::beginOutline rule=%d\n", fillRule);
88#endif
89 m_valid = true;
92 m_points.reset();
93 m_tags.reset();
95 m_outline.flags = fillRule == Qt::WindingFill
99 }
100
101 void endOutline();
102
104
106
107 inline void moveTo(const QPointF &pt) {
108#ifdef QT_DEBUG_CONVERT
109 printf("QOutlineMapper::moveTo() (%f, %f)\n", pt.x(), pt.y());
110#endif
111 closeSubpath();
113 m_elements << pt;
115 }
116
117 inline void lineTo(const QPointF &pt) {
118#ifdef QT_DEBUG_CONVERT
119 printf("QOutlineMapper::lineTo() (%f, %f)\n", pt.x(), pt.y());
120#endif
121 m_elements.add(pt);
123 }
124
125 void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep);
126
127 inline void closeSubpath() {
128 int element_count = m_elements.size();
129 if (element_count > 0) {
130 if (m_elements.at(element_count-1) != m_elements.at(m_subpath_start)) {
131#ifdef QT_DEBUG_CONVERT
132 printf(" - implicitly closing\n");
133#endif
134 // Put the object on the stack to avoid the odd case where
135 // lineTo reallocs the databuffer and the QPointF & will
136 // be invalidated.
138
139 // only do lineTo if we have element_type array...
140 if (m_element_types.size())
141 lineTo(pt);
142 else
143 m_elements << pt;
144
145 }
146 }
147 }
148
150 if (m_valid)
151 return &m_outline;
152 return nullptr;
153 }
154
157
159
160public:
161 QDataBuffer<QPainterPath::ElementType> m_element_types;
162 QDataBuffer<QPointF> m_elements;
163 QDataBuffer<QT_FT_Vector> m_points;
164 QDataBuffer<char> m_tags;
165 QDataBuffer<int> m_contours;
166
169 QRectF controlPointRect; // only valid after endOutline()
170
172
174
176
178
181};
182
184
185#endif // QOUTLINEMAPPER_P_H
void add(const Type &t)
Type & at(qsizetype i)
qsizetype size() const
Type * data() const
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)
\inmodule QtGui
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
Combined button and popup list for selecting options.
@ WindingFill
const GLfloat * m
GLsizei GLenum GLenum * types
GLenum GLenum GLsizei count
GLuint GLenum GLenum transform
GLfixed GLfixed GLint GLint GLfixed points
GLsizei const GLchar *const * path
GLenum GLenum GLenum GLenum GLenum scale
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
QT_BEGIN_NAMESPACE constexpr int QT_RASTER_COORD_LIMIT
#define QT_FT_OUTLINE_EVEN_ODD_FILL
#define QT_FT_OUTLINE_NONE
double qreal
Definition qtypes.h:187
QObject::connect nullptr