2 bar-line.cc -- implement Bar_line
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "all-font-metrics.hh"
12 #include "font-interface.hh"
14 #include "output-def.hh"
15 #include "paper-column.hh"
16 #include "staff-symbol-referencer.hh"
18 MAKE_SCHEME_CALLBACK (Bar_line, print, 1);
20 Bar_line::print (SCM smob)
22 Grob *me = unsmob_grob (smob);
24 SCM s = me->get_property ("glyph-name");
25 SCM barsize = me->get_property ("bar-size");
27 if (scm_is_string (s) && scm_is_number (barsize))
29 string str = ly_scm2string (s);
30 Real sz = robust_scm2double (barsize, 0);
34 return compound_barline (me, str, sz, false).smobbed_copy ();
40 Bar_line::compound_barline (Grob *me, string str, Real h,
43 Real kern = robust_scm2double (me->get_property ("kern"), 1);
44 Real thinkern = robust_scm2double (me->get_property ("thin-kern"), 1);
45 Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1);
46 Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1);
48 Real staffline = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
49 Real staff_space = Staff_symbol_referencer::staff_space (me);
52 thinkern *= staffline;
56 Stencil thin = simple_barline (me, hair, h, rounded);
57 Stencil thick = simple_barline (me, fatline, h, rounded);
58 Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
60 int lines = Staff_symbol_referencer::line_count (me);
62 = ((lines & 1 || lines == 0)
64 : (staff_space < 2 ? 2 : .5)) * staff_space;
66 colon.translate_axis (dist, Y_AXIS);
67 colon.add_stencil (dot);
68 colon.translate_axis (-dist / 2, Y_AXIS);
75 return Lookup::blank (Box (Interval (0, 0), Interval (-h / 2, h / 2)));
78 else if (str == "|." || (h == 0 && str == ":|"))
80 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
81 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
83 else if (str == ".|" || (h == 0 && str == "|:"))
85 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
86 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
90 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
91 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
92 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
96 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
97 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
98 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
100 else if (str == ":|:")
102 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
103 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
104 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
105 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
107 else if (str == ".|.")
109 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
110 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
112 else if (str == "||")
115 should align to other side? this never appears
118 m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
119 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
123 int c = (Staff_symbol_referencer::line_count (me));
125 for (int i = 0; i < c - 1; i++)
127 Real y = (- (c - 1.0) / 2 + 0.5 + i * staff_space);
130 d.translate_axis (y, Y_AXIS);
142 Bar_line::simple_barline (Grob *me,
149 ? me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"))
152 return Lookup::round_filled_box (Box (Interval (0, w),
153 Interval (-h / 2, h / 2)), blot);
156 MAKE_SCHEME_CALLBACK (Bar_line, calc_bar_size, 1);
158 Bar_line::calc_bar_size (SCM smob)
160 Grob *me = unsmob_grob (smob);
161 if (Grob *staff = Staff_symbol_referencer::get_staff_symbol (me))
163 Interval staff_y = staff->extent (staff, Y_AXIS);
164 return scm_from_double (staff_y.is_empty () ? 0.0 : staff_y.length ());
166 return scm_from_int (0);
170 ADD_INTERFACE (Bar_line,
171 "bar-line-interface",
175 "Print a special bar symbol. It replaces the \n"
176 "regular bar symbol with a special\n"
177 "symbol. The argument @var{bartype} is a string which specifies the\n"
178 "kind of bar to print. Options are @code{:|}, \n"
179 "@code{|:}, @code{:|:},\n"
180 "@code{||}, @code{|.},\n"
181 "@code{.|}, and @code{.|.}. \n"
183 "These produce, respectively, a right repeat, a left repeat, a double\n"
184 "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
185 "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
186 "but a line break is allowed at that spot.\n",