diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-04-10 20:11:50 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-04-10 20:11:50 +0000 |
| commit | 5be72612bc09d01581d572d152dafdd64f5cfd7e (patch) | |
| tree | 569b4adb875b53b26aa7166379c2b8d36a37439c /src/live_effects | |
| parent | Fix coding style issues in mirror symmetry code (diff) | |
| parent | added info about multiple pen feature in gui (diff) | |
| download | inkscape-5be72612bc09d01581d572d152dafdd64f5cfd7e.tar.gz inkscape-5be72612bc09d01581d572d152dafdd64f5cfd7e.zip | |
update to trunk
(bzr r13682.1.26)
Diffstat (limited to 'src/live_effects')
| -rw-r--r-- | src/live_effects/CMakeLists.txt | 51 | ||||
| -rw-r--r-- | src/live_effects/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-bspline.cpp | 368 | ||||
| -rw-r--r-- | src/live_effects/lpe-bspline.h | 10 | ||||
| -rw-r--r-- | src/live_effects/lpe-jointype.cpp | 129 | ||||
| -rw-r--r-- | src/live_effects/lpe-jointype.h | 5 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice2.cpp | 560 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice2.h | 63 | ||||
| -rw-r--r-- | src/live_effects/lpe-perspective-envelope.cpp | 277 | ||||
| -rw-r--r-- | src/live_effects/lpe-perspective-envelope.h | 18 | ||||
| -rw-r--r-- | src/live_effects/lpe-powerstroke.cpp | 33 | ||||
| -rw-r--r-- | src/live_effects/lpe-roughen.cpp | 206 | ||||
| -rw-r--r-- | src/live_effects/lpe-roughen.h | 14 | ||||
| -rw-r--r-- | src/live_effects/lpe-show_handles.cpp | 76 | ||||
| -rw-r--r-- | src/live_effects/lpe-show_handles.h | 14 | ||||
| -rw-r--r-- | src/live_effects/lpe-simplify.cpp | 190 | ||||
| -rw-r--r-- | src/live_effects/lpe-simplify.h | 48 | ||||
| -rw-r--r-- | src/live_effects/lpe-taperstroke.cpp | 204 | ||||
| -rw-r--r-- | src/live_effects/pathoutlineprovider.cpp | 803 | ||||
| -rw-r--r-- | src/live_effects/pathoutlineprovider.h | 55 |
20 files changed, 1072 insertions, 2054 deletions
diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index c8a02c810..c4b92e579 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -1,4 +1,3 @@ - set(live_effects_SRC effect.cpp lpe-angle_bisector.cpp @@ -6,6 +5,7 @@ set(live_effects_SRC lpe-bendpath.cpp lpe-boolops.cpp lpe-bounding-box.cpp + lpe-bspline.cpp lpe-circle_3pts.cpp lpe-circle_with_radius.cpp lpe-clone-original.cpp @@ -13,7 +13,7 @@ set(live_effects_SRC lpe-copy_rotate.cpp lpe-curvestitch.cpp lpe-dynastroke.cpp - lpe-ellipse-5pts.cpp + lpe-ellipse_5pts.cpp lpe-envelope.cpp lpe-extrude.cpp lpe-fill-between-many.cpp @@ -21,8 +21,11 @@ set(live_effects_SRC lpe-fillet-chamfer.cpp lpe-gears.cpp lpe-interpolate.cpp + lpe-interpolate_points.cpp + lpe-jointype.cpp lpe-knot.cpp lpe-lattice.cpp + lpe-lattice2.cpp lpe-line_segment.cpp lpe-mirror_symmetry.cpp lpe-offset.cpp @@ -30,43 +33,43 @@ set(live_effects_SRC lpe-path_length.cpp lpe-patternalongpath.cpp lpe-perp_bisector.cpp - lpe-perspective_path.cpp lpe-perspective-envelope.cpp + lpe-perspective_path.cpp lpe-powerstroke.cpp lpe-recursiveskeleton.cpp lpe-rough-hatches.cpp + lpe-roughen.cpp lpe-ruler.cpp lpe-show_handles.cpp lpe-simplify.cpp - # lpe-skeleton.cpp + lpe-skeleton.cpp lpe-sketch.cpp lpe-spiro.cpp - lpe-roughen.cpp lpe-tangent_to_curve.cpp + lpe-taperstroke.cpp lpe-test-doEffect-stack.cpp - lpe-bspline.cpp lpe-text_label.cpp - lpe-vonkoch.cpp lpegroupbbox.cpp lpeobject-reference.cpp + lpe-vonkoch.cpp lpeobject.cpp - spiro.cpp spiro-converters.cpp + spiro.cpp parameter/array.cpp parameter/bool.cpp parameter/filletchamferpointarray.cpp - parameter/parameter.cpp - parameter/path.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp + parameter/parameter.cpp parameter/path-reference.cpp + parameter/path.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - paramter/transformedpoint.cpp parameter/togglebutton.cpp + parameter/transformedpoint.cpp parameter/unit.cpp parameter/vector.cpp @@ -80,6 +83,7 @@ set(live_effects_SRC lpe-bendpath.h lpe-boolops.h lpe-bounding-box.h + lpe-bspline.h lpe-circle_3pts.h lpe-circle_with_radius.h lpe-clone-original.h @@ -87,7 +91,7 @@ set(live_effects_SRC lpe-copy_rotate.h lpe-curvestitch.h lpe-dynastroke.h - lpe-ellipse-5pts.h + lpe-ellipse_5pts.h lpe-envelope.h lpe-extrude.h lpe-fill-between-many.h @@ -95,8 +99,11 @@ set(live_effects_SRC lpe-fillet-chamfer.h lpe-gears.h lpe-interpolate.h + lpe-interpolate_points.h + lpe-jointype.h lpe-knot.h lpe-lattice.h + lpe-lattice2.h lpe-line_segment.h lpe-mirror_symmetry.h lpe-offset.h @@ -104,47 +111,47 @@ set(live_effects_SRC lpe-path_length.h lpe-patternalongpath.h lpe-perp_bisector.h - lpe-perspective_path.h lpe-perspective-envelope.h - lpe-powerstroke.h + lpe-perspective_path.h lpe-powerstroke-interpolators.h + lpe-powerstroke.h lpe-recursiveskeleton.h lpe-rough-hatches.h + lpe-roughen.h lpe-ruler.h - lpe-simplify.h lpe-show_handles.h + lpe-simplify.h lpe-skeleton.h lpe-sketch.h lpe-spiro.h - lpe-roughen.h lpe-tangent_to_curve.h + lpe-taperstroke.h lpe-test-doEffect-stack.h - lpe-bspline.h lpe-text_label.h lpe-vonkoch.h lpegroupbbox.h lpeobject-reference.h lpeobject.h - spiro.h spiro-converters.h + spiro.h parameter/array.h parameter/bool.h - parameter/filletchamferpointarray.h parameter/enum.h + parameter/filletchamferpointarray.h + parameter/originalpath.h + parameter/originalpatharray.h parameter/parameter.h parameter/path-reference.h parameter/path.h - parameter/originalpath.h - parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h parameter/random.h parameter/text.h parameter/togglebutton.h + parameter/transformedpoint.h parameter/unit.h parameter/vector.h - ) # add_inkscape_lib(live_effects_LIB "${live_effects_SRC}") diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index 8f0a3ac57..dace45739 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -109,8 +109,6 @@ ink_common_sources += \ live_effects/lpe-fill-between-many.h \ live_effects/lpe-ellipse_5pts.cpp \ live_effects/lpe-ellipse_5pts.h \ - live_effects/pathoutlineprovider.cpp \ - live_effects/pathoutlineprovider.h \ live_effects/lpe-jointype.cpp \ live_effects/lpe-jointype.h \ live_effects/lpe-taperstroke.cpp \ diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index b924d8a23..ecbfef76a 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -1,72 +1,40 @@ /* * Released under GNU GPL, read the file 'COPYING' for more information */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - #include <gtkmm.h> - -#if WITH_GLIBMM_2_32 -# include <glibmm/threads.h> -#endif - -#include <glib.h> -#include <glibmm/i18n.h> - - -#include "display/curve.h" -#include <2geom/bezier-curve.h> -#include <2geom/point.h> -#include "helper/geom-curves.h" #include "live_effects/lpe-bspline.h" -#include "live_effects/lpeobject.h" -#include "live_effects/parameter/parameter.h" #include "ui/widget/scalar.h" -#include "xml/repr.h" -#include "svg/svg.h" +#include "display/curve.h" +#include "helper/geom-curves.h" #include "sp-path.h" -#include "style.h" -#include "document-private.h" -#include "document.h" -#include "document-undo.h" -#include "verbs.h" -#include "sp-lpe-item.h" -#include "sp-namedview.h" -#include "display/sp-canvas.h" -#include <typeinfo> -#include <vector> -#include "util/units.h" -// For handling un-continuous paths: -#include "message-stack.h" -#include "inkscape.h" - -using Inkscape::DocumentUndo; +#include "svg/svg.h" +#include "xml/repr.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include <glibmm/i18n.h> namespace Inkscape { namespace LivePathEffect { -const double handleCubicGap = 0.01; -const double noPower = 0.0; -const double defaultStartPower = 0.3334; -const double defaultEndPower = 0.6667; +const double HANDLE_CUBIC_GAP = 0.01; +const double NO_POWER = 0.0; +const double DEFAULT_START_POWER = 0.3334; +const double DEFAULT_END_POWER = 0.6667; LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) : Effect(lpeobject), steps(_("Steps with CTRL:"), _("Change number of steps with CTRL pressed"), "steps", &wr, this, 2), helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 0), - ignoreCusp(_("Ignore cusp nodes"), _("Change ignoring cusp nodes"), "ignoreCusp", &wr, this, true), - onlySelected(_("Change only selected nodes"), _("Change only selected nodes"), "onlySelected", &wr, this, false), - weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, defaultStartPower) + ignore_cusp(_("Ignore cusp nodes"), _("Change ignoring cusp nodes"), "ignore_cusp", &wr, this, true), + only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), + weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, DEFAULT_START_POWER) { registerParameter(&weight); registerParameter(&steps); registerParameter(&helper_size); - registerParameter(&ignoreCusp); - registerParameter(&onlySelected); + registerParameter(&ignore_cusp); + registerParameter(&only_selected); - weight.param_set_range(noPower, 1); + weight.param_set_range(NO_POWER, 1); weight.param_set_increments(0.1, 0.1); weight.param_set_digits(4); @@ -83,7 +51,7 @@ LPEBSpline::~LPEBSpline() {} void LPEBSpline::doBeforeEffect (SPLPEItem const* /*lpeitem*/) { - if(!hp.empty()){ + if(!hp.empty()) { hp.clear(); } } @@ -101,30 +69,32 @@ void LPEBSpline::doOnApply(SPLPEItem const* lpeitem) void LPEBSpline::doEffect(SPCurve *curve) { - if (curve->get_segment_count() < 1){ + if (curve->get_segment_count() < 1) { return; } // Make copy of old path as it is changed during processing Geom::PathVector const original_pathv = curve->get_pathvector(); + curve->reset(); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) + if (path_it->empty()) { continue; - + } + hp.push_back(*path_it); Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); - SPCurve *nCurve = new SPCurve(); + SPCurve *curve_n = new SPCurve(); Geom::Point previousNode(0, 0); Geom::Point node(0, 0); - Geom::Point pointAt1(0, 0); - Geom::Point pointAt2(0, 0); - Geom::Point nextPointAt1(0, 0); - Geom::D2<Geom::SBasis> SBasisIn; - Geom::D2<Geom::SBasis> SBasisOut; - Geom::D2<Geom::SBasis> SBasisHelper; + Geom::Point point_at1(0, 0); + Geom::Point point_at2(0, 0); + Geom::Point next_point_at1(0, 0); + Geom::D2<Geom::SBasis> sbasis_in; + Geom::D2<Geom::SBasis> sbasis_out; + Geom::D2<Geom::SBasis> sbasis_helper; Geom::CubicBezier const *cubic = NULL; if (path_it->closed()) { // if the path is closed, maybe we have to stop a bit earlier because the @@ -140,27 +110,27 @@ void LPEBSpline::doEffect(SPCurve *curve) curve_endit = path_it->end_open(); } } - nCurve->moveto(curve_it1->initialPoint()); + curve_n->moveto(curve_it1->initialPoint()); while (curve_it1 != curve_endit) { SPCurve *in = new SPCurve(); in->moveto(curve_it1->initialPoint()); in->lineto(curve_it1->finalPoint()); cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); if (cubic) { - SBasisIn = in->first_segment()->toSBasis(); + sbasis_in = in->first_segment()->toSBasis(); if(are_near((*cubic)[1],(*cubic)[0]) && !are_near((*cubic)[2],(*cubic)[3])) { - pointAt1 = SBasisIn.valueAt(defaultStartPower); + point_at1 = sbasis_in.valueAt(DEFAULT_START_POWER); } else { - pointAt1 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[1], *in->first_segment())); + point_at1 = sbasis_in.valueAt(Geom::nearest_point((*cubic)[1], *in->first_segment())); } if(are_near((*cubic)[2],(*cubic)[3]) && !are_near((*cubic)[1],(*cubic)[0])) { - pointAt2 = SBasisIn.valueAt(defaultEndPower); + point_at2 = sbasis_in.valueAt(DEFAULT_END_POWER); } else { - pointAt2 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[2], *in->first_segment())); + point_at2 = sbasis_in.valueAt(Geom::nearest_point((*cubic)[2], *in->first_segment())); } } else { - pointAt1 = in->first_segment()->initialPoint(); - pointAt2 = in->first_segment()->finalPoint(); + point_at1 = in->first_segment()->initialPoint(); + point_at2 = in->first_segment()->finalPoint(); } in->reset(); delete in; @@ -170,14 +140,14 @@ void LPEBSpline::doEffect(SPCurve *curve) out->lineto(curve_it2->finalPoint()); cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it2); if (cubic) { - SBasisOut = out->first_segment()->toSBasis(); + sbasis_out = out->first_segment()->toSBasis(); if(are_near((*cubic)[1],(*cubic)[0]) && !are_near((*cubic)[2],(*cubic)[3])) { - nextPointAt1 = SBasisIn.valueAt(defaultStartPower); + next_point_at1 = sbasis_in.valueAt(DEFAULT_START_POWER); } else { - nextPointAt1 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[1], *out->first_segment())); + next_point_at1 = sbasis_out.valueAt(Geom::nearest_point((*cubic)[1], *out->first_segment())); } } else { - nextPointAt1 = out->first_segment()->initialPoint(); + next_point_at1 = out->first_segment()->initialPoint(); } out->reset(); delete out; @@ -186,14 +156,14 @@ void LPEBSpline::doEffect(SPCurve *curve) SPCurve *start = new SPCurve(); start->moveto(path_it->begin()->initialPoint()); start->lineto(path_it->begin()->finalPoint()); - Geom::D2<Geom::SBasis> SBasisStart = start->first_segment()->toSBasis(); - SPCurve *lineHelper = new SPCurve(); + Geom::D2<Geom::SBasis> sbasis_start = start->first_segment()->toSBasis(); + SPCurve *line_helper = new SPCurve(); cubic = dynamic_cast<Geom::CubicBezier const *>(&*path_it->begin()); if (cubic) { - lineHelper->moveto(SBasisStart.valueAt( + line_helper->moveto(sbasis_start.valueAt( Geom::nearest_point((*cubic)[1], *start->first_segment()))); } else { - lineHelper->moveto(start->first_segment()->initialPoint()); + line_helper->moveto(start->first_segment()->initialPoint()); } start->reset(); delete start; @@ -201,41 +171,41 @@ void LPEBSpline::doEffect(SPCurve *curve) SPCurve *end = new SPCurve(); end->moveto(curve_it1->initialPoint()); end->lineto(curve_it1->finalPoint()); - Geom::D2<Geom::SBasis> SBasisEnd = end->first_segment()->toSBasis(); + Geom::D2<Geom::SBasis> sbasis_end = end->first_segment()->toSBasis(); cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); if (cubic) { - lineHelper->lineto(SBasisEnd.valueAt( + line_helper->lineto(sbasis_end.valueAt( Geom::nearest_point((*cubic)[2], *end->first_segment()))); } else { - lineHelper->lineto(end->first_segment()->finalPoint()); + line_helper->lineto(end->first_segment()->finalPoint()); } end->reset(); delete end; - SBasisHelper = lineHelper->first_segment()->toSBasis(); - lineHelper->reset(); - delete lineHelper; - node = SBasisHelper.valueAt(0.5); - nCurve->curveto(pointAt1, pointAt2, node); - nCurve->move_endpoints(node, node); + sbasis_helper = line_helper->first_segment()->toSBasis(); + line_helper->reset(); + delete line_helper; + node = sbasis_helper.valueAt(0.5); + curve_n->curveto(point_at1, point_at2, node); + curve_n->move_endpoints(node, node); } else if ( curve_it2 == curve_endit) { - nCurve->curveto(pointAt1, pointAt2, curve_it1->finalPoint()); - nCurve->move_endpoints(path_it->begin()->initialPoint(), curve_it1->finalPoint()); + curve_n->curveto(point_at1, point_at2, curve_it1->finalPoint()); + curve_n->move_endpoints(path_it->begin()->initialPoint(), curve_it1->finalPoint()); } else { - SPCurve *lineHelper = new SPCurve(); - lineHelper->moveto(pointAt2); - lineHelper->lineto(nextPointAt1); - SBasisHelper = lineHelper->first_segment()->toSBasis(); - lineHelper->reset(); - delete lineHelper; + SPCurve *line_helper = new SPCurve(); + line_helper->moveto(point_at2); + line_helper->lineto(next_point_at1); + sbasis_helper = line_helper->first_segment()->toSBasis(); + line_helper->reset(); + delete line_helper; previousNode = node; - node = SBasisHelper.valueAt(0.5); + node = sbasis_helper.valueAt(0.5); Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); if((cubic && are_near((*cubic)[0],(*cubic)[1])) || (cubic2 && are_near((*cubic2)[2],(*cubic2)[3]))) { node = curve_it1->finalPoint(); } - nCurve->curveto(pointAt1, pointAt2, node); + curve_n->curveto(point_at1, point_at2, node); } - if(!are_near(node,curve_it1->finalPoint()) && helper_size > 0.0){ + if(!are_near(node,curve_it1->finalPoint()) && helper_size > 0.0) { drawHandle(node, helper_size); } ++curve_it1; @@ -243,15 +213,15 @@ void LPEBSpline::doEffect(SPCurve *curve) } //y cerramos la curva if (path_it->closed()) { - nCurve->closepath_current(); + curve_n->closepath_current(); } - curve->append(nCurve, false); - nCurve->reset(); - delete nCurve; + curve->append(curve_n, false); + curve_n->reset(); + delete curve_n; } - if(helper_size > 0.0){ + if(helper_size > 0.0) { Geom::PathVector const pathv = curve->get_pathvector(); - hp.push_back(pathv[0]); + hp.push_back(pathv[0]); } } @@ -286,40 +256,40 @@ Gtk::Widget *LPEBSpline::newWidget() Gtk::Widget *widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); if (param->param_key == "weight") { Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *defaultWeight = + Gtk::Button *default_weight = Gtk::manage(new Gtk::Button(Glib::ustring(_("Default weight")))); - defaultWeight->signal_clicked() + default_weight->signal_clicked() .connect(sigc::mem_fun(*this, &LPEBSpline::toDefaultWeight)); - buttons->pack_start(*defaultWeight, true, true, 2); - Gtk::Button *makeCusp = + buttons->pack_start(*default_weight, true, true, 2); + Gtk::Button *make_cusp = Gtk::manage(new Gtk::Button(Glib::ustring(_("Make cusp")))); - makeCusp->signal_clicked() + make_cusp->signal_clicked() .connect(sigc::mem_fun(*this, &LPEBSpline::toMakeCusp)); - buttons->pack_start(*makeCusp, true, true, 2); + buttons->pack_start(*make_cusp, true, true, 2); vbox->pack_start(*buttons, true, true, 2); } if (param->param_key == "weight" || param->param_key == "steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = + Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast<Inkscape::UI::Widget::Scalar *>(widg)); - widgRegistered->signal_value_changed() + widg_registered->signal_value_changed() .connect(sigc::mem_fun(*this, &LPEBSpline::toWeight)); - widg = dynamic_cast<Gtk::Widget *>(widgRegistered); + widg = dynamic_cast<Gtk::Widget *>(widg_registered); if (widg) { - Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widg); - std::vector< Gtk::Widget* > childList = scalarParameter->get_children(); - Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]); - entryWidg->set_width_chars(6); + Gtk::HBox * hbox_weight_steps = dynamic_cast<Gtk::HBox *>(widg); + std::vector< Gtk::Widget* > childList = hbox_weight_steps->get_children(); + Gtk::Entry* entry_widget = dynamic_cast<Gtk::Entry *>(childList[1]); + entry_widget->set_width_chars(6); } } - if (param->param_key == "onlySelected") { - Gtk::CheckButton *widgRegistered = + if (param->param_key == "only_selected") { + Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast<Gtk::CheckButton *>(widg)); - widg = dynamic_cast<Gtk::Widget *>(widgRegistered); + widg = dynamic_cast<Gtk::Widget *>(widg_registered); } - if (param->param_key == "ignoreCusp") { - Gtk::CheckButton *widgRegistered = + if (param->param_key == "ignore_cusp") { + Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast<Gtk::CheckButton *>(widg)); - widg = dynamic_cast<Gtk::Widget *>(widgRegistered); + widg = dynamic_cast<Gtk::Widget *>(widg_registered); } Glib::ustring *tip = param->param_getTooltip(); if (widg) { @@ -340,12 +310,12 @@ Gtk::Widget *LPEBSpline::newWidget() void LPEBSpline::toDefaultWeight() { - changeWeight(defaultStartPower); + changeWeight(DEFAULT_START_POWER); } void LPEBSpline::toMakeCusp() { - changeWeight(noPower); + changeWeight(NO_POWER); } void LPEBSpline::toWeight() @@ -353,22 +323,22 @@ void LPEBSpline::toWeight() changeWeight(weight); } -void LPEBSpline::changeWeight(double weightValue) +void LPEBSpline::changeWeight(double weight_ammount) { SPPath *path = dynamic_cast<SPPath *>(sp_lpe_item); - if(path){ + if(path) { SPCurve *curve = path->get_curve_for_edit(); - LPEBSpline::doBSplineFromWidget(curve, weightValue); + doBSplineFromWidget(curve, weight_ammount); gchar *str = sp_svg_write_path(curve->get_pathvector()); path->getRepr()->setAttribute("inkscape:original-d", str); } } -void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue) +void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) { using Geom::X; using Geom::Y; - + if (curve->get_segment_count() < 1) return; // Make copy of old path as it is changed during processing @@ -378,20 +348,20 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue) for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ + if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); - SPCurve *nCurve = new SPCurve(); - Geom::Point pointAt0(0, 0); - Geom::Point pointAt1(0, 0); - Geom::Point pointAt2(0, 0); - Geom::Point pointAt3(0, 0); - Geom::D2<Geom::SBasis> SBasisIn; - Geom::D2<Geom::SBasis> SBasisOut; + SPCurve *curve_n = new SPCurve(); + Geom::Point point_at0(0, 0); + Geom::Point point_at1(0, 0); + Geom::Point point_at2(0, 0); + Geom::Point point_at3(0, 0); + Geom::D2<Geom::SBasis> sbasis_in; + Geom::D2<Geom::SBasis> sbasis_out; Geom::CubicBezier const *cubic = NULL; if (path_it->closed()) { // if the path is closed, maybe we have to stop a bit earlier because the @@ -407,120 +377,120 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue) curve_endit = path_it->end_open(); } } - nCurve->moveto(curve_it1->initialPoint()); + curve_n->moveto(curve_it1->initialPoint()); while (curve_it1 != curve_endit) { SPCurve *in = new SPCurve(); in->moveto(curve_it1->initialPoint()); in->lineto(curve_it1->finalPoint()); cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); - pointAt0 = in->first_segment()->initialPoint(); - pointAt3 = in->first_segment()->finalPoint(); - SBasisIn = in->first_segment()->toSBasis(); - if (!onlySelected) { + point_at0 = in->first_segment()->initialPoint(); + point_at3 = in->first_segment()->finalPoint(); + sbasis_in = in->first_segment()->toSBasis(); + if (!only_selected) { if (cubic) { - if (!ignoreCusp || !Geom::are_near((*cubic)[1], pointAt0)) { - pointAt1 = SBasisIn.valueAt(weightValue); - if (weightValue != noPower) { - pointAt1 = - Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap); + if (!ignore_cusp || !Geom::are_near((*cubic)[1], point_at0)) { + point_at1 = sbasis_in.valueAt(weight_ammount); + if (weight_ammount != NO_POWER) { + point_at1 = + Geom::Point(point_at1[X] + HANDLE_CUBIC_GAP, point_at1[Y] + HANDLE_CUBIC_GAP); } } else { - pointAt1 = in->first_segment()->initialPoint(); + point_at1 = in->first_segment()->initialPoint(); } - if (!ignoreCusp || !Geom::are_near((*cubic)[2], pointAt3)) { - pointAt2 = SBasisIn.valueAt(1 - weightValue); - if (weightValue != noPower) { - pointAt2 = - Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap); + if (!ignore_cusp || !Geom::are_near((*cubic)[2], point_at3)) { + point_at2 = sbasis_in.valueAt(1 - weight_ammount); + if (weight_ammount != NO_POWER) { + point_at2 = + Geom::Point(point_at2[X] + HANDLE_CUBIC_GAP, point_at2[Y] + HANDLE_CUBIC_GAP); } } else { - pointAt2 = in->first_segment()->finalPoint(); + point_at2 = in->first_segment()->finalPoint(); } } else { - if (!ignoreCusp && weightValue != noPower) { - pointAt1 = SBasisIn.valueAt(weightValue); - if (weightValue != noPower) { - pointAt1 = - Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap); + if (!ignore_cusp && weight_ammount != NO_POWER) { + point_at1 = sbasis_in.valueAt(weight_ammount); + if (weight_ammount != NO_POWER) { + point_at1 = + Geom::Point(point_at1[X] + HANDLE_CUBIC_GAP, point_at1[Y] + HANDLE_CUBIC_GAP); } - pointAt2 = SBasisIn.valueAt(1 - weightValue); - if (weightValue != noPower) { - pointAt2 = - Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap); + point_at2 = sbasis_in.valueAt(1 - weight_ammount); + if (weight_ammount != NO_POWER) { + point_at2 = + Geom::Point(point_at2[X] + HANDLE_CUBIC_GAP, point_at2[Y] + HANDLE_CUBIC_GAP); } } else { - pointAt1 = in->first_segment()->initialPoint(); - pointAt2 = in->first_segment()->finalPoint(); + point_at1 = in->first_segment()->initialPoint(); + point_at2 = in->first_segment()->finalPoint(); } } } else { if (cubic) { - if (!ignoreCusp || !Geom::are_near((*cubic)[1], pointAt0)) { - if (isNodePointSelected(pointAt0)) { - pointAt1 = SBasisIn.valueAt(weightValue); - if (weightValue != noPower) { - pointAt1 = - Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap); + if (!ignore_cusp || !Geom::are_near((*cubic)[1], point_at0)) { + if (isNodePointSelected(point_at0)) { + point_at1 = sbasis_in.valueAt(weight_ammount); + if (weight_ammount != NO_POWER) { + point_at1 = + Geom::Point(point_at1[X] + HANDLE_CUBIC_GAP, point_at1[Y] + HANDLE_CUBIC_GAP); } } else { - pointAt1 = (*cubic)[1]; + point_at1 = (*cubic)[1]; } } else { - pointAt1 = in->first_segment()->initialPoint(); + point_at1 = in->first_segment()->initialPoint(); } - if (!ignoreCusp || !Geom::are_near((*cubic)[2], pointAt3)) { - if (isNodePointSelected(pointAt3)) { - pointAt2 = SBasisIn.valueAt(1 - weightValue); - if (weightValue != noPower) { - pointAt2 = - Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap); + if (!ignore_cusp || !Geom::are_near((*cubic)[2], point_at3)) { + if (isNodePointSelected(point_at3)) { + point_at2 = sbasis_in.valueAt(1 - weight_ammount); + if (weight_ammount != NO_POWER) { + point_at2 = + Geom::Point(point_at2[X] + HANDLE_CUBIC_GAP, point_at2[Y] + HANDLE_CUBIC_GAP); } } else { - pointAt2 = (*cubic)[2]; + point_at2 = (*cubic)[2]; } } else { - pointAt2 = in->first_segment()->finalPoint(); + point_at2 = in->first_segment()->finalPoint(); } } else { - if (!ignoreCusp && weightValue != noPower) { - if (isNodePointSelected(pointAt0)) { - pointAt1 = SBasisIn.valueAt(weightValue); - pointAt1 = - Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap); + if (!ignore_cusp && weight_ammount != NO_POWER) { + if (isNodePointSelected(point_at0)) { + point_at1 = sbasis_in.valueAt(weight_ammount); + point_at1 = + Geom::Point(point_at1[X] + HANDLE_CUBIC_GAP, point_at1[Y] + HANDLE_CUBIC_GAP); } else { - pointAt1 = in->first_segment()->initialPoint(); + point_at1 = in->first_segment()->initialPoint(); } - if (isNodePointSelected(pointAt3)) { - pointAt2 = SBasisIn.valueAt(weightValue); - pointAt2 = - Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap); + if (isNodePointSelected(point_at3)) { + point_at2 = sbasis_in.valueAt(weight_ammount); + point_at2 = + Geom::Point(point_at2[X] + HANDLE_CUBIC_GAP, point_at2[Y] + HANDLE_CUBIC_GAP); } else { - pointAt2 = in->first_segment()->finalPoint(); + point_at2 = in->first_segment()->finalPoint(); } } else { - pointAt1 = in->first_segment()->initialPoint(); - pointAt2 = in->first_segment()->finalPoint(); + point_at1 = in->first_segment()->initialPoint(); + point_at2 = in->first_segment()->finalPoint(); } } } in->reset(); delete in; - nCurve->curveto(pointAt1, pointAt2, pointAt3); + curve_n->curveto(point_at1, point_at2, point_at3); ++curve_it1; ++curve_it2; } if (path_it->closed()) { - nCurve->move_endpoints(path_it->begin()->initialPoint(), + curve_n->move_endpoints(path_it->begin()->initialPoint(), path_it->begin()->initialPoint()); } else { - nCurve->move_endpoints(path_it->begin()->initialPoint(), pointAt3); + curve_n->move_endpoints(path_it->begin()->initialPoint(), point_at3); } if (path_it->closed()) { - nCurve->closepath_current(); + curve_n->closepath_current(); } - curve->append(nCurve, false); - nCurve->reset(); - delete nCurve; + curve->append(curve_n, false); + curve_n->reset(); + delete curve_n; } } diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 642562b24..fc0f66353 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -6,9 +6,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "live_effects/effect.h" -#include "live_effects/parameter/bool.h" + #include <vector> namespace Inkscape { @@ -19,7 +18,8 @@ public: LPEBSpline(LivePathEffectObject *lpeobject); virtual ~LPEBSpline(); - virtual LPEPathFlashType pathFlashType() const { + virtual LPEPathFlashType pathFlashType() const + { return SUPPRESS_FLASH; } virtual void doOnApply(SPLPEItem const* lpeitem); @@ -39,8 +39,8 @@ public: private: ScalarParam helper_size; - BoolParam ignoreCusp; - BoolParam onlySelected; + BoolParam ignore_cusp; + BoolParam only_selected; ScalarParam weight; Geom::PathVector hp; diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index bf2526986..0111a0f99 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -8,7 +8,7 @@ */ #include "live_effects/parameter/enum.h" -#include "live_effects/pathoutlineprovider.h" +#include "helper/geom-pathstroke.h" #include "sp-shape.h" #include "style.h" @@ -28,19 +28,19 @@ namespace Inkscape { namespace LivePathEffect { static const Util::EnumData<unsigned> JoinTypeData[] = { - {LINEJOIN_STRAIGHT, N_("Beveled"), "bevel"}, - {LINEJOIN_ROUND, N_("Rounded"), "round"}, - {LINEJOIN_POINTY, N_("Miter"), "miter"}, - {LINEJOIN_REFLECTED, N_("Reflected"), "extrapolated"}, - {LINEJOIN_EXTRAPOLATED, N_("Extrapolated arc"), "extrp_arc"} + {JOIN_BEVEL, N_("Beveled"), "bevel"}, + {JOIN_ROUND, N_("Rounded"), "round"}, + {JOIN_MITER, N_("Miter"), "miter"}, + {JOIN_MITER_CLIP, N_("Miter Clip"), "miter-clip"}, + {JOIN_EXTRAPOLATE, N_("Extrapolated arc"), "extrp_arc"}, }; static const Util::EnumData<unsigned> CapTypeData[] = { - {BUTT_STRAIGHT, N_("Butt"), "butt"}, + {BUTT_FLAT, N_("Butt"), "butt"}, {BUTT_ROUND, N_("Rounded"), "round"}, {BUTT_SQUARE, N_("Square"), "square"}, - {BUTT_POINTY, N_("Peak"), "peak"}, - {BUTT_LEANED, N_("Leaned"), "leaned"} + {BUTT_PEAK, N_("Peak"), "peak"}, + //{BUTT_LEANED, N_("Leaned"), "leaned"} }; static const Util::EnumDataConverter<unsigned> CapTypeConverter(CapTypeData, sizeof(CapTypeData)/sizeof(*CapTypeData)); @@ -50,9 +50,9 @@ LPEJoinType::LPEJoinType(LivePathEffectObject *lpeobject) : Effect(lpeobject), line_width(_("Line width"), _("Thickness of the stroke"), "line_width", &wr, this, 1.), linecap_type(_("Line cap"), _("The end shape of the stroke"), "linecap_type", CapTypeConverter, &wr, this, butt_straight), - linejoin_type(_("Join:"), _("Determines the shape of the path's corners"), "linejoin_type", JoinTypeConverter, &wr, this, LINEJOIN_EXTRAPOLATED), - start_lean(_("Start path lean"), _("Start path lean"), "start_lean", &wr, this, 0.), - end_lean(_("End path lean"), _("End path lean"), "end_lean", &wr, this, 0.), + linejoin_type(_("Join:"), _("Determines the shape of the path's corners"), "linejoin_type", JoinTypeConverter, &wr, this, JOIN_EXTRAPOLATE), + //start_lean(_("Start path lean"), _("Start path lean"), "start_lean", &wr, this, 0.), + //end_lean(_("End path lean"), _("End path lean"), "end_lean", &wr, this, 0.), miter_limit(_("Miter limit:"), _("Maximum length of the miter join (in units of stroke width)"), "miter_limit", &wr, this, 100.), attempt_force_join(_("Force miter"), _("Overrides the miter limit and forces a join."), "attempt_force_join", &wr, this, true) { @@ -60,17 +60,16 @@ LPEJoinType::LPEJoinType(LivePathEffectObject *lpeobject) : registerParameter(&linecap_type); registerParameter(&line_width); registerParameter(&linejoin_type); - registerParameter(&start_lean); - registerParameter(&end_lean); + //registerParameter(&start_lean); + //registerParameter(&end_lean); registerParameter(&miter_limit); registerParameter(&attempt_force_join); - was_initialized = false; - start_lean.param_set_range(-1,1); - start_lean.param_set_increments(0.1, 0.1); - start_lean.param_set_digits(4); - end_lean.param_set_range(-1,1); - end_lean.param_set_increments(0.1, 0.1); - end_lean.param_set_digits(4); + //start_lean.param_set_range(-1,1); + //start_lean.param_set_increments(0.1, 0.1); + //start_lean.param_set_digits(4); + //end_lean.param_set_range(-1,1); + //end_lean.param_set_increments(0.1, 0.1); + //end_lean.param_set_digits(4); } LPEJoinType::~LPEJoinType() @@ -87,38 +86,30 @@ void LPEJoinType::doOnApply(SPLPEItem const* lpeitem) double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed : 1.; SPCSSAttr *css = sp_repr_css_attr_new (); - if (true) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "none"); + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_unset_property (css, "fill"); + sp_repr_css_set_property (css, "fill", "none"); } + sp_repr_css_set_property(css, "fill-rule", "nonzero"); sp_repr_css_set_property(css, "stroke", "none"); sp_desktop_apply_css_recursive(item, css, true); sp_repr_css_attr_unref (css); - if (!was_initialized) - { - was_initialized = true; - line_width.param_set_value(width); - } - } else { - g_warning("LPE Join Type can only be applied to paths (not groups)."); + + line_width.param_set_value(width); } } @@ -126,30 +117,25 @@ void LPEJoinType::doOnApply(SPLPEItem const* lpeitem) void LPEJoinType::doOnRemove(SPLPEItem const* lpeitem) { - if (SP_IS_SHAPE(lpeitem)) { SPLPEItem *item = const_cast<SPLPEItem*>(lpeitem); SPCSSAttr *css = sp_repr_css_attr_new (); - if (true) { - if (lpeitem->style->fill.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getFillPaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "stroke", str.c_str()); - } - } else if (lpeitem->style->fill.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "stroke", c); - } else { - sp_repr_css_set_property (css, "stroke", "none"); + if (lpeitem->style->fill.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getFillPaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "stroke", str.c_str()); } + } else if (lpeitem->style->fill.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->fill.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->fill_opacity.value))); + sp_repr_css_set_property (css, "stroke", c); } else { - sp_repr_css_unset_property (css, "stroke"); + sp_repr_css_set_property (css, "stroke", "none"); } Inkscape::CSSOStringStream os; @@ -164,15 +150,18 @@ void LPEJoinType::doOnRemove(SPLPEItem const* lpeitem) } } -// NOTE: I originally had all the outliner functions defined in here, but they were actually useful -// enough for other LPEs so I moved them all into pathoutlineprovider.cpp. The code here is just a -// wrapper around it. std::vector<Geom::Path> LPEJoinType::doEffect_path(std::vector<Geom::Path> const & path_in) { - return Outline::PathVectorOutline(path_in, line_width, static_cast<ButtTypeMod>(linecap_type.get_value()), - static_cast<LineJoinType>(linejoin_type.get_value()), - (attempt_force_join ? std::numeric_limits<double>::max() : miter_limit), - start_lean/2 ,end_lean/2); + Geom::PathVector ret; + for (size_t i = 0; i < path_in.size(); ++i) { + Geom::PathVector tmp = Inkscape::outline(path_in[i], line_width, + (attempt_force_join ? std::numeric_limits<double>::max() : miter_limit), + static_cast<LineJoinType>(linejoin_type.get_value()), + static_cast<LineCapType>(linecap_type.get_value())); + ret.insert(ret.begin(), tmp.begin(), tmp.end()); + } + + return ret; } } // namespace LivePathEffect diff --git a/src/live_effects/lpe-jointype.h b/src/live_effects/lpe-jointype.h index 73705666d..bca0961c9 100644 --- a/src/live_effects/lpe-jointype.h +++ b/src/live_effects/lpe-jointype.h @@ -33,11 +33,10 @@ private: ScalarParam line_width;
EnumParam<unsigned> linecap_type;
EnumParam<unsigned> linejoin_type;
- ScalarParam start_lean;
- ScalarParam end_lean;
+ //ScalarParam start_lean;
+ //ScalarParam end_lean;
ScalarParam miter_limit;
BoolParam attempt_force_join;
- bool was_initialized;
};
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index 08bbbd504..abd6e7786 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -1,6 +1,6 @@ /** \file * LPE <lattice2> implementation - + */ /* * Authors: @@ -11,7 +11,7 @@ * ~suv * Jabiertxo Arraiza * -* Copyright (C) 2007-2008 Authors +* Copyright (C) 2007-2008 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -42,63 +42,63 @@ namespace LivePathEffect { LPELattice2::LPELattice2(LivePathEffectObject *lpeobject) : Effect(lpeobject), - horizontalMirror(_("Mirror movements in horizontal"), _("Mirror movements in horizontal"), "horizontalMirror", &wr, this, false), - verticalMirror(_("Mirror movements in vertical"), _("Mirror movements in vertical"), "verticalMirror", &wr, this, false), - grid_point0(_("Control 0:"), _("Control 0 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint0", &wr, this), - grid_point1(_("Control 1:"), _("Control 1 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint1", &wr, this), - grid_point2(_("Control 2:"), _("Control 2 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint2", &wr, this), - grid_point3(_("Control 3:"), _("Control 3 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint3", &wr, this), - grid_point4(_("Control 4:"), _("Control 4 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint4", &wr, this), - grid_point5(_("Control 5:"), _("Control 5 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint5", &wr, this), - grid_point6(_("Control 6:"), _("Control 6 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint6", &wr, this), - grid_point7(_("Control 7:"), _("Control 7 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint7", &wr, this), - grid_point8x9(_("Control 8x9:"), _("Control 8x9 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint8x9", &wr, this), - grid_point10x11(_("Control 10x11:"), _("Control 10x11 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint10x11", &wr, this), - grid_point12(_("Control 12:"), _("Control 12 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint12", &wr, this), - grid_point13(_("Control 13:"), _("Control 13 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint13", &wr, this), - grid_point14(_("Control 14:"), _("Control 14 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint14", &wr, this), - grid_point15(_("Control 15:"), _("Control 15 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint15", &wr, this), - grid_point16(_("Control 16:"), _("Control 16 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint16", &wr, this), - grid_point17(_("Control 17:"), _("Control 17 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint17", &wr, this), - grid_point18(_("Control 18:"), _("Control 18 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint18", &wr, this), - grid_point19(_("Control 19:"), _("Control 19 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint19", &wr, this), - grid_point20x21(_("Control 20x21:"), _("Control 20x21 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint20x21", &wr, this), - grid_point22x23(_("Control 22x23:"), _("Control 22x23 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint22x23", &wr, this), - grid_point24x26(_("Control 24x26:"), _("Control 24x26 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint24x26", &wr, this), - grid_point25x27(_("Control 25x27:"), _("Control 25x27 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint25x27", &wr, this), - grid_point28x30(_("Control 28x30:"), _("Control 28x30 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint28x30", &wr, this), - grid_point29x31(_("Control 29x31:"), _("Control 29x31 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint29x31", &wr, this), - grid_point32x33x34x35(_("Control 32x33x34x35:"), _("Control 32x33x34x35 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint32x33x34x35", &wr, this), + horizontal_mirror(_("Mirror movements in horizontal"), _("Mirror movements in horizontal"), "horizontal_mirror", &wr, this, false), + vertical_mirror(_("Mirror movements in vertical"), _("Mirror movements in vertical"), "vertical_mirror", &wr, this, false), + grid_point_0(_("Control 0:"), _("Control 0 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint0", &wr, this), + grid_point_1(_("Control 1:"), _("Control 1 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint1", &wr, this), + grid_point_2(_("Control 2:"), _("Control 2 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint2", &wr, this), + grid_point_3(_("Control 3:"), _("Control 3 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint3", &wr, this), + grid_point_4(_("Control 4:"), _("Control 4 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint4", &wr, this), + grid_point_5(_("Control 5:"), _("Control 5 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint5", &wr, this), + grid_point_6(_("Control 6:"), _("Control 6 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint6", &wr, this), + grid_point_7(_("Control 7:"), _("Control 7 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint7", &wr, this), + grid_point_8x9(_("Control 8x9:"), _("Control 8x9 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint8x9", &wr, this), + grid_point_10x11(_("Control 10x11:"), _("Control 10x11 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint10x11", &wr, this), + grid_point_12(_("Control 12:"), _("Control 12 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint12", &wr, this), + grid_point_13(_("Control 13:"), _("Control 13 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint13", &wr, this), + grid_point_14(_("Control 14:"), _("Control 14 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint14", &wr, this), + grid_point_15(_("Control 15:"), _("Control 15 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint15", &wr, this), + grid_point_16(_("Control 16:"), _("Control 16 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint16", &wr, this), + grid_point_17(_("Control 17:"), _("Control 17 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint17", &wr, this), + grid_point_18(_("Control 18:"), _("Control 18 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint18", &wr, this), + grid_point_19(_("Control 19:"), _("Control 19 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint19", &wr, this), + grid_point_20x21(_("Control 20x21:"), _("Control 20x21 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint20x21", &wr, this), + grid_point_22x23(_("Control 22x23:"), _("Control 22x23 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint22x23", &wr, this), + grid_point_24x26(_("Control 24x26:"), _("Control 24x26 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint24x26", &wr, this), + grid_point_25x27(_("Control 25x27:"), _("Control 25x27 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint25x27", &wr, this), + grid_point_28x30(_("Control 28x30:"), _("Control 28x30 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint28x30", &wr, this), + grid_point_29x31(_("Control 29x31:"), _("Control 29x31 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint29x31", &wr, this), + grid_point_32x33x34x35(_("Control 32x33x34x35:"), _("Control 32x33x34x35 - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "gridpoint32x33x34x35", &wr, this), expanded(false) { // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter(&horizontalMirror); - registerParameter(&verticalMirror); - registerParameter(&grid_point0); - registerParameter(&grid_point1); - registerParameter(&grid_point2); - registerParameter(&grid_point3); - registerParameter(&grid_point4); - registerParameter(&grid_point5); - registerParameter(&grid_point6); - registerParameter(&grid_point7); - registerParameter(&grid_point8x9); - registerParameter(&grid_point10x11); - registerParameter(&grid_point12); - registerParameter(&grid_point13); - registerParameter(&grid_point14); - registerParameter(&grid_point15); - registerParameter(&grid_point16); - registerParameter(&grid_point17); - registerParameter(&grid_point18); - registerParameter(&grid_point19); - registerParameter(&grid_point20x21); - registerParameter(&grid_point22x23); - registerParameter(&grid_point24x26); - registerParameter(&grid_point25x27); - registerParameter(&grid_point28x30); - registerParameter(&grid_point29x31); - registerParameter(&grid_point32x33x34x35); + registerParameter(&horizontal_mirror); + registerParameter(&vertical_mirror); + registerParameter(&grid_point_0); + registerParameter(&grid_point_1); + registerParameter(&grid_point_2); + registerParameter(&grid_point_3); + registerParameter(&grid_point_4); + registerParameter(&grid_point_5); + registerParameter(&grid_point_6); + registerParameter(&grid_point_7); + registerParameter(&grid_point_8x9); + registerParameter(&grid_point_10x11); + registerParameter(&grid_point_12); + registerParameter(&grid_point_13); + registerParameter(&grid_point_14); + registerParameter(&grid_point_15); + registerParameter(&grid_point_16); + registerParameter(&grid_point_17); + registerParameter(&grid_point_18); + registerParameter(&grid_point_19); + registerParameter(&grid_point_20x21); + registerParameter(&grid_point_22x23); + registerParameter(&grid_point_24x26); + registerParameter(&grid_point_25x27); + registerParameter(&grid_point_28x30); + registerParameter(&grid_point_29x31); + registerParameter(&grid_point_32x33x34x35); } LPELattice2::~LPELattice2() @@ -113,7 +113,7 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd PathVector cubic = pathv_to_cubicbezier(pathv); Geom::Piecewise<Geom::D2<Geom::SBasis> > const &pwd2_in_linear_and_cubic = paths_to_pw(cubic); D2<SBasis2d> sb2; - + //Initialisation of the sb2 for(unsigned dim = 0; dim < 2; dim++) { sb2[dim].us = 3; @@ -125,46 +125,46 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd //Grouping the point params in a convenient vector std::vector<Geom::Point > handles(36); - - handles[0] = grid_point0; - handles[1] = grid_point1; - handles[2] = grid_point2; - handles[3] = grid_point3; - handles[4] = grid_point4; - handles[5] = grid_point5; - handles[6] = grid_point6; - handles[7] = grid_point7; - handles[8] = grid_point8x9; - handles[9] = grid_point8x9; - handles[10] = grid_point10x11; - handles[11] = grid_point10x11; - handles[12] = grid_point12; - handles[13] = grid_point13; - handles[14] = grid_point14; - handles[15] = grid_point15; - handles[16] = grid_point16; - handles[17] = grid_point17; - handles[18] = grid_point18; - handles[19] = grid_point19; - handles[20] = grid_point20x21; - handles[21] = grid_point20x21; - handles[22] = grid_point22x23; - handles[23] = grid_point22x23; - handles[24] = grid_point24x26; - handles[25] = grid_point25x27; - handles[26] = grid_point24x26; - handles[27] = grid_point25x27; - handles[28] = grid_point28x30; - handles[29] = grid_point29x31; - handles[30] = grid_point28x30; - handles[31] = grid_point29x31; - handles[32] = grid_point32x33x34x35; - handles[33] = grid_point32x33x34x35; - handles[34] = grid_point32x33x34x35; - handles[35] = grid_point32x33x34x35; + + handles[0] = grid_point_0; + handles[1] = grid_point_1; + handles[2] = grid_point_2; + handles[3] = grid_point_3; + handles[4] = grid_point_4; + handles[5] = grid_point_5; + handles[6] = grid_point_6; + handles[7] = grid_point_7; + handles[8] = grid_point_8x9; + handles[9] = grid_point_8x9; + handles[10] = grid_point_10x11; + handles[11] = grid_point_10x11; + handles[12] = grid_point_12; + handles[13] = grid_point_13; + handles[14] = grid_point_14; + handles[15] = grid_point_15; + handles[16] = grid_point_16; + handles[17] = grid_point_17; + handles[18] = grid_point_18; + handles[19] = grid_point_19; + handles[20] = grid_point_20x21; + handles[21] = grid_point_20x21; + handles[22] = grid_point_22x23; + handles[23] = grid_point_22x23; + handles[24] = grid_point_24x26; + handles[25] = grid_point_25x27; + handles[26] = grid_point_24x26; + handles[27] = grid_point_25x27; + handles[28] = grid_point_28x30; + handles[29] = grid_point_29x31; + handles[30] = grid_point_28x30; + handles[31] = grid_point_29x31; + handles[32] = grid_point_32x33x34x35; + handles[33] = grid_point_32x33x34x35; + handles[34] = grid_point_32x33x34x35; + handles[35] = grid_point_32x33x34x35; Geom::Point origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min()); - + double width = boundingbox_X.extent(); double height = boundingbox_Y.extent(); @@ -178,16 +178,16 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd for(unsigned iu = 0; iu < 2; iu++) { unsigned corner = iu + 2*iv; unsigned i = ui + vi*sb2[dim].us; - + //This is the offset from the Upperleft point Geom::Point base( (ui + iu*(4-2*ui))*width/4., (vi + iv*(4-2*vi))*height/4.); - + //Special action for corners if(vi == 0 && ui == 0) { base = Geom::Point(0,0); } - + // i = Upperleft corner of the considerated rectangle // corner = actual corner of the rectangle // origin = Upperleft point @@ -198,7 +198,7 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd } } } - + Piecewise<D2<SBasis> > output; output.push_cut(0.); for(unsigned i = 0; i < pwd2_in_linear_and_cubic.size(); i++) { @@ -228,28 +228,28 @@ LPELattice2::newWidget() vbox->set_homogeneous(false); vbox->set_spacing(6); Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); - Gtk::VBox * vboxExpander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); - vboxExpander->set_border_width(0); - vboxExpander->set_spacing(2); - Gtk::Button * resetButton = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset grid")))); - resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPELattice2::resetGrid)); - resetButton->set_size_request(140,30); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox_expander->set_border_width(0); + vbox_expander->set_spacing(2); + Gtk::Button * reset_button = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset grid")))); + reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPELattice2::resetGrid)); + reset_button->set_size_request(140,30); vbox->pack_start(*hbox, true,true,2); - hbox->pack_start(*resetButton, false, false,2); + hbox->pack_start(*reset_button, false, false,2); std::vector<Parameter *>::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter * param = *it; Gtk::Widget * widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); - if(param->param_key == "grid"){ + if(param->param_key == "grid") { widg = NULL; } Glib::ustring * tip = param->param_getTooltip(); if (widg) { - if (param->param_key == "horizontalMirror" || param->param_key == "verticalMirror") { + if (param->param_key == "horizontal_mirror" || param->param_key == "vertical_mirror") { vbox->pack_start(*widg, true, true, 2); } else { - vboxExpander->pack_start(*widg, true, true, 2); + vbox_expander->pack_start(*widg, true, true, 2); } if (tip) { widg->set_tooltip_text(*tip); @@ -262,63 +262,65 @@ LPELattice2::newWidget() ++it; } - + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show Points")))); - expander->add(*vboxExpander); + expander->add(*vbox_expander); expander->set_expanded(expanded); vbox->pack_start(*expander, true, true, 2); - expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPELattice2::on_expander_changed) ); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPELattice2::onExpanderChanged) ); return dynamic_cast<Gtk::Widget *>(vbox); } void -LPELattice2::on_expander_changed() +LPELattice2::onExpanderChanged() { expanded = expander->get_expanded(); - if(expander->get_expanded()){ + if(expander->get_expanded()) { expander->set_label (Glib::ustring(_("Hide Points"))); } else { expander->set_label (Glib::ustring(_("Show Points"))); } } void -LPELattice2::vertical(PointParam ¶mA, PointParam ¶mB, Geom::Line vert){ - Geom::Point A = paramA; - Geom::Point B = paramB; +LPELattice2::vertical(PointParam ¶m_one, PointParam ¶m_two, Geom::Line vert) +{ + Geom::Point A = param_one; + Geom::Point B = param_two; double Y = (A[Geom::Y] + B[Geom::Y])/2; A[Geom::Y] = Y; B[Geom::Y] = Y; Geom::Point nearest = vert.pointAt(vert.nearestPoint(A)); - double distA = Geom::distance(A,nearest); - double distB = Geom::distance(B,nearest); - double distanceMed = (distA + distB)/2; - if(A[Geom::X] > B[Geom::X]){ - distanceMed *= -1; + double distance_one = Geom::distance(A,nearest); + double distance_two = Geom::distance(B,nearest); + double distance_middle = (distance_one + distance_two)/2; + if(A[Geom::X] > B[Geom::X]) { + distance_middle *= -1; } - A[Geom::X] = nearest[Geom::X] - distanceMed; - B[Geom::X] = nearest[Geom::X] + distanceMed; - paramA.param_setValue(A, true); - paramB.param_setValue(B, true); + A[Geom::X] = nearest[Geom::X] - distance_middle; + B[Geom::X] = nearest[Geom::X] + distance_middle; + param_one.param_setValue(A, true); + param_two.param_setValue(B, true); } void -LPELattice2::horizontal(PointParam ¶mA, PointParam ¶mB, Geom::Line horiz){ - Geom::Point A = paramA; - Geom::Point B = paramB; +LPELattice2::horizontal(PointParam ¶m_one, PointParam ¶m_two, Geom::Line horiz) +{ + Geom::Point A = param_one; + Geom::Point B = param_two; double X = (A[Geom::X] + B[Geom::X])/2; A[Geom::X] = X; B[Geom::X] = X; Geom::Point nearest = horiz.pointAt(horiz.nearestPoint(A)); - double distA = Geom::distance(A,nearest); - double distB = Geom::distance(B,nearest); - double distanceMed = (distA + distB)/2; - if(A[Geom::Y] > B[Geom::Y]){ - distanceMed *= -1; + double distance_one = Geom::distance(A,nearest); + double distance_two = Geom::distance(B,nearest); + double distance_middle = (distance_one + distance_two)/2; + if(A[Geom::Y] > B[Geom::Y]) { + distance_middle *= -1; } - A[Geom::Y] = nearest[Geom::Y] - distanceMed; - B[Geom::Y] = nearest[Geom::Y] + distanceMed; - paramA.param_setValue(A, true); - paramB.param_setValue(B, true); + A[Geom::Y] = nearest[Geom::Y] - distance_middle; + B[Geom::Y] = nearest[Geom::Y] + distance_middle; + param_one.param_setValue(A, true); + param_two.param_setValue(B, true); } void @@ -326,31 +328,31 @@ LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); setDefaults(); - Geom::Line vert(grid_point8x9.param_get_default(),grid_point10x11.param_get_default()); - Geom::Line horiz(grid_point24x26.param_get_default(),grid_point25x27.param_get_default()); - if(verticalMirror){ - vertical(grid_point0, grid_point1,vert); - vertical(grid_point2, grid_point3,vert); - vertical(grid_point4, grid_point5,vert); - vertical(grid_point6, grid_point7,vert); - vertical(grid_point12, grid_point13,vert); - vertical(grid_point14, grid_point15,vert); - vertical(grid_point16, grid_point17,vert); - vertical(grid_point18, grid_point19,vert); - vertical(grid_point24x26, grid_point25x27,vert); - vertical(grid_point28x30, grid_point29x31,vert); + Geom::Line vert(grid_point_8x9.param_get_default(),grid_point_10x11.param_get_default()); + Geom::Line horiz(grid_point_24x26.param_get_default(),grid_point_25x27.param_get_default()); + if(vertical_mirror) { + vertical(grid_point_0, grid_point_1,vert); + vertical(grid_point_2, grid_point_3,vert); + vertical(grid_point_4, grid_point_5,vert); + vertical(grid_point_6, grid_point_7,vert); + vertical(grid_point_12, grid_point_13,vert); + vertical(grid_point_14, grid_point_15,vert); + vertical(grid_point_16, grid_point_17,vert); + vertical(grid_point_18, grid_point_19,vert); + vertical(grid_point_24x26, grid_point_25x27,vert); + vertical(grid_point_28x30, grid_point_29x31,vert); } - if(horizontalMirror){ - horizontal(grid_point0, grid_point2,horiz); - horizontal(grid_point1, grid_point3,horiz); - horizontal(grid_point4, grid_point6,horiz); - horizontal(grid_point5, grid_point7,horiz); - horizontal(grid_point8x9, grid_point10x11,horiz); - horizontal(grid_point12, grid_point14,horiz); - horizontal(grid_point13, grid_point15,horiz); - horizontal(grid_point16, grid_point18,horiz); - horizontal(grid_point17, grid_point19,horiz); - horizontal(grid_point20x21, grid_point22x23,horiz); + if(horizontal_mirror) { + horizontal(grid_point_0, grid_point_2,horiz); + horizontal(grid_point_1, grid_point_3,horiz); + horizontal(grid_point_4, grid_point_6,horiz); + horizontal(grid_point_5, grid_point_7,horiz); + horizontal(grid_point_8x9, grid_point_10x11,horiz); + horizontal(grid_point_12, grid_point_14,horiz); + horizontal(grid_point_13, grid_point_15,horiz); + horizontal(grid_point_16, grid_point_18,horiz); + horizontal(grid_point_17, grid_point_19,horiz); + horizontal(grid_point_20x21, grid_point_22x23,horiz); } SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); item->apply_to_clippath(item); @@ -385,111 +387,111 @@ LPELattice2::setDefaults() (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); Geom::Point gp8x9((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); Geom::Point gp10x11((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); Geom::Point gp12((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); Geom::Point gp13((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); Geom::Point gp14((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); Geom::Point gp15((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); Geom::Point gp16((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); Geom::Point gp17((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); Geom::Point gp18((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); Geom::Point gp19((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); Geom::Point gp20x21((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); Geom::Point gp22x23((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); Geom::Point gp24x26((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); Geom::Point gp25x27((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); Geom::Point gp28x30((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); Geom::Point gp29x31((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); Geom::Point gp32x33x34x35((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), - (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); - - grid_point0.param_update_default(gp0); - grid_point1.param_update_default(gp1); - grid_point2.param_update_default(gp2); - grid_point3.param_update_default(gp3); - grid_point4.param_update_default(gp4); - grid_point5.param_update_default(gp5); - grid_point6.param_update_default(gp6); - grid_point7.param_update_default(gp7); - grid_point8x9.param_update_default(gp8x9); - grid_point10x11.param_update_default(gp10x11); - grid_point12.param_update_default(gp12); - grid_point13.param_update_default(gp13); - grid_point14.param_update_default(gp14); - grid_point15.param_update_default(gp15); - grid_point16.param_update_default(gp16); - grid_point17.param_update_default(gp17); - grid_point18.param_update_default(gp18); - grid_point19.param_update_default(gp19); - grid_point20x21.param_update_default(gp20x21); - grid_point22x23.param_update_default(gp22x23); - grid_point24x26.param_update_default(gp24x26); - grid_point25x27.param_update_default(gp25x27); - grid_point28x30.param_update_default(gp28x30); - grid_point29x31.param_update_default(gp29x31); - grid_point32x33x34x35.param_update_default(gp32x33x34x35); + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + + grid_point_0.param_update_default(gp0); + grid_point_1.param_update_default(gp1); + grid_point_2.param_update_default(gp2); + grid_point_3.param_update_default(gp3); + grid_point_4.param_update_default(gp4); + grid_point_5.param_update_default(gp5); + grid_point_6.param_update_default(gp6); + grid_point_7.param_update_default(gp7); + grid_point_8x9.param_update_default(gp8x9); + grid_point_10x11.param_update_default(gp10x11); + grid_point_12.param_update_default(gp12); + grid_point_13.param_update_default(gp13); + grid_point_14.param_update_default(gp14); + grid_point_15.param_update_default(gp15); + grid_point_16.param_update_default(gp16); + grid_point_17.param_update_default(gp17); + grid_point_18.param_update_default(gp18); + grid_point_19.param_update_default(gp19); + grid_point_20x21.param_update_default(gp20x21); + grid_point_22x23.param_update_default(gp22x23); + grid_point_24x26.param_update_default(gp24x26); + grid_point_25x27.param_update_default(gp25x27); + grid_point_28x30.param_update_default(gp28x30); + grid_point_29x31.param_update_default(gp29x31); + grid_point_32x33x34x35.param_update_default(gp32x33x34x35); } void LPELattice2::resetGrid() { - grid_point0.param_set_default(); - grid_point1.param_set_default(); - grid_point2.param_set_default(); - grid_point3.param_set_default(); - grid_point4.param_set_default(); - grid_point5.param_set_default(); - grid_point6.param_set_default(); - grid_point7.param_set_default(); - grid_point8x9.param_set_default(); - grid_point10x11.param_set_default(); - grid_point12.param_set_default(); - grid_point13.param_set_default(); - grid_point14.param_set_default(); - grid_point15.param_set_default(); - grid_point16.param_set_default(); - grid_point17.param_set_default(); - grid_point18.param_set_default(); - grid_point19.param_set_default(); - grid_point20x21.param_set_default(); - grid_point22x23.param_set_default(); - grid_point24x26.param_set_default(); - grid_point25x27.param_set_default(); - grid_point28x30.param_set_default(); - grid_point29x31.param_set_default(); - grid_point32x33x34x35.param_set_default(); + grid_point_0.param_set_default(); + grid_point_1.param_set_default(); + grid_point_2.param_set_default(); + grid_point_3.param_set_default(); + grid_point_4.param_set_default(); + grid_point_5.param_set_default(); + grid_point_6.param_set_default(); + grid_point_7.param_set_default(); + grid_point_8x9.param_set_default(); + grid_point_10x11.param_set_default(); + grid_point_12.param_set_default(); + grid_point_13.param_set_default(); + grid_point_14.param_set_default(); + grid_point_15.param_set_default(); + grid_point_16.param_set_default(); + grid_point_17.param_set_default(); + grid_point_18.param_set_default(); + grid_point_19.param_set_default(); + grid_point_20x21.param_set_default(); + grid_point_22x23.param_set_default(); + grid_point_24x26.param_set_default(); + grid_point_25x27.param_set_default(); + grid_point_28x30.param_set_default(); + grid_point_29x31.param_set_default(); + grid_point_32x33x34x35.param_set_default(); } void @@ -519,55 +521,55 @@ LPELattice2::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom: hp_vec.clear(); SPCurve *c = new SPCurve(); - calculateCurve(grid_point0,grid_point4, c,true, true); - calculateCurve(grid_point4,grid_point8x9, c,true, false); - calculateCurve(grid_point8x9,grid_point5, c,true, false); - calculateCurve(grid_point5,grid_point1, c,true, false); - - calculateCurve(grid_point12,grid_point16, c,true, true); - calculateCurve(grid_point16,grid_point20x21, c,true, false); - calculateCurve(grid_point20x21,grid_point17, c,true, false); - calculateCurve(grid_point17,grid_point13, c,true, false); - - calculateCurve(grid_point24x26,grid_point28x30, c,true, true); - calculateCurve(grid_point28x30,grid_point32x33x34x35, c,true, false); - calculateCurve(grid_point32x33x34x35,grid_point29x31, c,true, false); - calculateCurve(grid_point29x31,grid_point25x27, c,true, false); - - calculateCurve(grid_point14,grid_point18, c,true, true); - calculateCurve(grid_point18,grid_point22x23, c,true, false); - calculateCurve(grid_point22x23,grid_point19, c,true, false); - calculateCurve(grid_point19,grid_point15, c,true, false); - - calculateCurve(grid_point2,grid_point6, c,true, true); - calculateCurve(grid_point6,grid_point10x11, c,true, false); - calculateCurve(grid_point10x11,grid_point7, c,true, false); - calculateCurve(grid_point7,grid_point3, c,true, false); - - calculateCurve(grid_point0,grid_point12, c,false, true); - calculateCurve(grid_point12,grid_point24x26, c,false, false); - calculateCurve(grid_point24x26,grid_point14, c,false, false); - calculateCurve(grid_point14,grid_point2, c,false, false); - - calculateCurve(grid_point4,grid_point16, c,false, true); - calculateCurve(grid_point16,grid_point28x30, c,false, false); - calculateCurve(grid_point28x30,grid_point18, c,false, false); - calculateCurve(grid_point18,grid_point6, c,false, false); - - calculateCurve(grid_point8x9,grid_point20x21, c,false, true); - calculateCurve(grid_point20x21,grid_point32x33x34x35, c,false, false); - calculateCurve(grid_point32x33x34x35,grid_point22x23, c,false, false); - calculateCurve(grid_point22x23,grid_point10x11, c,false, false); - - calculateCurve(grid_point5,grid_point17, c, false, true); - calculateCurve(grid_point17,grid_point29x31, c,false, false); - calculateCurve(grid_point29x31,grid_point19, c,false, false); - calculateCurve(grid_point19,grid_point7, c,false, false); - - calculateCurve(grid_point1,grid_point13, c, false, true); - calculateCurve(grid_point13,grid_point25x27, c,false, false); - calculateCurve(grid_point25x27,grid_point15, c,false, false); - calculateCurve(grid_point15,grid_point3, c, false, false); + calculateCurve(grid_point_0,grid_point_4, c,true, true); + calculateCurve(grid_point_4,grid_point_8x9, c,true, false); + calculateCurve(grid_point_8x9,grid_point_5, c,true, false); + calculateCurve(grid_point_5,grid_point_1, c,true, false); + + calculateCurve(grid_point_12,grid_point_16, c,true, true); + calculateCurve(grid_point_16,grid_point_20x21, c,true, false); + calculateCurve(grid_point_20x21,grid_point_17, c,true, false); + calculateCurve(grid_point_17,grid_point_13, c,true, false); + + calculateCurve(grid_point_24x26,grid_point_28x30, c,true, true); + calculateCurve(grid_point_28x30,grid_point_32x33x34x35, c,true, false); + calculateCurve(grid_point_32x33x34x35,grid_point_29x31, c,true, false); + calculateCurve(grid_point_29x31,grid_point_25x27, c,true, false); + + calculateCurve(grid_point_14,grid_point_18, c,true, true); + calculateCurve(grid_point_18,grid_point_22x23, c,true, false); + calculateCurve(grid_point_22x23,grid_point_19, c,true, false); + calculateCurve(grid_point_19,grid_point_15, c,true, false); + + calculateCurve(grid_point_2,grid_point_6, c,true, true); + calculateCurve(grid_point_6,grid_point_10x11, c,true, false); + calculateCurve(grid_point_10x11,grid_point_7, c,true, false); + calculateCurve(grid_point_7,grid_point_3, c,true, false); + + calculateCurve(grid_point_0,grid_point_12, c,false, true); + calculateCurve(grid_point_12,grid_point_24x26, c,false, false); + calculateCurve(grid_point_24x26,grid_point_14, c,false, false); + calculateCurve(grid_point_14,grid_point_2, c,false, false); + + calculateCurve(grid_point_4,grid_point_16, c,false, true); + calculateCurve(grid_point_16,grid_point_28x30, c,false, false); + calculateCurve(grid_point_28x30,grid_point_18, c,false, false); + calculateCurve(grid_point_18,grid_point_6, c,false, false); + + calculateCurve(grid_point_8x9,grid_point_20x21, c,false, true); + calculateCurve(grid_point_20x21,grid_point_32x33x34x35, c,false, false); + calculateCurve(grid_point_32x33x34x35,grid_point_22x23, c,false, false); + calculateCurve(grid_point_22x23,grid_point_10x11, c,false, false); + + calculateCurve(grid_point_5,grid_point_17, c, false, true); + calculateCurve(grid_point_17,grid_point_29x31, c,false, false); + calculateCurve(grid_point_29x31,grid_point_19, c,false, false); + calculateCurve(grid_point_19,grid_point_7, c,false, false); + + calculateCurve(grid_point_1,grid_point_13, c, false, true); + calculateCurve(grid_point_13,grid_point_25x27, c,false, false); + calculateCurve(grid_point_25x27,grid_point_15, c,false, false); + calculateCurve(grid_point_15,grid_point_3, c, false, false); hp_vec.push_back(c->get_pathvector()); } diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 086bdab7e..ff2e75641 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -34,7 +34,7 @@ public: virtual ~LPELattice2(); virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in); - + virtual void resetDefaults(SPItem const* item); virtual void doBeforeEffect(SPLPEItem const* lpeitem); @@ -49,46 +49,41 @@ public: virtual void setDefaults(); - virtual void on_expander_changed(); + virtual void onExpanderChanged(); virtual void resetGrid(); - //virtual void original_bbox(SPLPEItem const* lpeitem, bool absolute = false); - - //virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector<Geom::PathVector> &/*hp_vec*/); - - //virtual std::vector<Geom::PathVector> getHelperPaths(SPLPEItem const* lpeitem); protected: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); private: - BoolParam horizontalMirror; - BoolParam verticalMirror; - PointParam grid_point0; - PointParam grid_point1; - PointParam grid_point2; - PointParam grid_point3; - PointParam grid_point4; - PointParam grid_point5; - PointParam grid_point6; - PointParam grid_point7; - PointParam grid_point8x9; - PointParam grid_point10x11; - PointParam grid_point12; - PointParam grid_point13; - PointParam grid_point14; - PointParam grid_point15; - PointParam grid_point16; - PointParam grid_point17; - PointParam grid_point18; - PointParam grid_point19; - PointParam grid_point20x21; - PointParam grid_point22x23; - PointParam grid_point24x26; - PointParam grid_point25x27; - PointParam grid_point28x30; - PointParam grid_point29x31; - PointParam grid_point32x33x34x35; + BoolParam horizontal_mirror; + BoolParam vertical_mirror; + PointParam grid_point_0; + PointParam grid_point_1; + PointParam grid_point_2; + PointParam grid_point_3; + PointParam grid_point_4; + PointParam grid_point_5; + PointParam grid_point_6; + PointParam grid_point_7; + PointParam grid_point_8x9; + PointParam grid_point_10x11; + PointParam grid_point_12; + PointParam grid_point_13; + PointParam grid_point_14; + PointParam grid_point_15; + PointParam grid_point_16; + PointParam grid_point_17; + PointParam grid_point_18; + PointParam grid_point_19; + PointParam grid_point_20x21; + PointParam grid_point_22x23; + PointParam grid_point_24x26; + PointParam grid_point_25x27; + PointParam grid_point_28x30; + PointParam grid_point_29x31; + PointParam grid_point_32x33x34x35; bool expanded; Gtk::Expander * expander; diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index d60a13c23..4eac2d6eb 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -1,6 +1,6 @@ /** \file * LPE <perspective-envelope> implementation - + */ /* * Authors: @@ -8,8 +8,8 @@ * Aaron Spike, aaron@ekips.org from envelope and perspective phyton code * Dmitry Platonov, shadowjack@mail.ru, 2006 perspective approach & math * Jose Hevia (freon) Transform algorithm from envelope - * - * Copyright (C) 2007-2014 Authors + * + * Copyright (C) 2007-2014 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -27,8 +27,8 @@ namespace Inkscape { namespace LivePathEffect { enum DeformationType { - DEFORMATION_PERSPECTIVE, - DEFORMATION_ENVELOPE + DEFORMATION_PERSPECTIVE, + DEFORMATION_ENVELOPE }; static const Util::EnumData<unsigned> DeformationTypeData[] = { @@ -42,52 +42,53 @@ LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject) Effect(lpeobject), // initialise your parameters here: deform_type(_("Type"), _("Select the type of deformation"), "deform_type", DeformationTypeConverter, &wr, this, DEFORMATION_PERSPECTIVE), - Up_Left_Point(_("Top Left"), _("Top Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Up_Left_Point", &wr, this), - Up_Right_Point(_("Top Right"), _("Top Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Up_Right_Point", &wr, this), - Down_Left_Point(_("Down Left"), _("Down Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Down_Left_Point", &wr, this), - Down_Right_Point(_("Down Right"), _("Down Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "Down_Right_Point", &wr, this) + up_left_point(_("Top Left"), _("Top Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "up_left_point", &wr, this), + up_right_point(_("Top Right"), _("Top Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "up_right_point", &wr, this), + down_left_point(_("Down Left"), _("Down Left - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "down_left_point", &wr, this), + down_right_point(_("Down Right"), _("Down Right - <b>Ctrl+Alt+Click</b>: reset, <b>Ctrl</b>: move along axes"), "down_right_point", &wr, this) { // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast<Parameter *>(&deform_type)); - registerParameter( dynamic_cast<Parameter *>(&Up_Left_Point) ); - registerParameter( dynamic_cast<Parameter *>(&Up_Right_Point) ); - registerParameter( dynamic_cast<Parameter *>(&Down_Left_Point) ); - registerParameter( dynamic_cast<Parameter *>(&Down_Right_Point) ); + registerParameter(&deform_type); + registerParameter(&up_left_point); + registerParameter(&up_right_point); + registerParameter(&down_left_point); + registerParameter(&down_right_point); } LPEPerspectiveEnvelope::~LPEPerspectiveEnvelope() { } -void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) { +void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) +{ using Geom::X; using Geom::Y; double projmatrix[3][3]; - if(deform_type == DEFORMATION_PERSPECTIVE){ + if(deform_type == DEFORMATION_PERSPECTIVE) { std::vector<Geom::Point> handles(4); - handles[0] = Down_Left_Point; - handles[1] = Up_Left_Point; - handles[2] = Up_Right_Point; - handles[3] = Down_Right_Point; - std::vector<Geom::Point> sourceHandles(4); - sourceHandles[0] = Geom::Point(boundingbox_X.min(), boundingbox_Y.max()); - sourceHandles[1] = Geom::Point(boundingbox_X.min(), boundingbox_Y.min()); - sourceHandles[2] = Geom::Point(boundingbox_X.max(), boundingbox_Y.min()); - sourceHandles[3] = Geom::Point(boundingbox_X.max(), boundingbox_Y.max()); + handles[0] = down_left_point; + handles[1] = up_left_point; + handles[2] = up_right_point; + handles[3] = down_right_point; + std::vector<Geom::Point> source_handles(4); + source_handles[0] = Geom::Point(boundingbox_X.min(), boundingbox_Y.max()); + source_handles[1] = Geom::Point(boundingbox_X.min(), boundingbox_Y.min()); + source_handles[2] = Geom::Point(boundingbox_X.max(), boundingbox_Y.min()); + source_handles[3] = Geom::Point(boundingbox_X.max(), boundingbox_Y.max()); double solmatrix[8][8] = {{0}}; double free_term[8] = {0}; double gslSolmatrix[64]; - for(unsigned int i = 0; i < 4; ++i){ - solmatrix[i][0] = sourceHandles[i][X]; - solmatrix[i][1] = sourceHandles[i][Y]; + for(unsigned int i = 0; i < 4; ++i) { + solmatrix[i][0] = source_handles[i][X]; + solmatrix[i][1] = source_handles[i][Y]; solmatrix[i][2] = 1; - solmatrix[i][6] = -handles[i][X] * sourceHandles[i][X]; - solmatrix[i][7] = -handles[i][X] * sourceHandles[i][Y]; - solmatrix[i+4][3] = sourceHandles[i][X]; - solmatrix[i+4][4] = sourceHandles[i][Y]; + solmatrix[i][6] = -handles[i][X] * source_handles[i][X]; + solmatrix[i][7] = -handles[i][X] * source_handles[i][Y]; + solmatrix[i+4][3] = source_handles[i][X]; + solmatrix[i+4][4] = source_handles[i][Y]; solmatrix[i+4][5] = 1; - solmatrix[i+4][6] = -handles[i][Y] * sourceHandles[i][X]; - solmatrix[i+4][7] = -handles[i][Y] * sourceHandles[i][Y]; + solmatrix[i+4][6] = -handles[i][Y] * source_handles[i][X]; + solmatrix[i+4][7] = -handles[i][Y] * source_handles[i][Y]; free_term[i] = handles[i][X]; free_term[i+4] = handles[i][Y]; } @@ -110,7 +111,7 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) { h = 0; for( int i = 0; i < 3; i++ ) { for( int j = 0; j < 3; j++ ) { - if(h==8){ + if(h==8) { projmatrix[2][2] = 1.0; continue; } @@ -124,19 +125,19 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) { Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); curve->reset(); Geom::CubicBezier const *cubic = NULL; - Geom::Point pointAt1(0, 0); - Geom::Point pointAt2(0, 0); - Geom::Point pointAt3(0, 0); + Geom::Point point_at1(0, 0); + Geom::Point point_at2(0, 0); + Geom::Point point_at3(0, 0); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { //Si está vacÃo... if (path_it->empty()) - continue; + continue; //Itreadores SPCurve *nCurve = new SPCurve(); Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); - + if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); @@ -144,40 +145,40 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) { curve_endit = path_it->end_open(); } } - if(deform_type == DEFORMATION_PERSPECTIVE){ - nCurve->moveto(project_point(curve_it1->initialPoint(),projmatrix)); - }else{ - nCurve->moveto(project_point(curve_it1->initialPoint())); + if(deform_type == DEFORMATION_PERSPECTIVE) { + nCurve->moveto(projectPoint(curve_it1->initialPoint(),projmatrix)); + } else { + nCurve->moveto(projectPoint(curve_it1->initialPoint())); } while (curve_it1 != curve_endit) { - cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); - if (cubic) { - pointAt1 = (*cubic)[1]; - pointAt2 = (*cubic)[2]; - } else { - pointAt1 = curve_it1->initialPoint(); - pointAt2 = curve_it1->finalPoint(); - } - pointAt3 = curve_it1->finalPoint(); - if(deform_type == DEFORMATION_PERSPECTIVE){ - pointAt1 = project_point(pointAt1,projmatrix); - pointAt2 = project_point(pointAt2,projmatrix); - pointAt3 = project_point(pointAt3,projmatrix); - }else{ - pointAt1 = project_point(pointAt1); - pointAt2 = project_point(pointAt2); - pointAt3 = project_point(pointAt3); - } - nCurve->curveto(pointAt1, pointAt2, pointAt3); - ++curve_it1; - if(curve_it2 != curve_endit) { - ++curve_it2; - } + cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); + if (cubic) { + point_at1 = (*cubic)[1]; + point_at2 = (*cubic)[2]; + } else { + point_at1 = curve_it1->initialPoint(); + point_at2 = curve_it1->finalPoint(); + } + point_at3 = curve_it1->finalPoint(); + if(deform_type == DEFORMATION_PERSPECTIVE) { + point_at1 = projectPoint(point_at1,projmatrix); + point_at2 = projectPoint(point_at2,projmatrix); + point_at3 = projectPoint(point_at3,projmatrix); + } else { + point_at1 = projectPoint(point_at1); + point_at2 = projectPoint(point_at2); + point_at3 = projectPoint(point_at3); + } + nCurve->curveto(point_at1, point_at2, point_at3); + ++curve_it1; + if(curve_it2 != curve_endit) { + ++curve_it2; + } } //y cerramos la curva if (path_it->closed()) { - nCurve->move_endpoints(pointAt3, pointAt3); - nCurve->closepath_current(); + nCurve->move_endpoints(point_at3, point_at3); + nCurve->closepath_current(); } curve->append(nCurve, false); nCurve->reset(); @@ -185,41 +186,44 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) { } } -Geom::Point -LPEPerspectiveEnvelope::project_point(Geom::Point p){ +Geom::Point +LPEPerspectiveEnvelope::projectPoint(Geom::Point p) +{ double width = boundingbox_X.extent(); double height = boundingbox_Y.extent(); double delta_x = boundingbox_X.min() - p[X]; double delta_y = boundingbox_Y.max() - p[Y]; - Geom::Coord xratio = (delta_x * -1) / width; - Geom::Coord yratio = delta_y / height; + Geom::Coord x_ratio = (delta_x * -1) / width; + Geom::Coord y_ratio = delta_y / height; Geom::Line* horiz = new Geom::Line(); Geom::Line* vert = new Geom::Line(); - vert->setPoints (pointAtRatio(yratio,Down_Left_Point,Up_Left_Point),pointAtRatio(yratio,Down_Right_Point,Up_Right_Point)); - horiz->setPoints (pointAtRatio(xratio,Down_Left_Point,Down_Right_Point),pointAtRatio(xratio,Up_Left_Point,Up_Right_Point)); + vert->setPoints (pointAtRatio(y_ratio,down_left_point,up_left_point),pointAtRatio(y_ratio,down_right_point,up_right_point)); + horiz->setPoints (pointAtRatio(x_ratio,down_left_point,down_right_point),pointAtRatio(x_ratio,up_left_point,up_right_point)); OptCrossing crossPoint = intersection(*horiz,*vert); - if(crossPoint){ + if(crossPoint) { return horiz->pointAt(Geom::Coord(crossPoint->ta)); - }else{ + } else { return p; } } -Geom::Point -LPEPerspectiveEnvelope::project_point(Geom::Point p, double m[][3]){ +Geom::Point +LPEPerspectiveEnvelope::projectPoint(Geom::Point p, double m[][3]) +{ Geom::Coord x = p[0]; Geom::Coord y = p[1]; return Geom::Point( - Geom::Coord((x*m[0][0] + y*m[0][1] + m[0][2])/(x*m[2][0]+y*m[2][1]+m[2][2])), - Geom::Coord((x*m[1][0] + y*m[1][1] + m[1][2])/(x*m[2][0]+y*m[2][1]+m[2][2]))); + Geom::Coord((x*m[0][0] + y*m[0][1] + m[0][2])/(x*m[2][0]+y*m[2][1]+m[2][2])), + Geom::Coord((x*m[1][0] + y*m[1][1] + m[1][2])/(x*m[2][0]+y*m[2][1]+m[2][2]))); } Geom::Point -LPEPerspectiveEnvelope::pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B){ - Geom::Coord x = A[X] + (ratio * (B[X]-A[X])); - Geom::Coord y = A[Y]+ (ratio * (B[Y]-A[Y])); - return Point(x, y); +LPEPerspectiveEnvelope::pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B) +{ + Geom::Coord x = A[X] + (ratio * (B[X]-A[X])); + Geom::Coord y = A[Y]+ (ratio * (B[Y]-A[Y])); + return Point(x, y); } @@ -233,36 +237,35 @@ LPEPerspectiveEnvelope::newWidget() vbox->set_homogeneous(false); vbox->set_spacing(6); std::vector<Parameter *>::iterator it = param_vector.begin(); - Gtk::HBox * hboxUpHandles = Gtk::manage(new Gtk::HBox(false,0)); - Gtk::HBox * hboxDownHandles = Gtk::manage(new Gtk::HBox(false,0)); + Gtk::HBox * hbox_up_handles = Gtk::manage(new Gtk::HBox(false,0)); + Gtk::HBox * hbox_down_handles = Gtk::manage(new Gtk::HBox(false,0)); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter * param = *it; Gtk::Widget * widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); - if (param->param_key == "Up_Left_Point" || - param->param_key == "Up_Right_Point" || - param->param_key == "Down_Left_Point" || - param->param_key == "Down_Right_Point") - { - Gtk::HBox * pointParameter = dynamic_cast<Gtk::HBox *>(widg); - std::vector< Gtk::Widget* > childList = pointParameter->get_children(); - Gtk::HBox * pointParameterHBox = dynamic_cast<Gtk::HBox *>(childList[0]); - std::vector< Gtk::Widget* > childList2 = pointParameterHBox->get_children(); - pointParameterHBox->remove(childList2[0][0]); + if (param->param_key == "up_left_point" || + param->param_key == "up_right_point" || + param->param_key == "down_left_point" || + param->param_key == "down_right_point") { + Gtk::HBox * point_hbox = dynamic_cast<Gtk::HBox *>(widg); + std::vector< Gtk::Widget* > child_list = point_hbox->get_children(); + Gtk::HBox * point_hboxHBox = dynamic_cast<Gtk::HBox *>(child_list[0]); + std::vector< Gtk::Widget* > child_list2 = point_hboxHBox->get_children(); + point_hboxHBox->remove(child_list2[0][0]); Glib::ustring * tip = param->param_getTooltip(); if (widg) { - if(param->param_key == "Up_Left_Point"){ + if(param->param_key == "up_left_point") { Gtk::Label* handles = Gtk::manage(new Gtk::Label(Glib::ustring(_("Handles:")),Gtk::ALIGN_START)); vbox->pack_start(*handles, false, false, 2); - hboxUpHandles->pack_start(*widg, true, true, 2); - hboxUpHandles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET); - }else if(param->param_key == "Up_Right_Point"){ - hboxUpHandles->pack_start(*widg, true, true, 2); - }else if(param->param_key == "Down_Left_Point"){ - hboxDownHandles->pack_start(*widg, true, true, 2); - hboxDownHandles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET); - }else{ - hboxDownHandles->pack_start(*widg, true, true, 2); + hbox_up_handles->pack_start(*widg, true, true, 2); + hbox_up_handles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET); + } else if(param->param_key == "up_right_point") { + hbox_up_handles->pack_start(*widg, true, true, 2); + } else if(param->param_key == "down_left_point") { + hbox_down_handles->pack_start(*widg, true, true, 2); + hbox_down_handles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET); + } else { + hbox_down_handles->pack_start(*widg, true, true, 2); } if (tip) { widg->set_tooltip_text(*tip); @@ -271,7 +274,7 @@ LPEPerspectiveEnvelope::newWidget() widg->set_has_tooltip(false); } } - }else{ + } else { Glib::ustring * tip = param->param_getTooltip(); if (widg) { vbox->pack_start(*widg, true, true, 2); @@ -287,18 +290,18 @@ LPEPerspectiveEnvelope::newWidget() ++it; } - vbox->pack_start(*hboxUpHandles,true, true, 2); - Gtk::HBox * hboxMiddle = Gtk::manage(new Gtk::HBox(true,2)); - hboxMiddle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); - hboxMiddle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); - vbox->pack_start(*hboxMiddle, false, true, 2); - vbox->pack_start(*hboxDownHandles, true, true, 2); + vbox->pack_start(*hbox_up_handles,true, true, 2); + Gtk::HBox * hbox_middle = Gtk::manage(new Gtk::HBox(true,2)); + hbox_middle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); + hbox_middle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); + vbox->pack_start(*hbox_middle, false, true, 2); + vbox->pack_start(*hbox_down_handles, true, true, 2); Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); - Gtk::Button* resetButton = Gtk::manage(new Gtk::Button(Gtk::Stock::CLEAR)); - resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPEPerspectiveEnvelope::resetGrid)); - resetButton->set_size_request(140,30); + Gtk::Button* reset_button = Gtk::manage(new Gtk::Button(Gtk::Stock::CLEAR)); + reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPEPerspectiveEnvelope::resetGrid)); + reset_button->set_size_request(140,30); vbox->pack_start(*hbox, true,true,2); - hbox->pack_start(*resetButton, false, false,2); + hbox->pack_start(*reset_button, false, false,2); return dynamic_cast<Gtk::Widget *>(vbox); } @@ -315,24 +318,24 @@ LPEPerspectiveEnvelope::doBeforeEffect (SPLPEItem const* lpeitem) void LPEPerspectiveEnvelope::setDefaults() { - Geom::Point Up_Left(boundingbox_X.min(), boundingbox_Y.min()); - Geom::Point Up_Right(boundingbox_X.max(), boundingbox_Y.min()); - Geom::Point Down_Left(boundingbox_X.min(), boundingbox_Y.max()); - Geom::Point Down_Right(boundingbox_X.max(), boundingbox_Y.max()); - - Up_Left_Point.param_update_default(Up_Left); - Up_Right_Point.param_update_default(Up_Right); - Down_Right_Point.param_update_default(Down_Right); - Down_Left_Point.param_update_default(Down_Left); + Geom::Point up_left(boundingbox_X.min(), boundingbox_Y.min()); + Geom::Point up_right(boundingbox_X.max(), boundingbox_Y.min()); + Geom::Point down_left(boundingbox_X.min(), boundingbox_Y.max()); + Geom::Point down_right(boundingbox_X.max(), boundingbox_Y.max()); + + up_left_point.param_update_default(up_left); + up_right_point.param_update_default(up_right); + down_right_point.param_update_default(down_right); + down_left_point.param_update_default(down_left); } void LPEPerspectiveEnvelope::resetGrid() { - Up_Left_Point.param_set_default(); - Up_Right_Point.param_set_default(); - Down_Right_Point.param_set_default(); - Down_Left_Point.param_set_default(); + up_left_point.param_set_default(); + up_right_point.param_set_default(); + down_right_point.param_set_default(); + down_left_point.param_set_default(); } void @@ -340,8 +343,8 @@ LPEPerspectiveEnvelope::resetDefaults(SPItem const* item) { Effect::resetDefaults(item); original_bbox(SP_LPE_ITEM(item)); - resetGrid(); setDefaults(); + resetGrid(); } void @@ -351,11 +354,11 @@ LPEPerspectiveEnvelope::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::v SPCurve *c = new SPCurve(); c->reset(); - c->moveto(Up_Left_Point); - c->lineto(Up_Right_Point); - c->lineto(Down_Right_Point); - c->lineto(Down_Left_Point); - c->lineto(Up_Left_Point); + c->moveto(up_left_point); + c->lineto(up_right_point); + c->lineto(down_right_point); + c->lineto(down_left_point); + c->lineto(up_left_point); hp_vec.push_back(c->get_pathvector()); } diff --git a/src/live_effects/lpe-perspective-envelope.h b/src/live_effects/lpe-perspective-envelope.h index d3ff76445..e25f059a3 100644 --- a/src/live_effects/lpe-perspective-envelope.h +++ b/src/live_effects/lpe-perspective-envelope.h @@ -3,7 +3,7 @@ /** \file * LPE <perspective-envelope> implementation , see lpe-perspective-envelope.cpp. - + */ /* * Authors: @@ -11,8 +11,8 @@ * Aaron Spike, aaron@ekips.org from envelope and perspective phyton code * Dmitry Platonov, shadowjack@mail.ru, 2006 perspective approach & math * Jose Hevia (freon) Transform algorithm from envelope - * - * Copyright (C) 2007-2014 Authors + * + * Copyright (C) 2007-2014 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -34,9 +34,9 @@ public: virtual void doEffect(SPCurve *curve); - virtual Geom::Point project_point(Geom::Point p); + virtual Geom::Point projectPoint(Geom::Point p); - virtual Geom::Point project_point(Geom::Point p, double m[][3]); + virtual Geom::Point projectPoint(Geom::Point p, double m[][3]); virtual Geom::Point pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B); @@ -55,10 +55,10 @@ protected: private: EnumParam<unsigned> deform_type; - PointParam Up_Left_Point; - PointParam Up_Right_Point; - PointParam Down_Left_Point; - PointParam Down_Right_Point; + PointParam up_left_point; + PointParam up_right_point; + PointParam down_left_point; + PointParam down_right_point; LPEPerspectiveEnvelope(const LPEPerspectiveEnvelope&); LPEPerspectiveEnvelope& operator=(const LPEPerspectiveEnvelope&); diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index f7fe9592d..5d9d224e8 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -297,7 +297,8 @@ LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem) } else { sp_repr_css_unset_property (css, "fill"); } - + + sp_repr_css_set_property(css, "fill-rule", "nonzero"); sp_repr_css_set_property(css, "stroke", "none"); sp_desktop_apply_css_recursive(item, css, true); @@ -330,25 +331,21 @@ void LPEPowerStroke::doOnRemove(SPLPEItem const* lpeitem) if (SP_IS_SHAPE(lpeitem)) { SPLPEItem *item = const_cast<SPLPEItem*>(lpeitem); SPCSSAttr *css = sp_repr_css_attr_new (); - if (true) { - if (lpeitem->style->fill.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getFillPaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "stroke", str.c_str()); - } - } else if (lpeitem->style->fill.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "stroke", c); - } else { - sp_repr_css_set_property (css, "stroke", "none"); + if (lpeitem->style->fill.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getFillPaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "stroke", str.c_str()); } + } else if (lpeitem->style->fill.isColor()) { + char c[64] = {0}; + sp_svg_write_color (c, sizeof(c), lpeitem->style->fill.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->fill_opacity.value))); + sp_repr_css_set_property (css, "stroke", c); } else { - sp_repr_css_unset_property (css, "stroke"); + sp_repr_css_set_property (css, "stroke", "none"); } Inkscape::CSSOStringStream os; diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 8cef9a3a3..9d1c3152b 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -39,36 +39,36 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) unit(_("Unit"), _("Unit"), "unit", &wr, this), method(_("Method"), _("Division method"), "method", DMConverter, &wr, this, DM_SEGMENTS), - maxSegmentSize(_("Max. segment size"), _("Max. segment size"), - "maxSegmentSize", &wr, this, 10.), + max_segment_size(_("Max. segment size"), _("Max. segment size"), + "max_segment_size", &wr, this, 10.), segments(_("Number of segments"), _("Number of segments"), "segments", &wr, this, 2), - displaceX(_("Max. displacement in X"), _("Max. displacement in X"), - "displaceX", &wr, this, 10.), - displaceY(_("Max. displacement in Y"), _("Max. displacement in Y"), - "displaceY", &wr, this, 10.), - globalRandomize(_("Global randomize"), _("Global randomize"), - "globalRandomize", &wr, this, 1.), - shiftNodes(_("Shift nodes"), _("Shift nodes"), "shiftNodes", &wr, this, + displace_x(_("Max. displacement in X"), _("Max. displacement in X"), + "displace_x", &wr, this, 10.), + displace_y(_("Max. displacement in Y"), _("Max. displacement in Y"), + "displace_y", &wr, this, 10.), + global_randomize(_("Global randomize"), _("Global randomize"), + "global_randomize", &wr, this, 1.), + shift_nodes(_("Shift nodes"), _("Shift nodes"), "shift_nodes", &wr, this, true), - shiftNodeHandles(_("Shift node handles"), _("Shift node handles"), - "shiftNodeHandles", &wr, this, true) + shift_node_handles(_("Shift node handles"), _("Shift node handles"), + "shift_node_handles", &wr, this, true) { registerParameter(&unit); registerParameter(&method); - registerParameter(&maxSegmentSize); + registerParameter(&max_segment_size); registerParameter(&segments); - registerParameter(&displaceX); - registerParameter(&displaceY); - registerParameter(&globalRandomize); - registerParameter(&shiftNodes); - registerParameter(&shiftNodeHandles); - displaceX.param_set_range(0., Geom::infinity()); - displaceY.param_set_range(0., Geom::infinity()); - globalRandomize.param_set_range(0., Geom::infinity()); - maxSegmentSize.param_set_range(0., Geom::infinity()); - maxSegmentSize.param_set_increments(1, 1); - maxSegmentSize.param_set_digits(1); + registerParameter(&displace_x); + registerParameter(&displace_y); + registerParameter(&global_randomize); + registerParameter(&shift_nodes); + registerParameter(&shift_node_handles); + displace_x.param_set_range(0., Geom::infinity()); + displace_y.param_set_range(0., Geom::infinity()); + global_randomize.param_set_range(0., Geom::infinity()); + max_segment_size.param_set_range(0., Geom::infinity()); + max_segment_size.param_set_increments(1, 1); + max_segment_size.param_set_digits(1); segments.param_set_range(1, Geom::infinity()); segments.param_set_increments(1, 1); segments.param_set_digits(0); @@ -78,9 +78,9 @@ LPERoughen::~LPERoughen() {} void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) { - displaceX.resetRandomizer(); - displaceY.resetRandomizer(); - globalRandomize.resetRandomizer(); + displace_x.resetRandomizer(); + displace_y.resetRandomizer(); + global_randomize.resetRandomizer(); srand(1); SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); item->apply_to_clippath(item); @@ -99,37 +99,37 @@ Gtk::Widget *LPERoughen::newWidget() Parameter *param = *it; Gtk::Widget *widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); if (param->param_key == "unit") { - Gtk::Label *unitLabel = Gtk::manage(new Gtk::Label( + Gtk::Label *unit_label = Gtk::manage(new Gtk::Label( Glib::ustring(_("<b>Roughen unit</b>")), Gtk::ALIGN_START)); - unitLabel->set_use_markup(true); - vbox->pack_start(*unitLabel, false, false, 2); + unit_label->set_use_markup(true); + vbox->pack_start(*unit_label, false, false, 2); vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); } if (param->param_key == "method") { - Gtk::Label *methodLabel = Gtk::manage(new Gtk::Label( + Gtk::Label *method_label = Gtk::manage(new Gtk::Label( Glib::ustring(_("<b>Add nodes</b> Subdivide each segment")), Gtk::ALIGN_START)); - methodLabel->set_use_markup(true); - vbox->pack_start(*methodLabel, false, false, 2); + method_label->set_use_markup(true); + vbox->pack_start(*method_label, false, false, 2); vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); } - if (param->param_key == "displaceX") { - Gtk::Label *displaceXLabel = Gtk::manage(new Gtk::Label( + if (param->param_key == "displace_x") { + Gtk::Label *displace_x_label = Gtk::manage(new Gtk::Label( Glib::ustring(_("<b>Jitter nodes</b> Move nodes/handles")), Gtk::ALIGN_START)); - displaceXLabel->set_use_markup(true); - vbox->pack_start(*displaceXLabel, false, false, 2); + displace_x_label->set_use_markup(true); + vbox->pack_start(*displace_x_label, false, false, 2); vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); } - if (param->param_key == "globalRandomize") { - Gtk::Label *displaceXLabel = Gtk::manage(new Gtk::Label( + if (param->param_key == "global_randomize") { + Gtk::Label *global_rand = Gtk::manage(new Gtk::Label( Glib::ustring(_("<b>Extra roughen</b> Add a extra layer of rough")), Gtk::ALIGN_START)); - displaceXLabel->set_use_markup(true); - vbox->pack_start(*displaceXLabel, false, false, 2); + global_rand->set_use_markup(true); + vbox->pack_start(*global_rand, false, false, 2); vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); } @@ -150,23 +150,23 @@ Gtk::Widget *LPERoughen::newWidget() return dynamic_cast<Gtk::Widget *>(vbox); } -double LPERoughen::sign(double randNumber) +double LPERoughen::sign(double random_number) { if (rand() % 100 < 49) { - randNumber *= -1.; + random_number *= -1.; } - return randNumber; + return random_number; } Geom::Point LPERoughen::randomize() { Inkscape::Util::Unit const *svg_units = SP_ACTIVE_DESKTOP->namedview->svg_units; - double displaceXParsed = Inkscape::Util::Quantity::convert( - displaceX * globalRandomize, unit.get_abbreviation(), svg_units->abbr); - double displaceYParsed = Inkscape::Util::Quantity::convert( - displaceY * globalRandomize, unit.get_abbreviation(), svg_units->abbr); + double displace_x_parsed = Inkscape::Util::Quantity::convert( + displace_x * global_randomize, unit.get_abbreviation(), svg_units->abbr); + double displace_y_parsed = Inkscape::Util::Quantity::convert( + displace_y * global_randomize, unit.get_abbreviation(), svg_units->abbr); - Geom::Point output = Geom::Point(sign(displaceXParsed), sign(displaceYParsed)); + Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); return output; } @@ -193,32 +193,32 @@ void LPERoughen::doEffect(SPCurve *curve) } } Geom::Point initialMove(0, 0); - if (shiftNodes) { + if (shift_nodes) { initialMove = randomize(); } Geom::Point initialPoint = curve_it1->initialPoint() + initialMove; nCurve->moveto(initialPoint); - Geom::Point A0(0, 0); - Geom::Point A1(0, 0); - Geom::Point A2(0, 0); - Geom::Point A3(0, 0); + Geom::Point point0(0, 0); + Geom::Point point1(0, 0); + Geom::Point point2(0, 0); + Geom::Point point3(0, 0); bool first = true; while (curve_it1 != curve_endit) { Geom::CubicBezier const *cubic = NULL; - A0 = curve_it1->initialPoint(); - A1 = curve_it1->initialPoint(); - A2 = curve_it1->finalPoint(); - A3 = curve_it1->finalPoint(); + point0 = curve_it1->initialPoint(); + point1 = curve_it1->initialPoint(); + point2 = curve_it1->finalPoint(); + point3 = curve_it1->finalPoint(); cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); if (cubic) { - A1 = (*cubic)[1]; - if (shiftNodes && first) { - A1 = (*cubic)[1] + initialMove; + point1 = (*cubic)[1]; + if (shift_nodes && first) { + point1 = (*cubic)[1] + initialMove; } - A2 = (*cubic)[2]; - nCurve->curveto(A1, A2, A3); + point2 = (*cubic)[2]; + nCurve->curveto(point1, point2, point3); } else { - nCurve->lineto(A3); + nCurve->lineto(point3); } double length = Inkscape::Util::Quantity::convert( curve_it1->length(0.001), svg_units->abbr, unit.get_abbreviation()); @@ -226,7 +226,7 @@ void LPERoughen::doEffect(SPCurve *curve) if (method == DM_SEGMENTS) { splits = segments; } else { - splits = ceil(length / maxSegmentSize); + splits = ceil(length / max_segment_size); } for (unsigned int t = splits; t >= 1; t--) { if (t == 1 && splits != 1) { @@ -265,42 +265,42 @@ SPCurve *LPERoughen::addNodesAndJitter(const Geom::Curve *A, double t) { SPCurve *out = new SPCurve(); Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>(&*A); - Geom::Point A1(0, 0); - Geom::Point A2(0, 0); - Geom::Point A3(0, 0); - Geom::Point B1(0, 0); - Geom::Point B2(0, 0); - Geom::Point B3(0, 0); - if (shiftNodes) { - A3 = randomize(); - B3 = randomize(); + Geom::Point point1(0, 0); + Geom::Point point2(0, 0); + Geom::Point point3(0, 0); + Geom::Point point_b1(0, 0); + Geom::Point point_b2(0, 0); + Geom::Point point_b3(0, 0); + if (shift_nodes) { + point3 = randomize(); + point_b3 = randomize(); } - if (shiftNodeHandles) { - A1 = randomize(); - A2 = randomize(); - B1 = randomize(); - B2 = randomize(); + if (shift_node_handles) { + point1 = randomize(); + point2 = randomize(); + point_b1 = randomize(); + point_b2 = randomize(); } else { - A2 = A3; - B1 = A3; - B2 = B3; + point2 = point3; + point_b1 = point3; + point_b2 = point_b3; } if (cubic) { std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t); std::vector<Geom::Point> seg1 = div.first.points(), seg2 = div.second.points(); out->moveto(seg1[0]); - out->curveto(seg1[1] + A1, seg1[2] + A2, seg1[3] + A3); - out->curveto(seg2[1] + B1, seg2[2], seg2[3]); - } else if (shiftNodeHandles) { + out->curveto(seg1[1] + point1, seg1[2] + point2, seg1[3] + point3); + out->curveto(seg2[1] + point_b1, seg2[2], seg2[3]); + } else if (shift_node_handles) { out->moveto(A->initialPoint()); - out->curveto(A->pointAt(t / 3) + A1, A->pointAt((t / 3) * 2) + A2, - A->pointAt(t) + A3); - out->curveto(A->pointAt(t + (t / 3)) + B1, A->pointAt(t + ((t / 3) * 2)), + out->curveto(A->pointAt(t / 3) + point1, A->pointAt((t / 3) * 2) + point2, + A->pointAt(t) + point3); + out->curveto(A->pointAt(t + (t / 3)) + point_b1, A->pointAt(t + ((t / 3) * 2)), A->finalPoint()); } else { out->moveto(A->initialPoint()); - out->lineto(A->pointAt(t) + A3); + out->lineto(A->pointAt(t) + point3); out->lineto(A->finalPoint()); } return out; @@ -310,33 +310,33 @@ SPCurve *LPERoughen::jitter(const Geom::Curve *A) { SPCurve *out = new SPCurve(); Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>(&*A); - Geom::Point A1(0, 0); - Geom::Point A2(0, 0); - Geom::Point A3(0, 0); - if (shiftNodes) { - A3 = randomize(); + Geom::Point point1(0, 0); + Geom::Point point2(0, 0); + Geom::Point point3(0, 0); + if (shift_nodes) { + point3 = randomize(); } - if (shiftNodeHandles) { - A1 = randomize(); - A2 = randomize(); + if (shift_node_handles) { + point1 = randomize(); + point2 = randomize(); } else { - A2 = A3; + point2 = point3; } if (cubic) { out->moveto((*cubic)[0]); - out->curveto((*cubic)[1] + A1, (*cubic)[2] + A2, (*cubic)[3] + A3); - } else if (shiftNodeHandles) { + out->curveto((*cubic)[1] + point1, (*cubic)[2] + point2, (*cubic)[3] + point3); + } else if (shift_node_handles) { out->moveto(A->initialPoint()); - out->curveto(A->pointAt(0.3333) + A1, A->pointAt(0.6666) + A2, - A->finalPoint() + A3); + out->curveto(A->pointAt(0.3333) + point1, A->pointAt(0.6666) + point2, + A->finalPoint() + point3); } else { out->moveto(A->initialPoint()); - out->lineto(A->finalPoint() + A3); + out->lineto(A->finalPoint() + point3); } return out; } -Geom::Point LPERoughen::tpoint(Geom::Point A, Geom::Point B, double t) +Geom::Point LPERoughen::tPoint(Geom::Point A, Geom::Point B, double t) { using Geom::X; using Geom::Y; diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index 74331f1ef..ed9f06cf7 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -41,19 +41,19 @@ public: virtual void doBeforeEffect(SPLPEItem const * lpeitem); virtual SPCurve *addNodesAndJitter(const Geom::Curve *A, double t); virtual SPCurve *jitter(const Geom::Curve *A); - virtual Geom::Point tpoint(Geom::Point A, Geom::Point B, double t = 0.5); + virtual Geom::Point tPoint(Geom::Point A, Geom::Point B, double t = 0.5); virtual Gtk::Widget *newWidget(); private: UnitParam unit; EnumParam<DivisionMethod> method; - ScalarParam maxSegmentSize; + ScalarParam max_segment_size; ScalarParam segments; - RandomParam displaceX; - RandomParam displaceY; - RandomParam globalRandomize; - BoolParam shiftNodes; - BoolParam shiftNodeHandles; + RandomParam displace_x; + RandomParam displace_y; + RandomParam global_randomize; + BoolParam shift_nodes; + BoolParam shift_node_handles; LPERoughen(const LPERoughen &); LPERoughen &operator=(const LPERoughen &); diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 2d8148730..2638f312e 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -24,25 +24,25 @@ LPEShowHandles::LPEShowHandles(LivePathEffectObject *lpeobject) : Effect(lpeobject), nodes(_("Show nodes"), _("Show nodes"), "nodes", &wr, this, true), handles(_("Show handles"), _("Show handles"), "handles", &wr, this, true), - originalPath(_("Show path"), _("Show path"), "originalPath", &wr, this, true), - scaleNodesAndHandles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scaleNodesAndHandles", &wr, this, 10), - rotateNodes(_("Rotate nodes"), _("Rotate nodes"), "rotateNodes", &wr, this, 0) + original_path(_("Show path"), _("Show path"), "original_path", &wr, this, true), + scale_nodes_and_handles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scale_nodes_and_handles", &wr, this, 10), + rotate_nodes(_("Rotate nodes"), _("Rotate nodes"), "rotate_nodes", &wr, this, 0) { - registerParameter(dynamic_cast<Parameter *>(&nodes)); - registerParameter(dynamic_cast<Parameter *>(&handles)); - registerParameter(dynamic_cast<Parameter *>(&originalPath)); - registerParameter(dynamic_cast<Parameter *>(&scaleNodesAndHandles)); - registerParameter(dynamic_cast<Parameter *>(&rotateNodes)); - scaleNodesAndHandles.param_set_range(0, 500.); - scaleNodesAndHandles.param_set_increments(1, 1); - scaleNodesAndHandles.param_set_digits(2); - rotateNodes.param_set_range(0, 365); - rotateNodes.param_set_increments(1, 1); - rotateNodes.param_set_digits(0); - strokeWidth = 1.0; + registerParameter(&nodes); + registerParameter(&handles); + registerParameter(&original_path); + registerParameter(&scale_nodes_and_handles); + registerParameter(&rotate_nodes); + scale_nodes_and_handles.param_set_range(0, 500.); + scale_nodes_and_handles.param_set_increments(1, 1); + scale_nodes_and_handles.param_set_digits(2); + rotate_nodes.param_set_range(0, 365); + rotate_nodes.param_set_increments(1, 1); + rotate_nodes.param_set_digits(0); + stroke_width = 1.0; } -bool LPEShowHandles::alertsOff = false; +bool LPEShowHandles::alerts_off = false; /** * Sets default styles to element @@ -51,11 +51,11 @@ bool LPEShowHandles::alertsOff = false; void LPEShowHandles::doOnApply(SPLPEItem const* lpeitem) { - if(!alertsOff) { + if(!alerts_off) { char *msg = _("The \"show handles\" path effect will remove any custom style on the object you are applying it to. If this is not what you want, click Cancel."); Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); gint response = dialog.run(); - alertsOff = true; + alerts_off = true; if(response == GTK_RESPONSE_CANCEL) { SPLPEItem* item = const_cast<SPLPEItem*>(lpeitem); item->removeCurrentPathEffect(false); @@ -76,24 +76,24 @@ void LPEShowHandles::doOnApply(SPLPEItem const* lpeitem) void LPEShowHandles::doBeforeEffect (SPLPEItem const* lpeitem) { SPItem const* item = SP_ITEM(lpeitem); - strokeWidth = item->style->stroke_width.computed; + stroke_width = item->style->stroke_width.computed; } std::vector<Geom::Path> LPEShowHandles::doEffect_path (std::vector<Geom::Path> const & path_in) { std::vector<Geom::Path> path_out; Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); - if(originalPath) { + if(original_path) { for (unsigned int i=0; i < path_in.size(); i++) { path_out.push_back(path_in[i]); } } - if(!outlinepath.empty()) { - outlinepath.clear(); + if(!outline_path.empty()) { + outline_path.clear(); } generateHelperPath(original_pathv); - for (unsigned int i=0; i < outlinepath.size(); i++) { - path_out.push_back(outlinepath[i]); + for (unsigned int i=0; i < outline_path.size(); i++) { + path_out.push_back(outline_path[i]); } return path_out; } @@ -136,11 +136,11 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); if (cubic) { if(handles) { - if(!are_near((*cubic)[0],(*cubic)[1])){ + if(!are_near((*cubic)[0],(*cubic)[1])) { drawHandle((*cubic)[1]); drawHandleLine((*cubic)[0],(*cubic)[1]); } - if(!are_near((*cubic)[3],(*cubic)[2])){ + if(!are_near((*cubic)[3],(*cubic)[2])) { drawHandle((*cubic)[2]); drawHandleLine((*cubic)[3],(*cubic)[2]); } @@ -150,7 +150,7 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) drawNode(curve_it1->finalPoint()); } ++curve_it1; - if(curve_it2 != curve_endit){ + if(curve_it2 != curve_endit) { ++curve_it2; } } @@ -160,30 +160,30 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) void LPEShowHandles::drawNode(Geom::Point p) { - if(strokeWidth * scaleNodesAndHandles > 0.0) { - double diameter = strokeWidth * scaleNodesAndHandles; + if(stroke_width * scale_nodes_and_handles > 0.0) { + double diameter = stroke_width * scale_nodes_and_handles; char const * svgd; svgd = "M 0.05,0 A 0.05,0.05 0 0 1 0,0.05 0.05,0.05 0 0 1 -0.05,0 0.05,0.05 0 0 1 0,-0.05 0.05,0.05 0 0 1 0.05,0 Z M -0.5,-0.5 0.5,-0.5 0.5,0.5 -0.5,0.5 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Rotate::from_degrees(rotateNodes); + pathv *= Geom::Rotate::from_degrees(rotate_nodes); pathv *= Geom::Scale (diameter); pathv += p; - outlinepath.push_back(pathv[0]); - outlinepath.push_back(pathv[1]); + outline_path.push_back(pathv[0]); + outline_path.push_back(pathv[1]); } } void LPEShowHandles::drawHandle(Geom::Point p) { - if(strokeWidth * scaleNodesAndHandles > 0.0) { - double diameter = strokeWidth * scaleNodesAndHandles; + if(stroke_width * scale_nodes_and_handles > 0.0) { + double diameter = stroke_width * scale_nodes_and_handles; char const * svgd; svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); pathv *= Geom::Scale (diameter); pathv += p-Geom::Point(diameter * 0.35,diameter * 0.35); - outlinepath.push_back(pathv[0]); + outline_path.push_back(pathv[0]); } } @@ -192,14 +192,14 @@ void LPEShowHandles::drawHandleLine(Geom::Point p,Geom::Point p2) { Geom::Path path; - double diameter = strokeWidth * scaleNodesAndHandles; - if(diameter > 0.0 && Geom::distance(p,p2) > (diameter * 0.35)){ + double diameter = stroke_width * scale_nodes_and_handles; + if(diameter > 0.0 && Geom::distance(p,p2) > (diameter * 0.35)) { Geom::Ray ray2(p, p2); p2 = p2 - Geom::Point::polar(ray2.angle(),(diameter * 0.35)); } path.start( p ); path.appendNew<Geom::LineSegment>( p2 ); - outlinepath.push_back(path); + outline_path.push_back(path); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index a405c26ee..77b28e77a 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -20,7 +20,7 @@ class LPEShowHandles : public Effect , GroupBBoxEffect { public: LPEShowHandles(LivePathEffectObject *lpeobject); - virtual ~LPEShowHandles(){} + virtual ~LPEShowHandles() {} virtual void doOnApply(SPLPEItem const* lpeitem); @@ -42,13 +42,13 @@ private: BoolParam nodes; BoolParam handles; - BoolParam originalPath; - ScalarParam scaleNodesAndHandles; - ScalarParam rotateNodes; - double strokeWidth; - static bool alertsOff; + BoolParam original_path; + ScalarParam scale_nodes_and_handles; + ScalarParam rotate_nodes; + double stroke_width; + static bool alerts_off; - Geom::PathVector outlinepath; + Geom::PathVector outline_path; LPEShowHandles(const LPEShowHandles &); LPEShowHandles &operator=(const LPEShowHandles &); diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 1fe18dd5e..7fc20ede1 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -27,39 +27,39 @@ namespace LivePathEffect { LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) : Effect(lpeobject), - steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), - threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), - smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.), - helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5), - simplifyindividualpaths(_("Paths separately"), _("Simplifying paths (separately)"), "simplifyindividualpaths", &wr, this, false, - "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), - simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false, - "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")) - { - registerParameter(&steps); - registerParameter(&threshold); - registerParameter(&smooth_angles); - registerParameter(&helper_size); - registerParameter(&simplifyindividualpaths); - registerParameter(&simplifyJustCoalesce); + steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), + threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), + smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.), + helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5), + simplify_individual_paths(_("Paths separately"), _("Simplifying paths (separately)"), "simplify_individual_paths", &wr, this, false, + "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), + simplify_just_coalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplify_just_coalesce", &wr, this, false, + "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")) +{ + registerParameter(&steps); + registerParameter(&threshold); + registerParameter(&smooth_angles); + registerParameter(&helper_size); + registerParameter(&simplify_individual_paths); + registerParameter(&simplify_just_coalesce); - threshold.param_set_range(0.0001, Geom::infinity()); - threshold.param_set_increments(0.0001, 0.0001); - threshold.param_set_digits(6); + threshold.param_set_range(0.0001, Geom::infinity()); + threshold.param_set_increments(0.0001, 0.0001); + threshold.param_set_digits(6); - steps.param_set_range(0, 100); - steps.param_set_increments(1, 1); - steps.param_set_digits(0); + steps.param_set_range(0, 100); + steps.param_set_increments(1, 1); + steps.param_set_digits(0); - smooth_angles.param_set_range(0.0, 365.0); - smooth_angles.param_set_increments(10, 10); - smooth_angles.param_set_digits(2); + smooth_angles.param_set_range(0.0, 365.0); + smooth_angles.param_set_increments(10, 10); + smooth_angles.param_set_digits(2); - helper_size.param_set_range(0.0, 999.0); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(2); + helper_size.param_set_range(0.0, 999.0); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(2); - radiusHelperNodes = 6.0; + radius_helper_nodes = 6.0; } LPESimplify::~LPESimplify() {} @@ -67,12 +67,12 @@ LPESimplify::~LPESimplify() {} void LPESimplify::doBeforeEffect (SPLPEItem const* lpeitem) { - if(!hp.empty()){ + if(!hp.empty()) { hp.clear(); } bbox = SP_ITEM(lpeitem)->visualBounds(); SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); - radiusHelperNodes = helper_size; + radius_helper_nodes = helper_size; item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -91,9 +91,8 @@ LPESimplify::newWidget() if ((*it)->widget_is_visible) { Parameter * param = *it; Gtk::Widget * widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); - if (param->param_key == "simplifyindividualpaths" || - param->param_key == "simplifyJustCoalesce") - { + if (param->param_key == "simplify_individual_paths" || + param->param_key == "simplify_just_coalesce") { Glib::ustring * tip = param->param_getTooltip(); if (widg) { buttons->pack_start(*widg, true, true, 2); @@ -104,13 +103,13 @@ LPESimplify::newWidget() widg->set_has_tooltip(false); } } - } else{ + } else { Glib::ustring * tip = param->param_getTooltip(); if (widg) { - Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widg); - std::vector< Gtk::Widget* > childList = scalarParameter->get_children(); - Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]); - entryWidg->set_width_chars(8); + Gtk::HBox * horizontal_box = dynamic_cast<Gtk::HBox *>(widg); + std::vector< Gtk::Widget* > child_list = horizontal_box->get_children(); + Gtk::Entry* entry_widg = dynamic_cast<Gtk::Entry *>(child_list[1]); + entry_widg->set_width_chars(8); vbox->pack_start(*widg, true, true, 2); if (tip) { widg->set_tooltip_text(*tip); @@ -128,28 +127,29 @@ LPESimplify::newWidget() return dynamic_cast<Gtk::Widget *>(vbox); } -void -LPESimplify::doEffect(SPCurve *curve) { +void +LPESimplify::doEffect(SPCurve *curve) +{ Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); gdouble size = Geom::L2(bbox->dimensions()); //size /= Geom::Affine(0,0,0,0,0,0).descrim(); Path* pathliv = Path_for_pathvector(original_pathv); - if(simplifyindividualpaths){ + if(simplify_individual_paths) { size = Geom::L2(Geom::bounds_fast(original_pathv)->dimensions()); } - for (int unsigned i = 0; i < steps; i++){ - if ( simplifyJustCoalesce ) { - pathliv->Coalesce(threshold * size); - }else{ - pathliv->ConvertEvenLines(threshold * size); - pathliv->Simplify(threshold * size); + for (int unsigned i = 0; i < steps; i++) { + if ( simplify_just_coalesce ) { + pathliv->Coalesce(threshold * size); + } else { + pathliv->ConvertEvenLines(threshold * size); + pathliv->Simplify(threshold * size); } } Geom::PathVector result = Geom::parse_svg_path(pathliv->svg_dump_path()); generateHelperPathAndSmooth(result); curve->set_pathvector(result); SPDesktop* desktop = SP_ACTIVE_DESKTOP; - if(desktop && INK_IS_NODE_TOOL(desktop->event_context)){ + if(desktop && INK_IS_NODE_TOOL(desktop->event_context)) { Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); nt->update_helperpath(); } @@ -158,15 +158,15 @@ LPESimplify::doEffect(SPCurve *curve) { void LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) { - if(steps < 1){ + if(steps < 1) { return; } - Geom::PathVector tmpPath; + Geom::PathVector tmp_path; Geom::CubicBezier const *cubic = NULL; for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) { //Si está vacÃo... - if (path_it->empty()){ - continue; + if (path_it->empty()) { + continue; } //Itreadores Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve @@ -174,68 +174,68 @@ LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop SPCurve *nCurve = new SPCurve(); if (path_it->closed()) { - // if the path is closed, maybe we have to stop a bit earlier because the - // closing line segment has zerolength. - const Geom::Curve &closingline = - path_it->back_closed(); // the closing line segment is always of type - // Geom::LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } + // if the path is closed, maybe we have to stop a bit earlier because the + // closing line segment has zerolength. + const Geom::Curve &closingline = + path_it->back_closed(); // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } } - if(helper_size > 0){ + if(helper_size > 0) { drawNode(curve_it1->initialPoint()); } nCurve->moveto(curve_it1->initialPoint()); Geom::Point start = Geom::Point(0,0); while (curve_it1 != curve_endit) { cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); - Geom::Point pointAt1 = curve_it1->initialPoint(); - Geom::Point pointAt2 = curve_it1->finalPoint(); - Geom::Point pointAt3 = curve_it1->finalPoint(); - Geom::Point pointAt4 = curve_it1->finalPoint(); + Geom::Point point_at1 = curve_it1->initialPoint(); + Geom::Point point_at2 = curve_it1->finalPoint(); + Geom::Point point_at3 = curve_it1->finalPoint(); + Geom::Point point_at4 = curve_it1->finalPoint(); if (cubic) { - pointAt1 = (*cubic)[1]; - pointAt2 = (*cubic)[2]; + point_at1 = (*cubic)[1]; + point_at2 = (*cubic)[2]; } - if(start == Geom::Point(0,0)){ - start = pointAt1; + if(start == Geom::Point(0,0)) { + start = point_at1; } - - if(path_it->closed() && curve_it2 == curve_endit){ - pointAt4 = start; + + if(path_it->closed() && curve_it2 == curve_endit) { + point_at4 = start; } - if(curve_it2 != curve_endit){ + if(curve_it2 != curve_endit) { cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it2); if (cubic) { - pointAt4 = (*cubic)[1]; + point_at4 = (*cubic)[1]; } } - Geom::Ray ray1(pointAt2, pointAt3); - Geom::Ray ray2(pointAt3, pointAt4); + Geom::Ray ray1(point_at2, point_at3); + Geom::Ray ray2(point_at3, point_at4); double angle1 = Geom::rad_to_deg(ray1.angle()); double angle2 = Geom::rad_to_deg(ray2.angle()); - if((smooth_angles >= angle2 - angle1) && !are_near(pointAt4,pointAt3) && !are_near(pointAt2,pointAt3)){ - double dist = Geom::distance(pointAt2,pointAt3); + if((smooth_angles >= angle2 - angle1) && !are_near(point_at4,point_at3) && !are_near(point_at2,point_at3)) { + double dist = Geom::distance(point_at2,point_at3); Geom::Angle angleFixed = ray2.angle(); angleFixed -= Geom::Angle::from_degrees(180.0); - pointAt2 = Geom::Point::polar(angleFixed,dist) + pointAt3; + point_at2 = Geom::Point::polar(angleFixed,dist) + point_at3; } - nCurve->curveto(pointAt1, pointAt2, curve_it1->finalPoint()); + nCurve->curveto(point_at1, point_at2, curve_it1->finalPoint()); cubic = dynamic_cast<Geom::CubicBezier const *>(nCurve->last_segment()); if (cubic) { - pointAt1 = (*cubic)[1]; - pointAt2 = (*cubic)[2]; + point_at1 = (*cubic)[1]; + point_at2 = (*cubic)[2]; if(helper_size > 0) { - if(!are_near((*cubic)[0],(*cubic)[1])){ + if(!are_near((*cubic)[0],(*cubic)[1])) { drawHandle((*cubic)[1]); drawHandleLine((*cubic)[0],(*cubic)[1]); } - if(!are_near((*cubic)[3],(*cubic)[2])){ + if(!are_near((*cubic)[3],(*cubic)[2])) { drawHandle((*cubic)[2]); drawHandleLine((*cubic)[3],(*cubic)[2]); } @@ -250,17 +250,17 @@ LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) if (path_it->closed()) { nCurve->closepath_current(); } - tmpPath.push_back(nCurve->get_pathvector()[0]); + tmp_path.push_back(nCurve->get_pathvector()[0]); nCurve->reset(); delete nCurve; } - result = tmpPath; + result = tmp_path; } -void +void LPESimplify::drawNode(Geom::Point p) { - double r = radiusHelperNodes; + double r = radius_helper_nodes; char const * svgd; svgd = "M 0.55,0.5 A 0.05,0.05 0 0 1 0.5,0.55 0.05,0.05 0 0 1 0.45,0.5 0.05,0.05 0 0 1 0.5,0.45 0.05,0.05 0 0 1 0.55,0.5 Z M 0,0 1,0 1,1 0,1 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); @@ -273,7 +273,7 @@ LPESimplify::drawNode(Geom::Point p) void LPESimplify::drawHandle(Geom::Point p) { - double r = radiusHelperNodes; + double r = radius_helper_nodes; char const * svgd; svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); @@ -288,8 +288,8 @@ LPESimplify::drawHandleLine(Geom::Point p,Geom::Point p2) { Geom::Path path; path.start( p ); - double diameter = radiusHelperNodes; - if(helper_size > 0 && Geom::distance(p,p2) > (diameter * 0.35)){ + double diameter = radius_helper_nodes; + if(helper_size > 0 && Geom::distance(p,p2) > (diameter * 0.35)) { Geom::Ray ray2(p, p2); p2 = p2 - Geom::Point::polar(ray2.angle(),(diameter * 0.35)); } diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index c18c3ecdf..294d77b35 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -14,43 +14,43 @@ namespace Inkscape { namespace LivePathEffect { -class LPESimplify : public Effect , GroupBBoxEffect{ +class LPESimplify : public Effect , GroupBBoxEffect { public: - LPESimplify(LivePathEffectObject *lpeobject); - virtual ~LPESimplify(); + LPESimplify(LivePathEffectObject *lpeobject); + virtual ~LPESimplify(); - virtual void doEffect(SPCurve *curve); + virtual void doEffect(SPCurve *curve); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void generateHelperPathAndSmooth(Geom::PathVector &result); + virtual void generateHelperPathAndSmooth(Geom::PathVector &result); - virtual Gtk::Widget * newWidget(); + virtual Gtk::Widget * newWidget(); - virtual void drawNode(Geom::Point p); - - virtual void drawHandle(Geom::Point p); + virtual void drawNode(Geom::Point p); - virtual void drawHandleLine(Geom::Point p,Geom::Point p2); + virtual void drawHandle(Geom::Point p); + + virtual void drawHandleLine(Geom::Point p,Geom::Point p2); protected: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); private: - ScalarParam steps; - ScalarParam threshold; - ScalarParam smooth_angles; - ScalarParam helper_size; - ToggleButtonParam simplifyindividualpaths; - ToggleButtonParam simplifyJustCoalesce; - - double radiusHelperNodes; - Geom::PathVector hp; - Geom::OptRect bbox; - - LPESimplify(const LPESimplify &); - LPESimplify &operator=(const LPESimplify &); + ScalarParam steps; + ScalarParam threshold; + ScalarParam smooth_angles; + ScalarParam helper_size; + ToggleButtonParam simplify_individual_paths; + ToggleButtonParam simplify_just_coalesce; + + double radius_helper_nodes; + Geom::PathVector hp; + Geom::OptRect bbox; + + LPESimplify(const LPESimplify &); + LPESimplify &operator=(const LPESimplify &); }; diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 7a024147c..2c74af6d6 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -19,7 +19,8 @@ #include <2geom/circle.h> #include <2geom/sbasis-to-bezier.h> -#include "pathoutlineprovider.h" +#include "helper/geom-nodetype.h" +#include "helper/geom-pathstroke.h" #include "display/curve.h" #include "sp-shape.h" #include "style.h" @@ -60,11 +61,10 @@ namespace TpS { } // TpS static const Util::EnumData<unsigned> JoinType[] = { - {LINEJOIN_STRAIGHT, N_("Beveled"), "bevel"}, - {LINEJOIN_ROUND, N_("Rounded"), "round"}, - {LINEJOIN_REFLECTED, N_("Reflected"), "reflected"}, - {LINEJOIN_POINTY, N_("Miter"), "miter"}, - {LINEJOIN_EXTRAPOLATED, N_("Extrapolated"), "extrapolated"} + {JOIN_BEVEL, N_("Beveled"), "bevel"}, + {JOIN_ROUND, N_("Rounded"), "round"}, + {JOIN_MITER, N_("Miter"), "miter"}, + {JOIN_EXTRAPOLATE, N_("Extrapolated"), "extrapolated"}, }; static const Util::EnumDataConverter<unsigned> JoinTypeConverter(JoinType, sizeof (JoinType)/sizeof(*JoinType)); @@ -75,7 +75,7 @@ LPETaperStroke::LPETaperStroke(LivePathEffectObject *lpeobject) : attach_start(_("Start offset:"), _("Taper distance from path start"), "attach_start", &wr, this, 0.2), attach_end(_("End offset:"), _("The ending position of the taper"), "end_offset", &wr, this, 0.2), smoothing(_("Taper smoothing:"), _("Amount of smoothing to apply to the tapers"), "smoothing", &wr, this, 0.5), - join_type(_("Join type:"), _("Join type for non-smooth nodes"), "jointype", JoinTypeConverter, &wr, this, LINEJOIN_EXTRAPOLATED), + join_type(_("Join type:"), _("Join type for non-smooth nodes"), "jointype", JoinTypeConverter, &wr, this, JOIN_EXTRAPOLATE), miter_limit(_("Miter limit:"), _("Limit for miter joins"), "miter_limit", &wr, this, 100.) { show_orig_path = true; @@ -102,27 +102,24 @@ void LPETaperStroke::doOnApply(SPLPEItem const* lpeitem) double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed : 1.; SPCSSAttr *css = sp_repr_css_attr_new (); - if (true) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "none"); + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_unset_property (css, "fill"); + sp_repr_css_set_property (css, "fill", "none"); } + sp_repr_css_set_property(css, "fill-rule", "nonzero"); sp_repr_css_set_property(css, "stroke", "none"); sp_desktop_apply_css_recursive(item, css, true); @@ -130,7 +127,7 @@ void LPETaperStroke::doOnApply(SPLPEItem const* lpeitem) line_width.param_set_value(width); } else { - printf("WARNING: It only makes sense to apply Join Type to paths (not groups).\n"); + printf("WARNING: It only makes sense to apply Taper stroke to paths (not groups).\n"); } } @@ -142,25 +139,21 @@ void LPETaperStroke::doOnRemove(SPLPEItem const* lpeitem) SPLPEItem *item = const_cast<SPLPEItem*>(lpeitem); SPCSSAttr *css = sp_repr_css_attr_new (); - if (true) { - if (lpeitem->style->fill.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getFillPaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "stroke", str.c_str()); - } - } else if (lpeitem->style->fill.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "stroke", c); - } else { - sp_repr_css_set_property (css, "stroke", "none"); + if (lpeitem->style->fill.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getFillPaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "stroke", str.c_str()); } + } else if (lpeitem->style->fill.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->fill.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->fill_opacity.value))); + sp_repr_css_set_property (css, "stroke", c); } else { - sp_repr_css_unset_property (css, "stroke"); + sp_repr_css_set_property (css, "stroke", "none"); } Inkscape::CSSOStringStream os; @@ -179,15 +172,22 @@ using Geom::D2; using Geom::SBasis; // leave Geom::Path -Geom::Path return_at_first_cusp(Geom::Path const & path_in, double /*smooth_tolerance*/ = 0.05) { - return Geom::split_at_cusps(path_in)[0]; +static Geom::Path return_at_first_cusp(Geom::Path const & path_in, double /*smooth_tolerance*/ = 0.05) +{ + Geom::Path temp; + + for (unsigned i = 0; i < path_in.size(); i++) { + temp.append(path_in[i]); + if (Geom::get_nodetype(path_in[i], path_in[i + 1]) != Geom::NODE_SMOOTH ) { + break; + } + } + + return temp; } Piecewise<D2<SBasis> > stretch_along(Piecewise<D2<SBasis> > pwd2_in, Geom::Path pattern, double width); -// references to pointers -void subdivideCurve(Geom::Curve * curve_in, Geom::Coord t, Geom::Curve *& val_first, Geom::Curve *& val_second); - // actual effect Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) @@ -285,7 +285,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) // although this seems obvious, it can probably lead to bugs. if (!metInMiddle) { // append the outside outline of the path (goes with the direction of the path) - throwaway_path = Outline::PathOutsideOutline(pathv_out[1], -fabs(line_width), static_cast<LineJoinType>(join_type.get_value()), miter_limit); + throwaway_path = half_outline(pathv_out[1], fabs(line_width)/2., miter_limit, static_cast<LineJoinType>(join_type.get_value())); if (!zeroStart && real_path.size() >= 1 && throwaway_path.size() >= 1) { if (!Geom::are_near(real_path.finalPoint(), throwaway_path.initialPoint())) { real_path.appendNew<Geom::LineSegment>(throwaway_path.initialPoint()); @@ -317,7 +317,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) if (!metInMiddle) { // append the inside outline of the path (against direction) - throwaway_path = Outline::PathOutsideOutline(pathv_out[1].reverse(), -fabs(line_width), static_cast<LineJoinType>(join_type.get_value()), miter_limit); + throwaway_path = half_outline(pathv_out[1].reverse(), fabs(line_width)/2., miter_limit, static_cast<LineJoinType>(join_type.get_value())); if (!Geom::are_near(real_path.finalPoint(), throwaway_path.initialPoint()) && real_path.size() >= 1) { real_path.appendNew<Geom::LineSegment>(throwaway_path.initialPoint()); @@ -347,85 +347,18 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) */ Geom::PathVector LPETaperStroke::doEffect_simplePath(Geom::PathVector const & path_in) { - size_t size = path_in[0].size(); - - unsigned loc = (unsigned)attach_start; - Geom::Curve * curve_start = path_in[0] [loc].duplicate(); - - std::vector<Geom::Path> pathv_out; - Geom::Path path_out = Geom::Path(); - - Geom::Path trimmed_start = Geom::Path(); - Geom::Path trimmed_end = Geom::Path(); - - for (size_t i = 0; i < loc; ++i) { - trimmed_start.append(path_in[0] [i]); - } - - Geom::Curve * temp; - subdivideCurve(curve_start, attach_start - loc, temp, curve_start); - trimmed_start.append(*temp); - if (temp) delete temp; temp = 0; - - // special case: path is one segment long - // special case: what if the two knots occupy the same segment? - if ((size == 1) || ( size - unsigned(attach_end) - 1 == loc )) { - - // If you look into it, I don't actually think there is a working way to do this - // with only point math. So we use nearest_point instead. - Geom::Coord t = Geom::nearest_point(end_attach_point, *curve_start); - - // it is just a dumb segment - // we have to do some shifting here because the value changed when we reduced the length - // of the previous segment. - - subdivideCurve(curve_start, t, curve_start, temp); - trimmed_end.append(*temp); - if (temp) delete temp; temp = 0; - - for (size_t j = (size - attach_end) + 1; j < size; ++j) { - trimmed_end.append(path_in[0] [j]); - } + Geom::Coord endTime = path_in[0].size() - attach_end; - path_out.append(*curve_start); - pathv_out.push_back(trimmed_start); - pathv_out.push_back(path_out); - pathv_out.push_back(trimmed_end); - return pathv_out; - } - - pathv_out.push_back(trimmed_start); - - // append almost all of the rest of the path, ignore the curves that the knot is past (we'll get to it in a minute) - path_out.append(*curve_start); - - for (size_t k = loc + 1; k < (size - unsigned(attach_end)) - 1; ++k) { - path_out.append(path_in[0] [k]); - } - - // deal with the last segment in a very similar fashion to the first - loc = size - attach_end; - - Geom::Curve * curve_end = path_in[0] [loc].duplicate(); - - Geom::Coord t = Geom::nearest_point(end_attach_point, *curve_end); - - subdivideCurve(curve_end, t, curve_end, temp); - trimmed_end.append(*temp); - if (temp) delete temp; temp = 0; - - for (size_t j = (size - attach_end) + 1; j < size; ++j) { - trimmed_end.append(path_in[0] [j]); - } - - path_out.append(*curve_end); - pathv_out.push_back(path_out); - - pathv_out.push_back(trimmed_end); - - if (curve_end) delete curve_end; - if (curve_start) delete curve_start; - return pathv_out; + Geom::Path p1 = path_in[0].portion(0., attach_start); + Geom::Path p2 = path_in[0].portion(attach_start, endTime); + Geom::Path p3 = path_in[0].portion(endTime, path_in[0].size()); + + Geom::PathVector out; + out.push_back(p1); + out.push_back(p2); + out.push_back(p3); + + return out; } @@ -513,23 +446,6 @@ Piecewise<D2<SBasis> > stretch_along(Piecewise<D2<SBasis> > pwd2_in, Geom::Path } } -void subdivideCurve(Geom::Curve * curve_in, Geom::Coord t, Geom::Curve *& val_first, Geom::Curve *& val_second) -{ - if (Geom::LineSegment* linear = dynamic_cast<Geom::LineSegment*>(curve_in)) { - // special case for line segments - std::pair<Geom::LineSegment, Geom::LineSegment> seg_pair = linear->subdivide(t); - val_first = seg_pair.first.duplicate(); - val_second = seg_pair.second.duplicate(); - } else { - // all other cases: - Geom::CubicBezier cubic = Geom::sbasis_to_cubicbezier(curve_in->toSBasis()); - std::pair<Geom::CubicBezier, Geom::CubicBezier> cubic_pair = cubic.subdivide(t); - val_first = cubic_pair.first.duplicate(); - val_second = cubic_pair.second.duplicate(); - } -} - - void LPETaperStroke::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { KnotHolderEntity *e = new TpS::KnotHolderEntityAttachBegin(this); diff --git a/src/live_effects/pathoutlineprovider.cpp b/src/live_effects/pathoutlineprovider.cpp deleted file mode 100644 index 21a0fb809..000000000 --- a/src/live_effects/pathoutlineprovider.cpp +++ /dev/null @@ -1,803 +0,0 @@ -/* Author:
- * Liam P. White <inkscapebrony@gmail.com>
- *
- * Copyright (C) 2014 Author
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include <2geom/angle.h>
-#include <2geom/path.h>
-#include <2geom/circle.h>
-#include <2geom/sbasis-to-bezier.h>
-#include <2geom/shape.h>
-#include <2geom/transforms.h>
-#include <2geom/path-sink.h>
-#include <cstdio>
-
-#include "pathoutlineprovider.h"
-#include "livarot/path-description.h"
-#include "helper/geom-nodetype.h"
-#include "svg/svg.h"
-
-namespace Geom {
-/**
-* Refer to: Weisstein, Eric W. "Circle-Circle Intersection."
- From MathWorld--A Wolfram Web Resource.
- http://mathworld.wolfram.com/Circle-CircleIntersection.html
-*
-* @return 0 if no intersection
-* @return 1 if one circle is contained in the other
-* @return 2 if intersections are found (they are written to p0 and p1)
-*/
-static int circle_circle_intersection(Circle const &circle0, Circle const &circle1, Point & p0, Point & p1)
-{
- Point X0 = circle0.center();
- double r0 = circle0.ray();
- Point X1 = circle1.center();
- double r1 = circle1.ray();
-
- /* dx and dy are the vertical and horizontal distances between
- * the circle centers.
- */
- Point D = X1 - X0;
-
- /* Determine the straight-line distance between the centers. */
- double d = L2(D);
-
- /* Check for solvability. */
- if (d > (r0 + r1)) {
- /* no solution. circles do not intersect. */
- return 0;
- }
- if (d <= fabs(r0 - r1)) {
- /* no solution. one circle is contained in the other */
- return 1;
- }
-
- /* 'point 2' is the point where the line through the circle
- * intersection points crosses the line between the circle
- * centers.
- */
-
- /* Determine the distance from point 0 to point 2. */
- double a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
-
- /* Determine the coordinates of point 2. */
- Point p2 = X0 + D * (a/d);
-
- /* Determine the distance from point 2 to either of the
- * intersection points.
- */
- double h = std::sqrt((r0*r0) - (a*a));
-
- /* Now determine the offsets of the intersection points from
- * point 2.
- */
- Point r = (h/d)*rot90(D);
-
- /* Determine the absolute intersection points. */
- p0 = p2 + r;
- p1 = p2 - r;
-
- return 2;
-}
-/**
-* Find circle that touches inside of the curve, with radius matching the curvature, at time value \c t.
-* Because this method internally uses unitTangentAt, t should be smaller than 1.0 (see unitTangentAt).
-*/
-static Circle touching_circle( D2<SBasis> const &curve, double t, double tol=0.01 )
-{
- D2<SBasis> dM=derivative(curve);
- if ( are_near(L2sq(dM(t)),0.) ) {
- dM=derivative(dM);
- }
- if ( are_near(L2sq(dM(t)),0.) ) { // try second time
- dM=derivative(dM);
- }
- Piecewise<D2<SBasis> > unitv = unitVector(dM,tol);
- Piecewise<SBasis> dMlength = dot(Piecewise<D2<SBasis> >(dM),unitv);
- Piecewise<SBasis> k = cross(derivative(unitv),unitv);
- k = divide(k,dMlength,tol,3);
- double curv = k(t); // note that this value is signed
-
- Geom::Point normal = unitTangentAt(curve, t).cw();
- double radius = 1/curv;
- Geom::Point center = curve(t) + radius*normal;
- return Geom::Circle(center, fabs(radius));
-}
-
-std::vector<Geom::Path> split_at_cusps(const Geom::Path& in)
-{
- PathVector out = PathVector();
- Path temp = Path();
-
- for (unsigned i = 0; i < in.size(); i++) {
- temp.append(in[i]);
- if ( get_nodetype(in[i], in[i + 1]) != Geom::NODE_SMOOTH ) {
- out.push_back(temp);
- temp = Path();
- }
- }
- if (temp.size() > 0) {
- out.push_back(temp);
- }
- return out;
-}
-
-Geom::CubicBezier sbasis_to_cubicbezier(Geom::D2<Geom::SBasis> const & sbasis_in)
-{
- std::vector<Geom::Point> temp;
- sbasis_to_bezier(temp, sbasis_in, 4);
- return Geom::CubicBezier( temp );
-}
-
-static boost::optional<Geom::Point> intersection_point(Geom::Point const & origin_a, Geom::Point const & vector_a, Geom::Point const & origin_b, Geom::Point const & vector_b)
-{
- Geom::Coord denom = cross(vector_b, vector_a);
- if (!Geom::are_near(denom,0.)) {
- Geom::Coord t = (cross(origin_a,vector_b) + cross(vector_b,origin_b)) / denom;
- return origin_a + t * vector_a;
- }
- return boost::none;
-}
-
-} // namespace Geom
-
-namespace Outline {
-
-typedef Geom::D2<Geom::SBasis> D2SB;
-typedef Geom::Piecewise<D2SB> PWD2;
-
-// UTILITY
-
-unsigned bezierOrder (const Geom::Curve* curve_in)
-{
- using namespace Geom;
- if ( const BezierCurve* bz = dynamic_cast<const BezierCurve*>(curve_in) ) {
- return bz->order();
- }
- return 0;
-}
-
-/**
- * @return true if the angle formed by the curves and their handles is greater than 180 degrees clockwise, otherwise false.
- */
-bool outside_angle (const Geom::Curve& cbc1, const Geom::Curve& cbc2)
-{
- Geom::Point start_point;
- Geom::Point cross_point = cbc1.finalPoint();
- Geom::Point end_point;
-
- if (cross_point != cbc2.initialPoint()) {
- printf("WARNING: Non-contiguous path in Outline::outside_angle()");
- return false;
- }
-
- Geom::CubicBezier cubicBezier = Geom::sbasis_to_cubicbezier(cbc1.toSBasis());
- start_point = cubicBezier [2];
-
- /*
- * Because the node editor does not yet support true quadratics, paths are converted to
- * cubic beziers in the node tool with degenerate handles on one side.
- */
-
- if (are_near(start_point, cross_point, 0.0000001)) {
- start_point = cubicBezier [1];
- }
- cubicBezier = Geom::sbasis_to_cubicbezier(cbc2.toSBasis());
- end_point = cubicBezier [1];
- if (are_near(end_point, cross_point, 0.0000001)) {
- end_point = cubicBezier [2];
- }
-
- // got our three points, now let's see what their clockwise angle is
-
- // Definition of a Graham scan
-
- /********************************************************************
- # Three points are a counter-clockwise turn if ccw > 0, clockwise if
- # ccw < 0, and collinear if ccw = 0 because ccw is a determinant that
- # gives the signed area of the triangle formed by p1, p2 and p3.
- function ccw(p1, p2, p3):
- return (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x)
- *********************************************************************/
-
- double ccw = ( (cross_point.x() - start_point.x()) * (end_point.y() - start_point.y()) ) -
- ( (cross_point.y() - start_point.y()) * (end_point.x() - start_point.x()) );
- return ccw > 0;
-}
-
-// LINE JOINS
-
-typedef Geom::BezierCurveN<1u> BezierLine;
-
-/**
- * Removes the crossings on an interior join.
- * @param path_builder Contains the incoming segment; result is appended to this
- * @param outgoing The outgoing segment
- */
-void joinInside(Geom::Path& path_builder, Geom::Curve const& outgoing)
-{
- Geom::Curve const& incoming = path_builder.back();
-
- // Using Geom::crossings to find intersections between two curves
- Geom::Crossings cross = Geom::crossings(incoming, outgoing);
- if (!cross.empty()) {
- // Crossings found, create the join
- Geom::CubicBezier cubic = Geom::sbasis_to_cubicbezier(incoming.toSBasis());
- cubic = cubic.subdivide(cross[0].ta).first;
- // erase the last segment, as we're going to overwrite it now
- path_builder.erase_last();
- path_builder.append(cubic, Geom::Path::STITCH_DISCONTINUOUS);
-
- cubic = Geom::sbasis_to_cubicbezier(outgoing.toSBasis());
- cubic = cubic.subdivide(cross[0].tb).second;
- path_builder.append(cubic, Geom::Path::STITCH_DISCONTINUOUS);
- } else {
- // No crossings occurred, or Geom::crossings() failed; default to bevel
- if (Geom::are_near(incoming.finalPoint(), outgoing.initialPoint())) {
- path_builder.appendNew<BezierLine>(outgoing.initialPoint());
- } else {
- path_builder.setFinal(outgoing.initialPoint());
- }
- }
-}
-
-/**
- * Try to create a miter join. Falls back to bevel if no miter can be created.
- * @param path_builder Path to append curves to; back() is the incoming curve
- * @param outgoing Outgoing curve.
- * @param miter_limit When mitering, don't exceed this length
- * @param line_width The thickness of the line.
- */
-void miter_curves(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter_limit, double line_width)
-{
- using namespace Geom;
- Curve const& incoming = path_builder.back();
- Point tang1 = unitTangentAt(Geom::reverse(incoming.toSBasis()), 0.);
- Point tang2 = unitTangentAt(outgoing.toSBasis(), 0);
-
- boost::optional <Point> p = intersection_point (incoming.finalPoint(), tang1, outgoing.initialPoint(), tang2);
- if (p) {
- // check size of miter
- Point point_on_path = incoming.finalPoint() - rot90(tang1) * line_width;
- Coord len = distance(*p, point_on_path);
- if (len <= miter_limit) {
- // miter OK
- path_builder.appendNew<BezierLine>(*p);
- }
- }
- path_builder.appendNew<BezierLine>(outgoing.initialPoint());
-}
-
-/**
- * Smoothly extrapolate curves along a circular route. Falls back to miter if necessary.
- * @param path_builder Path to append curves to; back() is the incoming curve
- * @param outgoing Outgoing curve.
- * @param miter_limit When mitering, don't exceed this length
- * @param line_width The thickness of the line. Used for miter fallback.
- */
-void extrapolate_curves(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter_limit, double line_width)
-{
- Geom::Curve const& incoming = path_builder.back();
- Geom::Point endPt = outgoing.initialPoint();
-
- // The method used when extrapolating curves fails to work when either side of the join to be extrapolated
- // is a line segment. When this situation is encountered, fall back to a regular miter join.
- bool lineProblem = (dynamic_cast<const BezierLine *>(&incoming)) || (dynamic_cast<const BezierLine *>(&outgoing));
- if (lineProblem == false) {
- // Geom::Point tang1 = Geom::unitTangentAt(Geom::reverse(incoming.toSBasis()), 0.);
- Geom::Point tang2 = Geom::unitTangentAt(outgoing.toSBasis(), 0);
-
- Geom::Circle circle1 = Geom::touching_circle(Geom::reverse(incoming.toSBasis()), 0.);
- Geom::Circle circle2 = Geom::touching_circle(outgoing.toSBasis(), 0);
-
- Geom::Point points[2];
- int solutions = Geom::circle_circle_intersection(circle1, circle2, points[0], points[1]);
- if (solutions == 2) {
- Geom::Point sol(0,0);
- if ( dot(tang2,points[0]-endPt) > 0 ) {
- // points[0] is bad, choose points[1]
- sol = points[1];
- } else if ( dot(tang2,points[1]-endPt) > 0 ) { // points[0] could be good, now check points[1]
- // points[1] is bad, choose points[0]
- sol = points[0];
- } else {
- // both points are good, choose nearest
- sol = ( distanceSq(endPt, points[0]) < distanceSq(endPt, points[1]) ) ? points[0] : points[1];
- }
-
- Geom::EllipticalArc *arc0 = circle1.arc(incoming.finalPoint(), 0.5*(incoming.finalPoint()+sol), sol, true);
- Geom::EllipticalArc *arc1 = circle2.arc(sol, 0.5*(sol+endPt), endPt, true);
- try {
- if (arc0) {
- path_builder.append (arc0->toSBasis());
- delete arc0;
- arc0 = NULL;
- } else {
- throw std::exception();
- }
-
- if (arc1) {
- path_builder.append (arc1->toSBasis());
- delete arc1;
- arc1 = NULL;
- } else {
- throw std::exception();
- }
-
- } catch (std::exception const & ex) {
- printf("WARNING: Error extrapolating line join: %s\n", ex.what());
- path_builder.appendNew<Geom::LineSegment>(endPt);
- }
- } else {
- // 1 or no solutions found, default to miter
- miter_curves(path_builder, outgoing, miter_limit, line_width);
- }
- } else {
- // Line segments exist
- miter_curves(path_builder, outgoing, miter_limit, line_width);
- }
-}
-
-/**
- * Extrapolate curves by reflecting them along the line that would be given by beveling the join.
- * @param path_builder Path to append curves to; back() is the incoming curve
- * @param outgoing Outgoing curve.
- * @param miter_limit When mitering, don't exceed this length
- * @param line_width The thickness of the line. Used for miter fallback.
- */
-void reflect_curves(Geom::Path& path_builder, Geom::Curve const& outgoing, double miter_limit, double line_width)
-{
- using namespace Geom;
- Curve const& incoming = path_builder.back();
- // On the outside, we'll take the incoming curve, the outgoing curve, and
- // reflect them over the line formed by taking the unit tangent vector at times
- // 0 and 1, respectively, rotated by 90 degrees.
- Crossings cross;
-
- // reflect curves along the line that would be given by beveling the join
- Point tang1 = unitTangentAt(reverse(incoming.toSBasis()), 0.);
- D2SB newcurve1 = incoming.toSBasis() * reflection(-rot90(tang1), incoming.finalPoint());
- CubicBezier bzr1 = sbasis_to_cubicbezier(reverse(newcurve1));
-
- Point tang2 = Geom::unitTangentAt(outgoing.toSBasis(), 0.);
- D2SB newcurve2 = outgoing.toSBasis() * reflection(-rot90(tang2), outgoing.initialPoint());
- CubicBezier bzr2 = sbasis_to_cubicbezier(reverse(newcurve2));
-
- cross = crossings(bzr1, bzr2);
- if (cross.empty()) {
- // paths don't cross, fall back to miter
- miter_curves(path_builder, outgoing, miter_limit, line_width);
- } else {
- // reflected join
- std::pair<CubicBezier, CubicBezier> sub1 = bzr1.subdivide(cross[0].ta);
- std::pair<CubicBezier, CubicBezier> sub2 = bzr2.subdivide(cross[0].tb);
-
- // TODO it seems as if a bug in 2geom sometimes doesn't catch the first
- // crossing of paths, but the second instead; but only sometimes.
- path_builder.appendNew <CubicBezier> (sub1.first[1], sub1.first[2], sub2.second[0]);
- path_builder.appendNew <CubicBezier> (sub2.second[1], sub2.second[2], outgoing.initialPoint());
- }
-}
-
-// Ideal function pointer we want to pass
-typedef void JoinFunc(Geom::Path& /*path_builder*/, Geom::Curve const& /*outgoing*/, double /*miter_limit*/, double /*line_width*/);
-
-/**
- * Helper function for repeated logic in outlineHalf.
- */
-static void outlineHelper(Geom::Path& path_builder, Geom::PathVector* path_vec, bool outside, double width, double miter, JoinFunc func)
-{
- Geom::Curve * cbc2 = path_vec->front()[0].duplicate();
-
- if (outside) {
- func(path_builder, *cbc2, miter, width);
- } else {
- joinInside(path_builder, *cbc2);
- }
-
- // store it
- Geom::Path temp_path = path_vec->front();
- if (!outside) {
- // erase the first segment since the inside join code already appended it
- temp_path.erase(temp_path.begin());
- }
-
- if (temp_path.initialPoint() != path_builder.finalPoint()) {
- temp_path.setInitial(path_builder.finalPoint());
- }
-
- path_builder.append(temp_path);
-
- delete cbc2;
-}
-
-/**
- * Offsets exactly one half of a bezier spline (path).
- * @param path_in The input path to use. (To create the other side use path_in.reverse() )
- * @param line_width the line width to use (usually you want to divide this by 2)
- * @param miter_limit the miter parameter
- * @param func Join function to apply at each join.
- */
-
-Geom::Path outlineHalf(const Geom::Path& path_in, double line_width, double miter_limit, JoinFunc func)
-{
- // NOTE: it is important to notice the distinction between a Geom::Path and a livarot ::Path here!
- // if you do not see "Geom::" there is a different function set!
-
- Geom::PathVector pv = split_at_cusps(path_in);
-
- ::Path to_outline;
- ::Path outlined_result;
-
- Geom::Path path_builder = Geom::Path(); // the path to store the result in
- Geom::PathVector* path_vec; // needed because livarot returns a pointer (TODO make this not a pointer)
-
- // Do two curves at a time for efficiency, since the join function needs to know the outgoing curve as well
- const size_t k = pv.size();
- for (size_t u = 0; u < k; u += 2) {
- to_outline = Path();
- outlined_result = Path();
-
- to_outline.LoadPath(pv[u], Geom::identity(), false, false);
- to_outline.OutsideOutline(&outlined_result, line_width / 2, join_straight, butt_straight, 10);
- // now a curve has been outside outlined and loaded into outlined_result
-
- // get the Geom::Path
- path_vec = outlined_result.MakePathVector();
-
- // on the first run through, there is no join
- if (u == 0) {
- path_builder.start(path_vec->front().initialPoint());
- path_builder.append(path_vec->front());
- } else {
- outlineHelper(path_builder, path_vec, outside_angle(pv[u-1][pv[u-1].size()-1], pv[u][0]), line_width, miter_limit, func);
- }
-
- // outline the next segment, but don't store it yet
- if (path_vec)
- delete path_vec;
- path_vec = NULL;
-
- // odd number of paths
- if (u < k - 1) {
- outlined_result = Path();
- to_outline = Path();
-
- to_outline.LoadPath(pv[u+1], Geom::Affine(), false, false);
- to_outline.OutsideOutline(&outlined_result, line_width / 2, join_straight, butt_straight, 10);
-
- path_vec = outlined_result.MakePathVector();
- outlineHelper(path_builder, path_vec, outside_angle(pv[u][pv[u].size()-1], pv[u+1][0]), line_width, miter_limit, func);
-
- if (path_vec)
- delete path_vec;
- path_vec = NULL;
- }
- }
-
- if (path_in.closed()) {
- Geom::Curve * cbc1;
- Geom::Curve * cbc2;
-
- if ( path_in[path_in.size()].isDegenerate() ) {
- // handle case for last segment curved
- outlined_result = Path();
- to_outline = Path();
-
- Geom::Path oneCurve; oneCurve.append(path_in[0]);
-
- to_outline.LoadPath(oneCurve, Geom::Affine(), false, false);
- to_outline.OutsideOutline(&outlined_result, line_width / 2, join_straight, butt_straight, 10);
-
- path_vec = outlined_result.MakePathVector();
-
- cbc1 = path_builder[path_builder.size() - 1].duplicate();
- cbc2 = path_vec->front()[0].duplicate();
-
- delete path_vec;
- } else {
- // handle case for last segment straight
- // since the path doesn't actually give us access to it, we'll do it ourselves
- outlined_result = Path();
- to_outline = Path();
-
- Geom::Path oneCurve; oneCurve.append(Geom::LineSegment(path_in.finalPoint(), path_in.initialPoint()));
-
- to_outline.LoadPath(oneCurve, Geom::Affine(), false, false);
- to_outline.OutsideOutline(&outlined_result, line_width / 2, join_straight, butt_straight, 10);
-
- path_vec = outlined_result.MakePathVector();
-
- cbc1 = path_builder[path_builder.size() - 1].duplicate();
- cbc2 = (*path_vec)[0] [0].duplicate();
-
- outlineHelper(path_builder, path_vec, outside_angle(path_in[path_in.size()-1], oneCurve[0]), line_width, miter_limit, func);
-
- delete cbc1;
- cbc1 = cbc2->duplicate();
- delete path_vec;
-
- oneCurve = Geom::Path(); oneCurve.append(path_in[0]);
-
- to_outline.LoadPath(oneCurve, Geom::Affine(), false, false);
- to_outline.OutsideOutline(&outlined_result, line_width / 2, join_straight, butt_straight, 10);
-
- path_vec = outlined_result.MakePathVector();
- delete cbc2; cbc2 = (*path_vec)[0] [0].duplicate();
- delete path_vec;
- }
-
- Geom::Path temporary;
- temporary.append(*cbc1);
-
- Geom::Curve const & prev_curve = path_in[path_in.size()].isDegenerate() ? path_in[path_in.size() - 1] : path_in[path_in.size()];
- Geom::Path isStraight;
- isStraight.append(prev_curve);
- isStraight.append(path_in[0]);
- // does closing path require a join?
- if (Geom::split_at_cusps(isStraight).size() > 1) {
- bool outside = outside_angle(prev_curve, path_in[0]);
- if (outside) {
- func(temporary, *cbc2, miter_limit, line_width);
- } else {
- joinInside(temporary, *cbc2);
- path_builder.erase(path_builder.begin());
- }
-
- // extract the appended curves
- path_builder.erase_last();
- if (Geom::are_near(path_builder.finalPoint(), temporary.initialPoint())) {
- path_builder.setFinal(temporary.initialPoint());
- } else {
- path_builder.appendNew<BezierLine>(temporary.initialPoint());
- }
- path_builder.append(temporary);
- } else {
- // closing path does not require a join
- path_builder.setFinal(path_builder.initialPoint());
- }
- path_builder.close();
-
- if (cbc1) delete cbc1;
- if (cbc2) delete cbc2;
- }
-
- return path_builder;
-}
-
-Geom::PathVector outlinePath(const Geom::PathVector& path_in, double line_width, LineJoinType join, ButtTypeMod butt, double miter_lim, bool extrapolate, double start_lean, double end_lean)
-{
- Geom::PathVector path_out;
-
- unsigned pv_size = path_in.size();
- for (unsigned i = 0; i < pv_size; i++) {
-
- if (path_in[i].size() > 1) {
- Geom::Path with_direction;
- Geom::Path against_direction;
-
- with_direction = Outline::outlineHalf(path_in[i], -line_width, miter_lim, extrapolate ? extrapolate_curves : reflect_curves);
- against_direction = Outline::outlineHalf(path_in[i].reverse(), -line_width, miter_lim, extrapolate ? extrapolate_curves : reflect_curves);
-
- Geom::PathBuilder pb;
-
- pb.moveTo(with_direction.initialPoint());
- pb.append(with_direction);
-
- //add in our line caps
- if (!path_in[i].closed()) {
- switch (butt) {
- case BUTT_STRAIGHT:
- pb.lineTo(against_direction.initialPoint());
- break;
- case BUTT_ROUND:
- pb.arcTo((-line_width) / 2, (-line_width) / 2, 0., true, true, against_direction.initialPoint() );
- break;
- case BUTT_POINTY: {
- Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(path_in[i].back().toSBasis()), 0.);
- double radius = 0.5 * Geom::distance(with_direction.finalPoint(), against_direction.initialPoint());
- Geom::Point midpoint = 0.5 * (with_direction.finalPoint() + against_direction.initialPoint()) + radius*end_deriv;
- pb.lineTo(midpoint);
- pb.lineTo(against_direction.initialPoint());
- break;
- }
- case BUTT_SQUARE: {
- Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(path_in[i].back().toSBasis()), 0.);
- double radius = 0.5 * Geom::distance(with_direction.finalPoint(), against_direction.initialPoint());
- pb.lineTo(with_direction.finalPoint() + radius*end_deriv);
- pb.lineTo(against_direction.initialPoint() + radius*end_deriv);
- pb.lineTo(against_direction.initialPoint());
- break;
- }
- case BUTT_LEANED: {
- Geom::Point end_deriv = -Geom::unitTangentAt(Geom::reverse(path_in[i].back().toSBasis()), 0.);
- double maxRadius = (end_lean+0.5) * Geom::distance(with_direction.finalPoint(), against_direction.initialPoint());
- double minRadius = ((end_lean*-1)+0.5) * Geom::distance(with_direction.finalPoint(), against_direction.initialPoint());
- pb.lineTo(with_direction.finalPoint() + maxRadius*end_deriv);
- pb.lineTo(against_direction.initialPoint() + minRadius*end_deriv);
- pb.lineTo(against_direction.initialPoint());
- break;
- }
- }
- } else {
- pb.moveTo(against_direction.initialPoint());
- }
-
- pb.append(against_direction);
-
- //cap (if necessary)
- if (!path_in[i].closed()) {
- switch (butt) {
- case BUTT_STRAIGHT:
- pb.lineTo(with_direction.initialPoint());
- break;
- case BUTT_ROUND:
- pb.arcTo((-line_width) / 2, (-line_width) / 2, 0., true, true, with_direction.initialPoint() );
- break;
- case BUTT_POINTY: {
- Geom::Point end_deriv = -Geom::unitTangentAt(path_in[i].front().toSBasis(), 0.);
- double radius = 0.5 * Geom::distance(against_direction.finalPoint(), with_direction.initialPoint());
- Geom::Point midpoint = 0.5 * (against_direction.finalPoint() + with_direction.initialPoint()) + radius*end_deriv;
- pb.lineTo(midpoint);
- pb.lineTo(with_direction.initialPoint());
- break;
- }
- case BUTT_SQUARE: {
- Geom::Point end_deriv = -Geom::unitTangentAt(path_in[i].front().toSBasis(), 0.);
- double radius = 0.5 * Geom::distance(against_direction.finalPoint(), with_direction.initialPoint());
- pb.lineTo(against_direction.finalPoint() + radius*end_deriv);
- pb.lineTo(with_direction.initialPoint() + radius*end_deriv);
- pb.lineTo(with_direction.initialPoint());
- break;
- }
- case BUTT_LEANED: {
- Geom::Point end_deriv = -Geom::unitTangentAt(path_in[i].front().toSBasis(), 0.);
- double maxRadius = (start_lean+0.5) * Geom::distance(against_direction.finalPoint(), with_direction.initialPoint());
- double minRadius = ((start_lean*-1)+0.5) * Geom::distance(against_direction.finalPoint(), with_direction.initialPoint());
- pb.lineTo(against_direction.finalPoint() + minRadius*end_deriv);
- pb.lineTo(with_direction.initialPoint() + maxRadius*end_deriv);
- pb.lineTo(with_direction.initialPoint());
- break;
- }
- }
- }
- pb.flush();
- path_out.push_back(pb.peek()[0]);
- if (path_in[i].closed()) {
- path_out.push_back(pb.peek()[1]);
- }
- } else {
- Path p = Path();
- Path outlinepath = Path();
- ButtType original_butt;
- switch (butt) {
- case BUTT_STRAIGHT:
- original_butt = butt_straight;
- break;
- case BUTT_ROUND:
- original_butt = butt_round;
- break;
- case butt_pointy: {
- original_butt = butt_pointy;
- break;
- }
- case BUTT_SQUARE: {
- original_butt = butt_square;
- break;
- }
- case BUTT_LEANED: {
- original_butt = butt_straight;
- break;
- }
- }
- p.LoadPath(path_in[i], Geom::Affine(), false, false);
- p.Outline(&outlinepath, line_width / 2, static_cast<join_typ>(join), original_butt, miter_lim);
- Geom::PathVector *pv_p = outlinepath.MakePathVector();
- //somewhat hack-ish
- path_out.push_back( (*pv_p)[0].reverse() );
- if (pv_p) delete pv_p;
- }
- }
- return path_out;
-}
-
-#define miter_lim fabs(line_width * miter_limit)
-
-Geom::PathVector PathVectorOutline(Geom::PathVector const & path_in, double line_width, ButtTypeMod linecap_type, LineJoinType linejoin_type, double miter_limit, double start_lean, double end_lean)
-{
- std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
- if (path_in.empty()) {
- return path_out;
- }
- Path p = Path();
- Path outlinepath = Path();
- for (unsigned i = 0; i < path_in.size(); i++) {
- p.LoadPath(path_in[i], Geom::Affine(), false, ( (i==0) ? false : true));
- }
-
- // magic!
- ButtType original_butt;
- switch (linecap_type) {
- case BUTT_STRAIGHT:
- original_butt = butt_straight;
- break;
- case BUTT_ROUND:
- original_butt = butt_round;
- break;
- case butt_pointy: {
- original_butt = butt_pointy;
- break;
- }
- case BUTT_SQUARE: {
- original_butt = butt_square;
- break;
- }
- case BUTT_LEANED: {
- original_butt = butt_straight;
- break;
- }
- }
- if (linejoin_type <= LINEJOIN_POINTY) {
- p.Outline(&outlinepath, line_width / 2, static_cast<join_typ>(linejoin_type),
- original_butt, miter_lim);
- // fix memory leak
- std::vector<Geom::Path> *pv_p = outlinepath.MakePathVector();
- path_out = *pv_p;
- delete pv_p;
-
- } else if (linejoin_type == LINEJOIN_REFLECTED) {
- // reflected arc join
- path_out = outlinePath(path_in, line_width, static_cast<LineJoinType>(linejoin_type),
- linecap_type , miter_lim, false, start_lean, end_lean);
-
- } else if (linejoin_type == LINEJOIN_EXTRAPOLATED) {
- // extrapolated arc join
- path_out = outlinePath(path_in, line_width, LINEJOIN_STRAIGHT, linecap_type, miter_lim, true, start_lean, end_lean);
- }
-
- return path_out;
-}
-
-Geom::Path PathOutsideOutline(Geom::Path const & path_in, double line_width, LineJoinType linejoin_type, double miter_limit)
-{
-
- Geom::Path path_out;
-
- if (linejoin_type <= LINEJOIN_POINTY || path_in.size() <= 1) {
-
- Geom::PathVector * pathvec;
-
- Path path_tangent = Path();
- Path path_outline = Path();
- path_outline.LoadPath(path_in, Geom::Affine(), false, false);
- path_outline.OutsideOutline(&path_tangent, line_width / 2, static_cast<join_typ>(linejoin_type), butt_straight, miter_lim);
-
- pathvec = path_tangent.MakePathVector();
- path_out = pathvec->front();
- delete pathvec;
- return path_out;
- } else if (linejoin_type == LINEJOIN_REFLECTED) {
- path_out = outlineHalf(path_in, line_width, miter_lim, reflect_curves);
- return path_out;
- } else if (linejoin_type == LINEJOIN_EXTRAPOLATED) {
- path_out = outlineHalf(path_in, line_width, miter_lim, extrapolate_curves);
- return path_out;
- }
- return path_out;
-}
-
-} // namespace Outline
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8 :
diff --git a/src/live_effects/pathoutlineprovider.h b/src/live_effects/pathoutlineprovider.h deleted file mode 100644 index c17584be2..000000000 --- a/src/live_effects/pathoutlineprovider.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SEEN_PATH_OUTLINE_H -#define SEEN_PATH_OUTLINE_H - -/* Author: - * Liam P. White <inkscapebrony@gmail.com> - * - * Copyright (C) 2014 Author - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <livarot/Path.h> -#include <livarot/LivarotDefs.h> - -enum LineJoinType { - LINEJOIN_STRAIGHT, - LINEJOIN_ROUND, - LINEJOIN_POINTY, - LINEJOIN_REFLECTED, - LINEJOIN_EXTRAPOLATED -}; -enum ButtTypeMod { - BUTT_STRAIGHT, - BUTT_ROUND, - BUTT_SQUARE, - BUTT_POINTY, - BUTT_LEANED -}; - -namespace Geom -{ - Geom::CubicBezier sbasis_to_cubicbezier(Geom::D2<Geom::SBasis> const & sbasis_in); - std::vector<Geom::Path> split_at_cusps(const Geom::Path& in); -} - -namespace Outline -{ - unsigned bezierOrder (const Geom::Curve* curve_in); - std::vector<Geom::Path> PathVectorOutline(std::vector<Geom::Path> const & path_in, double line_width, ButtTypeMod linecap_type, - LineJoinType linejoin_type, double miter_limit, double start_lean = 0, double end_lean = 0); - Geom::Path PathOutsideOutline(Geom::Path const & path_in, double line_width, LineJoinType linejoin_type, double miter_limit); -} - -#endif // SEEN_PATH_OUTLINE_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : |
