1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QOPENGLTRIANGULATINGSTROKER_P_H
43 #define QOPENGLTRIANGULATINGSTROKER_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 QTriangulatingStroker
57 QTriangulatingStroker() : m_vertices(0) {}
58 void process(const QVectorPath &path, const QPen &pen, const QRectF &clip);
60 inline int vertexCount() const { return m_vertices.size(); }
61 inline const float *vertices() const { return m_vertices.data(); }
63 inline void setInvScale(qreal invScale) { m_inv_scale = invScale; }
66 inline void emitLineSegment(float x, float y, float nx, float ny);
67 void moveTo(const qreal *pts);
68 inline void lineTo(const qreal *pts);
69 void cubicTo(const qreal *pts);
70 void join(const qreal *pts);
71 inline void normalVector(float x1, float y1, float x2, float y2, float *nx, float *ny);
72 void endCap(const qreal *pts);
73 void arcPoints(float cx, float cy, float fromX, float fromY, float toX, float toY, QVarLengthArray<float> &points);
74 void endCapOrJoinClosed(const qreal *start, const qreal *cur, bool implicitClose, bool endsAtStart);
77 QDataBuffer<float> m_vertices;
79 float m_cx, m_cy; // current points
80 float m_nvx, m_nvy; // normal vector...
84 int m_roundness; // Number of line segments in a round join
85 qreal m_sin_theta; // sin(m_roundness / 360);
86 qreal m_cos_theta; // cos(m_roundness / 360);
88 float m_curvyness_mul;
89 float m_curvyness_add;
91 Qt::PenJoinStyle m_join_style;
92 Qt::PenCapStyle m_cap_style;
95 class QDashedStrokeProcessor
98 QDashedStrokeProcessor();
100 void process(const QVectorPath &path, const QPen &pen, const QRectF &clip);
102 inline void addElement(QPainterPath::ElementType type, qreal x, qreal y) {
108 inline int elementCount() const { return m_types.size(); }
109 inline qreal *points() const { return m_points.data(); }
110 inline QPainterPath::ElementType *elementTypes() const { return m_types.data(); }
112 inline void setInvScale(qreal invScale) { m_inv_scale = invScale; }
115 QDataBuffer<qreal> m_points;
116 QDataBuffer<QPainterPath::ElementType> m_types;
117 QDashStroker m_dash_stroker;
121 inline void QTriangulatingStroker::normalVector(float x1, float y1, float x2, float y2,
122 float *nx, float *ny)
130 pw = m_width / qAbs(dy);
132 pw = m_width / qAbs(dx);
134 pw = m_width / sqrt(dx*dx + dy*dy);
140 inline void QTriangulatingStroker::emitLineSegment(float x, float y, float vx, float vy)
142 m_vertices.add(x + vx);
143 m_vertices.add(y + vy);
144 m_vertices.add(x - vx);
145 m_vertices.add(y - vy);
148 void QTriangulatingStroker::lineTo(const qreal *pts)
150 emitLineSegment(pts[0], pts[1], m_nvx, m_nvy);