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-line_segment.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 'src/live_effects/lpe-line_segment.cpp')
-rw-r--r-- | src/live_effects/lpe-line_segment.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp new file mode 100644 index 0000000..b0e9c3d --- /dev/null +++ b/src/live_effects/lpe-line_segment.cpp @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * LPE <line_segment> implementation + */ + +/* + * Authors: + * Maximilian Albert + * + * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com> + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "live_effects/lpe-line_segment.h" +#include "ui/tools/lpe-tool.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include <glibmm/i18n.h> + +namespace Inkscape { +namespace LivePathEffect { + +static const Util::EnumData<EndType> EndTypeData[] = { + {END_CLOSED , N_("Closed"), "closed"}, + {END_OPEN_INITIAL , N_("Open start"), "open_start"}, + {END_OPEN_FINAL , N_("Open end"), "open_end"}, + {END_OPEN_BOTH , N_("Open both"), "open_both"}, +}; +static const Util::EnumDataConverter<EndType> EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData)); + +LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + end_type(_("End type:"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH) +{ + /* register all your parameters here, so Inkscape knows which parameters this effect has: */ + registerParameter(&end_type); +} + +LPELineSegment::~LPELineSegment() += default; + +void +LPELineSegment::doBeforeEffect (SPLPEItem const* lpeitem) +{ + Inkscape::UI::Tools::lpetool_get_limiting_bbox_corners(lpeitem->document, bboxA, bboxB); +} + +Geom::PathVector +LPELineSegment::doEffect_path (Geom::PathVector const & path_in) +{ + Geom::PathVector output; + + A = path_in.initialPoint(); + B = path_in.finalPoint(); + + Geom::Rect dummyRect(bboxA, bboxB); + std::optional<Geom::LineSegment> intersection_segment = Geom::Line(A, B).clip(dummyRect); + + if (!intersection_segment) { + g_print ("Possible error - no intersection with limiting bounding box.\n"); + return path_in; + } + + if (end_type == END_OPEN_INITIAL || end_type == END_OPEN_BOTH) { + A = intersection_segment->initialPoint(); + } + + if (end_type == END_OPEN_FINAL || end_type == END_OPEN_BOTH) { + B = intersection_segment->finalPoint(); + } + + Geom::Path path(A); + path.appendNew<Geom::LineSegment>(B); + + output.push_back(path); + + return output; +} + +} //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 : |