1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QTRIANGULATINGSTROKER_P_H
43 #define QTRIANGULATINGSTROKER_P_H
45 #include <private/qdatabuffer_p.h>
46 #include <qvarlengtharray.h>
47 #include <private/qvectorpath_p.h>
48 #include <private/qbezier_p.h>
49 #include <private/qnumeric_p.h>
50 #include <private/qmath_p.h>
54 class Q_GUI_EXPORT QTriangulatingStroker
57 QTriangulatingStroker() : m_vertices(0), m_cx(0), m_cy(0), m_nvx(0), m_nvy(0), m_width(1), m_miter_limit(2),
58 m_roundness(0), m_sin_theta(0), m_cos_theta(0), m_inv_scale(1), m_curvyness_mul(1), m_curvyness_add(0),
59 m_join_style(Qt::BevelJoin), m_cap_style(Qt::SquareCap) {}
61 void process(const QVectorPath &path, const QPen &pen, const QRectF &clip, QPainter::RenderHints hints);
63 inline int vertexCount() const { return m_vertices.size(); }
64 inline const float *vertices() const { return m_vertices.data(); }
66 inline void setInvScale(qreal invScale) { m_inv_scale = invScale; }
69 inline void emitLineSegment(float x, float y, float nx, float ny);
70 void moveTo(const qreal *pts);
71 inline void lineTo(const qreal *pts);
72 void cubicTo(const qreal *pts);
73 void join(const qreal *pts);
74 inline void normalVector(float x1, float y1, float x2, float y2, float *nx, float *ny);
75 void endCap(const qreal *pts);
76 void arcPoints(float cx, float cy, float fromX, float fromY, float toX, float toY, QVarLengthArray<float> &points);
77 void endCapOrJoinClosed(const qreal *start, const qreal *cur, bool implicitClose, bool endsAtStart);
80 QDataBuffer<float> m_vertices;
82 float m_cx, m_cy; // current points
83 float m_nvx, m_nvy; // normal vector...
87 int m_roundness; // Number of line segments in a round join
88 qreal m_sin_theta; // sin(m_roundness / 360);
89 qreal m_cos_theta; // cos(m_roundness / 360);
91 float m_curvyness_mul;
92 float m_curvyness_add;
94 Qt::PenJoinStyle m_join_style;
95 Qt::PenCapStyle m_cap_style;
98 class Q_GUI_EXPORT QDashedStrokeProcessor
101 QDashedStrokeProcessor();
103 void process(const QVectorPath &path, const QPen &pen, const QRectF &clip, QPainter::RenderHints hints);
105 inline void addElement(QPainterPath::ElementType type, qreal x, qreal y) {
111 inline int elementCount() const { return m_types.size(); }
112 inline qreal *points() const { return m_points.data(); }
113 inline QPainterPath::ElementType *elementTypes() const { return m_types.data(); }
115 inline void setInvScale(qreal invScale) { m_inv_scale = invScale; }
118 QDataBuffer<qreal> m_points;
119 QDataBuffer<QPainterPath::ElementType> m_types;
120 QDashStroker m_dash_stroker;
124 inline void QTriangulatingStroker::normalVector(float x1, float y1, float x2, float y2,
125 float *nx, float *ny)
129 Q_ASSERT(dx != 0 || dy != 0);
134 pw = m_width / qAbs(dy);
136 pw = m_width / qAbs(dx);
138 pw = m_width / sqrt(dx*dx + dy*dy);
144 inline void QTriangulatingStroker::emitLineSegment(float x, float y, float vx, float vy)
146 m_vertices.add(x + vx);
147 m_vertices.add(y + vy);
148 m_vertices.add(x - vx);
149 m_vertices.add(y - vy);
152 void QTriangulatingStroker::lineTo(const qreal *pts)
154 emitLineSegment(pts[0], pts[1], m_nvx, m_nvy);