]> 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 0ff02bf2e07e1c73d9b9a2b94f52362b4fee062a..8a7efdc6d3b46f7cdb6f25516da3aa0d7aed5ce9 100644 (file)
@@ -15,7 +15,7 @@ source file of the GNU LilyPond music typesetter
 #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"
 
@@ -39,13 +39,12 @@ 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 ();
@@ -68,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 */
          if (me->get_grob_property ("outer") != SCM_EOL)
-           // r *= -1; // huh?
            {
              width -= d * r;
            }
@@ -102,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);
@@ -134,7 +133,7 @@ Text_spanner::brew_molecule (SCM smob)
 
   /* ugh */
   
-  Real thick = me->paper_l ()->get_var ("stafflinethickness");  
+  Real thick = me->get_paper ()->get_var ("linethickness");  
   SCM st = me->get_grob_property ("thickness");
   if (gh_number_p (st))
     {
@@ -145,7 +144,7 @@ Text_spanner::brew_molecule (SCM smob)
   
   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;
@@ -153,9 +152,9 @@ 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)
            {
              edge_line[d] = Line_spanner::line_molecule (me, thick, dx, dy);
@@ -172,7 +171,7 @@ Text_spanner::brew_molecule (SCM smob)
     m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
   if (!line.empty_b ())
     m.add_at_edge (X_AXIS, RIGHT, line,
-                  edge_line[LEFT].empty_b () ? 0 : - thick/2);
+                  edge_line[LEFT].empty_b () ? 0 : -thick/2);
   if (!edge_line[RIGHT].empty_b ())
     m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], -thick/2);
   if (!edge[RIGHT].empty_b ())
@@ -184,6 +183,7 @@ 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 
@@ -195,29 +195,20 @@ void
 Text_spanner::setup_pedal_bracket(Spanner *me)
 {
 
-  Real thick = me->paper_l ()->get_var ("stafflinethickness");  
+  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> w, broken;
+  Drul_array<bool> broken;
   Drul_array<Real> height, width, shorten, r;
 
   SCM pa = me->get_grob_property ("if-text-padding");
-  SCM ew = me->get_grob_property ("edge-width");
+  SCM ew = me->get_grob_property ("edge-widen");
   SCM eh = me->get_grob_property ("edge-height");
   SCM sp = me->get_grob_property ("shorten-pair");
-  SCM wl = me->get_grob_property ("left-widen");
-  SCM wr = me->get_grob_property ("right-widen");
-
-  // Pedal has an angled left edge \__  or an angled right edge __/ 
-  w[LEFT] = w[RIGHT] = false;
-  if (gh_boolean_p (wl) )  
-    w[LEFT]   = to_boolean (wl);
-  if (gh_boolean_p (wr) )  
-    w[RIGHT]  = to_boolean (wr);
   
   Direction d = LEFT;
   Interval e;
@@ -226,24 +217,25 @@ Text_spanner::setup_pedal_bracket(Spanner *me)
   if (gh_number_p (pa) )
     padding = gh_scm2double (pa);
 
-  do {
-    Item *b = me->get_bound (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 ( w[d] && gh_pair_p (ew) )
-      width[d] +=  gh_scm2double (index_cell (ew, d)) * d;
-    if ( !broken[d] && (gh_pair_p (eh) ) )
-      height[d] = gh_scm2double (index_cell (eh, d));
-    if ( gh_pair_p (sp) )
-      shorten[d] =  gh_scm2double (index_cell (sp, d));
-  }
+  do
+    {
+      Item *b = me->get_bound (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);
   
   Real extra_short = 0;
@@ -252,55 +244,54 @@ Text_spanner::setup_pedal_bracket(Spanner *me)
   if ( to_boolean (me->get_grob_property ("text-start")) )
     {
       height[LEFT] = 0;
-      Grob * textbit = me->get_parent(Y_AXIS);
       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 (me);
-           Molecule mol = Text_item::text2molecule (me, 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] -= me->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]);
-
-  me->set_grob_property ("edge-height", gh_cons ( gh_double2scm ( height[LEFT] ) , 
-                                                 gh_double2scm ( height[RIGHT]) ) );
-  me->set_grob_property ("edge-width",  gh_cons ( gh_double2scm ( width[LEFT]  ), 
-                                                 gh_double2scm ( width[RIGHT] ) ));
-  me->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]);
+    }
 
-ADD_INTERFACE (Pianopedal,"piano-pedal-interface",
-  "",
-  "pedal-type edge-width edge-height shorten-pair text-start left-widen right-widen");
+  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 dash-length edge-height edge-width edge-text shorten-pair type");
+              "generic text spanner",
+              "dash-period if-text-padding dash-length edge-height edge-widen edge-text shorten-pair type thickness outer width-correct");