Qt 4.8
qoutlinemapper_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
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  */
88 {
89 public:
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  {
100  }
101 
107  void setMatrix(const QTransform &m)
108  {
109  m_m11 = m.m11();
110  m_m12 = m.m12();
111  m_m13 = m.m13();
112  m_m21 = m.m21();
113  m_m22 = m.m22();
114  m_m23 = m.m23();
115  m_m33 = m.m33();
116  m_dx = m.dx();
117  m_dy = m.dy();
118  m_txop = m.type();
119  }
120 
121  void beginOutline(Qt::FillRule fillRule)
122  {
123 #ifdef QT_DEBUG_CONVERT
124  printf("QOutlineMapper::beginOutline rule=%d\n", fillRule);
125 #endif
126  m_valid = true;
127  m_elements.reset();
130  m_points.reset();
131  m_tags.reset();
132  m_contours.reset();
133  m_outline.flags = fillRule == Qt::WindingFill
136  m_subpath_start = 0;
137  }
138 
139  void endOutline();
140 
141  void clipElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
142 
143  void convertElements(const QPointF *points, const QPainterPath::ElementType *types, int count);
144 
145  inline void moveTo(const QPointF &pt) {
146 #ifdef QT_DEBUG_CONVERT
147  printf("QOutlineMapper::moveTo() (%f, %f)\n", pt.x(), pt.y());
148 #endif
149  closeSubpath();
151  m_elements << pt;
153  }
154 
155  inline void lineTo(const QPointF &pt) {
156 #ifdef QT_DEBUG_CONVERT
157  printf("QOutlineMapper::lineTo() (%f, %f)\n", pt.x(), pt.y());
158 #endif
159  m_elements.add(pt);
161  }
162 
163  inline void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep) {
164 #ifdef QT_DEBUG_CONVERT
165  printf("QOutlineMapper::curveTo() (%f, %f)\n", ep.x(), ep.y());
166 #endif
167  m_elements << cp1 << cp2 << ep;
171  }
172 
173  inline void closeSubpath() {
174  int element_count = m_elements.size();
175  if (element_count > 0) {
176  if (m_elements.at(element_count-1) != m_elements.at(m_subpath_start)) {
177 #ifdef QT_DEBUG_CONVERT
178  printf(" - implicitly closing\n");
179 #endif
180  // Put the object on the stack to avoid the odd case where
181  // lineTo reallocs the databuffer and the QPointF & will
182  // be invalidated.
184 
185  // only do lineTo if we have element_type array...
186  if (m_element_types.size())
187  lineTo(pt);
188  else
189  m_elements << pt;
190 
191  }
192  }
193  }
194 
196  if (m_valid)
197  return &m_outline;
198  return 0;
199  }
200 
201  QT_FT_Outline *convertPath(const QPainterPath &path);
202  QT_FT_Outline *convertPath(const QVectorPath &path);
203 
205 
206 public:
213 
216 
217  QRectF controlPointRect; // only valid after endOutline()
218 
221 
223 
224  // Matrix
234 
235  bool m_valid;
237 };
238 
240 
241 #endif // QOUTLINEMAPPER_P_H
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
void curveTo(const QPointF &cp1, const QPointF &cp2, const QPointF &ep)
#define QT_FT_OUTLINE_EVEN_ODD_FILL
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
QT_FT_Outline m_outline
void lineTo(const QPointF &pt)
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Type * data() const
Definition: qdatabuffer_p.h:84
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void moveTo(const QPointF &pt)
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
FillRule
Definition: qnamespace.h:1485
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
TransformationType type() const
Returns the transformation type of this matrix.
QDataBuffer< QPointF > m_elements_dev
QDataBuffer< QT_FT_Vector > m_points
QDataBuffer< QPointF > m_polygon_dev
QDataBuffer< char > m_tags
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QT_FT_Outline * outline()
QPainterPath::ElementType * elementTypes() const
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const int QT_RASTER_COORD_LIMIT
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.
Type & at(int i)
Definition: qdatabuffer_p.h:86
unsigned int uint
Definition: qglobal.h:996
QDataBuffer< QPointF > m_elements
void add(const Type &t)
Definition: qdatabuffer_p.h:93
static const struct @32 types[]
#define QT_FT_OUTLINE_NONE
void beginOutline(Qt::FillRule fillRule)
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
QDataBuffer< QPainterPath::ElementType > m_element_types
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
void clipElements(const QPointF *points, const QPainterPath::ElementType *types, int count)
QT_FT_Outline * convertPath(const QPainterPath &path)
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
QDataBuffer< int > m_contours
qreal m33() const
Returns the division factor.
Definition: qtransform.h:269
void reset()
Definition: qdatabuffer_p.h:79
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
int size() const
Definition: qdatabuffer_p.h:83