]> git.donarmstrong.com Git - lilypond.git/commitdiff
prevent collision of mensural ligature and next grob
authorBenkő Pál <benko.pal@gmail.com>
Tue, 23 Oct 2012 18:12:56 +0000 (20:12 +0200)
committerDavid Kastrup <dak@gnu.org>
Tue, 30 Oct 2012 08:08:30 +0000 (09:08 +0100)
compute the actual X extent of a mensural ligature and
create a rod of that length through the minimum-length property
and the set-spacing-rods mechanism

lily/mensural-ligature-engraver.cc
scm/define-grobs.scm

index 62799ec55c663aa99c13408e4b2a7c1e9053b7bf..8f70fa4e487a0a84d1b0d436e0d8e77851269409 100644 (file)
@@ -67,8 +67,10 @@ public:
 private:
   void transform_heads (vector<Grob_info> const &primitives);
   void propagate_properties (Spanner *ligature,
-                             vector<Grob_info> const &primitives);
-  void fold_up_primitives (vector<Grob_info> const &primitives);
+                             vector<Grob_info> const &primitives,
+                             Real &min_length);
+  void fold_up_primitives (vector<Grob_info> const &primitives,
+                           Real &min_length);
 };
 
 IMPLEMENT_TRANSLATOR_LISTENER (Mensural_ligature_engraver, ligature);
@@ -338,7 +340,8 @@ Mensural_ligature_engraver::transform_heads (vector<Grob_info> const &primitives
  */
 void
 Mensural_ligature_engraver::propagate_properties (Spanner *ligature,
-                                                  vector<Grob_info> const &primitives)
+                                                  vector<Grob_info> const &primitives,
+                                                  Real &min_length)
 {
   Real thickness
     = robust_scm2double (ligature->get_property ("thickness"), 1.3);
@@ -352,6 +355,7 @@ Mensural_ligature_engraver::propagate_properties (Spanner *ligature,
     = Font_interface::get_default_font (ligature)->
       find_by_name ("noteheads.sM3ligmensural").extent (X_AXIS).length ();
 
+  min_length = 0.0;
   Item *prev_primitive = NULL;
   for (vsize i = 0; i < primitives.size (); i++)
     {
@@ -364,9 +368,11 @@ Mensural_ligature_engraver::propagate_properties (Spanner *ligature,
         {
         case MLP_BREVIS:
         case MLP_LONGA:
+          min_length += head_width;
           primitive->set_property ("head-width", scm_from_double (head_width));
           break;
         case MLP_MAXIMA:
+          min_length += maxima_head_width;
           primitive->set_property ("head-width",
                                    scm_from_double (maxima_head_width));
           break;
@@ -379,6 +385,7 @@ Mensural_ligature_engraver::propagate_properties (Spanner *ligature,
           {
             SCM flexa_scm = primitive->get_property ("flexa-width");
             Real const flexa_width = robust_scm2double (flexa_scm, 2.0);
+            min_length += flexa_width + thickness;
             SCM head_width = scm_from_double (0.5 * (flexa_width + thickness));
             primitive->set_property ("head-width", head_width);
             prev_primitive->set_property ("head-width", head_width);
@@ -395,7 +402,8 @@ Mensural_ligature_engraver::propagate_properties (Spanner *ligature,
 }
 
 void
-Mensural_ligature_engraver::fold_up_primitives (vector<Grob_info> const &primitives)
+Mensural_ligature_engraver::fold_up_primitives (vector<Grob_info> const &primitives,
+                                                Real &min_length)
 {
   Item *first = 0;
   Real distance = 0.0;
@@ -418,7 +426,7 @@ Mensural_ligature_engraver::fold_up_primitives (vector<Grob_info> const &primiti
       Real head_width = scm_to_double (current->get_property ("head-width"));
       distance += head_width - thickness;
 
-      if (Rhythmic_head::dot_count (current) > 0)
+      if (size_t const dot_count = Rhythmic_head::dot_count (current))
         /*
           Move dots above/behind the ligature.
           dots should also avoid staff lines.
@@ -454,6 +462,8 @@ Mensural_ligature_engraver::fold_up_primitives (vector<Grob_info> const &primiti
               else if (delta == 1 || delta == -1)
                 vert_shift -= delta * staff_space;
             }
+          else
+            min_length += head_width * dot_count;
 
           dot_gr->translate_axis (vert_shift, Y_AXIS);
 
@@ -470,9 +480,19 @@ void
 Mensural_ligature_engraver::build_ligature (Spanner *ligature,
                                             vector<Grob_info> const &primitives)
 {
+  /*
+    the X extent of the actual graphics representing the ligature;
+    less space than that means collision
+  */
+  Real min_length;
+
   transform_heads (primitives);
-  propagate_properties (ligature, primitives);
-  fold_up_primitives (primitives);
+  propagate_properties (ligature, primitives, min_length);
+  fold_up_primitives (primitives, min_length);
+
+  if (robust_scm2double (ligature->get_property ("minimum-length"), 0.0)
+      < min_length)
+    ligature->set_property ("minimum-length", scm_from_double (min_length));
 }
 
 ADD_ACKNOWLEDGER (Mensural_ligature_engraver, rest);
index 28bc6d04d4199d2f0528b3b5ecce554f7ff93f68..1ebd9c34e88263d05d7b92dccb541b848e62d332 100644 (file)
 
     (MensuralLigature
      . (
+       (springs-and-rods . ,ly:spanner::set-spacing-rods)
        (stencil . ,ly:mensural-ligature::print)
        (thickness . 1.3)
        (meta . ((class . Spanner)