diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /src/live_effects/lpe-path_length.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/live_effects/lpe-path_length.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp new file mode 100644 index 0000000..3a4ca88 --- /dev/null +++ b/src/live_effects/lpe-path_length.cpp @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * LPE <path_length> implementation. + */ +/* + * Authors: + * Maximilian Albert <maximilian.albert@gmail.com> + * Johan Engelen + * + * Copyright (C) 2007-2008 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "live_effects/lpe-path_length.h" +#include "util/units.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include <glibmm/i18n.h> + +namespace Inkscape { +namespace LivePathEffect { + +LPEPathLength::LPEPathLength(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), + info_text(this), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), + display_unit(_("Display unit"), _("Print unit after path length"), "display_unit", &wr, this, true) +{ + registerParameter(&scale); + registerParameter(&info_text); + registerParameter(&unit); + registerParameter(&display_unit); +} + +LPEPathLength::~LPEPathLength() += default; + +Geom::Piecewise<Geom::D2<Geom::SBasis> > +LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) +{ + using namespace Geom; + + /* convert the measured length to the correct unit ... */ + double lengthval = Geom::length(pwd2_in) * scale; + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation()); + + /* ... set it as the canvas text ... */ + gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, + display_unit ? unit.get_abbreviation() : ""); + info_text.param_setValue(arc_length); + g_free(arc_length); + + info_text.setPosAndAnchor(pwd2_in, 0.5, 10); + + // TODO: how can we compute the area (such that cw turns don't count negative)? + // should we display the area here, too, or write a new LPE for this? + Piecewise<D2<SBasis> > A = integral(pwd2_in); + Point c; + double area; + if (centroid(pwd2_in, c, area)) { + //g_print ("Area is zero\n"); + } + //g_print ("Area: %f\n", area); + if (!this->isVisible()) { + info_text.param_setValue(""); + } + return pwd2_in; +} + +} //namespace LivePathEffect +} /* namespace Inkscape */ + +/* + 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 : |