1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QOUTLINEMAPPER_P_H
|
---|
43 | #define QOUTLINEMAPPER_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include <QtCore/qrect.h>
|
---|
57 |
|
---|
58 | #include <QtGui/qtransform.h>
|
---|
59 | #include <QtGui/qpainterpath.h>
|
---|
60 |
|
---|
61 | #define QT_FT_BEGIN_HEADER
|
---|
62 | #define QT_FT_END_HEADER
|
---|
63 |
|
---|
64 | #include <private/qrasterdefs_p.h>
|
---|
65 | #include <private/qdatabuffer_p.h>
|
---|
66 | #include "qpaintengineex_p.h"
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | // This limitations comes from qgrayraster.c. Any higher and
|
---|
71 | // rasterization of shapes will produce incorrect results.
|
---|
72 | const int QT_RASTER_COORD_LIMIT = 32767;
|
---|
73 |
|
---|
74 | //#define QT_DEBUG_CONVERT
|
---|
75 |
|
---|
76 | /********************************************************************************
|
---|
77 | * class QOutlineMapper
|
---|
78 | *
|
---|
79 | * Used to map between QPainterPath and the QT_FT_Outline structure used by the
|
---|
80 | * freetype scanconvertor.
|
---|
81 | *
|
---|
82 | * The outline mapper uses a path iterator to get points from the path,
|
---|
83 | * so that it is possible to transform the points as they are converted. The
|
---|
84 | * callback can be a noop, translate or full-fledged xform. (Tests indicated
|
---|
85 | * that using a C callback was low cost).
|
---|
86 | */
|
---|
87 | class QOutlineMapper
|
---|
88 | {
|
---|
89 | public:
|
---|
90 | QOutlineMapper() :
|
---|
91 | m_element_types(0),
|
---|
92 | m_elements(0),
|
---|
93 | m_elements_dev(0),
|
---|
94 | m_points(0),
|
---|
95 | m_tags(0),
|
---|
96 | m_contours(0),
|
---|
97 | m_polygon_dev(0),
|
---|
98 | m_in_clip_elements(false),
|
---|
99 | m_round_coords(false)
|
---|
100 | {
|
---|
101 | }
|
---|
102 |
|
---|
103 | /*!
|
---|
104 | Sets up the matrix to be used for conversion. This also
|
---|
105 | sets up the qt_path_iterator function that is used as a callback
|
---|
106 | to get points.
|
---|
107 | */
|
---|
108 | void setMatrix(const QTransform &m)
|
---|
109 | {
|
---|
110 | m_m11 = m.m11();
|
---|
111 | m_m12 = m.m12();
|
---|
112 | m_m13 = m.m13();
|
---|
113 | m_m21 = m.m21();
|
---|
114 | m_m22 = m.m22();
|
---|
115 | m_m23 = m.m23();
|
---|
116 | m_m33 = m.m33();
|
---|
117 | m_dx = m.dx();
|
---|
118 | m_dy = m.dy();
|
---|
119 | m_txop = m.type();
|
---|
120 | }
|
---|
121 |
|
---|
122 | void beginOutline(Qt::FillRule fillRule)
|
---|
123 | {
|
---|
124 | #ifdef QT_DEBUG_CONVERT
|
---|
125 | printf("QOutlineMapper::beginOutline rule=%d\n", fillRule);
|
---|
126 | #endif
|
---|
127 | m_valid = true;
|
---|
128 | m_elements.reset();
|
---|
129 | m_elements_dev.reset();
|
---|
130 | m_element_types.reset();
|
---|
131 | m_points.reset();
|
---|
132 | m_tags.reset();
|
---|
133 | m_contours.reset();
|
---|
134 | m_outline.flags = fillRule == Qt::WindingFill
|
---|
135 | ? QT_FT_OUTLINE_NONE
|
---|
136 | : QT_FT_OUTLINE_EVEN_ODD_FILL;
|
---|
137 | m_subpath_start = 0;
|
---|
138 | }
|
---|
139 |
|
---|
140 | void endOutline();
|
---|
141 |
|
---|
142 | void clipElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
|
---|
143 |
|
---|
144 | void convertElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
|
---|
145 |
|
---|
146 | inline void moveTo(const QPointF &pt) {
|
---|
147 | #ifdef QT_DEBUG_CONVERT
|
---|
148 | printf("QOutlineMapper::moveTo() (%f, %f)\n", pt.x(), pt.y());
|
---|
149 | #endif
|
---|
150 | closeSubpath();
|
---|
151 | m_subpath_start = m_elements.size();
|
---|
152 | m_elements << pt;
|
---|
153 | m_element_types << QPainterPath::MoveToElement;
|
---|
154 | }
|
---|
155 |
|
---|
156 | inline void lineTo(const QPointF &pt) {
|
---|
157 | #ifdef QT_DEBUG_CONVERT
|
---|
158 | printf("QOutlineMapper::lineTo() (%f, %f)\n", pt.x(), pt.y());
|
---|
159 | #endif
|
---|
160 | m_elements.add(pt);
|
---|
161 | m_element_types << QPainterPath::LineToElement;
|
---|
162 | }
|
---|
163 |
|
---|
164 | inline void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep) {
|
---|
165 | #ifdef QT_DEBUG_CONVERT
|
---|
166 | printf("QOutlineMapper::curveTo() (%f, %f)\n", ep.x(), ep.y());
|
---|
167 | #endif
|
---|
168 | m_elements << cp1 << cp2 << ep;
|
---|
169 | m_element_types << QPainterPath::CurveToElement
|
---|
170 | << QPainterPath::CurveToDataElement
|
---|
171 | << QPainterPath::CurveToDataElement;
|
---|
172 | }
|
---|
173 |
|
---|
174 | inline void closeSubpath() {
|
---|
175 | int element_count = m_elements.size();
|
---|
176 | if (element_count > 0) {
|
---|
177 | if (m_elements.at(element_count-1) != m_elements.at(m_subpath_start)) {
|
---|
178 | #ifdef QT_DEBUG_CONVERT
|
---|
179 | printf(" - implicitly closing\n");
|
---|
180 | #endif
|
---|
181 | // Put the object on the stack to avoid the odd case where
|
---|
182 | // lineTo reallocs the databuffer and the QPointF & will
|
---|
183 | // be invalidated.
|
---|
184 | QPointF pt = m_elements.at(m_subpath_start);
|
---|
185 |
|
---|
186 | // only do lineTo if we have element_type array...
|
---|
187 | if (m_element_types.size())
|
---|
188 | lineTo(pt);
|
---|
189 | else
|
---|
190 | m_elements << pt;
|
---|
191 |
|
---|
192 | }
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | QT_FT_Outline *outline() {
|
---|
197 | if (m_valid)
|
---|
198 | return &m_outline;
|
---|
199 | return 0;
|
---|
200 | }
|
---|
201 |
|
---|
202 | QT_FT_Outline *convertPath(const QPainterPath &path);
|
---|
203 | QT_FT_Outline *convertPath(const QVectorPath &path);
|
---|
204 |
|
---|
205 | void setCoordinateRounding(bool coordinateRounding) { m_round_coords = coordinateRounding; }
|
---|
206 |
|
---|
207 | inline QPainterPath::ElementType *elementTypes() const { return m_element_types.size() == 0 ? 0 : m_element_types.data(); }
|
---|
208 |
|
---|
209 | public:
|
---|
210 | QDataBuffer<QPainterPath::ElementType> m_element_types;
|
---|
211 | QDataBuffer<QPointF> m_elements;
|
---|
212 | QDataBuffer<QPointF> m_elements_dev;
|
---|
213 | QDataBuffer<QT_FT_Vector> m_points;
|
---|
214 | QDataBuffer<char> m_tags;
|
---|
215 | QDataBuffer<int> m_contours;
|
---|
216 |
|
---|
217 | QRect m_clip_rect;
|
---|
218 | QDataBuffer<QPointF> m_polygon_dev;
|
---|
219 |
|
---|
220 | QRectF controlPointRect; // only valid after endOutline()
|
---|
221 |
|
---|
222 | QT_FT_Outline m_outline;
|
---|
223 | uint m_txop;
|
---|
224 |
|
---|
225 | int m_subpath_start;
|
---|
226 |
|
---|
227 | // Matrix
|
---|
228 | qreal m_m11;
|
---|
229 | qreal m_m12;
|
---|
230 | qreal m_m13;
|
---|
231 | qreal m_m21;
|
---|
232 | qreal m_m22;
|
---|
233 | qreal m_m23;
|
---|
234 | qreal m_m33;
|
---|
235 | qreal m_dx;
|
---|
236 | qreal m_dy;
|
---|
237 |
|
---|
238 | bool m_valid;
|
---|
239 | bool m_in_clip_elements;
|
---|
240 |
|
---|
241 | private:
|
---|
242 | bool m_round_coords;
|
---|
243 | };
|
---|
244 |
|
---|
245 | QT_END_NAMESPACE
|
---|
246 |
|
---|
247 | #endif // QOUTLINEMAPPER_P_H
|
---|