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