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"
17 #include "line-interface.hh"
19 MAKE_SCHEME_CALLBACK (Bar_line, print, 1);
21 Bar_line::print (SCM smob)
23 Grob *me = unsmob_grob (smob);
25 SCM s = me->get_property ("glyph-name");
26 SCM barsize = me->get_property ("bar-size");
28 if (scm_is_string (s) && scm_is_number (barsize))
30 string str = ly_scm2string (s);
31 Real sz = robust_scm2double (barsize, 0);
35 return compound_barline (me, str, sz, false).smobbed_copy ();
41 Bar_line::compound_barline (Grob *me, string str, Real h,
44 Real kern = robust_scm2double (me->get_property ("kern"), 1);
45 Real thinkern = robust_scm2double (me->get_property ("thin-kern"), 1);
46 Real hair = robust_scm2double (me->get_property ("hair-thickness"), 1);
47 Real fatline = robust_scm2double (me->get_property ("thick-thickness"), 1);
49 Real staffline = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
50 Real staff_space = Staff_symbol_referencer::staff_space (me);
53 thinkern *= staffline;
57 Stencil thin = simple_barline (me, hair, h, rounded);
58 Stencil thick = simple_barline (me, fatline, h, rounded);
59 Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
61 int lines = Staff_symbol_referencer::line_count (me);
63 = ((lines & 1 || lines == 0)
65 : (staff_space < 2 ? 2 : .5)) * staff_space;
67 colon.translate_axis (dist, Y_AXIS);
68 colon.add_stencil (dot);
69 colon.translate_axis (-dist / 2, Y_AXIS);
76 return Lookup::blank (Box (Interval (0, 0), Interval (-h / 2, h / 2)));
79 else if (str == "|." || (h == 0 && str == ":|"))
81 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
82 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
84 else if (str == ".|" || (h == 0 && str == "|:"))
86 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
87 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
91 m.add_at_edge (X_AXIS, LEFT, thick, 0, 0);
92 m.add_at_edge (X_AXIS, LEFT, thin, kern, 0);
93 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
97 m.add_at_edge (X_AXIS, RIGHT, thick, 0, 0);
98 m.add_at_edge (X_AXIS, RIGHT, thin, kern, 0);
99 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
101 else if (str == ":|:")
103 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
104 m.add_at_edge (X_AXIS, LEFT, colon, kern, 0);
105 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
106 m.add_at_edge (X_AXIS, RIGHT, colon, kern, 0);
108 else if (str == ".|.")
110 m.add_at_edge (X_AXIS, LEFT, thick, thinkern, 0);
111 m.add_at_edge (X_AXIS, RIGHT, thick, kern, 0);
113 else if (str == "||")
116 should align to other side? this never appears
119 m.add_at_edge (X_AXIS, RIGHT, thin, 0, 0);
120 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern, 0);
124 int c = (Staff_symbol_referencer::line_count (me));
126 for (int i = 0; i < c - 1; i++)
128 Real y = (- (c - 1.0) / 2 + 0.5 + i) * staff_space;
131 d.translate_axis (y, Y_AXIS);
135 else if (str == "dashed")
137 m = dashed_bar_line (me, h, hair);
147 Bar_line::simple_barline (Grob *me,
154 ? me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"))
157 return Lookup::round_filled_box (Box (Interval (0, w),
158 Interval (-h / 2, h / 2)), blot);
161 MAKE_SCHEME_CALLBACK (Bar_line, calc_bar_size, 1);
163 Bar_line::calc_bar_size (SCM smob)
165 Grob *me = unsmob_grob (smob);
166 if (Grob *staff = Staff_symbol_referencer::get_staff_symbol (me))
168 Interval staff_y = staff->extent (staff, Y_AXIS);
169 return scm_from_double (staff_y.is_empty () ? 0.0 : staff_y.length ());
171 return scm_from_int (0);
176 Bar_line::dashed_bar_line (Grob *me, Real h, Real thick)
179 = 1.0 - robust_scm2double (me->get_property ("gap"), 0.3);
181 this is a tad complex for what we want to achieve, but with a
182 simple line, the round blotting interferes with staff line
185 Real ss = Staff_symbol_referencer::staff_space (me);
186 int count = Staff_symbol_referencer::line_count (me);
187 Real line_thick = Staff_symbol_referencer::line_thickness (me);
189 if (fabs (line_thick + (count -1) * ss - h) < 0.1) // ugh.
192 me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
194 Real half_space = ss/2;
197 for (int i = (count-1); i >= -(count-1); i -= 2)
199 Real top_y = min ((i + dash_size) * half_space,
200 (count-1) * half_space + line_thick / 2);
201 Real bot_y = max ((i - dash_size) * half_space,
202 -(count-1) * half_space - line_thick/2);
204 bar.add_stencil (Lookup::round_filled_box (Box (Interval (0,thick),
205 Interval (bot_y, top_y)),
213 We have to scale the dashing so it starts and ends with half a
216 int dashes = int (rint (h / ss));
217 Real total_dash_size = h / dashes;
218 Real factor = (dash_size - thick) / ss;
220 SCM at = scm_list_n (ly_symbol2scm ("dashed-line"),
221 scm_from_double (thick),
222 scm_from_double (factor * total_dash_size),
223 scm_from_double ((1-factor) * total_dash_size),
226 scm_from_double (factor * total_dash_size * 0.5),
230 box.add_point (Offset (0, 0));
231 box.add_point (Offset (0, h));
234 s.translate (Offset (thick/2, -h/2));
241 ADD_INTERFACE (Bar_line,
242 "bar-line-interface",
246 "Print a special bar symbol. It replaces the \n"
247 "regular bar symbol with a special\n"
248 "symbol. The argument @var{bartype} is a string which specifies the\n"
249 "kind of bar to print. Options are @code{:|}, \n"
250 "@code{|:}, @code{:|:},\n"
251 "@code{||}, @code{|.},\n"
252 "@code{.|}, and @code{.|.}. \n"
254 "These produce, respectively, a right repeat, a left repeat, a double\n"
255 "repeat, a double bar, a start bar, an end bar, and a thick double bar.\n"
256 "In addition, there is an option @code{||:} which is equivalent to\n"
257 "@code{|:} except at line breaks, where it produces a double bar (@code{||})\n"
258 "at the end of the line and a repeat sign (@code{|:}) at the beginning\n"
260 "If @var{bartype} is set to @code{empty} then nothing is printed,\n"
261 "but a line break is allowed at that spot.\n"
263 "@code{gap} is used for the gaps in dashed barlines."