1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QOUTLINEMAPPER_P_H
43 #define QOUTLINEMAPPER_P_H
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.
56 #include <QtCore/qrect.h>
58 #include <QtGui/qtransform.h>
59 #include <QtGui/qpainterpath.h>
61 #define QT_FT_BEGIN_HEADER
62 #define QT_FT_END_HEADER
64 #include <private/qrasterdefs_p.h>
65 #include <private/qdatabuffer_p.h>
66 #include "qpaintengineex_p.h"
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;
74 //#define QT_DEBUG_CONVERT
76 Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
78 /********************************************************************************
79 * class QOutlineMapper
81 * Used to map between QPainterPath and the QT_FT_Outline structure used by the
82 * freetype scanconvertor.
84 * The outline mapper uses a path iterator to get points from the path,
85 * so that it is possible to transform the points as they are converted. The
86 * callback can be a noop, translate or full-fledged xform. (Tests indicated
87 * that using a C callback was low cost).
98 m_in_clip_elements(false),
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
108 void setMatrix(const QTransform &m)
122 qt_scaleForTransform(m, &scale);
123 m_curve_threshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale);
126 void beginOutline(Qt::FillRule fillRule)
128 #ifdef QT_DEBUG_CONVERT
129 printf("QOutlineMapper::beginOutline rule=%d\n", fillRule);
133 m_element_types.reset();
137 m_outline.flags = fillRule == Qt::WindingFill
139 : QT_FT_OUTLINE_EVEN_ODD_FILL;
145 void clipElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
147 void convertElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
149 inline void moveTo(const QPointF &pt) {
150 #ifdef QT_DEBUG_CONVERT
151 printf("QOutlineMapper::moveTo() (%f, %f)\n", pt.x(), pt.y());
154 m_subpath_start = m_elements.size();
156 m_element_types << QPainterPath::MoveToElement;
159 inline void lineTo(const QPointF &pt) {
160 #ifdef QT_DEBUG_CONVERT
161 printf("QOutlineMapper::lineTo() (%f, %f)\n", pt.x(), pt.y());
164 m_element_types << QPainterPath::LineToElement;
167 void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep);
169 inline void closeSubpath() {
170 int element_count = m_elements.size();
171 if (element_count > 0) {
172 if (m_elements.at(element_count-1) != m_elements.at(m_subpath_start)) {
173 #ifdef QT_DEBUG_CONVERT
174 printf(" - implicitly closing\n");
176 // Put the object on the stack to avoid the odd case where
177 // lineTo reallocs the databuffer and the QPointF & will
179 QPointF pt = m_elements.at(m_subpath_start);
181 // only do lineTo if we have element_type array...
182 if (m_element_types.size())
191 QT_FT_Outline *outline() {
197 QT_FT_Outline *convertPath(const QPainterPath &path);
198 QT_FT_Outline *convertPath(const QVectorPath &path);
200 void setCoordinateRounding(bool coordinateRounding) { m_round_coords = coordinateRounding; }
202 inline QPainterPath::ElementType *elementTypes() const { return m_element_types.size() == 0 ? 0 : m_element_types.data(); }
205 QDataBuffer<QPainterPath::ElementType> m_element_types;
206 QDataBuffer<QPointF> m_elements;
207 QDataBuffer<QT_FT_Vector> m_points;
208 QDataBuffer<char> m_tags;
209 QDataBuffer<int> m_contours;
212 QRectF controlPointRect; // only valid after endOutline()
214 QT_FT_Outline m_outline;
230 qreal m_curve_threshold;
233 bool m_in_clip_elements;
241 #endif // QOUTLINEMAPPER_P_H