From f87993d7e26957b39d35decde42716d9d2f145e2 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Wed, 30 Jul 2008 12:05:20 +0000 Subject: New function to set text position and anchor relative to a given path (bzr r6475) --- src/live_effects/parameter/text.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/live_effects/parameter/text.cpp') 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) { -- cgit v1.2.3