2 line-spanner.cc -- implement Line_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "line-spanner.hh"
13 #include "paper-def.hh"
14 #include "paper-column.hh"
15 #include "staff-symbol-referencer.hh"
18 Line_spanner::line_atom (Grob* me, Real dx, Real dy)
21 SCM type = me->get_grob_property ("type");
22 if (gh_symbol_p (type)
23 && (type == ly_symbol2scm ("line")
24 || type == ly_symbol2scm ("dashed-line")
25 || type == ly_symbol2scm ("dotted-line")))
27 Real staff_space = Staff_symbol_referencer::staff_space (me);
28 Real thick = me->paper_l ()->get_var ("stafflinethickness");
30 SCM s = me->get_grob_property ("line-thickness");
32 thick *= gh_scm2double (s);
34 // maybe these should be in line-thickness?
35 Real length = staff_space;
36 s = me->get_grob_property ("dash-length");
38 length = gh_scm2double (s) * staff_space;
40 Real period = 2 * length + thick;
41 s = me->get_grob_property ("dash-period");
43 period = gh_scm2double (s) * staff_space;
45 if (type == ly_symbol2scm ("dotted-line"))
48 if (type == ly_symbol2scm ("line"))
49 length = period + thick;
51 Real on = length - thick;
52 Real off = period - on;
54 list = gh_list (ly_symbol2scm ("dashed-line"),
55 gh_double2scm (thick),
66 MAKE_SCHEME_CALLBACK (Line_spanner, brew_molecule, 1);
68 Line_spanner::brew_molecule (SCM smob)
70 Grob *me= unsmob_grob (smob);
71 Spanner *spanner = dynamic_cast<Spanner*> (me);
73 Grob *common[] = { 0, 0 };
74 common[X_AXIS] = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
75 common[Y_AXIS] = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), Y_AXIS);
77 if (!common[X_AXIS] || !common[Y_AXIS])
81 spanner->get_bound (LEFT)->relative_coordinate (common[X_AXIS], X_AXIS)
82 - spanner->get_bound (RIGHT)->relative_coordinate (common[X_AXIS], X_AXIS)
83 + spanner->get_bound (RIGHT)->extent (spanner->get_bound (RIGHT),
85 - spanner->get_bound (LEFT)->extent (spanner->get_bound (LEFT),
89 spanner->get_bound (LEFT)->relative_coordinate (common[Y_AXIS], Y_AXIS)
90 - spanner->get_bound (RIGHT)->relative_coordinate (common[Y_AXIS], Y_AXIS)
91 + spanner->get_bound (RIGHT)->extent (spanner->get_bound (RIGHT),
93 - spanner->get_bound (LEFT)->extent (spanner->get_bound (LEFT),
97 Real gap = gh_scm2double (me->get_grob_property ("gap"));
99 o *= (o.length () - 2 * gap) / o.length ();
101 SCM list = Line_spanner::line_atom (me, o[X_AXIS], o[Y_AXIS]);
106 Box b (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
108 line = Molecule (b, list);
109 line.translate_axis (spanner->get_bound (LEFT)->extent (spanner->get_bound (LEFT), X_AXIS).length (), X_AXIS);
110 Offset g = o * (gap / o.length ());
113 return line.smobbed_copy ();