24 const int maxLen = 255;
28 if (*str == QLatin1Char(
'-')) {
31 }
else if (*str == QLatin1Char(
'+')) {
34 while (str != end && isDigit(str->unicode()) && pos < maxLen) {
35 temp[pos++] = str->toLatin1();
38 if (str != end && *str == QLatin1Char(
'.') && pos < maxLen) {
42 while (str != end && isDigit(str->unicode()) && pos < maxLen) {
43 temp[pos++] = str->toLatin1();
46 bool exponent =
false;
47 if (str != end && (*str == QLatin1Char(
'e') || *str == QLatin1Char(
'E')) && pos < maxLen) {
51 if (str != end && (*str == QLatin1Char(
'-') || *str == QLatin1Char(
'+')) && pos < maxLen) {
52 temp[pos++] = str->toLatin1();
55 while (str != end && 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);
126 qreal th0, qreal th1,
127 qreal rx, qreal ry, qreal xAxisRotation)
130 qreal a00, a01, a10, a11;
131 qreal x1, y1, x2, y2, x3, y3;
135 sinTh = qSin(qDegreesToRadians(xAxisRotation));
136 cosTh = qCos(qDegreesToRadians(xAxisRotation));
143 thHalf = 0.5 * (th1 - th0);
144 t = (8.0 / 3.0) * qSin(thHalf * 0.5) * qSin(thHalf * 0.5) / qSin(thHalf);
145 x1 = xc + qCos(th0) - t * qSin(th0);
146 y1 = yc + qSin(th0) + t * qCos(th0);
149 x2 = x3 + t * qSin(th1);
150 y2 = y3 - t * qCos(th1);
152 path.cubicTo(a00 * x1 + a01 * y1, a10 * x1 + a11 * y1,
153 a00 * x2 + a01 * y2, a10 * x2 + a11 * y2,
154 a00 * x3 + a01 * y3, a10 * x3 + a11 * y3);
160 qreal x_axis_rotation,
165 qreal curx, qreal cury)
168 if (QPointF(curx, cury) == QPointF(x, y))
171 qreal sin_th, cos_th;
172 qreal a00, a01, a10, a11;
173 qreal x0, y0, x1, y1, xc, yc;
174 qreal d, sfactor, sfactor_sq;
175 qreal th0, th1, th_arc;
177 qreal dx, dy, dx1, dy1, Pr1, Pr2, Px, Py, check;
182 if (qFuzzyIsNull(rx) || qFuzzyIsNull(ry)) {
190 sin_th = qSin(qDegreesToRadians(x_axis_rotation));
191 cos_th = qCos(qDegreesToRadians(x_axis_rotation));
193 dx = (curx - x) / 2.0;
194 dy = (cury - y) / 2.0;
195 dx1 = cos_th * dx + sin_th * dy;
196 dy1 = -sin_th * dx + cos_th * dy;
202 check = Px / Pr1 + Py / Pr2;
204 rx = rx * qSqrt(check);
205 ry = ry * qSqrt(check);
212 x0 = a00 * curx + a01 * cury;
213 y0 = a10 * curx + a11 * cury;
214 x1 = a00 * x + a01 * y;
215 y1 = a10 * x + a11 * y;
217
218
219
220
221 d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
222 sfactor_sq = 1.0 / d - 0.25;
223 if (sfactor_sq < 0) sfactor_sq = 0;
224 sfactor = qSqrt(sfactor_sq);
225 if (sweep_flag == large_arc_flag) sfactor = -sfactor;
226 xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0);
227 yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0);
230 th0 = qAtan2(y0 - yc, x0 - xc);
231 th1 = qAtan2(y1 - yc, x1 - xc);
234 if (th_arc < 0 && sweep_flag)
236 else if (th_arc > 0 && !sweep_flag)
239 n_segs = qCeil(qAbs(th_arc / (M_PI * 0.5 + 0.001)));
241 for (i = 0; i < n_segs; i++) {
242 pathArcSegment(path, xc, yc,
243 th0 + i * th_arc / n_segs,
244 th0 + (i + 1) * th_arc / n_segs,
245 rx, ry, x_axis_rotation);
252 qreal x0 = 0, y0 = 0;
256 const QChar *str = dataStr.constData();
257 const QChar *end = str + dataStr.size();
260 QChar pathElem = *str;
262 if (pathElem.isSpace())
264 QVarLengthArray<qreal, 8> arg;
265 parseNumbersArray(str, end, arg);
266 if (pathElem == QLatin1Char(
'z') || pathElem == QLatin1Char(
'Z'))
268 const qreal *num = arg.constData();
269 int count = arg.size();
273 switch (pathElem.unicode()) {
280 x = x0 = num[0] + offsetX;
281 y = y0 = num[1] + offsetY;
289 pathElem = QLatin1Char(
'l');
307 pathElem = QLatin1Char(
'L');
325 x = num[0] + offsetX;
326 y = num[1] + offsetY;
347 x = num[0] + offsetX;
361 y = num[0] + offsetY;
380 QPointF c1(num[0] + offsetX, num[1] + offsetY);
381 QPointF c2(num[2] + offsetX, num[3] + offsetY);
382 QPointF e(num[4] + offsetX, num[5] + offsetY);
385 path.cubicTo(c1, c2, e);
397 QPointF c1(num[0], num[1]);
398 QPointF c2(num[2], num[3]);
399 QPointF e(num[4], num[5]);
402 path.cubicTo(c1, c2, e);
415 if (lastMode ==
'c' || lastMode ==
'C' ||
416 lastMode ==
's' || lastMode ==
'S')
417 c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
420 QPointF c2(num[0] + offsetX, num[1] + offsetY);
421 QPointF e(num[2] + offsetX, num[3] + offsetY);
424 path.cubicTo(c1, c2, e);
437 if (lastMode ==
'c' || lastMode ==
'C' ||
438 lastMode ==
's' || lastMode ==
'S')
439 c1 = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
442 QPointF c2(num[0], num[1]);
443 QPointF e(num[2], num[3]);
446 path.cubicTo(c1, c2, e);
458 QPointF c(num[0] + offsetX, num[1] + offsetY);
459 QPointF e(num[2] + offsetX, num[3] + offsetY);
474 QPointF c(num[0], num[1]);
475 QPointF e(num[2], num[3]);
490 QPointF e(num[0] + offsetX, num[1] + offsetY);
494 if (lastMode ==
'q' || lastMode ==
'Q' ||
495 lastMode ==
't' || lastMode ==
'T')
496 c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
511 QPointF e(num[0], num[1]);
515 if (lastMode ==
'q' || lastMode ==
'Q' ||
516 lastMode ==
't' || lastMode ==
'T')
517 c = QPointF(2*x-ctrlPt.x(), 2*y-ctrlPt.y());
534 qreal xAxisRotation = (*num++);
535 qreal largeArcFlag = (*num++);
536 qreal sweepFlag = (*num++);
537 qreal ex = (*num++) + offsetX;
538 qreal ey = (*num++) + offsetY;
542 pathArc(path, rx, ry, xAxisRotation,
int(largeArcFlag),
543 int(sweepFlag), ex, ey, curx, cury);
557 qreal xAxisRotation = (*num++);
558 qreal largeArcFlag = (*num++);
559 qreal sweepFlag = (*num++);
565 pathArc(path, rx, ry, xAxisRotation,
int(largeArcFlag),
566 int(sweepFlag), ex, ey, curx, cury);
575 lastMode = pathElem.toLatin1();