]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/text-spanner.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / text-spanner.cc
index 127de061a356e6d738e68920da7d5d3249ccfab4..8a7efdc6d3b46f7cdb6f25516da3aa0d7aed5ce9 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  text-spanner.cc -- implement Text_spanner
+text-spanner.cc -- implement Text_spanner
 
-  source file of the GNU LilyPond music typesetter
+source file of the GNU LilyPond music typesetter
 
-  (c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
+(c) 2000--2002 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "molecule.hh"
 #include "font-interface.hh"
 #include "dimensions.hh"
 #include "paper-def.hh"
-#include "debug.hh"
+#include "warn.hh"
 #include "paper-column.hh"
 #include "staff-symbol-referencer.hh"
 
 /*
   TODO:
-    - vertical start / vertical end (fixme-name) |
-    - contination types (vert. star, vert. end)  |-> eat volta-spanner
-    - more styles
-    - more texts/positions
- */
+  - vertical start / vertical end (fixme-name) |
+  - contination types (vert. star, vert. end)  |-> eat volta-bracket
+  - more styles
+  - more texts/positions
+*/
 
 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
 
+/*
+  TODO: this function is too long, too hairy.
+
+  TODO: document this. What the heck is happening here?
+*/
 SCM
 Text_spanner::brew_molecule (SCM smob) 
 {
   Grob *me= unsmob_grob (smob);
   Spanner *spanner = dynamic_cast<Spanner*> (me);
-
-  if (spanner->has_interface (ly_symbol2scm ("piano-pedal-interface")) ) 
+  
+  if (spanner->internal_has_interface (ly_symbol2scm ("piano-pedal-interface")))
     {
       setup_pedal_bracket(spanner);
     }
 
-
   /* Ugh, must be same as Hairpin::brew_molecule.  */
   Real padding = gh_scm2double (me->get_grob_property ("if-text-padding"));
   Real broken_left =  spanner->get_broken_left_end_align ();
@@ -63,10 +67,10 @@ Text_spanner::brew_molecule (SCM smob)
          Real r = 0.0;
          if (!e.empty_b ())
            r = e[-d] + padding;
+
          /* Text spanners such as ottava, should span from outer limits of
-          noteheads, iso (de)cresc. spanners that span the inner space */
+            noteheads, iso (de)cresc. spanners that span the inner space */
          if (me->get_grob_property ("outer") != SCM_EOL)
-           // r *= -1; // huh?
            {
              width -= d * r;
            }
@@ -83,6 +87,7 @@ Text_spanner::brew_molecule (SCM smob)
   width += gh_scm2double (me->get_grob_property ("width-correct"));
   /* /Ugh */
 
+  // who is ecs? --hwn
 
   SCM properties = Font_interface::font_alist_chain (me);
 
@@ -96,7 +101,7 @@ Text_spanner::brew_molecule (SCM smob)
          /*  Don't repeat edge text for broken end */
          if (!broken[d])
            {
-             SCM text = index_cell (edge_text, d);
+             SCM text = index_get_cell (edge_text, d);
              edge[d] = Text_item::text2molecule (me, text, properties);
              if (!edge[d].empty_b ())
                edge[d].align_to (Y_AXIS, CENTER);
@@ -127,13 +132,19 @@ Text_spanner::brew_molecule (SCM smob)
     }
 
   /* ugh */
-  Real thick = me->paper_l ()->get_var ("stafflinethickness");  
   
-  Molecule line = Line_spanner::line_molecule (me, width, 0);
+  Real thick = me->get_paper ()->get_var ("linethickness");  
+  SCM st = me->get_grob_property ("thickness");
+  if (gh_number_p (st))
+    {
+      thick *=  gh_scm2double (st);
+
+    }
+  Molecule line = Line_spanner::line_molecule (me, thick, width, 0);
   
   Drul_array<Molecule> edge_line;
   s = me->get_grob_property ("edge-height");
-  SCM ew = me->get_grob_property ("edge-width");
+  SCM ew = me->get_grob_property ("edge-widen");
   if (gh_pair_p (s))
     {
       Direction d = LEFT;
@@ -141,17 +152,12 @@ Text_spanner::brew_molecule (SCM smob)
       do
        {
          Real dx = ( gh_pair_p (ew)  ? 
-                     gh_scm2double (index_cell (ew, d)) * - dir  :  
+                     gh_scm2double (index_get_cell (ew, d)) * d :  
                      0 );
-         Real dy = gh_scm2double (index_cell (s, d)) * - dir;
+         Real dy = gh_scm2double (index_get_cell (s, d)) * - dir;
          if (dy)
            {
-             SCM list = Line_spanner::line_atom (me, dx, dy);
-             Box b (Interval (-thick, 0),
-                    dy > 0
-                    ? Interval (0, dy)
-                    : Interval (dy, 0));
-             edge_line[d] = Molecule (b, list);
+             edge_line[d] = Line_spanner::line_molecule (me, thick, dx, dy);
            }
        }
       while (flip (&d) != LEFT);
@@ -164,9 +170,10 @@ Text_spanner::brew_molecule (SCM smob)
   if (!edge_line[LEFT].empty_b ())
     m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
   if (!line.empty_b ())
-    m.add_at_edge (X_AXIS, RIGHT, line, 0);
+    m.add_at_edge (X_AXIS, RIGHT, line,
+                  edge_line[LEFT].empty_b () ? 0 : -thick/2);
   if (!edge_line[RIGHT].empty_b ())
-    m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], 0);
+    m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], -thick/2);
   if (!edge[RIGHT].empty_b ())
     m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
   m.translate_axis (broken_left + extra_off[LEFT] + shorten[LEFT], X_AXIS);
