Qt 4.8
qstroker_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 QSTROKER_P_H
43 #define QSTROKER_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 "QtGui/qpainterpath.h"
57 #include "private/qdatabuffer_p.h"
58 #include "private/qnumeric_p.h"
59 
61 
62 // #define QFIXED_IS_26_6
63 
64 #if defined QFIXED_IS_26_6
65 typedef int qfixed;
66 #define qt_real_to_fixed(real) qfixed(real * 64)
67 #define qt_int_to_fixed(real) qfixed(int(real) << 6)
68 #define qt_fixed_to_real(fixed) qreal(fixed / qreal(64))
69 #define qt_fixed_to_int(fixed) int(fixed >> 6)
70 struct qfixed2d
71 {
72  qfixed x;
73  qfixed y;
74 
75  bool operator==(const qfixed2d &other) const { return x == other.x && y == other.y; }
76 };
77 #elif defined QFIXED_IS_32_32
78 typedef qint64 qfixed;
79 #define qt_real_to_fixed(real) qfixed(real * double(qint64(1) << 32))
80 #define qt_fixed_to_real(fixed) qreal(fixed / double(qint64(1) << 32))
81 struct qfixed2d
82 {
83  qfixed x;
84  qfixed y;
85 
86  bool operator==(const qfixed2d &other) const { return x == other.x && y == other.y; }
87 };
88 #elif defined QFIXED_IS_16_16
89 typedef int qfixed;
90 #define qt_real_to_fixed(real) qfixed(real * qreal(1 << 16))
91 #define qt_fixed_to_real(fixed) qreal(fixed / qreal(1 << 16))
92 struct qfixed2d
93 {
94  qfixed x;
95  qfixed y;
96 
97  bool operator==(const qfixed2d &other) const { return x == other.x && y == other.y; }
98 };
99 #else
100 typedef qreal qfixed;
101 #define qt_real_to_fixed(real) qfixed(real)
102 #define qt_fixed_to_real(fixed) fixed
103 struct qfixed2d
104 {
107 
108  bool operator==(const qfixed2d &other) const { return qFuzzyCompare(x, other.x)
109  && qFuzzyCompare(y, other.y); }
110 };
111 #endif
112 
113 #define QT_PATH_KAPPA 0.5522847498
114 
115 QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength,
116  QPointF *controlPoints, int *point_count);
117 
119 
120 typedef void (*qStrokerMoveToHook)(qfixed x, qfixed y, void *data);
121 typedef void (*qStrokerLineToHook)(qfixed x, qfixed y, void *data);
122 typedef void (*qStrokerCubicToHook)(qfixed c1x, qfixed c1y,
123  qfixed c2x, qfixed c2y,
124  qfixed ex, qfixed ey,
125  void *data);
126 
127 // qtransform.cpp
128 Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
129 
131 {
132 public:
133  struct Element {
137 
138  inline bool isMoveTo() const { return type == QPainterPath::MoveToElement; }
139  inline bool isLineTo() const { return type == QPainterPath::LineToElement; }
140  inline bool isCurveTo() const { return type == QPainterPath::CurveToElement; }
141 
142  operator qfixed2d () { qfixed2d pt = { x, y }; return pt; }
143  };
144 
145  QStrokerOps();
146  virtual ~QStrokerOps();
147 
151 
152  virtual void begin(void *customData);
153  virtual void end();
154 
155  inline void moveTo(qfixed x, qfixed y);
156  inline void lineTo(qfixed x, qfixed y);
157  inline void cubicTo(qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey);
158 
159  void strokePath(const QPainterPath &path, void *data, const QTransform &matrix);
160  void strokePolygon(const QPointF *points, int pointCount, bool implicit_close,
161  void *data, const QTransform &matrix);
162  void strokeEllipse(const QRectF &ellipse, void *data, const QTransform &matrix);
163 
164  QRectF clipRect() const { return m_clip_rect; }
165  void setClipRect(const QRectF &clip) { m_clip_rect = clip; }
166 
168  {
169  qreal scale;
170  qt_scaleForTransform(transform, &scale);
171  m_dashThreshold = scale == 0 ? qreal(0.5) : (qreal(0.5) / scale);
172  }
173 
174  void setCurveThreshold(qfixed threshold) { m_curveThreshold = threshold; }
175  qfixed curveThreshold() const { return m_curveThreshold; }
176 
177 protected:
178  inline void emitMoveTo(qfixed x, qfixed y);
179  inline void emitLineTo(qfixed x, qfixed y);
180  inline void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey);
181 
182  virtual void processCurrentSubpath() = 0;
184 
188 
193 
194 };
195 
197 {
198 public:
199 
207  };
208 
209  QStroker();
210  ~QStroker();
211 
212  void setStrokeWidth(qfixed width) { m_strokeWidth = width; }
213  qfixed strokeWidth() const { return m_strokeWidth; }
214 
215  void setCapStyle(Qt::PenCapStyle capStyle) { m_capStyle = joinModeForCap(capStyle); }
216  Qt::PenCapStyle capStyle() const { return capForJoinMode(m_capStyle); }
217  LineJoinMode capStyleMode() const { return m_capStyle; }
218 
219  void setJoinStyle(Qt::PenJoinStyle style) { m_joinStyle = joinModeForJoin(style); }
220  Qt::PenJoinStyle joinStyle() const { return joinForJoinMode(m_joinStyle); }
221  LineJoinMode joinStyleMode() const { return m_joinStyle; }
222 
223  void setMiterLimit(qfixed length) { m_miterLimit = length; }
224  qfixed miterLimit() const { return m_miterLimit; }
225 
226  void joinPoints(qfixed x, qfixed y, const QLineF &nextLine, LineJoinMode join);
227  inline void emitMoveTo(qfixed x, qfixed y);
228  inline void emitLineTo(qfixed x, qfixed y);
229  inline void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey);
230 
231 protected:
232  static Qt::PenCapStyle capForJoinMode(LineJoinMode mode);
233  static LineJoinMode joinModeForCap(Qt::PenCapStyle);
234 
235  static Qt::PenJoinStyle joinForJoinMode(LineJoinMode mode);
236  static LineJoinMode joinModeForJoin(Qt::PenJoinStyle joinStyle);
237 
238  virtual void processCurrentSubpath();
239 
242 
245 
248 
251 };
252 
254 {
255 public:
256  QDashStroker(QStroker *stroker);
257 
258  QStroker *stroker() const { return m_stroker; }
259 
260  static QVector<qfixed> patternForStyle(Qt::PenStyle style);
261 
262  void setDashPattern(const QVector<qfixed> &dashPattern) { m_dashPattern = dashPattern; }
263  QVector<qfixed> dashPattern() const { return m_dashPattern; }
264 
265  void setDashOffset(qreal offset) { m_dashOffset = offset; }
266  qreal dashOffset() const { return m_dashOffset; }
267 
268  virtual void begin(void *data);
269  virtual void end();
270 
271  inline void setStrokeWidth(qreal width) { m_stroke_width = width; }
272  inline void setMiterLimit(qreal limit) { m_miter_limit = limit; }
273 
274 protected:
275  virtual void processCurrentSubpath();
276 
280 
283 };
284 
285 
286 /*******************************************************************************
287  * QStrokerOps inline membmers
288  */
289 
291 {
292  Q_ASSERT(m_moveTo);
293  m_moveTo(x, y, m_customData);
294 }
295 
297 {
298  Q_ASSERT(m_lineTo);
299  m_lineTo(x, y, m_customData);
300 }
301 
302 inline void QStrokerOps::emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
303 {
304  Q_ASSERT(m_cubicTo);
305  m_cubicTo(c1x, c1y, c2x, c2y, ex, ey, m_customData);
306 }
307 
309 {
310  if (m_elements.size()>1)
311  processCurrentSubpath();
312  m_elements.reset();
314  m_elements.add(e);
315 }
316 
318 {
320  m_elements.add(e);
321 }
322 
323 inline void QStrokerOps::cubicTo(qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey)
324 {
325  Element c1 = { QPainterPath::CurveToElement, x1, y1 };
326  Element c2 = { QPainterPath::CurveToDataElement, x2, y2 };
328  m_elements.add(c1);
329  m_elements.add(c2);
330  m_elements.add(e);
331 }
332 
333 /*******************************************************************************
334  * QStroker inline members
335  */
337 {
338  m_back2X = m_back1X;
339  m_back2Y = m_back1Y;
340  m_back1X = x;
341  m_back1Y = y;
343 }
344 
346 {
347  m_back2X = m_back1X;
348  m_back2Y = m_back1Y;
349  m_back1X = x;
350  m_back1Y = y;
352 }
353 
354 inline void QStroker::emitCubicTo(qfixed c1x, qfixed c1y,
355  qfixed c2x, qfixed c2y,
356  qfixed ex, qfixed ey)
357 {
358  if (c2x == ex && c2y == ey) {
359  if (c1x == ex && c1y == ey) {
360  m_back2X = m_back1X;
361  m_back2Y = m_back1Y;
362  } else {
363  m_back2X = c1x;
364  m_back2Y = c1y;
365  }
366  } else {
367  m_back2X = c2x;
368  m_back2Y = c2y;
369  }
370  m_back1X = ex;
371  m_back1Y = ey;
372  QStrokerOps::emitCubicTo(c1x, c1y, c2x, c2y, ex, ey);
373 }
374 
375 /*******************************************************************************
376  * QDashStroker inline members
377  */
378 inline void QDashStroker::begin(void *data)
379 {
380  if (m_stroker)
381  m_stroker->begin(data);
382  QStrokerOps::begin(data);
383 }
384 
385 inline void QDashStroker::end()
386 {
388  if (m_stroker)
389  m_stroker->end();
390 }
391 
393 
394 #endif // QSTROKER_P_H
bool operator==(const qfixed2d &other) const
Definition: qstroker_p.h:108
qfixed m_back1Y
Definition: qstroker_p.h:247
qStrokerLineToHook m_lineTo
Definition: qstroker_p.h:191
qfixed strokeWidth() const
Definition: qstroker_p.h:213
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
void setClipRect(const QRectF &clip)
Definition: qstroker_p.h:165
QDataBuffer< Element > m_elements
Definition: qstroker_p.h:183
bool isMoveTo() const
Definition: qstroker_p.h:138
double qreal
Definition: qglobal.h:1193
qStrokerMoveToHook m_moveTo
Definition: qstroker_p.h:190
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPainterPath::ElementType type
Definition: qstroker_p.h:134
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
void lineTo(qfixed x, qfixed y)
Definition: qstroker_p.h:317
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
Definition: qstroker_p.h:354
void setDashOffset(qreal offset)
Definition: qstroker_p.h:265
void emitLineTo(qfixed x, qfixed y)
Definition: qstroker_p.h:296
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
void setStrokeWidth(qfixed width)
Definition: qstroker_p.h:212
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
LineJoinMode capStyleMode() const
Definition: qstroker_p.h:217
QRectF m_clip_rect
Definition: qstroker_p.h:185
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey)
Definition: qstroker_p.h:302
void setJoinStyle(Qt::PenJoinStyle style)
Definition: qstroker_p.h:219
qreal qt_t_for_arc_angle(qreal angle)
Definition: qstroker.cpp:796
void(* qStrokerMoveToHook)(qfixed x, qfixed y, void *data)
Definition: qstroker_p.h:120
qStrokerCubicToHook m_cubicTo
Definition: qstroker_p.h:192
void setDashPattern(const QVector< qfixed > &dashPattern)
Definition: qstroker_p.h:262
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setCurveThresholdFromTransform(const QTransform &transform)
Definition: qstroker_p.h:167
QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength, QPointF *controlPoints, int *point_count)
Creates a number of curves for a given arc definition.
Definition: qstroker.cpp:859
void setCurveThreshold(qfixed threshold)
Definition: qstroker_p.h:174
PenStyle
Definition: qnamespace.h:1134
void setCubicToHook(qStrokerCubicToHook cubicToHook)
Definition: qstroker_p.h:150
void cubicTo(qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey)
Definition: qstroker_p.h:323
PenCapStyle
Definition: qnamespace.h:1147
void emitMoveTo(qfixed x, qfixed y)
Definition: qstroker_p.h:336
qfixed m_curveThreshold
Definition: qstroker_p.h:186
void setMiterLimit(qreal limit)
Definition: qstroker_p.h:272
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
bool isLineTo() const
Definition: qstroker_p.h:139
virtual void end()
Finishes the stroke.
Definition: qstroker_p.h:385
static void moveToHook(qfixed x, qfixed y, void *data)
Definition: qpdf.cpp:716
qfixed m_back2Y
Definition: qstroker_p.h:250
void emitMoveTo(qfixed x, qfixed y)
Definition: qstroker_p.h:290
qreal m_dashOffset
Definition: qstroker_p.h:279
#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
qfixed x
Definition: qstroker_p.h:105
qreal dashOffset() const
Definition: qstroker_p.h:266
void * m_customData
Definition: qstroker_p.h:189
virtual void begin(void *data)
Prepares the stroker.
Definition: qstroker_p.h:378
QRectF clipRect() const
Definition: qstroker_p.h:164
void setCapStyle(Qt::PenCapStyle capStyle)
Definition: qstroker_p.h:215
QVector< qfixed > m_dashPattern
Definition: qstroker_p.h:278
static const char * data(const QByteArray &arr)
LineJoinMode m_joinStyle
Definition: qstroker_p.h:244
LineJoinMode joinStyleMode() const
Definition: qstroker_p.h:221
qfixed y
Definition: qstroker_p.h:106
PenJoinStyle
Definition: qnamespace.h:1154
__int64 qint64
Definition: qglobal.h:942
qfixed m_strokeWidth
Definition: qstroker_p.h:240
void(* qStrokerLineToHook)(qfixed x, qfixed y, void *data)
Definition: qstroker_p.h:121
virtual void end()
Finishes the stroke.
Definition: qstroker.cpp:224
qfixed m_miterLimit
Definition: qstroker_p.h:241
qfixed miterLimit() const
Definition: qstroker_p.h:224
qfixed curveThreshold() const
Definition: qstroker_p.h:175
virtual void begin(void *customData)
Prepares the stroker.
Definition: qstroker.cpp:213
qreal angle(const QPointF &p1, const QPointF &p2)
static void cubicToHook(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
Definition: qpdf.cpp:735
QStroker * stroker() const
Definition: qstroker_p.h:258
void setMiterLimit(qfixed length)
Definition: qstroker_p.h:223
QStroker * m_stroker
Definition: qstroker_p.h:277
static void lineToHook(qfixed x, qfixed y, void *data)
Definition: qpdf.cpp:727
qfixed m_back1X
Definition: qstroker_p.h:246
qfixed m_back2X
Definition: qstroker_p.h:249
qreal m_stroke_width
Definition: qstroker_p.h:281
QVector< qfixed > dashPattern() const
Definition: qstroker_p.h:263
bool isCurveTo() const
Definition: qstroker_p.h:140
void setLineToHook(qStrokerLineToHook lineToHook)
Definition: qstroker_p.h:149
qfixed m_dashThreshold
Definition: qstroker_p.h:187
qreal m_miter_limit
Definition: qstroker_p.h:282
void(* qStrokerCubicToHook)(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
Definition: qstroker_p.h:122
void moveTo(qfixed x, qfixed y)
Definition: qstroker_p.h:308
void setMoveToHook(qStrokerMoveToHook moveToHook)
Definition: qstroker_p.h:148
Qt::PenCapStyle capStyle() const
Definition: qstroker_p.h:216
Qt::PenJoinStyle joinStyle() const
Definition: qstroker_p.h:220
static const KeyPair *const end
void emitLineTo(qfixed x, qfixed y)
Definition: qstroker_p.h:345
qreal qfixed
Definition: qstroker_p.h:100
LineJoinMode m_capStyle
Definition: qstroker_p.h:243
void setStrokeWidth(qreal width)
Definition: qstroker_p.h:271
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65