]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol.cc
7f9c295a008c7ee279f726453ba008207ce04ad1
[lilypond.git] / lily / staff-symbol.cc
1 /*
2   staff-symbol.cc -- implement Staff_symbol
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "staff-symbol.hh"
10
11 #include "lookup.hh"
12 #include "dimensions.hh"
13 #include "output-def.hh"
14 #include "warn.hh"
15 #include "item.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "spanner.hh"
18
19 MAKE_SCHEME_CALLBACK (Staff_symbol, print, 1);
20
21 SCM
22 Staff_symbol::print (SCM smob)
23 {
24   Grob *me = unsmob_grob (smob);
25   Spanner *sp = dynamic_cast<Spanner *> (me);
26   Grob *common
27     = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
28
29   Interval span_points (0, 0);
30
31   /*
32     For raggedright without ragged staffs, simply set width to the linewidth.
33
34     (ok -- lousy UI, since width is in staff spaces)
35
36     --hwn.
37   */
38   Real t = me->layout ()->get_dimension (ly_symbol2scm ("linethickness"));
39   t *= robust_scm2double (me->get_property ("thickness"), 1.0);
40
41   Direction d = LEFT;
42   do
43     {
44       SCM width_scm = me->get_property ("width");
45       if (d == RIGHT && scm_is_number (width_scm))
46         {
47           /*
48             don't multiply by Staff_symbol_referencer::staff_space (me),
49             since that would make aligning staff symbols of different sizes to
50             one right margin hell.
51           */
52           span_points[RIGHT] = scm_to_double (width_scm);
53         }
54       else
55         {
56           Item *x = sp->get_bound (d);
57
58           span_points[d] = x->relative_coordinate (common, X_AXIS);
59           if (!x->break_status_dir ()
60               && !x->extent (x, X_AXIS).is_empty ())
61             span_points[d] += x->extent (x, X_AXIS)[d];
62         }
63
64       span_points[d] -= d* t / 2;
65     }
66   while (flip (&d) != LEFT);
67
68   int l = Staff_symbol::line_count (me);
69
70   Real height = (l - 1) * staff_space (me) / 2;
71   Stencil a
72     = Lookup::horizontal_line (span_points
73                                -me->relative_coordinate (common, X_AXIS),
74                                t);
75
76   Stencil m;
77   for (int i = 0; i < l; i++)
78     {
79       Stencil b (a);
80       b.translate_axis (height - i * staff_space (me), Y_AXIS);
81       m.add_stencil (b);
82     }
83   return m.smobbed_copy ();
84 }
85
86 int
87 Staff_symbol::get_steps (Grob *me)
88 {
89   return line_count (me) * 2;
90 }
91
92 int
93 Staff_symbol::line_count (Grob *me)
94 {
95   SCM c = me->get_property ("line-count");
96   if (scm_is_number (c))
97     return scm_to_int (c);
98   else
99     return 0;
100 }
101
102 Real
103 Staff_symbol::staff_space (Grob *me)
104 {
105   return robust_scm2double (me->get_property ("staff-space"), 1.0);
106 }
107
108 Real
109 Staff_symbol::get_line_thickness (Grob *me)
110 {
111   Real lt = me->layout ()->get_dimension (ly_symbol2scm ("linethickness"));
112
113   return robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
114 }
115
116 Real
117 Staff_symbol::get_ledger_line_thickness (Grob *me)
118 {
119   SCM lt_pair = me->get_property ("ledger-line-thickness");
120   Offset z = robust_scm2offset (lt_pair, Offset (1.0, 0.1));
121
122   return z[X_AXIS] * get_line_thickness (me) + z[Y_AXIS] * staff_space (me);
123 }
124
125 ADD_INTERFACE (Staff_symbol, "staff-symbol-interface",
126                "This spanner draws the lines of a staff. "
127                "A staff symbol definines a vertical unit, the staff space. "
128                "Quantities that go by a half staff space are called positions "
129                "The center (i.e. middle line "
130                "or space) is position 0. The length of the symbol may be set by hand "
131                "through the @code{width} property. ",
132
133                "ledger-line-thickness width staff-space thickness line-count");