From: cilix42 Date: Wed, 30 Jul 2008 12:05:20 +0000 (+0000) Subject: New function to set text position and anchor relative to a given path X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=85bc45682f5dd745ceb7f01b0d47efd35853844f;p=inkscape.git New function to set text position and anchor relative to a given path --- 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 { @@ -49,6 +50,23 @@ TextParam::setPos(Geom::Point pos) sp_canvastext_set_coords (canvas_text, pos); } +void +TextParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool use_curvature) +{ + using namespace Geom; + + Piecewise > 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) { 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 > &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; };