]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/self-alignment-interface.cc
Issue 2245: always align dynamics and lyrics on "main" notehead
[lilypond.git] / lily / self-alignment-interface.cc
index 54d4a8ec6f5635e4cf0c1112022510a7261f0ea0..664a111642362ba1174d1715ded14a1a134d65db 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2004--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 2004--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -79,27 +79,6 @@ Self_alignment_interface::centered_on_x_parent (SCM smob)
   return centered_on_object (unsmob_grob (smob)->get_parent (X_AXIS), X_AXIS);
 }
 
-MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_note_columns, 1);
-SCM
-Self_alignment_interface::centered_on_note_columns (SCM smob)
-{
-  Item *it = unsmob_item (smob)->get_column ();
-  if (!it)
-    return scm_from_double (0.0);
-
-  extract_grob_set (it, "elements", elts);
-  vector<Grob *> ncs;
-  Interval centers;
-  for (vsize i = 0; i < elts.size (); i++)
-    if (Note_column::has_interface (elts[i]))
-      centers.add_point (scm_to_double (centered_on_object (elts[i], X_AXIS)));
-
-  if (centers.is_empty ())
-    return scm_from_double (0.0);
-
-  return scm_from_double (centers.center ());
-}
-
 MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_y_parent, 1);
 SCM
 Self_alignment_interface::centered_on_y_parent (SCM smob)
@@ -107,13 +86,6 @@ Self_alignment_interface::centered_on_y_parent (SCM smob)
   return centered_on_object (unsmob_grob (smob)->get_parent (Y_AXIS), Y_AXIS);
 }
 
-MAKE_SCHEME_CALLBACK (Self_alignment_interface, x_centered_on_y_parent, 1);
-SCM
-Self_alignment_interface::x_centered_on_y_parent (SCM smob)
-{
-  return centered_on_object (unsmob_grob (smob)->get_parent (Y_AXIS), X_AXIS);
-}
-
 MAKE_SCHEME_CALLBACK (Self_alignment_interface, aligned_on_x_parent, 1);
 SCM
 Self_alignment_interface::aligned_on_x_parent (SCM smob)
@@ -132,10 +104,23 @@ SCM
 Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
 {
   Grob *him = me->get_parent (a);
+  Interval he;
   if (Paper_column::has_interface (him))
-    return scm_from_double (0.0);
-
-  Interval he = him->extent (him, a);
+      /*
+        PaperColumn extents aren't reliable (they depend on size and alignment
+        of PaperColumn's children), so we align on NoteColumn instead.
+        This happens e.g. for lyrics without associatedVoice.
+      */
+    he = Paper_column::get_interface_extent
+              (him, ly_symbol2scm ("note-column-interface"), a);
+  else
+    {
+      if (ly_scm2bool(me->internal_get_property (ly_symbol2scm ("X-align-on-main-noteheads")))
+          && Note_column::has_interface (him))
+        he = Note_column::calc_main_heads_extent(him);
+      else
+        he = him->extent (him, a);
+    }
 
   SCM sym = (a == X_AXIS) ? ly_symbol2scm ("self-alignment-X")
             : ly_symbol2scm ("self-alignment-Y");
@@ -166,18 +151,10 @@ Self_alignment_interface::aligned_on_parent (Grob *me, Axis a)
 }
 
 void
-Self_alignment_interface::set_center_parent (Grob *me, Axis a)
-{
-  add_offset_callback (me,
-                       (a == X_AXIS) ? centered_on_x_parent_proc : centered_on_y_parent_proc,
-                       a);
-}
-
-void
-Self_alignment_interface::set_align_self (Grob *me, Axis a)
+Self_alignment_interface::set_aligned_on_parent (Grob *me, Axis a)
 {
   add_offset_callback (me,
-                       (a == X_AXIS) ? x_aligned_on_self_proc : y_aligned_on_self_proc,
+                       (a == X_AXIS) ? aligned_on_x_parent_proc : aligned_on_y_parent_proc,
                        a);
 }
 
@@ -198,4 +175,5 @@ ADD_INTERFACE (Self_alignment_interface,
                /* properties */
                "self-alignment-X "
                "self-alignment-Y "
+               "X-align-on-main-noteheads "
               );