From 85bc45682f5dd745ceb7f01b0d47efd35853844f Mon Sep 17 00:00:00 2001 From: cilix42 Date: Wed, 30 Jul 2008 12:05:20 +0000 Subject: [PATCH] New function to set text position and anchor relative to a given path --- src/live_effects/parameter/text.cpp | 18 ++++++++++++++++++ src/live_effects/parameter/text.h | 2 ++ 2 files changed, 20 insertions(+) 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; }; -- 2.30.2