Code

add support for rounded caps with the calligraphy tool
authormental <mental@users.sourceforge.net>
Mon, 4 Sep 2006 03:37:42 +0000 (03:37 +0000)
committermental <mental@users.sourceforge.net>
Mon, 4 Sep 2006 03:37:42 +0000 (03:37 +0000)
src/dyna-draw-context.cpp
src/dyna-draw-context.h
src/preferences-skeleton.h

index 3eb84570d071b69bb5ab3221c8877782337eb87e..1dbb91785c5bebc5e5a4e789aa8e0e3d29c0f841 100644 (file)
@@ -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);
index 27d3291da63e5307a2d26fc74173d89955a71805..6387672704786f3232f9c267f942feb7bcf891af 100644 (file)
@@ -94,6 +94,7 @@ struct SPDynaDrawContext
     double vel_thin;
     double flatness;
     double tremor;
+    double cap_rounding;
 
     Inkscape::MessageContext *_message_context;
 
index 111fc6bf1f5c463ad674e97b7da320caaef28b51..1992f07cfe76de917f93b2f3ddf0c0af1f6a8776 100644 (file)
@@ -63,7 +63,7 @@ static char const preferences_skeleton[] =
 "    <eventcontext id=\"calligraphic\" style=\"fill:black;fill-opacity:1;fill-rule:nonzero;stroke:none;\"\n"
 "                       mass=\"0.02\" drag=\"1\" angle=\"30\" width=\"0.15\" thinning=\"0.1\" flatness=\"0.9\"  usecurrent=\"1\"\n"
 "                       usepressure=\"0\" usetilt=\"0\" keep_selected=\"1\"/>\n"
-"    <eventcontext id=\"text\"  usecurrent=\"0\" gradientdrag=\"1\"\n" 
+"    <eventcontext id=\"text\"  usecurrent=\"0\" gradientdrag=\"1\" cap_rounding=\"0.0\"\n" 
 "                       font_sample=\"AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()\"\n"
 "                  style=\"fill:black;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans;font-style:normal;font-weight:normal;font-size:12px;\" selcue=\"1\"/>\n"
 "    <eventcontext id=\"nodes\" selcue=\"1\" gradientdrag=\"1\" show_handles=\"1\" sculpting_profile=\"1\" />\n"