From: jfbarraud Date: Fri, 5 Jun 2009 08:45:30 +0000 (+0000) Subject: made ruler lpe "official" + restored a "unit" param and fixed end mark on closed... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=822f89451bdca5665d48668154c774a45ec30c85;p=inkscape.git made ruler lpe "official" + restored a "unit" param and fixed end mark on closed path. --- diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 088e9ff3a..316495eb4 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -100,7 +100,6 @@ const Util::EnumData LPETypeData[] = { {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, - {RULER, N_("Ruler"), "ruler"}, {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, {TEXT_LABEL, N_("Text label"), "text_label"}, #endif @@ -118,6 +117,7 @@ const Util::EnumData LPETypeData[] = { {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"}, {ROUGH_HATCHES, N_("Hatches (rough)"), "rough_hatches"}, {SKETCH, N_("Sketch"), "sketch"}, + {RULER, N_("Ruler"), "ruler"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 1df0e127a..67bffa1e2 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -40,6 +40,7 @@ static const Util::EnumDataConverter BorderMarkTypeConverter(Bor LPERuler::LPERuler(LivePathEffectObject *lpeobject) : Effect(lpeobject), + unit(_("Unit"), _("Unit"), "unit", &wr, this), mark_distance(_("Mark distance"), _("Distance between successive ruler marks"), "mark_distance", &wr, this, 20.0), mark_length(_("Major length"), _("Length of major ruler marks"), "mark_length", &wr, this, 14.0), minor_mark_length(_("Minor length"), _("Length of minor ruler marks"), "minor_mark_length", &wr, this, 7.0), @@ -49,6 +50,7 @@ LPERuler::LPERuler(LivePathEffectObject *lpeobject) : offset(_("Offset"), _("Offset of first mark"), "offset", &wr, this, 0.0), border_marks(_("Border marks"), _("Choose whether to draw marks at the beginning and end of the path"), "border_marks", BorderMarkTypeConverter, &wr, this, BORDERMARK_BOTH) { + registerParameter(dynamic_cast(&unit)); registerParameter(dynamic_cast(&mark_distance)); registerParameter(dynamic_cast(&mark_length)); registerParameter(dynamic_cast(&minor_mark_length)); @@ -80,8 +82,14 @@ LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const { using namespace Geom; - n_major = mark_length * n; - n_minor = minor_mark_length * n; + gboolean success; + double real_mark_length = mark_length; + success = sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + double real_minor_mark_length = minor_mark_length; + success = sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + + n_major = real_mark_length * n; + n_minor = real_minor_mark_length * n; Point C, D; switch (marktype) { @@ -122,12 +130,17 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise > const & pwd2_i //find at which times to draw a mark: std::vector s_cuts; - for (double s = offset; s > roots = multi_roots(arclength, s_cuts); std::vector t_cuts; - g_warning("times:"); for (unsigned v=0; v > const & pwd2_i if (border_marks == BORDERMARK_END || border_marks == BORDERMARK_BOTH){ Point A = pwd2_in.lastValue(); Point n = rot90(unit_vector(speed.lastValue()))*sign; + //speed.lastValue() is somtimes wrong when the path is closed: a tiny line seg might added at the end to fix rounding errors... + //TODO: Find a better fix!! (How do we know if the path was closed?) + if ( A == pwd2_in.firstValue() && + speed.segs.size() > 1 && + speed.segs.back()[X].size() <= 1 && + speed.segs.back()[Y].size() <= 1 && + speed.segs.back()[X].tailError(0) <= 1e-10 && + speed.segs.back()[Y].tailError(0) <= 1e-10 + ){ + n = rot90(unit_vector(speed.segs[speed.segs.size()-2].at1()))*sign; + } output.concat (ruler_mark(A, n, MARK_MAJOR)); } diff --git a/src/live_effects/lpe-ruler.h b/src/live_effects/lpe-ruler.h index 6a7a7282b..0c72f1637 100644 --- a/src/live_effects/lpe-ruler.h +++ b/src/live_effects/lpe-ruler.h @@ -19,6 +19,7 @@ #include "live_effects/parameter/text.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/unit.h" namespace Inkscape { namespace LivePathEffect { @@ -52,6 +53,7 @@ private: Geom::Piecewise > ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const &marktype); ScalarParam mark_distance; + UnitParam unit; ScalarParam mark_length; ScalarParam minor_mark_length; ScalarParam major_mark_steps;