From: mental Date: Mon, 4 Sep 2006 03:37:42 +0000 (+0000) Subject: add support for rounded caps with the calligraphy tool X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=dff6032fede2324e21595c06b906f8bec5ffc860;p=inkscape.git add support for rounded caps with the calligraphy tool --- diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 3eb84570d..1dbb91785 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -162,6 +162,7 @@ sp_dyna_draw_context_init(SPDynaDrawContext *ddc) ddc->vel_thin = 0.1; ddc->flatness = 0.9; + ddc->cap_rounding = 0.0; ddc->abs_width = false; ddc->keep_selected = true; @@ -228,6 +229,7 @@ sp_dyna_draw_context_setup(SPEventContext *ec) sp_event_context_read(ec, "usetilt"); sp_event_context_read(ec, "abs_width"); sp_event_context_read(ec, "keep_selected"); + sp_event_context_read(ec, "cap_rounding"); ddc->is_drawing = false; @@ -268,6 +270,8 @@ sp_dyna_draw_context_set(SPEventContext *ec, gchar const *key, gchar const *val) ddc->abs_width = (val && strcmp(val, "0")); } else if (!strcmp(key, "keep_selected")) { ddc->keep_selected = (val && strcmp(val, "0")); + } else if (!strcmp(key, "cap_rounding")) { + ddc->cap_rounding = ( val ? g_ascii_strtod (val, NULL) : 0.0 ); } //g_print("DDC: %g %g %g %g\n", ddc->mass, ddc->drag, ddc->angle, ddc->width); @@ -689,6 +693,17 @@ set_to_accumulated(SPDynaDrawContext *dc) /* TODO: annotate */ "dyna-draw-context.cpp:689"); } +static void +add_cap(SPCurve *curve, NR::Point const &from, NR::Point const &to, + double rounding) +{ + NR::Point vec = rounding * NR::rot90( ( to - from ) / sqrt(2.0) ); + + if ( NR::L2(vec) > DYNA_EPSILON ) { + sp_curve_curveto(curve, from + vec, to + vec, to); + } +} + static void accumulate_calligraphic(SPDynaDrawContext *dc) { @@ -696,7 +711,9 @@ accumulate_calligraphic(SPDynaDrawContext *dc) sp_curve_reset(dc->accumulated); /* Is this required ?? */ SPCurve *rev_cal2 = sp_curve_reverse(dc->cal2); sp_curve_append(dc->accumulated, dc->cal1, FALSE); + add_cap(dc->accumulated, sp_curve_last_point(dc->cal1), sp_curve_first_point(rev_cal2), dc->cap_rounding); sp_curve_append(dc->accumulated, rev_cal2, TRUE); + add_cap(dc->accumulated, sp_curve_last_point(rev_cal2), sp_curve_first_point(dc->cal1), dc->cap_rounding); sp_curve_closepath(dc->accumulated); sp_curve_unref(rev_cal2); diff --git a/src/dyna-draw-context.h b/src/dyna-draw-context.h index 27d3291da..638767270 100644 --- a/src/dyna-draw-context.h +++ b/src/dyna-draw-context.h @@ -94,6 +94,7 @@ struct SPDynaDrawContext double vel_thin; double flatness; double tremor; + double cap_rounding; Inkscape::MessageContext *_message_context; diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 111fc6bf1..1992f07cf 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -63,7 +63,7 @@ static char const preferences_skeleton[] = " \n" -" \n" " \n"