author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
||
60 |
QT_BEGIN_NAMESPACE |
|
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 |
{ |
|
105 |
qfixed x; |
|
106 |
qfixed y; |
|
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 |
||
118 |
qreal qt_t_for_arc_angle(qreal angle); |
|
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 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
127 |
// qtransform.cpp |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
128 |
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
129 |
|
0 | 130 |
class Q_GUI_EXPORT QStrokerOps |
131 |
{ |
|
132 |
public: |
|
133 |
struct Element { |
|
134 |
QPainterPath::ElementType type; |
|
135 |
qfixed x; |
|
136 |
qfixed y; |
|
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 |
||
148 |
void setMoveToHook(qStrokerMoveToHook moveToHook) { m_moveTo = moveToHook; } |
|
149 |
void setLineToHook(qStrokerLineToHook lineToHook) { m_lineTo = lineToHook; } |
|
150 |
void setCubicToHook(qStrokerCubicToHook cubicToHook) { m_cubicTo = cubicToHook; } |
|
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 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
167 |
void setCurveThresholdFromTransform(const QTransform &transform) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
168 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
169 |
qreal scale; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
170 |
qt_scaleForTransform(transform, &scale); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
171 |
setCurveThreshold(scale == 0 ? qreal(0.5) : (qreal(0.5) / scale)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
172 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
173 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
174 |
void setCurveThreshold(qfixed threshold) { m_curveThreshold = threshold; } |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
175 |
qfixed curveThreshold() const { return m_curveThreshold; } |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
176 |
|
0 | 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; |
|
183 |
QDataBuffer<Element> m_elements; |
|
184 |
||
185 |
QRectF m_clip_rect; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
186 |
qfixed m_curveThreshold; |
0 | 187 |
|
188 |
void *m_customData; |
|
189 |
qStrokerMoveToHook m_moveTo; |
|
190 |
qStrokerLineToHook m_lineTo; |
|
191 |
qStrokerCubicToHook m_cubicTo; |
|
192 |
||
193 |
}; |
|
194 |
||
195 |
class Q_GUI_EXPORT QStroker : public QStrokerOps |
|
196 |
{ |
|
197 |
public: |
|
198 |
||
199 |
enum LineJoinMode { |
|
200 |
FlatJoin, |
|
201 |
SquareJoin, |
|
202 |
MiterJoin, |
|
203 |
RoundJoin, |
|
204 |
RoundCap, |
|
205 |
SvgMiterJoin |
|
206 |
}; |
|
207 |
||
208 |
QStroker(); |
|
209 |
~QStroker(); |
|
210 |
||
211 |
void setStrokeWidth(qfixed width) { m_strokeWidth = width; } |
|
212 |
qfixed strokeWidth() const { return m_strokeWidth; } |
|
213 |
||
214 |
void setCapStyle(Qt::PenCapStyle capStyle) { m_capStyle = joinModeForCap(capStyle); } |
|
215 |
Qt::PenCapStyle capStyle() const { return capForJoinMode(m_capStyle); } |
|
216 |
LineJoinMode capStyleMode() const { return m_capStyle; } |
|
217 |
||
218 |
void setJoinStyle(Qt::PenJoinStyle style) { m_joinStyle = joinModeForJoin(style); } |
|
219 |
Qt::PenJoinStyle joinStyle() const { return joinForJoinMode(m_joinStyle); } |
|
220 |
LineJoinMode joinStyleMode() const { return m_joinStyle; } |
|
221 |
||
222 |
void setMiterLimit(qfixed length) { m_miterLimit = length; } |
|
223 |
qfixed miterLimit() const { return m_miterLimit; } |
|
224 |
||
225 |
void joinPoints(qfixed x, qfixed y, const QLineF &nextLine, LineJoinMode join); |
|
226 |
inline void emitMoveTo(qfixed x, qfixed y); |
|
227 |
inline void emitLineTo(qfixed x, qfixed y); |
|
228 |
inline void emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey); |
|
229 |
||
230 |
protected: |
|
231 |
static Qt::PenCapStyle capForJoinMode(LineJoinMode mode); |
|
232 |
static LineJoinMode joinModeForCap(Qt::PenCapStyle); |
|
233 |
||
234 |
static Qt::PenJoinStyle joinForJoinMode(LineJoinMode mode); |
|
235 |
static LineJoinMode joinModeForJoin(Qt::PenJoinStyle joinStyle); |
|
236 |
||
237 |
virtual void processCurrentSubpath(); |
|
238 |
||
239 |
qfixed m_strokeWidth; |
|
240 |
qfixed m_miterLimit; |
|
241 |
||
242 |
LineJoinMode m_capStyle; |
|
243 |
LineJoinMode m_joinStyle; |
|
244 |
||
245 |
qfixed m_back1X; |
|
246 |
qfixed m_back1Y; |
|
247 |
||
248 |
qfixed m_back2X; |
|
249 |
qfixed m_back2Y; |
|
250 |
}; |
|
251 |
||
252 |
class Q_GUI_EXPORT QDashStroker : public QStrokerOps |
|
253 |
{ |
|
254 |
public: |
|
255 |
QDashStroker(QStroker *stroker); |
|
256 |
||
257 |
QStroker *stroker() const { return m_stroker; } |
|
258 |
||
259 |
static QVector<qfixed> patternForStyle(Qt::PenStyle style); |
|
260 |
||
261 |
void setDashPattern(const QVector<qfixed> &dashPattern) { m_dashPattern = dashPattern; } |
|
262 |
QVector<qfixed> dashPattern() const { return m_dashPattern; } |
|
263 |
||
264 |
void setDashOffset(qreal offset) { m_dashOffset = offset; } |
|
265 |
qreal dashOffset() const { return m_dashOffset; } |
|
266 |
||
267 |
virtual void begin(void *data); |
|
268 |
virtual void end(); |
|
269 |
||
270 |
inline void setStrokeWidth(qreal width) { m_stroke_width = width; } |
|
271 |
inline void setMiterLimit(qreal limit) { m_miter_limit = limit; } |
|
272 |
||
273 |
protected: |
|
274 |
virtual void processCurrentSubpath(); |
|
275 |
||
276 |
QStroker *m_stroker; |
|
277 |
QVector<qfixed> m_dashPattern; |
|
278 |
qreal m_dashOffset; |
|
279 |
||
280 |
qreal m_stroke_width; |
|
281 |
qreal m_miter_limit; |
|
282 |
}; |
|
283 |
||
284 |
||
285 |
/******************************************************************************* |
|
286 |
* QStrokerOps inline membmers |
|
287 |
*/ |
|
288 |
||
289 |
inline void QStrokerOps::emitMoveTo(qfixed x, qfixed y) |
|
290 |
{ |
|
291 |
Q_ASSERT(m_moveTo); |
|
292 |
m_moveTo(x, y, m_customData); |
|
293 |
} |
|
294 |
||
295 |
inline void QStrokerOps::emitLineTo(qfixed x, qfixed y) |
|
296 |
{ |
|
297 |
Q_ASSERT(m_lineTo); |
|
298 |
m_lineTo(x, y, m_customData); |
|
299 |
} |
|
300 |
||
301 |
inline void QStrokerOps::emitCubicTo(qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey) |
|
302 |
{ |
|
303 |
Q_ASSERT(m_cubicTo); |
|
304 |
m_cubicTo(c1x, c1y, c2x, c2y, ex, ey, m_customData); |
|
305 |
} |
|
306 |
||
307 |
inline void QStrokerOps::moveTo(qfixed x, qfixed y) |
|
308 |
{ |
|
309 |
if (m_elements.size()>1) |
|
310 |
processCurrentSubpath(); |
|
311 |
m_elements.reset(); |
|
312 |
Element e = { QPainterPath::MoveToElement, x, y }; |
|
313 |
m_elements.add(e); |
|
314 |
} |
|
315 |
||
316 |
inline void QStrokerOps::lineTo(qfixed x, qfixed y) |
|
317 |
{ |
|
318 |
Element e = { QPainterPath::LineToElement, x, y }; |
|
319 |
m_elements.add(e); |
|
320 |
} |
|
321 |
||
322 |
inline void QStrokerOps::cubicTo(qfixed x1, qfixed y1, qfixed x2, qfixed y2, qfixed ex, qfixed ey) |
|
323 |
{ |
|
324 |
Element c1 = { QPainterPath::CurveToElement, x1, y1 }; |
|
325 |
Element c2 = { QPainterPath::CurveToDataElement, x2, y2 }; |
|
326 |
Element e = { QPainterPath::CurveToDataElement, ex, ey }; |
|
327 |
m_elements.add(c1); |
|
328 |
m_elements.add(c2); |
|
329 |
m_elements.add(e); |
|
330 |
} |
|
331 |
||
332 |
/******************************************************************************* |
|
333 |
* QStroker inline members |
|
334 |
*/ |
|
335 |
inline void QStroker::emitMoveTo(qfixed x, qfixed y) |
|
336 |
{ |
|
337 |
m_back2X = m_back1X; |
|
338 |
m_back2Y = m_back1Y; |
|
339 |
m_back1X = x; |
|
340 |
m_back1Y = y; |
|
341 |
QStrokerOps::emitMoveTo(x, y); |
|
342 |
} |
|
343 |
||
344 |
inline void QStroker::emitLineTo(qfixed x, qfixed y) |
|
345 |
{ |
|
346 |
m_back2X = m_back1X; |
|
347 |
m_back2Y = m_back1Y; |
|
348 |
m_back1X = x; |
|
349 |
m_back1Y = y; |
|
350 |
QStrokerOps::emitLineTo(x, y); |
|
351 |
} |
|
352 |
||
353 |
inline void QStroker::emitCubicTo(qfixed c1x, qfixed c1y, |
|
354 |
qfixed c2x, qfixed c2y, |
|
355 |
qfixed ex, qfixed ey) |
|
356 |
{ |
|
357 |
if (c2x == ex && c2y == ey) { |
|
358 |
if (c1x == ex && c1y == ey) { |
|
359 |
m_back2X = m_back1X; |
|
360 |
m_back2Y = m_back1Y; |
|
361 |
} else { |
|
362 |
m_back2X = c1x; |
|
363 |
m_back2Y = c1y; |
|
364 |
} |
|
365 |
} else { |
|
366 |
m_back2X = c2x; |
|
367 |
m_back2Y = c2y; |
|
368 |
} |
|
369 |
m_back1X = ex; |
|
370 |
m_back1Y = ey; |
|
371 |
QStrokerOps::emitCubicTo(c1x, c1y, c2x, c2y, ex, ey); |
|
372 |
} |
|
373 |
||
374 |
/******************************************************************************* |
|
375 |
* QDashStroker inline members |
|
376 |
*/ |
|
377 |
inline void QDashStroker::begin(void *data) |
|
378 |
{ |
|
379 |
if (m_stroker) |
|
380 |
m_stroker->begin(data); |
|
381 |
QStrokerOps::begin(data); |
|
382 |
} |
|
383 |
||
384 |
inline void QDashStroker::end() |
|
385 |
{ |
|
386 |
QStrokerOps::end(); |
|
387 |
if (m_stroker) |
|
388 |
m_stroker->end(); |
|
389 |
} |
|
390 |
||
391 |
QT_END_NAMESPACE |
|
392 |
||
393 |
#endif // QSTROKER_P_H |