bool SmoothPathPlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 0) { PageItem *currItem = currDoc->m_Selection->itemAt(0); QPainterPath pp; if (currItem->itemType() == PageItem::PolyLine) pp = currItem->PoLine.toQPainterPath(false); else pp = currItem->PoLine.toQPainterPath(true); QList<QPolygonF> polyList = pp.toSubpathPolygons(); QPainterPath result; for (int a = 0; a < polyList.count(); a++) { result.addPath(bezierFit(polyList[a], 5.0)); } currItem->PoLine.fromQPainterPath(result); currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); currDoc->regionsChanged()->update(QRectF()); currDoc->changed(); } return true; }
bool SubdividePlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; double nearT = 0.5; uint docSelectionCount = currDoc->m_Selection->count(); if (docSelectionCount != 0) { for (uint aa = 0; aa < docSelectionCount; ++aa) { FPointArray points; PageItem *currItem = currDoc->m_Selection->itemAt(aa); if (currDoc->nodeEdit.isContourLine) { uint psize = currItem->ContourLine.size(); for (uint a = 0; a < psize-3; a += 4) { if (currItem->ContourLine.point(a).x() > 900000) { points.setMarker(); continue; } FPoint base = currItem->ContourLine.point(a); FPoint c1 = currItem->ContourLine.point(a+1); FPoint base2 = currItem->ContourLine.point(a+2); FPoint c2 = currItem->ContourLine.point(a+3); FPoint cn1 = (1.0 - nearT) * base + nearT * c1; FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2); FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2); FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2; FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3; if ((base == c1) && (base2 == c2)) { points.addPoint(base); points.addPoint(c1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(base2); points.addPoint(c2); } else { points.addPoint(base); points.addPoint(cn1); points.addPoint(bp1); points.addPoint(cn2); points.addPoint(bp1); points.addPoint(cn3); points.addPoint(base2); points.addPoint(cn4); } } currItem->ContourLine = points; } else { uint psize = currItem->PoLine.size(); for (uint a = 0; a < psize-3; a += 4) { if (currItem->PoLine.point(a).x() > 900000) { points.setMarker(); continue; } FPoint base = currItem->PoLine.point(a); FPoint c1 = currItem->PoLine.point(a+1); FPoint base2 = currItem->PoLine.point(a+2); FPoint c2 = currItem->PoLine.point(a+3); FPoint cn1 = (1.0 - nearT) * base + nearT * c1; FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2); FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2); FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2; FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3; if ((base == c1) && (base2 == c2)) { points.addPoint(base); points.addPoint(c1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(base2); points.addPoint(c2); } else { points.addPoint(base); points.addPoint(cn1); points.addPoint(bp1); points.addPoint(cn2); points.addPoint(bp1); points.addPoint(cn3); points.addPoint(base2); points.addPoint(cn4); } } currItem->PoLine = points; currItem->Frame = false; currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); } } currDoc->regionsChanged()->update(QRectF()); currDoc->changed(); } return true; }