24 const int maxLen = 255;
28 if (*str == QLatin1Char(
'-')) {
31 }
else if (*str == QLatin1Char(
'+')) {
34 while (isDigit(str->unicode()) && pos < maxLen) {
35 temp[pos++] = str->toLatin1();
38 if (*str == QLatin1Char(
'.') && pos < maxLen) {
42 while (isDigit(str->unicode()) && pos < maxLen) {
43 temp[pos++] = str->toLatin1();
46 bool exponent =
false;
47 if ((*str == QLatin1Char(
'e') || *str == QLatin1Char(
'E')) && pos < maxLen) {
51 if ((*str == QLatin1Char(
'-') || *str == QLatin1Char(
'+')) && pos < maxLen) {
52 temp[pos++] = str->toLatin1();
55 while (isDigit(str->unicode()) && pos < maxLen) {
56 temp[pos++] = str->toLatin1();
64 if (!exponent && pos < 10) {
72 while(*t && *t !=
'.') {
86 val = ((qreal)ival)/((qreal)div);
94 val = qstrtod(temp,
nullptr, &ok);
122 qreal th0, qreal th1,
123 qreal rx, qreal ry, qreal xAxisRotation)
126 qreal a00, a01, a10, a11;
127 qreal x1, y1, x2, y2, x3, y3;
131 sinTh = qSin(qDegreesToRadians(xAxisRotation));
132 cosTh = qCos(qDegreesToRadians(xAxisRotation));
139 thHalf = 0.5 * (th1 - th0);
140 t = (8.0 / 3.0) * qSin(thHalf * 0.5) * qSin(thHalf * 0.5) / qSin(thHalf);
141 x1 = xc + qCos(th0) - t * qSin(th0);
142 y1 = yc + qSin(th0) + t * qCos(th0);
145 x2 = x3 + t * qSin(th1);
146 y2 = y3 - t * qCos(th1);
148 path.cubicTo(a00 * x1 + a01 * y1, a10 * x1 + a11 * y1,
149 a00 * x2 + a01 * y2, a10 * x2 + a11 * y2,
150 a00 * x3 + a01 * y3, a10 * x3 + a11 * y3);
156 qreal x_axis_rotation,
161 qreal curx, qreal cury)
164 if (QPointF(curx, cury) == QPointF(x, y))
167 qreal sin_th, cos_th;
168 qreal a00, a01, a10, a11;
169 qreal x0, y0, x1, y1, xc, yc;
170 qreal d, sfactor, sfactor_sq;
171 qreal th0, th1, th_arc;
173 qreal dx, dy, dx1, dy1, Pr1, Pr2, Px, Py, check;
178 if (qFuzzyIsNull(rx) || qFuzzyIsNull(ry)) {
186 sin_th = qSin(qDegreesToRadians(x_axis_rotation));
187 cos_th = qCos(qDegreesToRadians(x_axis_rotation));
189 dx = (curx - x) / 2.0;
190 dy = (cury - y) / 2.0;
191 dx1 = cos_th * dx + sin_th * dy;
192 dy1 = -sin_th * dx + cos_th * dy;
198 check = Px / Pr1 + Py / Pr2;
200 rx = rx * qSqrt(check);
201 ry = ry * qSqrt(check);
208 x0 = a00 * curx + a01 * cury;
209 y0 = a10 * curx + a11 * cury;
210 x1 = a00 * x + a01 * y;
211 y1 = a10 * x + a11 * y;
213
214
215
216
217 d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
218 sfactor_sq = 1.0 / d - 0.25;
219 if (sfactor_sq < 0) sfactor_sq = 0;
220 sfactor = qSqrt(sfactor_sq);
221 if (sweep_flag == large_arc_flag) sfactor = -sfactor;
222 xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0);
223 yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0);
226 th0 = qAtan2(y0 - yc, x0 - xc);
227 th1 = qAtan2(y1 - yc, x1 - xc);
230 if (th_arc < 0 && sweep_flag)
232 else if (th_arc > 0 && !sweep_flag)
235 n_segs = qCeil(qAbs(th_arc / (M_PI * 0.5 + 0.001)));
237 for (i = 0; i < n_segs; i++) {
238 pathArcSegment(path, xc, yc,
239 th0 + i * th_arc / n_segs,
240 th0 + (i + 1) * th_arc / n_segs,
241 rx, ry, x_axis_rotation);
248 qreal x0 = 0, y0 = 0;
252 const QChar *str = dataStr.constData();
253 const QChar *end = str + dataStr.size();
256 while (str->isSpace())
258 QChar pathElem = *str;
260 QVarLengthArray<qreal, 8> arg;
261 parseNumbersArray(str, arg);
262 if (pathElem == QLatin1Char(
'z') || pathElem == QLatin1Char(
'Z'))
264 const qreal *num = arg.constData();
265 int count = arg.size();
269 switch (pathElem.unicode()) {
276 x = x0 = num[0] + offsetX;
277 y = y0 = num[1] + offsetY;
285 pathElem = QLatin1Char(
'l');
303 pathElem = QLatin1Char(
'L');
321 x = num[0] + offsetX;
322 y = num[1] + offsetY;
343 x = num[0] + offsetX;
357 y = num[0] + offsetY;
376 QPointF c1(num[0] + offsetX, num[1] + offsetY);
377 QPointF c2(num[2] + offsetX, num[3] + offsetY);
378 QPointF e(num[4] + offsetX, num[5] + offsetY);
381 path.cubicTo(c1, c2, e);
393 QPointF c1(num[0], num[1]);
394 QPointF c2(num[2], num[3]);
395 QPointF e(num[4], num[5]);
398 path.cubicTo(c1, c2, e);
411 if (lastMode ==
'c' || lastMode ==
'C' ||
412 lastMode ==
's' || lastMode ==
'S')
413 c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
416 QPointF c2(num[0] + offsetX, num[1] + offsetY);
417 QPointF e(num[2] + offsetX, num[3] + offsetY);
420 path.cubicTo(c1, c2, e);
433 if (lastMode ==
'c' || lastMode ==
'C' ||
434 lastMode ==
's' || lastMode ==
'S')
435 c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
438 QPointF c2(num[0], num[1]);
439 QPointF e(num[2], num[3]);
442 path.cubicTo(c1, c2, e);
454 QPointF c(num[0] + offsetX, num[1] + offsetY);
455 QPointF e(num[2] + offsetX, num[3] + offsetY);
470 QPointF c(num[0], num[1]);
471 QPointF e(num[2], num[3]);
486 QPointF e(num[0] + offsetX, num[1] + offsetY);
490 if (lastMode ==
'q' || lastMode ==
'Q' ||
491 lastMode ==
't' || lastMode ==
'T')
492 c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
507 QPointF e(num[0], num[1]);
511 if (lastMode ==
'q' || lastMode ==
'Q' ||
512 lastMode ==
't' || lastMode ==
'T')
513 c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
530 qreal xAxisRotation = (*num++);
531 qreal largeArcFlag = (*num++);
532 qreal sweepFlag = (*num++);
533 qreal ex = (*num++) + offsetX;
534 qreal ey = (*num++) + offsetY;
538 pathArc(path, rx, ry, xAxisRotation,
int(largeArcFlag),
539 int(sweepFlag), ex, ey, curx, cury);
553 qreal xAxisRotation = (*num++);
554 qreal largeArcFlag = (*num++);
555 qreal sweepFlag = (*num++);
561 pathArc(path, rx, ry, xAxisRotation,
int(largeArcFlag),
562 int(sweepFlag), ex, ey, curx, cury);
571 lastMode = pathElem.toLatin1();