| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | void QTriangulatingStroker::endCapOrJoinClosed(const qreal *start, const qreal *cur, | - |
| 10 | bool implicitClose, bool endsAtStart) | - |
| 11 | { | - |
| 12 | if (endsAtStart) { never evaluated: endsAtStart | 0 |
| 13 | join(start + 2); | - |
| 14 | } else if (implicitClose) { never evaluated: implicitClose | 0 |
| 15 | join(start); | - |
| 16 | lineTo(start); | - |
| 17 | join(start+2); | - |
| 18 | } else { | 0 |
| 19 | endCap(cur); | - |
| 20 | } | 0 |
| 21 | int count = m_vertices.size(); | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | float x = m_vertices.at(count-2); | - |
| 27 | float y = m_vertices.at(count-1); | - |
| 28 | m_vertices.add(x); | - |
| 29 | m_vertices.add(y); | - |
| 30 | } | 0 |
| 31 | | - |
| 32 | static inline void skipDuplicatePoints(const qreal **pts, const qreal *endPts) | - |
| 33 | { | - |
| 34 | while ((*pts + 2) < endPts && float((*pts)[0]) == float((*pts)[2]) never evaluated: (*pts + 2) < endPts never evaluated: float((*pts)[0]) == float((*pts)[2]) | 0 |
| 35 | && float((*pts)[1]) == float((*pts)[3])) never evaluated: float((*pts)[1]) == float((*pts)[3]) | 0 |
| 36 | { | - |
| 37 | *pts += 2; | - |
| 38 | } | 0 |
| 39 | } | 0 |
| 40 | | - |
| 41 | void QTriangulatingStroker::process(const QVectorPath &path, const QPen &pen, const QRectF &, QPainter::RenderHints hints) | - |
| 42 | { | - |
| 43 | const qreal *pts = path.points(); | - |
| 44 | const QPainterPath::ElementType *types = path.elements(); | - |
| 45 | int count = path.elementCount(); | - |
| 46 | if (count < 2) never evaluated: count < 2 | 0 |
| 47 | return; | 0 |
| 48 | | - |
| 49 | float realWidth = qpen_widthf(pen); | - |
| 50 | if (realWidth == 0) never evaluated: realWidth == 0 | 0 |
| 51 | realWidth = 1; never executed: realWidth = 1; | 0 |
| 52 | | - |
| 53 | m_width = realWidth / 2; | - |
| 54 | | - |
| 55 | bool cosmetic = qt_pen_is_cosmetic(pen, hints); | - |
| 56 | if (cosmetic) { never evaluated: cosmetic | 0 |
| 57 | m_width = m_width * m_inv_scale; | - |
| 58 | } | 0 |
| 59 | | - |
| 60 | m_join_style = qpen_joinStyle(pen); | - |
| 61 | m_cap_style = qpen_capStyle(pen); | - |
| 62 | m_vertices.reset(); | - |
| 63 | m_miter_limit = pen.miterLimit() * qpen_widthf(pen); | - |
| 64 | if (realWidth < 2.5 && (cosmetic || m_inv_scale == 1)) { never evaluated: realWidth < 2.5 never evaluated: cosmetic never evaluated: m_inv_scale == 1 | 0 |
| 65 | if (m_cap_style == Qt::RoundCap) never evaluated: m_cap_style == Qt::RoundCap | 0 |
| 66 | m_cap_style = Qt::SquareCap; never executed: m_cap_style = Qt::SquareCap; | 0 |
| 67 | if (m_join_style == Qt::RoundJoin) never evaluated: m_join_style == Qt::RoundJoin | 0 |
| 68 | m_join_style = Qt::MiterJoin; never executed: m_join_style = Qt::MiterJoin; | 0 |
| 69 | m_curvyness_add = 0.5; | - |
| 70 | m_curvyness_mul = Q_PI / 8 / m_inv_scale; | - |
| 71 | m_roundness = 1; | - |
| 72 | } else if (cosmetic) { never evaluated: cosmetic | 0 |
| 73 | m_curvyness_add = realWidth / 2; | - |
| 74 | m_curvyness_mul = Q_PI / 8; | - |
| 75 | m_roundness = qMax<int>(4, realWidth * Q_PI / 8); | - |
| 76 | } else { | 0 |
| 77 | m_curvyness_add = m_width; | - |
| 78 | m_curvyness_mul = Q_PI / 8 / m_inv_scale; | - |
| 79 | m_roundness = qMax<int>(4, realWidth * m_curvyness_mul); | - |
| 80 | } | 0 |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | if (m_roundness > 24) never evaluated: m_roundness > 24 | 0 |
| 85 | m_roundness = 24; never executed: m_roundness = 24; | 0 |
| 86 | | - |
| 87 | m_sin_theta = qFastSin(Q_PI / m_roundness); | - |
| 88 | m_cos_theta = qFastCos(Q_PI / m_roundness); | - |
| 89 | | - |
| 90 | const qreal *endPts = pts + (count<<1); | - |
| 91 | const qreal *startPts = 0; | - |
| 92 | | - |
| 93 | Qt::PenCapStyle cap = m_cap_style; | - |
| 94 | | - |
| 95 | if (!types) { | 0 |
| 96 | skipDuplicatePoints(&pts, endPts); | - |
| 97 | if ((pts + 2) == endPts) never evaluated: (pts + 2) == endPts | 0 |
| 98 | return; | 0 |
| 99 | | - |
| 100 | startPts = pts; | - |
| 101 | | - |
| 102 | bool endsAtStart = float(startPts[0]) == float(endPts[-2]) never evaluated: float(startPts[0]) == float(endPts[-2]) | 0 |
| 103 | && float(startPts[1]) == float(endPts[-1]); never evaluated: float(startPts[1]) == float(endPts[-1]) | 0 |
| 104 | | - |
| 105 | if (endsAtStart || path.hasImplicitClose()) never evaluated: endsAtStart never evaluated: path.hasImplicitClose() | 0 |
| 106 | m_cap_style = Qt::FlatCap; never executed: m_cap_style = Qt::FlatCap; | 0 |
| 107 | moveTo(pts); | - |
| 108 | m_cap_style = cap; | - |
| 109 | pts += 2; | - |
| 110 | skipDuplicatePoints(&pts, endPts); | - |
| 111 | lineTo(pts); | - |
| 112 | pts += 2; | - |
| 113 | skipDuplicatePoints(&pts, endPts); | - |
| 114 | while (pts < endPts) { never evaluated: pts < endPts | 0 |
| 115 | join(pts); | - |
| 116 | lineTo(pts); | - |
| 117 | pts += 2; | - |
| 118 | skipDuplicatePoints(&pts, endPts); | - |
| 119 | } | 0 |
| 120 | endCapOrJoinClosed(startPts, pts-2, path.hasImplicitClose(), endsAtStart); | - |
| 121 | | - |
| 122 | } else { | 0 |
| 123 | bool endsAtStart = false; | - |
| 124 | QPainterPath::ElementType previousType = QPainterPath::MoveToElement; | - |
| 125 | const qreal *previousPts = pts; | - |
| 126 | while (pts < endPts) { never evaluated: pts < endPts | 0 |
| 127 | switch (*types) { | - |
| 128 | case QPainterPath::MoveToElement: { | - |
| 129 | if (previousType != QPainterPath::MoveToElement) never evaluated: previousType != QPainterPath::MoveToElement | 0 |
| 130 | endCapOrJoinClosed(startPts, previousPts, path.hasImplicitClose(), endsAtStart); never executed: endCapOrJoinClosed(startPts, previousPts, path.hasImplicitClose(), endsAtStart); | 0 |
| 131 | | - |
| 132 | startPts = pts; | - |
| 133 | skipDuplicatePoints(&startPts, endPts); | - |
| 134 | if (startPts + 2 >= endPts) never evaluated: startPts + 2 >= endPts | 0 |
| 135 | return; | 0 |
| 136 | | - |
| 137 | int end = (endPts - pts) / 2; | - |
| 138 | int i = 2; | - |
| 139 | while (i<end && types[i] != QPainterPath::MoveToElement) { never evaluated: types[i] != QPainterPath::MoveToElement | 0 |
| 140 | ++i; | - |
| 141 | } | 0 |
| 142 | endsAtStart = float(startPts[0]) == float(pts[i*2 - 2]) never evaluated: float(startPts[0]) == float(pts[i*2 - 2]) | 0 |
| 143 | && float(startPts[1]) == float(pts[i*2 - 1]); never evaluated: float(startPts[1]) == float(pts[i*2 - 1]) | 0 |
| 144 | if (endsAtStart || path.hasImplicitClose()) never evaluated: endsAtStart never evaluated: path.hasImplicitClose() | 0 |
| 145 | m_cap_style = Qt::FlatCap; never executed: m_cap_style = Qt::FlatCap; | 0 |
| 146 | | - |
| 147 | moveTo(startPts); | - |
| 148 | m_cap_style = cap; | - |
| 149 | previousType = QPainterPath::MoveToElement; | - |
| 150 | previousPts = pts; | - |
| 151 | pts+=2; | - |
| 152 | ++types; | - |
| 153 | break; } | 0 |
| 154 | case QPainterPath::LineToElement: | - |
| 155 | if (float(m_cx) != float(pts[0]) || float(m_cy) != float(pts[1])) { never evaluated: float(m_cx) != float(pts[0]) never evaluated: float(m_cy) != float(pts[1]) | 0 |
| 156 | if (previousType != QPainterPath::MoveToElement) never evaluated: previousType != QPainterPath::MoveToElement | 0 |
| 157 | join(pts); never executed: join(pts); | 0 |
| 158 | lineTo(pts); | - |
| 159 | previousType = QPainterPath::LineToElement; | - |
| 160 | previousPts = pts; | - |
| 161 | } | 0 |
| 162 | pts+=2; | - |
| 163 | ++types; | - |
| 164 | break; | 0 |
| 165 | case QPainterPath::CurveToElement: | - |
| 166 | if (float(m_cx) != float(pts[0]) || float(m_cy) != float(pts[1]) never evaluated: float(m_cx) != float(pts[0]) never evaluated: float(m_cy) != float(pts[1]) | 0 |
| 167 | || float(pts[0]) != float(pts[2]) || float(pts[1]) != float(pts[3]) never evaluated: float(pts[0]) != float(pts[2]) never evaluated: float(pts[1]) != float(pts[3]) | 0 |
| 168 | || float(pts[2]) != float(pts[4]) || float(pts[3]) != float(pts[5])) never evaluated: float(pts[2]) != float(pts[4]) never evaluated: float(pts[3]) != float(pts[5]) | 0 |
| 169 | { | - |
| 170 | if (float(m_cx) != float(pts[0]) || float(m_cy) != float(pts[1])) { never evaluated: float(m_cx) != float(pts[0]) never evaluated: float(m_cy) != float(pts[1]) | 0 |
| 171 | if (previousType != QPainterPath::MoveToElement) never evaluated: previousType != QPainterPath::MoveToElement | 0 |
| 172 | join(pts); never executed: join(pts); | 0 |
| 173 | } | 0 |
| 174 | cubicTo(pts); | - |
| 175 | previousType = QPainterPath::CurveToElement; | - |
| 176 | previousPts = pts + 4; | - |
| 177 | } | 0 |
| 178 | pts+=6; | - |
| 179 | types+=3; | - |
| 180 | break; | 0 |
| 181 | default: | - |
| 182 | qt_noop(); | - |
| 183 | break; | 0 |
| 184 | } | - |
| 185 | } | 0 |
| 186 | | - |
| 187 | if (previousType != QPainterPath::MoveToElement) never evaluated: previousType != QPainterPath::MoveToElement | 0 |
| 188 | endCapOrJoinClosed(startPts, previousPts, path.hasImplicitClose(), endsAtStart); never executed: endCapOrJoinClosed(startPts, previousPts, path.hasImplicitClose(), endsAtStart); | 0 |
| 189 | } | 0 |
| 190 | } | - |
| 191 | | - |
| 192 | void QTriangulatingStroker::moveTo(const qreal *pts) | - |
| 193 | { | - |
| 194 | m_cx = pts[0]; | - |
| 195 | m_cy = pts[1]; | - |
| 196 | | - |
| 197 | float x2 = pts[2]; | - |
| 198 | float y2 = pts[3]; | - |
| 199 | normalVector(m_cx, m_cy, x2, y2, &m_nvx, &m_nvy); | - |
| 200 | | - |
| 201 | | - |
| 202 | | - |
| 203 | | - |
| 204 | | - |
| 205 | bool invisibleJump = m_vertices.size(); | - |
| 206 | | - |
| 207 | switch (m_cap_style) { | - |
| 208 | case Qt::FlatCap: | - |
| 209 | if (invisibleJump) { never evaluated: invisibleJump | 0 |
| 210 | m_vertices.add(m_cx + m_nvx); | - |
| 211 | m_vertices.add(m_cy + m_nvy); | - |
| 212 | } | 0 |
| 213 | break; | 0 |
| 214 | case Qt::SquareCap: { | - |
| 215 | float sx = m_cx - m_nvy; | - |
| 216 | float sy = m_cy + m_nvx; | - |
| 217 | if (invisibleJump) { never evaluated: invisibleJump | 0 |
| 218 | m_vertices.add(sx + m_nvx); | - |
| 219 | m_vertices.add(sy + m_nvy); | - |
| 220 | } | 0 |
| 221 | emitLineSegment(sx, sy, m_nvx, m_nvy); | - |
| 222 | break; } | 0 |
| 223 | case Qt::RoundCap: { | - |
| 224 | QVarLengthArray<float> points; | - |
| 225 | arcPoints(m_cx, m_cy, m_cx + m_nvx, m_cy + m_nvy, m_cx - m_nvx, m_cy - m_nvy, points); | - |
| 226 | m_vertices.resize(m_vertices.size() + points.size() + 2 * int(invisibleJump)); | - |
| 227 | int count = m_vertices.size(); | - |
| 228 | int front = 0; | - |
| 229 | int end = points.size() / 2; | - |
| 230 | while (front != end) { never evaluated: front != end | 0 |
| 231 | m_vertices.at(--count) = points[2 * end - 1]; | - |
| 232 | m_vertices.at(--count) = points[2 * end - 2]; | - |
| 233 | --end; | - |
| 234 | if (front == end) never evaluated: front == end | 0 |
| 235 | break; | 0 |
| 236 | m_vertices.at(--count) = points[2 * front + 1]; | - |
| 237 | m_vertices.at(--count) = points[2 * front + 0]; | - |
| 238 | ++front; | - |
| 239 | } | 0 |
| 240 | | - |
| 241 | if (invisibleJump) { never evaluated: invisibleJump | 0 |
| 242 | m_vertices.at(count - 1) = m_vertices.at(count + 1); | - |
| 243 | m_vertices.at(count - 2) = m_vertices.at(count + 0); | - |
| 244 | } | 0 |
| 245 | break; } | 0 |
| 246 | default: break; | 0 |
| 247 | } | - |
| 248 | emitLineSegment(m_cx, m_cy, m_nvx, m_nvy); | - |
| 249 | } | 0 |
| 250 | | - |
| 251 | void QTriangulatingStroker::cubicTo(const qreal *pts) | - |
| 252 | { | - |
| 253 | const QPointF *p = (const QPointF *) pts; | - |
| 254 | QBezier bezier = QBezier::fromPoints(*(p - 1), p[0], p[1], p[2]); | - |
| 255 | | - |
| 256 | QRectF bounds = bezier.bounds(); | - |
| 257 | float rad = qMax(bounds.width(), bounds.height()); | - |
| 258 | int threshold = qMin<float>(64, (rad + m_curvyness_add) * m_curvyness_mul); | - |
| 259 | if (threshold < 4) never evaluated: threshold < 4 | 0 |
| 260 | threshold = 4; never executed: threshold = 4; | 0 |
| 261 | qreal threshold_minus_1 = threshold - 1; | - |
| 262 | float vx, vy; | - |
| 263 | | - |
| 264 | float cx = m_cx, cy = m_cy; | - |
| 265 | float x, y; | - |
| 266 | | - |
| 267 | for (int i=1; i<threshold; ++i) { never evaluated: i<threshold | 0 |
| 268 | qreal t = qreal(i) / threshold_minus_1; | - |
| 269 | QPointF p = bezier.pointAt(t); | - |
| 270 | x = p.x(); | - |
| 271 | y = p.y(); | - |
| 272 | | - |
| 273 | normalVector(cx, cy, x, y, &vx, &vy); | - |
| 274 | | - |
| 275 | emitLineSegment(x, y, vx, vy); | - |
| 276 | | - |
| 277 | cx = x; | - |
| 278 | cy = y; | - |
| 279 | } | 0 |
| 280 | | - |
| 281 | m_cx = cx; | - |
| 282 | m_cy = cy; | - |
| 283 | | - |
| 284 | m_nvx = vx; | - |
| 285 | m_nvy = vy; | - |
| 286 | } | 0 |
| 287 | | - |
| 288 | void QTriangulatingStroker::join(const qreal *pts) | - |
| 289 | { | - |
| 290 | | - |
| 291 | normalVector(m_cx, m_cy, pts[0], pts[1], &m_nvx, &m_nvy); | - |
| 292 | | - |
| 293 | switch (m_join_style) { | - |
| 294 | case Qt::BevelJoin: | - |
| 295 | break; | 0 |
| 296 | case Qt::SvgMiterJoin: | - |
| 297 | case Qt::MiterJoin: { | - |
| 298 | | - |
| 299 | int count = m_vertices.size(); | - |
| 300 | float prevNvx = m_vertices.at(count - 2) - m_cx; | - |
| 301 | float prevNvy = m_vertices.at(count - 1) - m_cy; | - |
| 302 | float xprod = prevNvx * m_nvy - prevNvy * m_nvx; | - |
| 303 | float px, py, qx, qy; | - |
| 304 | | - |
| 305 | | - |
| 306 | if (qFuzzyIsNull(xprod)) never evaluated: qFuzzyIsNull(xprod) | 0 |
| 307 | break; | 0 |
| 308 | | - |
| 309 | | - |
| 310 | if (xprod < 0) { never evaluated: xprod < 0 | 0 |
| 311 | px = m_vertices.at(count - 2); | - |
| 312 | py = m_vertices.at(count - 1); | - |
| 313 | qx = m_cx - m_nvx; | - |
| 314 | qy = m_cy - m_nvy; | - |
| 315 | } else { | 0 |
| 316 | px = m_vertices.at(count - 4); | - |
| 317 | py = m_vertices.at(count - 3); | - |
| 318 | qx = m_cx + m_nvx; | - |
| 319 | qy = m_cy + m_nvy; | - |
| 320 | } | 0 |
| 321 | | - |
| 322 | | - |
| 323 | float pu = px * prevNvx + py * prevNvy; | - |
| 324 | float qv = qx * m_nvx + qy * m_nvy; | - |
| 325 | float ix = (m_nvy * pu - prevNvy * qv) / xprod; | - |
| 326 | float iy = (prevNvx * qv - m_nvx * pu) / xprod; | - |
| 327 | | - |
| 328 | | - |
| 329 | if ((ix - px) * (ix - px) + (iy - py) * (iy - py) <= m_miter_limit * m_miter_limit) { never evaluated: (ix - px) * (ix - px) + (iy - py) * (iy - py) <= m_miter_limit * m_miter_limit | 0 |
| 330 | m_vertices.add(ix); | - |
| 331 | m_vertices.add(iy); | - |
| 332 | m_vertices.add(ix); | - |
| 333 | m_vertices.add(iy); | - |
| 334 | } | 0 |
| 335 | | - |
| 336 | | - |
| 337 | | - |
| 338 | | - |
| 339 | | - |
| 340 | | - |
| 341 | break; } | 0 |
| 342 | case Qt::RoundJoin: { | - |
| 343 | QVarLengthArray<float> points; | - |
| 344 | int count = m_vertices.size(); | - |
| 345 | float prevNvx = m_vertices.at(count - 2) - m_cx; | - |
| 346 | float prevNvy = m_vertices.at(count - 1) - m_cy; | - |
| 347 | if (m_nvx * prevNvy - m_nvy * prevNvx < 0) { never evaluated: m_nvx * prevNvy - m_nvy * prevNvx < 0 | 0 |
| 348 | arcPoints(0, 0, m_nvx, m_nvy, -prevNvx, -prevNvy, points); | - |
| 349 | for (int i = points.size() / 2; i > 0; --i) | 0 |
| 350 | emitLineSegment(m_cx, m_cy, points[2 * i - 2], points[2 * i - 1]); never executed: emitLineSegment(m_cx, m_cy, points[2 * i - 2], points[2 * i - 1]); | 0 |
| 351 | } else { | 0 |
| 352 | arcPoints(0, 0, -prevNvx, -prevNvy, m_nvx, m_nvy, points); | - |
| 353 | for (int i = 0; i < points.size() / 2; ++i) never evaluated: i < points.size() / 2 | 0 |
| 354 | emitLineSegment(m_cx, m_cy, points[2 * i + 0], points[2 * i + 1]); never executed: emitLineSegment(m_cx, m_cy, points[2 * i + 0], points[2 * i + 1]); | 0 |
| 355 | } | 0 |
| 356 | break; } | 0 |
| 357 | default: break; | 0 |
| 358 | } | - |
| 359 | | - |
| 360 | emitLineSegment(m_cx, m_cy, m_nvx, m_nvy); | - |
| 361 | } | 0 |
| 362 | | - |
| 363 | void QTriangulatingStroker::endCap(const qreal *) | - |
| 364 | { | - |
| 365 | switch (m_cap_style) { | - |
| 366 | case Qt::FlatCap: | - |
| 367 | break; | 0 |
| 368 | case Qt::SquareCap: | - |
| 369 | emitLineSegment(m_cx + m_nvy, m_cy - m_nvx, m_nvx, m_nvy); | - |
| 370 | break; | 0 |
| 371 | case Qt::RoundCap: { | - |
| 372 | QVarLengthArray<float> points; | - |
| 373 | int count = m_vertices.size(); | - |
| 374 | arcPoints(m_cx, m_cy, m_vertices.at(count - 2), m_vertices.at(count - 1), m_vertices.at(count - 4), m_vertices.at(count - 3), points); | - |
| 375 | int front = 0; | - |
| 376 | int end = points.size() / 2; | - |
| 377 | while (front != end) { never evaluated: front != end | 0 |
| 378 | m_vertices.add(points[2 * end - 2]); | - |
| 379 | m_vertices.add(points[2 * end - 1]); | - |
| 380 | --end; | - |
| 381 | if (front == end) never evaluated: front == end | 0 |
| 382 | break; | 0 |
| 383 | m_vertices.add(points[2 * front + 0]); | - |
| 384 | m_vertices.add(points[2 * front + 1]); | - |
| 385 | ++front; | - |
| 386 | } | 0 |
| 387 | break; } | 0 |
| 388 | default: break; | 0 |
| 389 | } | - |
| 390 | } | 0 |
| 391 | | - |
| 392 | void QTriangulatingStroker::arcPoints(float cx, float cy, float fromX, float fromY, float toX, float toY, QVarLengthArray<float> &points) | - |
| 393 | { | - |
| 394 | float dx1 = fromX - cx; | - |
| 395 | float dy1 = fromY - cy; | - |
| 396 | float dx2 = toX - cx; | - |
| 397 | float dy2 = toY - cy; | - |
| 398 | | - |
| 399 | | - |
| 400 | while (dx1 * dy2 - dx2 * dy1 < 0) { never evaluated: dx1 * dy2 - dx2 * dy1 < 0 | 0 |
| 401 | float tmpx = dx1 * m_cos_theta - dy1 * m_sin_theta; | - |
| 402 | float tmpy = dx1 * m_sin_theta + dy1 * m_cos_theta; | - |
| 403 | dx1 = tmpx; | - |
| 404 | dy1 = tmpy; | - |
| 405 | points.append(cx + dx1); | - |
| 406 | points.append(cy + dy1); | - |
| 407 | } | 0 |
| 408 | | - |
| 409 | | - |
| 410 | while (dx1 * dx2 + dy1 * dy2 < 0) { never evaluated: dx1 * dx2 + dy1 * dy2 < 0 | 0 |
| 411 | float tmpx = dx1 * m_cos_theta - dy1 * m_sin_theta; | - |
| 412 | float tmpy = dx1 * m_sin_theta + dy1 * m_cos_theta; | - |
| 413 | dx1 = tmpx; | - |
| 414 | dy1 = tmpy; | - |
| 415 | points.append(cx + dx1); | - |
| 416 | points.append(cy + dy1); | - |
| 417 | } | 0 |
| 418 | | - |
| 419 | | - |
| 420 | while (dx1 * dy2 - dx2 * dy1 > 0) { never evaluated: dx1 * dy2 - dx2 * dy1 > 0 | 0 |
| 421 | float tmpx = dx1 * m_cos_theta - dy1 * m_sin_theta; | - |
| 422 | float tmpy = dx1 * m_sin_theta + dy1 * m_cos_theta; | - |
| 423 | dx1 = tmpx; | - |
| 424 | dy1 = tmpy; | - |
| 425 | points.append(cx + dx1); | - |
| 426 | points.append(cy + dy1); | - |
| 427 | } | 0 |
| 428 | | - |
| 429 | | - |
| 430 | if (!points.isEmpty()) never evaluated: !points.isEmpty() | 0 |
| 431 | points.resize(points.size() - 2); never executed: points.resize(points.size() - 2); | 0 |
| 432 | } | 0 |
| 433 | | - |
| 434 | static void qdashprocessor_moveTo(qreal x, qreal y, void *data) | - |
| 435 | { | - |
| 436 | ((QDashedStrokeProcessor *) data)->addElement(QPainterPath::MoveToElement, x, y); | - |
| 437 | } | 0 |
| 438 | | - |
| 439 | static void qdashprocessor_lineTo(qreal x, qreal y, void *data) | - |
| 440 | { | - |
| 441 | ((QDashedStrokeProcessor *) data)->addElement(QPainterPath::LineToElement, x, y); | - |
| 442 | } | 0 |
| 443 | | - |
| 444 | static void qdashprocessor_cubicTo(qreal, qreal, qreal, qreal, qreal, qreal, void *) | - |
| 445 | { | - |
| 446 | qt_noop(); | - |
| 447 | } | 0 |
| 448 | | - |
| 449 | QDashedStrokeProcessor::QDashedStrokeProcessor() | - |
| 450 | : m_points(0), m_types(0), | - |
| 451 | m_dash_stroker(0), m_inv_scale(1) | - |
| 452 | { | - |
| 453 | m_dash_stroker.setMoveToHook(qdashprocessor_moveTo); | - |
| 454 | m_dash_stroker.setLineToHook(qdashprocessor_lineTo); | - |
| 455 | m_dash_stroker.setCubicToHook(qdashprocessor_cubicTo); | - |
| 456 | } | 0 |
| 457 | | - |
| 458 | void QDashedStrokeProcessor::process(const QVectorPath &path, const QPen &pen, const QRectF &clip, QPainter::RenderHints hints) | - |
| 459 | { | - |
| 460 | | - |
| 461 | const qreal *pts = path.points(); | - |
| 462 | const QPainterPath::ElementType *types = path.elements(); | - |
| 463 | int count = path.elementCount(); | - |
| 464 | | - |
| 465 | bool cosmetic = qt_pen_is_cosmetic(pen, hints); | - |
| 466 | | - |
| 467 | m_points.reset(); | - |
| 468 | m_types.reset(); | - |
| 469 | m_points.reserve(path.elementCount()); | - |
| 470 | m_types.reserve(path.elementCount()); | - |
| 471 | | - |
| 472 | qreal width = qpen_widthf(pen); | - |
| 473 | if (width == 0) never evaluated: width == 0 | 0 |
| 474 | width = 1; never executed: width = 1; | 0 |
| 475 | | - |
| 476 | m_dash_stroker.setDashPattern(pen.dashPattern()); | - |
| 477 | m_dash_stroker.setStrokeWidth(cosmetic ? width * m_inv_scale : width); | - |
| 478 | m_dash_stroker.setDashOffset(pen.dashOffset()); | - |
| 479 | m_dash_stroker.setMiterLimit(pen.miterLimit()); | - |
| 480 | m_dash_stroker.setClipRect(clip); | - |
| 481 | | - |
| 482 | float curvynessAdd, curvynessMul; | - |
| 483 | | - |
| 484 | | - |
| 485 | if (width < 2.5 && (cosmetic || m_inv_scale == 1)) { never evaluated: width < 2.5 never evaluated: cosmetic never evaluated: m_inv_scale == 1 | 0 |
| 486 | curvynessAdd = 0.5; | - |
| 487 | curvynessMul = Q_PI / 8 / m_inv_scale; | - |
| 488 | } else if (cosmetic) { never evaluated: cosmetic | 0 |
| 489 | curvynessAdd= width / 2; | - |
| 490 | curvynessMul= Q_PI / 8; | - |
| 491 | } else { | 0 |
| 492 | curvynessAdd = width * m_inv_scale; | - |
| 493 | curvynessMul = Q_PI / 8 / m_inv_scale; | - |
| 494 | } | 0 |
| 495 | | - |
| 496 | if (count < 2) never evaluated: count < 2 | 0 |
| 497 | return; | 0 |
| 498 | | - |
| 499 | const qreal *endPts = pts + (count<<1); | - |
| 500 | | - |
| 501 | m_dash_stroker.begin(this); | - |
| 502 | | - |
| 503 | if (!types) { | 0 |
| 504 | m_dash_stroker.moveTo(pts[0], pts[1]); | - |
| 505 | pts += 2; | - |
| 506 | while (pts < endPts) { never evaluated: pts < endPts | 0 |
| 507 | m_dash_stroker.lineTo(pts[0], pts[1]); | - |
| 508 | pts += 2; | - |
| 509 | } | 0 |
| 510 | } else { | 0 |
| 511 | while (pts < endPts) { never evaluated: pts < endPts | 0 |
| 512 | switch (*types) { | - |
| 513 | case QPainterPath::MoveToElement: | - |
| 514 | m_dash_stroker.moveTo(pts[0], pts[1]); | - |
| 515 | pts += 2; | - |
| 516 | ++types; | - |
| 517 | break; | 0 |
| 518 | case QPainterPath::LineToElement: | - |
| 519 | m_dash_stroker.lineTo(pts[0], pts[1]); | - |
| 520 | pts += 2; | - |
| 521 | ++types; | - |
| 522 | break; | 0 |
| 523 | case QPainterPath::CurveToElement: { | - |
| 524 | QBezier b = QBezier::fromPoints(*(((const QPointF *) pts) - 1), | - |
| 525 | *(((const QPointF *) pts)), | - |
| 526 | *(((const QPointF *) pts) + 1), | - |
| 527 | *(((const QPointF *) pts) + 2)); | - |
| 528 | QRectF bounds = b.bounds(); | - |
| 529 | float rad = qMax(bounds.width(), bounds.height()); | - |
| 530 | int threshold = qMin<float>(64, (rad + curvynessAdd) * curvynessMul); | - |
| 531 | if (threshold < 4) never evaluated: threshold < 4 | 0 |
| 532 | threshold = 4; never executed: threshold = 4; | 0 |
| 533 | | - |
| 534 | qreal threshold_minus_1 = threshold - 1; | - |
| 535 | for (int i=0; i<threshold; ++i) { never evaluated: i<threshold | 0 |
| 536 | QPointF pt = b.pointAt(i / threshold_minus_1); | - |
| 537 | m_dash_stroker.lineTo(pt.x(), pt.y()); | - |
| 538 | } | 0 |
| 539 | pts += 6; | - |
| 540 | types += 3; | - |
| 541 | break; } | 0 |
| 542 | default: break; | 0 |
| 543 | } | - |
| 544 | } | 0 |
| 545 | } | 0 |
| 546 | | - |
| 547 | m_dash_stroker.end(); | - |
| 548 | } | 0 |
| 549 | | - |
| 550 | | - |
| 551 | | - |
| | |