diff options
| author | Maximilian Albert <maximilian.albert@gmail.com> | 2008-07-30 12:05:20 +0000 |
|---|---|---|
| committer | cilix42 <cilix42@users.sourceforge.net> | 2008-07-30 12:05:20 +0000 |
| commit | f87993d7e26957b39d35decde42716d9d2f145e2 (patch) | |
| tree | 974f8aa51f3e6f15ccaca3bcd9e37d0060936687 | |
| parent | add placeholder for expert contributors (diff) | |
| download | inkscape-f87993d7e26957b39d35decde42716d9d2f145e2.tar.gz inkscape-f87993d7e26957b39d35decde42716d9d2f145e2.zip | |
New function to set text position and anchor relative to a given path
(bzr r6475)
| -rw-r--r-- | src/live_effects/parameter/text.cpp | 18 | ||||
| -rw-r--r-- | src/live_effects/parameter/text.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index fab69578a..dea750091 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -19,6 +19,7 @@ #include "ui/widget/registered-widget.h" #include "inkscape.h" #include "verbs.h" +#include <2geom/sbasis-geometric.h> namespace Inkscape { @@ -50,6 +51,23 @@ TextParam::setPos(Geom::Point pos) } void +TextParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, + const double t, const double length, bool use_curvature) +{ + using namespace Geom; + + Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); + double t_reparam = pwd2_reparam.cuts.back() * t; + Point pos = pwd2_reparam.valueAt(t_reparam); + Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); + Point n = -rot90(dir); + double angle = Geom::angle_between(dir, Point(1,0)); + + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor(canvas_text, std::sin(angle), -std::cos(angle)); +} + +void TextParam::setAnchor(double x_value, double y_value) { anchor_x = x_value; diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index c3eddd9fa..fafe9fe32 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -41,6 +41,8 @@ public: void param_setValue(const Glib::ustring newvalue); virtual void param_set_default(); void setPos(Geom::Point pos); + void setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, + const double t, const double length, bool use_curvature = false); void setAnchor(double x_value, double y_value); const Glib::ustring get_value() { return defvalue; }; |
