2 staff-symbol.cc -- implement Staff_symbol
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "dimensions.hh"
11 #include "paper-def.hh"
12 #include "molecule.hh"
15 #include "staff-symbol.hh"
16 #include "staff-symbol-referencer.hh"
21 MAKE_SCHEME_CALLBACK (Staff_symbol,brew_molecule,1);
24 Staff_symbol::brew_molecule (SCM smob)
26 Grob *me = unsmob_grob (smob);
27 Spanner* sp = dynamic_cast<Spanner*> (me);
29 = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
31 bool paper_raggedright = to_boolean (me->paper_l ()->get_scmvar ("raggedright"));
32 bool grob_raggedright = to_boolean (me->get_grob_property ("ragged-right"));
35 SCM width_scm = me->get_grob_property ("width");
36 if (gh_number_p (width_scm)) // user-defined width
39 gh_scm2double (width_scm) *
40 Staff_symbol_referencer::staff_space (me);
42 else // determine width automatically
44 if (paper_raggedright && !grob_raggedright)
46 // *prevent* staff symbol from being ragged right; instead, use
47 // paper variable "linewidth"
48 width = me->paper_l ()->get_var ("linewidth");
50 else // determine width from my own bounds
52 width = sp->get_bound (RIGHT)->relative_coordinate (common , X_AXIS);
56 // respect indentation, if any
57 width -= sp->get_bound (LEFT)->relative_coordinate (common, X_AXIS);
61 warning (_f ("staff symbol: indentation yields beyond end of line"));
65 Real t = me->paper_l ()->get_var ("linethickness");
66 SCM my_thick = me->get_grob_property("thickness");
67 if (gh_number_p(my_thick))
68 t *= gh_scm2double (my_thick);
70 int l = Staff_symbol::line_count (me);
72 Real height = (l-1) * staff_space (me) /2;
74 for (int i=0; i < l; i++)
77 Lookup::filledbox (Box (Interval (0,width),
78 Interval (-t/2, t/2)));
80 a.translate_axis (height - i * staff_space (me), Y_AXIS);
84 return m.smobbed_copy ();
88 Staff_symbol::steps_i (Grob*me)
90 return line_count (me) * 2;
94 Staff_symbol::line_count (Grob*me)
96 SCM c = me->get_grob_property ("line-count");
98 return gh_scm2int (c);
104 Staff_symbol::staff_space (Grob*me)
108 SCM s = me->get_grob_property ("staff-space");
110 ss *= gh_scm2double (s);
117 ADD_INTERFACE (Staff_symbol,"staff-symbol-interface",
118 "This spanner draws the lines of a staff. The center (i.e. middle line
119 or space) is position 0.",
121 "ragged-right staff-space thickness line-count");