]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hyphen-spanner.cc
2003 -> 2004
[lilypond.git] / lily / hyphen-spanner.cc
index eb64b7d13469e21e7c19bc1ce8b0254172f771ed..09699d7546cf4c55676f86ac1b0429f2351684bf 100644 (file)
@@ -3,9 +3,9 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1999 Glen Prideaux <glenprideaux@iname.com>
+  (c) 1999--2004 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);
+  Drul_array<Item*> bounds (sp->get_bound (LEFT),
+                           sp->get_bound (RIGHT));
+  
+  Grob * common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
 
-  Score_element * common = sp;
+  Interval span_points;
   Direction d = LEFT;
   do
     {
-      common = common->common_refpoint( sp->get_bound (d), X_AXIS);
+      Interval iv = bounds[d]->extent (common, X_AXIS);
+
+      span_points[d] = iv.is_empty ()
+       ? bounds[d]->relative_coordinate (common, X_AXIS)
+       : iv[-d];
     }
   while (flip (&d) != LEFT);
-  Interval bounds;
   
-  do
-    {
-      Real  x = sp->get_bound (d)->relative_coordinate (common, X_AXIS);
-      Interval ext =  sp->get_bound (d)->extent (X_AXIS);
-      bounds[d] = (x + ext[-d]);
-    }
-  while (flip (&d) != LEFT);
+  Real lt = sp->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
+  Real th = robust_scm2double (sp->get_grob_property ("thickness"), 1) * lt ;
+  Real h = robust_scm2double (sp->get_grob_property ("height"), 0.5);
 
+  // interval?
   
+  Real dp = robust_scm2double (sp->get_grob_property ("dash-period"), 1.0);
+  Real dl = robust_scm2double (sp->get_grob_property ("length"), .5 );
+
+  if (dp < dl)
+    dp = 1.5 * dl;
+
+  Real l = span_points.length ();
+  int n = int (ceil (l/dp - 0.5));
+  if (n <= 0)
+    n = 1;
+
+  Real space_left = l - dl - (n-1)* dp;
+
+  /*
+    If there is not enough space, the hyphen should disappear.
+   */
+  if (space_left < 0)
+    return SCM_EOL;
   
-  Real ss = sp->paper_l ()->get_var ("staffspace");
-  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")) * ss;
-  Real l = gh_scm2double (sp->get_elt_property ("minimum-length")) * ss;  
-  // The hyphen can exist in the word space of the left lyric ...
-  SCM space =  sp->get_bound (LEFT)->get_elt_property ("word-space");
-  if (gh_number_p (space))
-    {
-      bounds[LEFT] -=  gh_scm2double (space)*ss;
-    }
-  Real w  = bounds.length ();
-  /* for length, use a geometric mean of the available space and some minimum
-  */
-  if(l < w)
-    l = sqrt(l*w);
-  else
+  Box b (Interval (0, dl), Interval (h,h+th));
+  Molecule dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
+
+  Molecule total;
+  for (int i = 0; i < n; i++)
     {
-      /* OK, we have a problem. Usually this means that we're on the
-         first column, and we have a long lyric which extends to near
-         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());
-      if (sc != NULL &&
-         sc->break_status_dir () == RIGHT)
-       {
-         /* We are on the first column, so it's probably harmless to
-             get the minimum length back by extending leftwards into
-             the space under the clef/key sig/time sig */
-         bounds[LEFT] = bounds[RIGHT] - l;
-       }
-      else 
-       {
-         /* We can't get the length desired. Maybe we should warn. */
-         l = w;
-       }
+      Molecule m (dash_mol);
+      m.translate_axis (span_points[LEFT] + i * dp + space_left / 2, X_AXIS);
+      total.add_molecule (m);
     }
-  Box b  (Interval (-l/2,l/2), Interval (h,h+th));
-  Molecule mol (sp->lookup_l ()->filledbox (b));
-  mol.translate_axis (bounds.center ()
-                     -sp->relative_coordinate (common, X_AXIS),
-                     X_AXIS);
-  return mol.create_scheme ();
-}
-  
-void
-Hyphen_spanner::set_textitem (Direction d, Score_element* b)
-{
-  elt_l_->set_bound (d, b);
-  elt_l_->add_dependency (b);
-}
 
-Hyphen_spanner::Hyphen_spanner (Spanner*s)
-{
-  elt_l_ = s;
+  total.translate_axis ( -sp->relative_coordinate (common, X_AXIS), X_AXIS);
+  return total.smobbed_copy ();
 }
 
+
+ADD_INTERFACE (Hyphen_spanner, "lyric-hyphen-interface",
+              "A centred hyphen is a simple line between lyrics used to divide syllables",
+              "thickness height dash-period length");
+
+