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),
68 Warning: this thing is a cross-staff object, so it should have empty Y-dimensions.
70 (If not, you risk that this is called from the staff-alignment
71 routine, via molecule_extent. At this point, the staffs aren't
72 separated yet, so it doesn't work cross-staff.
76 MAKE_SCHEME_CALLBACK (Line_spanner, brew_molecule, 1);
78 Line_spanner::brew_molecule (SCM smob)
80 Grob *me= unsmob_grob (smob);
81 Spanner *spanner = dynamic_cast<Spanner*> (me);
83 Grob *common[] = { 0, 0 };
85 Item *l = spanner->get_bound (LEFT);
86 Item *r = spanner->get_bound (RIGHT);
89 FIXME: should also do something sensible across line breaks.
91 if (l->break_status_dir () || r->break_status_dir ())
94 for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
96 common[a] = l->common_refpoint (r, a);
103 for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
105 dxy[a] = r->extent (common[a], a)[LEFT] -
106 l->extent (common[a], a)[RIGHT];
110 Real gap = gh_scm2double (me->get_grob_property ("gap"));
112 Offset my_off(me->relative_coordinate (common[X_AXIS], X_AXIS),
113 me->relative_coordinate (common[Y_AXIS], Y_AXIS) );
115 Offset his_off(l->relative_coordinate (common[X_AXIS], X_AXIS),
116 l->relative_coordinate (common[Y_AXIS], Y_AXIS) );
118 dxy *= (dxy.length () - 2 * gap) / dxy.length ();
120 SCM list = Line_spanner::line_atom (me, dxy[X_AXIS], dxy[Y_AXIS]);
125 Box b (Interval (0, dxy[X_AXIS]), Interval (0, dxy[Y_AXIS]));
127 line = Molecule (b, list);
128 line.translate_axis (l->extent (l, X_AXIS).length (), X_AXIS);
131 Offset g = dxy * (gap / dxy.length ());
132 line.translate (g - my_off + his_off);
134 return line.smobbed_copy ();