]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hyphen-spanner.cc
po-replace
[lilypond.git] / lily / hyphen-spanner.cc
index aa0673eb71d854b6d808ec5c3b694a291bcb7edc..8231c4b2a6390c56e3a40fca444ee88d99bb57a7 100644 (file)
@@ -5,7 +5,7 @@
 
   (c) 1999 Glen Prideaux <glenprideaux@iname.com>
 
 (adapted from lyric-extender)
+ (adapted from lyric-extender)
 */
 
 #include <math.h>
 #include "spanner.hh"
 #include "item.hh"
 
-MAKE_SCHEME_CALLBACK(Hyphen_spanner,brew_molecule,1)
+MAKE_SCHEME_CALLBACK (Hyphen_spanner,brew_molecule,1)
 
 SCM 
 Hyphen_spanner::brew_molecule (SCM smob)
 {
-  Spanner * sp = dynamic_cast<Spanner*> (unsmob_element (smob));
+  Spanner * sp = unsmob_spanner (smob);
 
-  Score_element * common = sp;
+  Grob * common = sp;
   Direction d = LEFT;
   do
     {
-      common = common->common_refpointsp->get_bound (d), X_AXIS);
+      common = common->common_refpoint (sp->get_bound (d), X_AXIS);
     }
   while (flip (&d) != LEFT);
   Interval bounds;
   
   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_elt_property ("thickness")) * lt ;
-  Real h = gh_scm2double (sp->get_elt_property ("height"));
-  Real l = gh_scm2double (sp->get_elt_property ("minimum-length"));  
+  Real lt = sp->paper_l ()->get_var ("linethickness");
+  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_elt_property ("word-space");
+  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);
+   */
+  if (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
@@ -63,7 +80,7 @@ Hyphen_spanner::brew_molecule (SCM smob)
          the offset for stuff */
       /* This test for being on the first column has been shamelessly
          ripped from spanner.cc */
-      Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound(LEFT)->column_l());
+      Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound (LEFT)->column_l ());
       if (sc != NULL &&
          sc->break_status_dir () == RIGHT)
        {
@@ -78,16 +95,15 @@ Hyphen_spanner::brew_molecule (SCM smob)
          l = w;
        }
     }
-  Box b  (Interval (-l/2,l/2), Interval (h,h+th));
+  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 ();
 }
   
 void
-Hyphen_spanner::set_textitem (Direction d, Score_element* b)
+Hyphen_spanner::set_textitem (Direction d, Grob* b)
 {
   elt_l_->set_bound (d, b);
   elt_l_->add_dependency (b);
@@ -98,3 +114,11 @@ Hyphen_spanner::Hyphen_spanner (Spanner*s)
   elt_l_ = s;
 }
 
+
+
+ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
+  "A centred hyphen is a simple line between lyrics used to divide
+syllables.   The length of the hyphen line should stretch based on the
+size of the gap between syllables.",
+  "thickness height minimum-length maximum-length word-space");
+