Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
text.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
4 *
5 * Authors:
6 * Maximilian Albert
7 * Johan Engelen
8 *
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#include "text.h"
13
15#include <glibmm/i18n.h>
16#include <gtkmm/box.h>
17#include <gtkmm/button.h>
18
19#include "inkscape.h"
20
22#include "live_effects/effect.h"
23#include "ui/icon-names.h"
24#include "ui/pack.h"
26
27namespace Inkscape {
28namespace LivePathEffect {
29
30TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip,
31 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
32 Effect* effect, const Glib::ustring default_value )
33 : Parameter(label, tip, key, wr, effect)
34 , value(default_value)
35 , defvalue(default_value)
36{
37 if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { // FIXME: we shouldn't use this!
38 canvas_text = make_canvasitem<CanvasItemText>(desktop->getCanvasTemp(), Geom::Point(0, 0), default_value);
39 }
40}
41
42TextParam::~TextParam() = default;
43
44void
49
50void
51TextParam::param_update_default(const gchar * default_value)
52{
53 defvalue = (Glib::ustring)default_value;
54}
55
56// This is a bit silly, we should have an option in the constructor to not create the canvas_text object.
57void
62
63void
65{
66 if (canvas_text) {
67 canvas_text->set_coord(pos);
68 }
69}
70
71void
73 const double t, const double length, bool /*use_curvature*/)
74{
75 using namespace Geom;
76
77 Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1);
78 double t_reparam = pwd2_reparam.cuts.back() * t;
79 Point pos = pwd2_reparam.valueAt(t_reparam);
80 Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam));
81 Point n = -rot90(dir);
82 double angle = Geom::angle_between(dir, Point(1,0));
83 if (canvas_text) {
84 canvas_text->set_coord(pos + n * length);
85 canvas_text->set_anchor(Geom::Point(std::sin(angle), -std::cos(angle)));
86 }
87}
88
89void
90TextParam::setAnchor(double x_value, double y_value)
91{
92 anchor_x = x_value;
93 anchor_y = y_value;
94 if (canvas_text) {
96 }
97}
98
99bool
100TextParam::param_readSVGValue(const gchar * strvalue)
101{
102 param_setValue(strvalue);
103 return true;
104}
105
106Glib::ustring
108{
109 return value;
110}
111
112Glib::ustring
114{
115 return defvalue;
116}
117
118void
120{
121 Glib::ustring str(rsu->getText());
122 param_setValue(str);
123 write_to_SVG();
124}
125
126Gtk::Widget *
128{
129 auto const rsu = Gtk::make_managed<UI::Widget::RegisteredText>(
131 rsu->setText(value);
132 rsu->setProgrammatically = false;
133 rsu->set_undo_parameters(_("Change text parameter"), INKSCAPE_ICON("dialog-path-effects"));
134 auto const text_container = Gtk::make_managed<Gtk::Box>();
135 auto const set = Gtk::make_managed<Gtk::Button>(Glib::ustring("✔"));
136 set->signal_clicked()
137 .connect(sigc::bind(sigc::mem_fun(*this, &TextParam::setTextParam),rsu));
138 UI::pack_start(*text_container, *rsu, false, false, 2);
139 UI::pack_start(*text_container, *set, false, false, 2);
140 text_container->set_halign(Gtk::Align::END);
141 return text_container;
142}
143
144void TextParam::param_setValue(Glib::ustring newvalue)
145{
146 if (value != newvalue) {
148 }
149 value = std::move(newvalue);
150 if (canvas_text) {
151 canvas_text->set_text(value);
152 }
153}
154
155} /* namespace LivePathEffect */
156} /* namespace Inkscape */
157
158/*
159 Local Variables:
160 mode:c++
161 c-file-style:"stroustrup"
162 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163 indent-tabs-mode:nil
164 fill-column:99
165 End:
166*/
167// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
Function defined as discrete pieces.
Definition piecewise.h:71
output_type valueAt(double t) const
Definition piecewise.h:102
std::vector< double > cuts
Definition piecewise.h:75
Two-dimensional point that doubles as a vector.
Definition point.h:66
Inkscape::XML::Node * getRepr()
Definition effect.cpp:1934
Inkscape::UI::Widget::Registry * param_wr
Definition parameter.h:99
TextParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect, const Glib::ustring default_value="")
Definition text.cpp:30
Gtk::Widget * param_newWidget() override
Definition text.cpp:127
void setPosAndAnchor(const Geom::Piecewise< Geom::D2< Geom::SBasis > > &pwd2, const double t, const double length, bool use_curvature=false)
Definition text.cpp:72
void param_setValue(Glib::ustring newvalue)
Definition text.cpp:144
CanvasItemPtr< CanvasItemText > canvas_text
Definition text.h:64
Glib::ustring param_getDefaultSVGValue() const override
Definition text.cpp:113
void param_set_default() override
Definition text.cpp:45
bool param_readSVGValue(const gchar *strvalue) override
Definition text.cpp:100
void param_update_default(const gchar *default_value) override
Definition text.cpp:51
Glib::ustring param_getSVGValue() const override
Definition text.cpp:107
void setTextParam(Inkscape::UI::Widget::RegisteredText *rsu)
Definition text.cpp:119
void setAnchor(double x_value, double y_value)
Definition text.cpp:90
void setPos(Geom::Point pos)
Definition text.cpp:64
Glib::ustring const getText() const
Get the text in the entry.
Definition text.cpp:26
To do: update description of desktop.
Definition desktop.h:149
Inkscape::CanvasItemGroup * getCanvasTemp() const
Definition desktop.h:202
Macro for icon names used in Inkscape.
Glib::ustring label
Various utility functions.
Definition affine.h:22
Coord length(LineSegment const &seg)
double angle_between(Line const &l1, Line const &l2)
Definition line.h:456
Bezier derivative(Bezier const &a)
Definition bezier.cpp:282
Piecewise< D2< SBasis > > arc_length_parametrization(D2< SBasis > const &M, unsigned order=3, double tol=.01)
Point unit_vector(Point const &a)
D2< T > rot90(D2< T > const &a)
Definition d2.h:397
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
two-dimensional geometric operators.
SPDesktop * desktop