-
- SCM size = me->get_property ("bar-size");
-
- if (!scm_is_number (size)
- || !Staff_symbol_referencer::get_staff_symbol (me))
- return ly_interval2scm (Interval ());
-
- Real h = scm_to_double (size);
- return ly_interval2scm (Interval (-h/2, h/2));
+ if (Grob *staff = Staff_symbol_referencer::get_staff_symbol (me))
+ {
+ result = staff->extent (staff, Y_AXIS);
+
+ /* Due to rounding problems, bar lines extending to the outermost edges
+ of the staff lines appear wrongly in on-screen display
+ (and, to a lesser extent, in print) - they stick out a pixel.
+ The solution is to extend bar lines only to the middle
+ of the staff line - unless they have different colors,
+ when it would be undesirable.
+ */
+ SCM bar_line_color = me->get_property ("color");
+ SCM staff_color = staff->get_property ("color");
+ Real radius = Staff_symbol_referencer::staff_radius (me);
+ if (bar_line_color == staff_color && radius)
+ result *= (1 - 0.5 * (Staff_symbol_referencer::line_thickness (me) / radius));
+ }
+ return ly_interval2scm (result);
- int c = (Staff_symbol_referencer::line_count (me));
-
- for (int i = 0; i < c - 1; i++)
- {
- Real y = (- (c - 1.0) / 2 + 0.5 + i) * staff_space;
- Stencil d (dot);
-
- d.translate_axis (y, Y_AXIS);
- m.add_stencil (d);
- }
+ if (Grob *staff = Staff_symbol_referencer::get_staff_symbol (me))
+ {
+ Interval staff_extent = staff->extent (staff, Y_AXIS);
+
+ /*
+ assume staff lines are disposed equally at unit space;
+ put a dot into each space within extent (may extend staff_extent).
+
+ staff_extent is an interval of two integers or two half-integers;
+ in the former case dots are to be placed at half-integers,
+ in the latter at integers.
+
+ these integers are not exact due to staff line thickness.
+ */
+ int const pos = int (rint (staff_extent.at (UP) * 2));
+ Real const correction = pos & 1 ? 0.0 : 0.5;
+
+ for (int i = int (rint (extent.at (DOWN) + (0.5 - correction))),
+ e = int (rint (extent.at (UP) + (0.5 - correction)));
+ i < e;
+ ++i)
+ {
+ Stencil d (dot);
+
+ d.translate_axis (i + correction, Y_AXIS);
+ m.add_stencil (d);
+ }
+ }
- for (int i = (count-1); i >= -(count-1); i -= 2)
- {
- Real top_y = min ((i + dash_size) * half_space,
- (count-1) * half_space + line_thick / 2);
- Real bot_y = max ((i - dash_size) * half_space,
- -(count-1) * half_space - line_thick/2);
-
- bar.add_stencil (Lookup::round_filled_box (Box (Interval (0, thick),
- Interval (bot_y, top_y)),
- blot));
- }
+ for (int i = 0; i <= dashes; ++i)
+ {
+ Real top_y = extent.at (DOWN)
+ + (i == dashes ? h : (i + half_dash) * ss);
+ Real bot_y = extent.at (DOWN) + (i ? (i - half_dash) * ss : 0.0);
+
+ bar.add_stencil (Lookup::round_filled_box (Box (Interval (0, thick),
+ Interval (bot_y, top_y)),
+ blot));
+ }
- "Bar line.\n"
- "\n"
- "Print a special bar symbol. It replaces the regular bar"
- " symbol with a special symbol. The argument @var{bartype}"
- " is a string which specifies the kind of bar line to print."
- " Options are @code{|}, @code{:|}, @code{|:}, @code{:|:}, @code{:|.|:},"
- " @code{:|.:}, @code{.}, @code{||}, @code{|.}, @code{.|}, @code{.|.},"
- " @code{|.|}, @code{:}, @code{dashed}, @code{'} and @code{S}.\n"
- "\n"
- "These produce, respectively, a normal bar line, a right repeat, a left repeat,"
- " a thick double repeat, a thin-thick-thin double repeat,"
- " a thin-thick double repeat, a thick bar, a double bar, a start bar,"
- " an end bar, a thick double bar, a thin-thick-thin bar,"
- " a dotted bar, a dashed bar, a tick as bar line and a segno bar.\n"
- "\n"
- "In addition, there is an option"
- " @code{||:} which is equivalent to @code{|:} except at line"
- " breaks, where it produces a double bar (@code{||}) at the"
- " end of the line and a repeat sign (@code{|:}) at the"
- " beginning of the new line.\n"
- "\n"
- "For segno, @code{S} produces a segno sign except at line breaks,"
- " where it produces a double bar (@code{||}) at the"
- " end of the line and a segno sign at the beginning of the new line."
- " @code{|S} is equivalent to @code{S} but produces a simple bar line"
- " (@code{|}) instead of a double bar line (@code{||}) at line breaks."
- " @code{S|} produces the segno sign at line breaks and starts the following"
- " line without special bar lines.\n"
- "\n"
- "@code{S|:} and @code{:|S} are used for repeat/segno combinations that are"
- " separated at line breaks. Alternatively, @code{.S|:} and @code{:|S.}"
- " may be used which combine repeat signs and segno at the same line in"
- " case of a line break. @code{:|S|:} is a combination of a left repeat"
- " (@code{:|}), a segno (@code{S}) and a right repeat @code{|:} which"
- " splits before the segno at line breaks; @code{:|S.|:} splits after"
- " the segno sign.\n"
- "\n"
- "If @var{bartype} is set to @code{empty} then nothing is"
- " printed, but a line break is allowed at that spot.\n"
- "\n"
- "@code{gap} is used for the gaps in dashed bar lines.",
-
- /* properties */
- "allow-span-bar "
- "gap "
- "kern "
- "thin-kern "
- "hair-thickness "
- "thick-thickness "
- "glyph "
- "glyph-name "
- "bar-size "
- "bar-extent "
- );
+ "Bar line.\n"
+ "\n"
+ "Print a special bar symbol. It replaces the regular bar"
+ " symbol with a special symbol. The argument @var{bartype}"
+ " is a string which specifies the kind of bar line to print."
+ " Options are @code{|}, @code{:|}, @code{|:}, @code{:|:}, @code{:|.|:},"
+ " @code{:|.:}, @code{.}, @code{||}, @code{|.}, @code{.|}, @code{.|.},"
+ " @code{|.|}, @code{:}, @code{dashed}, @code{'} and @code{S}.\n"
+ "\n"
+ "These produce, respectively, a normal bar line, a right repeat, a left repeat,"
+ " a thick double repeat, a thin-thick-thin double repeat,"
+ " a thin-thick double repeat, a thick bar, a double bar, a start bar,"
+ " an end bar, a thick double bar, a thin-thick-thin bar,"
+ " a dotted bar, a dashed bar, a tick as bar line and a segno bar.\n"
+ "\n"
+ "In addition, there is an option"
+ " @code{||:} which is equivalent to @code{|:} except at line"
+ " breaks, where it produces a double bar (@code{||}) at the"
+ " end of the line and a repeat sign (@code{|:}) at the"
+ " beginning of the new line.\n"
+ "\n"
+ "For segno, @code{S} produces a segno sign except at line breaks,"
+ " where it produces a double bar (@code{||}) at the"
+ " end of the line and a segno sign at the beginning of the new line."
+ " @code{|S} is equivalent to @code{S} but produces a simple bar line"
+ " (@code{|}) instead of a double bar line (@code{||}) at line breaks."
+ " @code{S|} produces the segno sign at line breaks and starts the following"
+ " line without special bar lines.\n"
+ "\n"
+ "@code{S|:} and @code{:|S} are used for repeat/segno combinations that are"
+ " separated at line breaks. Alternatively, @code{.S|:} and @code{:|S.}"
+ " may be used which combine repeat signs and segno at the same line in"
+ " case of a line break. @code{:|S|:} is a combination of a left repeat"
+ " (@code{:|}), a segno (@code{S}) and a right repeat @code{|:} which"
+ " splits before the segno at line breaks; @code{:|S.|:} splits after"
+ " the segno sign.\n"
+ "\n"
+ "If @var{bartype} is set to @code{empty} then nothing is"
+ " printed, but a line break is allowed at that spot.\n"
+ "\n"
+ "@code{gap} is used for the gaps in dashed bar lines.",
+
+ /* properties */
+ "allow-span-bar "
+ "gap "
+ "kern "
+ "thin-kern "
+ "hair-thickness "
+ "has-span-bar "
+ "thick-thickness "
+ "glyph "
+ "glyph-name "
+ "bar-extent "
+ );