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