- * robust_scm2double (me->get_property ("dash-period"), 1.0);
-
- if (period < 0)
- return Stencil ();
-
- stil = make_dashed_line (thick, from, to, period, fraction);
+ * robust_scm2double (me->get_property ("dash-period"), 1.0);
+
+ if (period <= 0)
+ return Stencil ();
+
+ Real len = (to - from).length ();
+ /*
+ Dashed lines should begin and end with a dash. Therefore,
+ there will be one more dash than complete dash + whitespace
+ units (full periods).
+ */
+ int full_period_count =
+ (int) rint ((len - period * fraction) / period);
+ full_period_count = max (0, full_period_count);
+ if (full_period_count > 0)
+ {
+ /*
+ TODO: figure out something intelligent for really short
+ sections.
+ */
+ period = len / (fraction + full_period_count);
+ }
+ stencil = make_dashed_line (thick, from, to, period, fraction);