@@ -176,105 +183,115 @@ Text_spanner::brew_molecule (SCM smob)
 
 
 
+
 /* 
    Piano pedal brackets are a special case of a text spanner.
    Pedal up-down (restart) indicated by the angled right and left edges 
    of consecutive pedals touching exactly to form an __/\__
    Chris Jackson <chris@fluffhouse.org.uk>
-
-   TODO: Pedal line extending to the end of the note
 */
 
 void 
-Text_spanner::setup_pedal_bracket(Spanner *s)
+Text_spanner::setup_pedal_bracket(Spanner *me)
 {
 
-  Real thick = s->paper_l ()->get_var ("stafflinethickness");  
-  Real ss = Staff_symbol_referencer::staff_space (s);
+  Real thick = me->get_paper ()->get_var ("linethickness");  
+  SCM st = me->get_grob_property ("thickness");
+  if (gh_number_p (st))
+    {
+      thick *=  gh_scm2double (st);
+    }  
 
-  Drul_array<bool> a, broken;
+  Drul_array<bool> broken;
   Drul_array<Real> height, width, shorten, r;
 
-  // Pedal has an angled left edge \__  or an angled right edge __/ 
-  a[LEFT] = a[RIGHT] = false;
-  SCM al = s->get_grob_property ("angle-left");
-  SCM ar = s->get_grob_property ("angle-right");
-  if (gh_boolean_p (al) )  
-    a[LEFT]   = to_boolean (al);
-  if (gh_boolean_p (ar) )  
-    a[RIGHT]  = to_boolean (ar);
-  
-  height[LEFT] = ( to_boolean (s->get_grob_property ("text-start")) ?
-                  0 :
-                  ss );
-  height[RIGHT] = ss;
+  SCM pa = me->get_grob_property ("if-text-padding");
+  SCM ew = me->get_grob_property ("edge-widen");
+  SCM eh = me->get_grob_property ("edge-height");
+  SCM sp = me->get_grob_property ("shorten-pair");
   
   Direction d = LEFT;
   Interval e;
   Real padding = 0;
-  SCM pa = (s->get_grob_property ("if-text-padding"));
+
   if (gh_number_p (pa) )
     padding = gh_scm2double (pa);
-  do {
-    Item *b = s->get_bound (d);
 
-    e = b->extent (b, X_AXIS);
-    if (!e.empty_b ())
-      r[d] = d * (e[-d] + padding);
+  do
+    {
+      Item *b = me->get_bound (d);
 
-    broken[d] = b->break_status_dir () != CENTER;
-    width[d]  = (a[d]  ? ss*d/2 :  0);
-    if (broken[d])
+      e = b->extent (b, X_AXIS);
+      if (!e.empty_b ())
+       r[d] = d * (e[-d] + padding);
+
+      broken[d] = b->break_status_dir () != CENTER;
+      width[d]  =  0;
       height[d] =  0;
-  }
+      shorten[d] = 0;
+      if ( ly_number_pair_p (ew) )
+       width[d] +=  gh_scm2double (index_get_cell (ew, d));
+      if ( !broken[d] && (ly_number_pair_p (eh) ) )
+       height[d] += gh_scm2double (index_get_cell (eh, d));
+      if ( ly_number_pair_p (sp) )
+       shorten[d] +=  gh_scm2double (index_get_cell (sp, d));
+    }
   while (flip (&d) != LEFT);
   
-  shorten[RIGHT] =  shorten[LEFT]  =  0;
   Real extra_short = 0;
   // For 'Mixed' style pedals, i.e.  a bracket preceded by text:  Ped._____|
   // need to shorten by the extent of the text grob
-  if ( to_boolean (s->get_grob_property ("text-start")) )
+  if ( to_boolean (me->get_grob_property ("text-start")) )
     {
-      Grob * textbit = s->get_parent(Y_AXIS);
+      height[LEFT] = 0;
       extra_short = padding;
-      if (textbit->has_interface(ly_symbol2scm("piano-pedal-interface")))
-       // for pretty Ped. scripts. 
-       {
-         e = textbit->extent(textbit, Y_AXIS);
-         extra_short += e.length();
-       }
-      if (textbit->has_interface(ly_symbol2scm("text-interface"))) 
-       // for plain text, e.g., Sost. Ped.
+      if (Grob *textbit = unsmob_grob (me->get_grob_property("pedal-text")))
        {
-         SCM text  =  textbit->get_grob_property("text"); 
-         if (gh_string_p (text)) {
-           SCM properties = Font_interface::font_alist_chain (s);
-           Molecule mol = Text_item::text2molecule (s, text, properties);
-           extra_short += mol.extent(X_AXIS).length() / 2;
-         }
+         if (textbit->internal_has_interface(ly_symbol2scm("text-interface")))
+           // for plain text, e.g., Sost. Ped.
+           {
+             SCM text  =  textbit->get_grob_property("text"); 
+             if (gh_string_p (text)) {
+               SCM properties = Font_interface::font_alist_chain (me);
+               Molecule mol = Text_item::text2molecule (me, text, properties);
+               extra_short += mol.extent(X_AXIS).length() / 2;
+             }
+           }
        }
       shorten[RIGHT] -= thick;
     }
 
-  // Shorten a \____ on the left so that it will touch an adjoining ___/ 
-  shorten[LEFT] += abs(width[LEFT]) * 2   +  extra_short ;
+  shorten[LEFT] += extra_short ;
   
-  if (broken[LEFT]) {
-    shorten[LEFT] -= s->get_broken_left_end_align () ;
-    shorten[RIGHT] -= r[RIGHT];
-  }
-  else 
-    // Shorten bracket on the right so it ends just before the spanned note.
-    shorten[RIGHT]  +=  thick  -  (r[LEFT]  +  r[RIGHT]);
-
-  // Hmm. TODO: This should be set in grob-description.scm, but side-positioning
-  // of consecutive brackets only seems to work if direction is +1 within the engraver. 
-  s->set_grob_property ("direction", gh_int2scm(-1)); 
-
-  s->set_grob_property ("edge-height", gh_cons ( gh_double2scm ( height[LEFT] ) , 
-                                                gh_double2scm ( height[RIGHT]) ) );
-  s->set_grob_property ("edge-width",  gh_cons ( gh_double2scm ( width[LEFT]  ), 
-                                                gh_double2scm ( width[RIGHT] ) ));
-  s->set_grob_property ("shorten-pair", gh_cons ( gh_double2scm ( shorten[LEFT] ), 
-                                            gh_double2scm ( shorten[RIGHT] ) ));
+  if (broken[LEFT])
+    {
+      shorten[LEFT]  -=  me->get_broken_left_end_align () ;
+      shorten[RIGHT]  +=  abs(width[RIGHT])  +  thick  -  r[RIGHT];
+    }
+
+  else
+    {
+      // Shorten a ____/ on the right so that it will touch an adjoining \___
+      shorten[RIGHT]  +=  abs(width[LEFT])  +  abs(width[RIGHT])  +  thick;
+      // Also shorten so that it ends just before the spanned note.
+      shorten[RIGHT]  -=  (r[LEFT]  +  r[RIGHT]);
+    }
+
+  me->set_grob_property ("edge-height", ly_interval2scm (height));
+  me->set_grob_property ("edge-widen",  ly_interval2scm(width));
+  me->set_grob_property ("shorten-pair", ly_interval2scm (shorten));
 }
+
+
+struct Pianopedal
+{
+  static bool has_interface (Grob*);
+};
+ADD_INTERFACE (Pianopedal,"piano-pedal-interface",
+              "",
+              "pedal-type edge-widen edge-height shorten-pair text-start left-widen right-widen pedal-text");
+
+ADD_INTERFACE (Text_spanner,"text-spanner-interface",
+              "generic text spanner",
+              "dash-period if-text-padding dash-length edge-height edge-widen edge-text shorten-pair type thickness outer width-correct");
+