void XmlLoader::readPath(QDomElement const &element) { QString tempStr; QPointF endPoint; QPointF c1; QPointF c2; QDomElement elem = element; QPainterPath path; if (!elem.isNull()) { QString dCont; dCont = elem.attribute("d").remove(0, 1); dCont.append(" Z"); for (int i = 0; i < dCont.length() - 1;) { int j = 0; if (dCont[i] == 'M') { j = i + 2; while (isNotLCMZ(dCont, j)) { while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setY(tempStr.toFloat()); ++j; tempStr.clear(); } path.moveTo(endPoint); i = j; } else if (dCont[i] == 'L') { j = i + 2; while (isNotLCMZ(dCont, j)) { while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setY(tempStr.toFloat()); ++j; tempStr.clear(); } path.lineTo(endPoint); i = j; } else if (dCont[i] == 'C') { j = i + 2; while(isNotLCMZ(dCont, j)) { while (!(dCont[j] == ' ')) { tempStr.append(dCont[j]); ++j; } c1.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } c1.setY(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } c2.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } c2.setY(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setX(tempStr.toFloat()); tempStr.clear(); ++j; while (dCont[j] != ' ') { tempStr.append(dCont[j]); ++j; } endPoint.setY(tempStr.toFloat()); tempStr.clear(); ++j; } path.cubicTo(c1, c2, endPoint); i = j; } else if (dCont[i] == 'Z') { path.closeSubpath(); } } } Path *item = new Path(path); item->translate(mDrift.x(), mDrift.y()); item->readPenBrush(elem); mScene->addItem(item); mScene->setZValue(item); }
void SdfRenderer::path_draw(QDomElement &element) { QPointF end_point; QPointF c1; QPointF c2; QDomElement elem = element; QPainterPath path; if (!elem.isNull()) { QString d_cont; d_cont = elem.attribute("d").remove(0, 1); d_cont.append(" Z"); for (i = 0; i < d_cont.length() - 1;) { if (d_cont[i] == 'M') { j = i + 2; while (isNotLCMZ(d_cont, j)) { while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); ++j; s1.clear(); } path.moveTo(end_point); i = j; } else if (d_cont[i] == 'L') { j = i + 2; while (isNotLCMZ(d_cont, j)) { while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); ++j; s1.clear(); } path.lineTo(end_point); i = j; } else if (d_cont[i] == 'C') { j = i + 2; while(isNotLCMZ(d_cont, j)) { while (!(d_cont[j] == ' ')) { s1.append(d_cont[j]); ++j; } c1.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } c1.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } c2.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } c2.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setX(s1.toFloat() * current_size_x / first_size_x + mStartX); s1.clear(); ++j; while (d_cont[j] != ' ') { s1.append(d_cont[j]); ++j; } end_point.setY(s1.toFloat() * current_size_y / first_size_y + mStartY); s1.clear(); ++j; } path.cubicTo(c1, c2, end_point); i = j; } else if (d_cont[i] == 'Z') { path.closeSubpath(); logger ("loggerZ.txt", "DONE"); } } } parsestyle(element); painter->drawPath(path); }