]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar-line.cc
The grand \paper -> \layout, \bookpaper -> \paper renaming.
[lilypond.git] / lily / bar-line.cc
1 /*
2   bar.cc -- implement Bar
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 <math.h>
10
11 #include "lookup.hh"
12 #include "paper-column.hh"
13 #include "grob.hh"
14 #include "bar-line.hh"
15 #include "string.hh"
16 #include "stencil.hh"
17 #include "output-def.hh"
18 #include "font-interface.hh"
19
20 #include "all-font-metrics.hh"
21 #include "item.hh"
22 #include "staff-symbol-referencer.hh"
23
24 MAKE_SCHEME_CALLBACK (Bar_line,print,1);
25
26 SCM 
27 Bar_line::print (SCM smob) 
28 {
29   Grob * me = unsmob_grob (smob);
30
31   SCM s = me->get_property ("glyph");
32   SCM barsiz_proc = me->get_property ("bar-size-procedure");
33   if (scm_is_string (s) && ly_c_procedure_p (barsiz_proc))
34     {
35       String str  =ly_scm2string (s);
36       SCM siz = scm_call_1 (barsiz_proc, me->self_scm ());
37       Real sz = robust_scm2double (siz, 0);
38       if (sz <= 0)
39         return SCM_EOL;
40       
41       return compound_barline (me, str, sz).smobbed_copy ();
42     }
43   return SCM_EOL;
44 }
45
46
47 Stencil
48 Bar_line::compound_barline (Grob*me, String str, Real h)
49 {
50   Real kern = robust_scm2double (me->get_property ("kern"), 1);
51   Real thinkern = robust_scm2double (me->get_property ("thin-kern"), 1);
52   Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1);
53   Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1);
54
55   Real staffline = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
56   Real staff_space = Staff_symbol_referencer::staff_space (me);
57
58   kern *= staffline;
59   thinkern *= staffline;
60   hair *= staffline;
61   fatline *= staffline;
62
63   Stencil thin = simple_barline (me, hair, h);
64   Stencil thick = simple_barline (me, fatline, h);
65   Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots-dot");
66
67   int lines =Staff_symbol_referencer::line_count (me);
68   Real dist 
69     = ((lines & 1 || lines == 0)
70        ? 1
71        : (staff_space < 2 ? 2 : .5) ) * staff_space;
72   Stencil colon (dot);
73   colon.translate_axis (dist,Y_AXIS);
74   colon.add_stencil (dot);
75   colon.translate_axis (-dist/2,Y_AXIS);
76
77   Stencil m;
78   if (str == "||:")
79     str = "|:";
80   
81   if (str == "")
82     {
83       return Lookup::blank (Box (Interval (0, 0), Interval (-h/2, h/2)));
84     }
85   else if (str == "|")
86     {
87       return thin;
88     }
89   else if (str == "|." || (h == 0 && str == ":|"))
90     {
91       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);      
92       m.add_at_edge (X_AXIS, LEFT, thin, kern,0 );
93     }
94   else if (str == ".|" || (h == 0 && str == "|:"))
95     {
96       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
97       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
98     }
99   else if (str == ":|")
100     {
101       m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
102       m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
103       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);      
104     }
105   else if (str == "|:")
106     {
107       m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
108       m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
109       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);      
110     }
111   else if (str == ":|:")
112     {
113       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
114       m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
115       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
116       m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);      
117     }
118   else if (str == ".|.")
119     {
120       m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
121       m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
122     }
123   else if (str == "||")
124     {
125       /*
126         should align to other side? this never appears
127         on the system-start?
128       */
129       m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
130       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
131     }
132   else if (str == ":")
133     {
134       int c = (Staff_symbol_referencer::line_count (me));
135       
136       for (int i = 0 ; i < c - 1; i++)
137         {
138           Real y = (- (c-1.0) / 2 + 0.5  +   i * staff_space);
139           Stencil d (dot);
140
141           d. translate_axis (y,Y_AXIS);
142           m.add_stencil (d);
143         }
144     }
145   return m;
146 }
147
148 Stencil
149 Bar_line::simple_barline (Grob *me,
150                           Real w,
151                           Real h) 
152 {
153   Real blot = me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter"));
154   
155   return Lookup::round_filled_box (Box (Interval (0,w), Interval (-h/2, h/2)), blot);
156 }
157
158 MAKE_SCHEME_CALLBACK (Bar_line,before_line_breaking ,1);
159
160 SCM
161 Bar_line::before_line_breaking (SCM smob)
162 {
163   Grob*me=unsmob_grob (smob);
164   Item * item = dynamic_cast<Item*> (me);
165   
166   SCM g = me->get_property ("glyph");
167   SCM orig = g;
168   Direction bsd = item->break_status_dir ();
169   if (scm_is_string (g) && bsd)
170     {
171       SCM proc = me->get_property ("break-glyph-function");
172       g = scm_call_2 (proc, g, scm_int2num (bsd));
173     }
174   
175   if (!scm_is_string (g))
176     {
177       me->set_property ("print-function", SCM_EOL);
178       me->set_extent (SCM_EOL, X_AXIS);
179       // leave y_extent for spanbar? 
180     }
181
182   if (! ly_c_equal_p (g, orig))
183     me->set_property ("glyph", g);
184
185   return SCM_UNSPECIFIED;
186 }
187   
188
189
190
191 MAKE_SCHEME_CALLBACK (Bar_line,get_staff_bar_size,1);
192 SCM
193 Bar_line::get_staff_bar_size (SCM smob) 
194 {
195   Grob*me = unsmob_grob (smob);
196   Real ss = Staff_symbol_referencer::staff_space (me);
197   SCM size = me->get_property ("bar-size");
198   if (scm_is_number (size))
199     return scm_make_real (scm_to_double (size)*ss);
200   else if (Staff_symbol_referencer::get_staff_symbol (me))
201     {
202       /*
203         If there is no staff-symbol, we get -1 from the next
204         calculation. That's a nonsense value, which would collapse the
205         barline so we return 0.0 in the next alternative.
206       */
207       return scm_make_real ((Staff_symbol_referencer::line_count (me) -1) * ss);
208     }
209   else
210     return scm_int2num (0);
211 }
212
213
214
215 ADD_INTERFACE (Bar_line, "bar-line-interface",
216   "Bar line.\n"
217 "\n"
218 "Print a special bar symbol. It replaces the \n"
219 "regular bar symbol with a special\n"
220 "symbol.  The argument @var{bartype} is a string which specifies the\n"
221 "kind of bar to print.  Options are @code{:|},\n"
222 "@code{|:}, @code{:|:},\n"
223 "@code{||}, @code{|.},\n"
224 "@code{.|}, and @code{.|.}. \n"
225 "\n"
226 "These produce, respectively, a right repeat, a left repeat, a double\n"
227 "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
228 "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
229 "but a line break is allowed at that spot.\n",
230   "bar-size-procedure kern thin-kern hair-thickness thick-thickness glyph bar-size break-glyph-function");