1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** \file
3 * LPE <text_label> implementation
4 */
5 /*
6 * Authors:
7 * Maximilian Albert
8 * Johan Engelen
9 *
10 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15 #include "live_effects/lpe-text_label.h"
16
17 // TODO due to internal breakage in glibmm headers, this must be last:
18 #include <glibmm/i18n.h>
19
20 namespace Inkscape {
21 namespace LivePathEffect {
22
LPETextLabel(LivePathEffectObject * lpeobject)23 LPETextLabel::LPETextLabel(LivePathEffectObject *lpeobject) :
24 Effect(lpeobject),
25 label(_("Label:"), _("Text label attached to the path"), "label", &wr, this, "This is a label")
26 {
27 registerParameter(&label);
28 }
29
30 LPETextLabel::~LPETextLabel()
31 = default;
32
33 Geom::Piecewise<Geom::D2<Geom::SBasis> >
doEffect_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis>> const & pwd2_in)34 LPETextLabel::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
35 {
36 using namespace Geom;
37
38 double t = (pwd2_in.cuts.front() + pwd2_in.cuts.back()) / 2;
39 Point pos(pwd2_in.valueAt(t));
40 Point dir(unit_vector(derivative(pwd2_in).valueAt(t)));
41 Point n(-rot90(dir) * 30);
42
43 double angle = angle_between(dir, Point(1,0));
44 label.setPos(pos + n);
45 label.setAnchor(std::sin(angle), -std::cos(angle));
46
47 return pwd2_in;
48 }
49
50 } //namespace LivePathEffect
51 } /* namespace Inkscape */
52
53 /*
54 Local Variables:
55 mode:c++
56 c-file-style:"stroustrup"
57 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
58 indent-tabs-mode:nil
59 fill-column:99
60 End:
61 */
62 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
63