]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hyphen-spanner.cc
release: 1.5.28
[lilypond.git] / lily / hyphen-spanner.cc
index 433a107ba6ae989e1a538147260c474053b20d8b..6b42b5b5547e175a953f47b0bb3bd13244810f41 100644 (file)
@@ -24,7 +24,7 @@ MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
 SCM 
 Hyphen_spanner::brew_molecule (SCM smob)
 {
-  Spanner * sp = dynamic_cast<Spanner*> (unsmob_grob (smob));
+  Spanner * sp = unsmob_spanner (smob);
 
   Grob * common = sp;
   Direction d = LEFT;
@@ -37,25 +37,42 @@ Hyphen_spanner::brew_molecule (SCM smob)
   
   do
     {
-      bounds[d] = sp->get_bound (d)->extent (common, X_AXIS)[-d];
+      Interval iv = sp->get_bound (d)->extent (common, X_AXIS);
+
+      bounds[d] = iv.empty_b ()
+       ? sp->get_bound (d)->relative_coordinate (common, X_AXIS)
+       : iv[-d];
     }
   while (flip (&d) != LEFT);
   
   Real lt = sp->paper_l ()->get_var ("stafflinethickness");
   Real th = gh_scm2double (sp->get_grob_property ("thickness")) * lt ;
   Real h = gh_scm2double (sp->get_grob_property ("height"));
+
+  // interval?
   Real l = gh_scm2double (sp->get_grob_property ("minimum-length"));  
+  Real x = gh_scm2double (sp->get_grob_property ("maximum-length"));
   // The hyphen can exist in the word space of the left lyric ...
   SCM space =  sp->get_bound (LEFT)->get_grob_property ("word-space");
   if (gh_number_p (space))
     {
       bounds[LEFT] -=  gh_scm2double (space);
     }
-  Real w  = bounds.length ();
+
+  /*
+    we should probably do something more intelligent when bounds is
+    empty, but at least this doesn't crash.
+  */      
+  Real w  = bounds.empty_b () ? 0 : bounds.length ();
+  
   /* for length, use a geometric mean of the available space and some minimum
-  */
+   */
   if (l < w)
-    l = sqrt (l*w);
+    {
+      l = sqrt (l*w);
+      if (l > x)
+       l = x;
+    }
   else
     {
       /* OK, we have a problem. Usually this means that we're on the
@@ -80,9 +97,8 @@ Hyphen_spanner::brew_molecule (SCM smob)
     }
   Box b (Interval (-l/2,l/2), Interval (h,h+th));
   Molecule mol (Lookup::filledbox (b));
-  mol.translate_axis (bounds.center ()
-                     -sp->relative_coordinate (common, X_AXIS),
-                     X_AXIS);
+  Real ct = bounds.empty_b () ? 0 : bounds.center () ;
+  mol.translate_axis (ct -sp->relative_coordinate (common, X_AXIS), X_AXIS);
   return mol.smobbed_copy ();
 }