lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ends of barlines are hidden in staff lines. (issue4809057)


From: lemniskata . bernoullego
Subject: Ends of barlines are hidden in staff lines. (issue4809057)
Date: Fri, 29 Jul 2011 05:15:01 +0000

Reviewers: hanwenn,

Message:

http://lists.gnu.org/archive/html/lilypond-devel/2011-07/msg01051.html
2011/7/27 Han-Wen Nienhuys <address@hidden>:

Due to rounding, PDF viewers can err
the placement of the barline by a pixel.
[so that it looks like sticking out of staff]

You can make the problem disappear by

- hard coding the output to a certain resolution
- making the bar go to the middle of the staffline,
   rather than the outside.

both have disadvantages.

This patch does the second thing.  What disadvantages do you see besides
what happens when barline and staff have different colors?

cheers,
Janek

Description:
Ends of barlines are hidden in staff lines.

Barlines are made a little shorter, so that the end of the barline
doesn't touch
the outer edge of staff line - it ends in the middle of staff line now.
This prevets artifacts in pdf viewing and printing.

Please review this at http://codereview.appspot.com/4809057/

Affected files:
  M lily/bar-line.cc
  M lily/include/staff-symbol-referencer.hh
  M lily/staff-symbol-referencer.cc


Index: lily/bar-line.cc
diff --git a/lily/bar-line.cc b/lily/bar-line.cc
index a2d6588726bb823c03075ca65dc35b663ecffaa3..64ca4d0dbd7bbb80f8c8aa87e4ec8966e2d7e58d 100644
--- a/lily/bar-line.cc
+++ b/lily/bar-line.cc
@@ -34,8 +34,22 @@ Bar_line::calc_bar_extent (SCM smob)
   Interval result;
   Grob *me = unsmob_grob (smob);
   if (Grob *staff = Staff_symbol_referencer::get_staff_symbol (me))
-    result = staff->extent (staff, Y_AXIS);
-
+    {
+      result = staff->extent (staff, Y_AXIS);
+
+ /* Due to rounding problems, barlines 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 barlines 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_symbol_referencer::color (me);
+      if (bar_line_color == staff_color)
+       result *= (1 - 0.5 * (Staff_symbol_referencer::line_thickness (me) /
+                             Staff_symbol_referencer::staff_radius (me)));
+    }
   return ly_interval2scm (result);
 }

Index: lily/include/staff-symbol-referencer.hh
diff --git a/lily/include/staff-symbol-referencer.hh b/lily/include/staff-symbol-referencer.hh index ed6156c62c78b1a1acae8423c1906d6e10cf8226..39889f2388f7a0111bad4c8d41207a5c26444641 100644
--- a/lily/include/staff-symbol-referencer.hh
+++ b/lily/include/staff-symbol-referencer.hh
@@ -40,6 +40,7 @@ public:
      typeface. ie. leading is vertical space.
   */
   static Real line_thickness (Grob *);
+  static SCM color (Grob *);
   static Real staff_space (Grob *);
   static Grob *get_staff_symbol (Grob *);
   static bool on_line (Grob *, int);
Index: lily/staff-symbol-referencer.cc
diff --git a/lily/staff-symbol-referencer.cc b/lily/staff-symbol-referencer.cc index 2939e0c0614fdb035fe5a62409c4708f7bbf03ee..fcf7c3b76a900ce0bbd33fd4e08da8f3c1fcca6c 100644
--- a/lily/staff-symbol-referencer.cc
+++ b/lily/staff-symbol-referencer.cc
@@ -63,6 +63,15 @@ Staff_symbol_referencer::staff_space (Grob *me)
   return 1.0;
 }

+SCM
+Staff_symbol_referencer::color (Grob *me)
+{
+  Grob *st = get_staff_symbol (me);
+  if (st)
+    return st->get_property ("color");
+  return ly_symbol2scm ("black");
+}
+
 Real
 Staff_symbol_referencer::line_thickness (Grob *me)
 {





reply via email to

[Prev in Thread] Current Thread [Next in Thread]