| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qpaintengineex_p.h"
|
|---|
| 43 | #include "qpainter_p.h"
|
|---|
| 44 | #include "qstroker_p.h"
|
|---|
| 45 | #include <private/qpainterpath_p.h>
|
|---|
| 46 |
|
|---|
| 47 | #include <qvarlengtharray.h>
|
|---|
| 48 | #include <qdebug.h>
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 52 |
|
|---|
| 53 | /*******************************************************************************
|
|---|
| 54 | *
|
|---|
| 55 | * class QVectorPath
|
|---|
| 56 | *
|
|---|
| 57 | */
|
|---|
| 58 |
|
|---|
| 59 | const QRealRect &QVectorPath::controlPointRect() const
|
|---|
| 60 | {
|
|---|
| 61 | if (m_hints & ControlPointRect)
|
|---|
| 62 | return m_cp_rect;
|
|---|
| 63 |
|
|---|
| 64 | if (m_count == 0) {
|
|---|
| 65 | m_cp_rect.x1 = m_cp_rect.x2 = m_cp_rect.y1 = m_cp_rect.y2 = 0;
|
|---|
| 66 | m_hints |= ControlPointRect;
|
|---|
| 67 | return m_cp_rect;
|
|---|
| 68 | }
|
|---|
| 69 | Q_ASSERT(m_points && m_count > 0);
|
|---|
| 70 |
|
|---|
| 71 | const qreal *pts = m_points;
|
|---|
| 72 | m_cp_rect.x1 = m_cp_rect.x2 = *pts;
|
|---|
| 73 | ++pts;
|
|---|
| 74 | m_cp_rect.y1 = m_cp_rect.y2 = *pts;
|
|---|
| 75 | ++pts;
|
|---|
| 76 |
|
|---|
| 77 | const qreal *epts = m_points + (m_count << 1);
|
|---|
| 78 | while (pts < epts) {
|
|---|
| 79 | qreal x = *pts;
|
|---|
| 80 | if (x < m_cp_rect.x1) m_cp_rect.x1 = x;
|
|---|
| 81 | else if (x > m_cp_rect.x2) m_cp_rect.x2 = x;
|
|---|
| 82 | ++pts;
|
|---|
| 83 |
|
|---|
| 84 | qreal y = *pts;
|
|---|
| 85 | if (y < m_cp_rect.y1) m_cp_rect.y1 = y;
|
|---|
| 86 | else if (y > m_cp_rect.y2) m_cp_rect.y2 = y;
|
|---|
| 87 | ++pts;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | m_hints |= ControlPointRect;
|
|---|
| 91 | return m_cp_rect;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | const QVectorPath &qtVectorPathForPath(const QPainterPath &path)
|
|---|
| 95 | {
|
|---|
| 96 | Q_ASSERT(path.d_func());
|
|---|
| 97 | return path.d_func()->vectorPath();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | #ifndef QT_NO_DEBUG_STREAM
|
|---|
| 101 | QDebug Q_GUI_EXPORT &operator<<(QDebug &s, const QVectorPath &path)
|
|---|
| 102 | {
|
|---|
| 103 | QRealRect vectorPathBounds = path.controlPointRect();
|
|---|
| 104 | QRectF rf(vectorPathBounds.x1, vectorPathBounds.y1,
|
|---|
| 105 | vectorPathBounds.x2 - vectorPathBounds.x1, vectorPathBounds.y2 - vectorPathBounds.y1);
|
|---|
| 106 | s << "QVectorPath(size:" << path.elementCount()
|
|---|
| 107 | << " hints:" << hex << path.hints()
|
|---|
| 108 | << rf << ")";
|
|---|
| 109 | return s;
|
|---|
| 110 | }
|
|---|
| 111 | #endif
|
|---|
| 112 |
|
|---|
| 113 | /*******************************************************************************
|
|---|
| 114 | *
|
|---|
| 115 | * class QPaintEngineExPrivate:
|
|---|
| 116 | *
|
|---|
| 117 | */
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | struct StrokeHandler {
|
|---|
| 121 | QDataBuffer<qreal> pts;
|
|---|
| 122 | QDataBuffer<QPainterPath::ElementType> types;
|
|---|
| 123 | };
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | QPaintEngineExPrivate::QPaintEngineExPrivate()
|
|---|
| 127 | : dasher(&stroker),
|
|---|
| 128 | strokeHandler(0),
|
|---|
| 129 | activeStroker(0),
|
|---|
| 130 | strokerPen(Qt::NoPen)
|
|---|
| 131 | {
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 | QPaintEngineExPrivate::~QPaintEngineExPrivate()
|
|---|
| 136 | {
|
|---|
| 137 | delete strokeHandler;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | /*******************************************************************************
|
|---|
| 143 | *
|
|---|
| 144 | * class QPaintEngineEx:
|
|---|
| 145 | *
|
|---|
| 146 | */
|
|---|
| 147 |
|
|---|
| 148 | static QPainterPath::ElementType qpaintengineex_ellipse_types[] = {
|
|---|
| 149 | QPainterPath::MoveToElement,
|
|---|
| 150 | QPainterPath::CurveToElement,
|
|---|
| 151 | QPainterPath::CurveToDataElement,
|
|---|
| 152 | QPainterPath::CurveToDataElement,
|
|---|
| 153 |
|
|---|
| 154 | QPainterPath::CurveToElement,
|
|---|
| 155 | QPainterPath::CurveToDataElement,
|
|---|
| 156 | QPainterPath::CurveToDataElement,
|
|---|
| 157 |
|
|---|
| 158 | QPainterPath::CurveToElement,
|
|---|
| 159 | QPainterPath::CurveToDataElement,
|
|---|
| 160 | QPainterPath::CurveToDataElement,
|
|---|
| 161 |
|
|---|
| 162 | QPainterPath::CurveToElement,
|
|---|
| 163 | QPainterPath::CurveToDataElement,
|
|---|
| 164 | QPainterPath::CurveToDataElement
|
|---|
| 165 | };
|
|---|
| 166 |
|
|---|
| 167 | static QPainterPath::ElementType qpaintengineex_line_types_16[] = {
|
|---|
| 168 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 169 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 170 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 171 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 172 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 173 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 174 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 175 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 176 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 177 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 178 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 179 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 180 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 181 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 182 | QPainterPath::MoveToElement, QPainterPath::LineToElement,
|
|---|
| 183 | QPainterPath::MoveToElement, QPainterPath::LineToElement
|
|---|
| 184 | };
|
|---|
| 185 |
|
|---|
| 186 | static QPainterPath::ElementType qpaintengineex_rect4_types_32[] = {
|
|---|
| 187 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 1
|
|---|
| 188 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 2
|
|---|
| 189 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 3
|
|---|
| 190 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 4
|
|---|
| 191 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 5
|
|---|
| 192 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 6
|
|---|
| 193 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 7
|
|---|
| 194 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 8
|
|---|
| 195 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 9
|
|---|
| 196 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 10
|
|---|
| 197 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 11
|
|---|
| 198 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 12
|
|---|
| 199 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 13
|
|---|
| 200 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 14
|
|---|
| 201 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 15
|
|---|
| 202 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 16
|
|---|
| 203 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 17
|
|---|
| 204 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 18
|
|---|
| 205 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 19
|
|---|
| 206 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 20
|
|---|
| 207 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 21
|
|---|
| 208 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 22
|
|---|
| 209 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 23
|
|---|
| 210 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 24
|
|---|
| 211 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 25
|
|---|
| 212 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 26
|
|---|
| 213 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 27
|
|---|
| 214 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 28
|
|---|
| 215 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 29
|
|---|
| 216 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 30
|
|---|
| 217 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 31
|
|---|
| 218 | QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 32
|
|---|
| 219 | };
|
|---|
| 220 |
|
|---|
| 221 | static void qpaintengineex_moveTo(qreal x, qreal y, void *data) {
|
|---|
| 222 | ((StrokeHandler *) data)->pts.add(x);
|
|---|
| 223 | ((StrokeHandler *) data)->pts.add(y);
|
|---|
| 224 | ((StrokeHandler *) data)->types.add(QPainterPath::MoveToElement);
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | static void qpaintengineex_lineTo(qreal x, qreal y, void *data) {
|
|---|
| 228 | ((StrokeHandler *) data)->pts.add(x);
|
|---|
| 229 | ((StrokeHandler *) data)->pts.add(y);
|
|---|
| 230 | ((StrokeHandler *) data)->types.add(QPainterPath::LineToElement);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | static void qpaintengineex_cubicTo(qreal c1x, qreal c1y, qreal c2x, qreal c2y, qreal ex, qreal ey, void *data) {
|
|---|
| 234 | ((StrokeHandler *) data)->pts.add(c1x);
|
|---|
| 235 | ((StrokeHandler *) data)->pts.add(c1y);
|
|---|
| 236 | ((StrokeHandler *) data)->types.add(QPainterPath::CurveToElement);
|
|---|
| 237 |
|
|---|
| 238 | ((StrokeHandler *) data)->pts.add(c2x);
|
|---|
| 239 | ((StrokeHandler *) data)->pts.add(c2y);
|
|---|
| 240 | ((StrokeHandler *) data)->types.add(QPainterPath::CurveToDataElement);
|
|---|
| 241 |
|
|---|
| 242 | ((StrokeHandler *) data)->pts.add(ex);
|
|---|
| 243 | ((StrokeHandler *) data)->pts.add(ey);
|
|---|
| 244 | ((StrokeHandler *) data)->types.add(QPainterPath::CurveToDataElement);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | QPaintEngineEx::QPaintEngineEx(QPaintEngineExPrivate &data)
|
|---|
| 248 | : QPaintEngine(data, AllFeatures)
|
|---|
| 249 | {
|
|---|
| 250 | extended = true;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 | QPainterState *QPaintEngineEx::createState(QPainterState *orig) const
|
|---|
| 255 | {
|
|---|
| 256 | if (!orig)
|
|---|
| 257 | return new QPainterState;
|
|---|
| 258 | return new QPainterState(orig);
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp
|
|---|
| 262 |
|
|---|
| 263 | void QPaintEngineEx::stroke(const QVectorPath &path, const QPen &pen)
|
|---|
| 264 | {
|
|---|
| 265 | #ifdef QT_DEBUG_DRAW
|
|---|
| 266 | qDebug() << "QPaintEngineEx::stroke()" << pen;
|
|---|
| 267 | #endif
|
|---|
| 268 |
|
|---|
|
|---|