]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-bracket.cc
* mf/GNUmakefile: always trace pfa fonts.
[lilypond.git] / lily / tuplet-bracket.cc
index b00c319c23f961f5897b57d115e67e53d1fa5e0a..306ff7b679258e8575d4a5e6af402342d8199db6 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c)  1997--2003 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 /*
@@ -69,7 +69,7 @@ Tuplet_bracket::parallel_beam (Grob *me, Link_array<Grob> const &cols, bool *equ
   Spanner*sp = dynamic_cast<Spanner*> (me);  
 
   *equally_long= false;
-  if (! ( b1 && (b1 == b2) && !sp->broken_b() ))
+  if (! (b1 && (b1 == b2) && !sp->broken_b()))
       return 0;
 
   Link_array<Grob> beam_stems = Pointer_group_interface__extract_grobs
@@ -134,6 +134,14 @@ Tuplet_bracket::brew_molecule (SCM smob)
     number_visibility = !par_beam;
        
   Grob * commonx = columns[0]->common_refpoint (columns.top (),X_AXIS);
+
+  /*
+    Tuplet brackets are normally not broken, but we shouldn't crash if
+    they are.
+   */
+  commonx = commonx->common_refpoint (sp->get_bound(LEFT), X_AXIS);
+  commonx = commonx->common_refpoint (sp->get_bound(RIGHT), X_AXIS);  
+  
   Direction dir = Directional_element_interface::get (me);
 
   Grob * lgr = get_x_bound_grob (columns[0], dir);
@@ -142,15 +150,17 @@ Tuplet_bracket::brew_molecule (SCM smob)
   Real x1 = rgr->extent (commonx,X_AXIS)[RIGHT];
 
   Real w = x1 -x0;
-
+  
   Real ly = gh_scm2double (me->get_grob_property ("left-position"));
   Real ry = gh_scm2double (me->get_grob_property ("right-position"));  
   SCM number = me->get_grob_property ("text");
-  
+
+  Paper_def *pap = me->get_paper ();
   if (gh_string_p (number) && number_visibility)
     {
       SCM properties = Font_interface::font_alist_chain (me);
-      Molecule num = Text_item::text2molecule (me, number, properties);
+      SCM snum = Text_item::interpret_markup (pap->self_scm (), properties, number);
+      Molecule num = *unsmob_molecule (snum);
       num.align_to (X_AXIS, CENTER);
       num.translate_axis (w/2, X_AXIS);
       num.align_to (Y_AXIS, CENTER);
@@ -159,29 +169,42 @@ Tuplet_bracket::brew_molecule (SCM smob)
 
       mol.add_molecule (num);
     }
-      
-  if (bracket_visibility)      
+
+
+  /*
+    No bracket when it would be smaller than the number.
+
+    TODO: should use GAP in calculation too.
+   */
+  if (bracket_visibility && number_visibility
+      && mol.extent (X_AXIS).length () > w)
     {
-      Real  lt =  me->get_paper ()->get_var ("linethickness");
+      bracket_visibility = false;
+    }
   
+  if (bracket_visibility)      
+    {
+      Real  lt =  pap->get_realvar (ly_symbol2scm ("linethickness"));
+
       SCM thick = me->get_grob_property ("thickness");
       if (gh_number_p (thick))
        lt *= gh_scm2double (thick);
-      
+
       SCM gap = me->get_grob_property ("gap");
-      SCM ew = me->get_grob_property ("edge-widen");
+      
+      SCM fl = me->get_grob_property ("bracket-flare");
       SCM eh = me->get_grob_property ("edge-height");
       SCM sp = me->get_grob_property ("shorten-pair");
       
       Direction d = LEFT;
-      Drul_array<Real> height, width, shorten;
+      Drul_array<Real> height, flare, shorten;
       do {
-       width[d] =  height[d] = shorten[d] = 0.0;
-       if ( ly_number_pair_p (ew) )
-         width[d] +=  gh_scm2double (index_get_cell (ew, d));
-       if ( ly_number_pair_p (eh) )
+       flare[d] =  height[d] = shorten[d] = 0.0;
+       if (is_number_pair (fl))
+         flare[d] +=  gh_scm2double (index_get_cell (fl, d));
+       if (is_number_pair (eh))
          height[d] += gh_scm2double (index_get_cell (eh, d)) * - dir;
-       if ( ly_number_pair_p (sp) )
+       if (is_number_pair (sp))
          shorten[d] +=  gh_scm2double (index_get_cell (sp, d));
       }
       while (flip (&d) != LEFT);
@@ -190,7 +213,7 @@ Tuplet_bracket::brew_molecule (SCM smob)
                                     w, ry - ly, lt,
                                     height,
                                     gh_scm2double (gap),
-                                    width,
+                                    flare,
                                     shorten);
       mol.add_molecule (brack);
     }
@@ -202,49 +225,50 @@ Tuplet_bracket::brew_molecule (SCM smob)
 
 /*
   should move to lookup?
+
+  TODO: this will fail for very short (shorter than the flare)
+  brackets.
  */
 Molecule
 Tuplet_bracket::make_bracket (Axis protusion_axis,
                              Real dx, Real dy, Real thick, Drul_array<Real> height,
                              Real gap,
-                             Drul_array<Real> widen,
+                             Drul_array<Real> flare,
                              Drul_array<Real> shorten)
 {
-  Real len = Offset (dx,dy).length ();
-  Real gapx = dx * (gap /  len);
-  Real gapy = dy * (gap /  len);
-  Drul_array<Real> shortx, shorty;
+  Offset dz = Offset (dx,dy);
+  Drul_array<Offset> corners (Offset(0,0), dz);
+  
+  Real length = dz.length ();
+  Drul_array<Offset> gap_corners;
+
+  
+  Axis bracket_axis = other_axis (protusion_axis);
+
+  Drul_array<Offset> straight_corners = corners;
+
   Direction d = LEFT;
   do {
-    shortx[d] = dx * (shorten[d] /  len);
-    shorty[d] = dy * (shorten[d] /  len);
-  }
-  while (flip (&d) != LEFT);
-  Axis other = other_axis (protusion_axis);
-  
-  Molecule l1 = Lookup::line (thick, Offset(shortx[LEFT], shorty[LEFT]),
-                             Offset ( (dx - gapx)/2, (dy - gapy)/2 ));
-
-  Molecule l2 = Lookup::line (thick, Offset((dx + gapx) / 2,(dy + gapy) / 2),
-                             Offset (dx - shortx[RIGHT], dy - shorty[RIGHT]));
-
-  Offset protusion;
-  protusion[other] = -widen[LEFT];
-  protusion[protusion_axis] = height[LEFT];
-  Molecule p1 = Lookup::line (thick, 
-                             Offset(shortx[LEFT], shorty[LEFT]), 
-                             Offset(shortx[LEFT], shorty[LEFT]) + protusion);
-  protusion[other] = widen[RIGHT];
-  protusion[protusion_axis] = height[RIGHT];
-  Molecule p2 = Lookup::line (thick, 
-                             Offset(dx - shortx[RIGHT], dy - shorty[RIGHT]), 
-                             Offset(dx - shortx[RIGHT], dy - shorty[RIGHT]) + protusion);  
+    straight_corners[d] += - d * shorten[d] /length * dz;
+    gap_corners[d] = (dz * 0.5) + d * gap / length * dz;
+  } while (flip (&d) != LEFT);
+
+  Drul_array<Offset> flare_corners = straight_corners;
+  do {
+    flare_corners[d][bracket_axis] = straight_corners[d][bracket_axis];
+    flare_corners[d][protusion_axis] += height[d];
+    straight_corners[d][bracket_axis] += - d * flare[d];
+  } while (flip (&d) != LEFT);
 
   Molecule m;
-  m.add_molecule (p1);
-  m.add_molecule (p2);
-  m.add_molecule (l1);
-  m.add_molecule (l2);
+  do {
+
+    m.add_molecule (Lookup::line (thick, straight_corners[d],
+                                 gap_corners[d]));
+    
+    m.add_molecule (Lookup::line (thick, straight_corners[d],
+                                 flare_corners[d]));
+  } while (flip (&d) != LEFT);
 
   return m;  
 }
@@ -308,7 +332,7 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
     {
       Real notey = columns[i]->extent (commony, Y_AXIS)[dir] 
        - me->relative_coordinate (commony, Y_AXIS);
-
+      
       Real x = columns[i]->relative_coordinate (commonx, X_AXIS) - x0;
       Real tuplety =  *dy * x * factor;
 
@@ -322,11 +346,12 @@ Tuplet_bracket::calc_position_and_height (Grob*me,Real *offset, Real * dy)
   
   /*
     horizontal brackets should not collide with staff lines.
+    
    */
-  if (*dy == 0)
+  Real ss= Staff_symbol_referencer::staff_space (me);
+  if (*dy == 0 && fabs (*offset) <  ss * Staff_symbol_referencer::staff_radius (me))
     {
       // quantize, then do collision check.
-      Real ss= Staff_symbol_referencer::staff_space (me);
       *offset *= 2 / ss;
       
       *offset = rint (*offset);
@@ -394,7 +419,7 @@ Tuplet_bracket::after_line_breaking (SCM smob)
     }
   if (dynamic_cast<Spanner*> (me)->broken_b ())
     {
-      me->warning ( "Tuplet_bracket was across linebreak. Farewell cruel world.");
+      me->warning ("Tuplet_bracket was across linebreak. Farewell cruel world.");
       me->suicide();
       return SCM_UNSPECIFIED;
     }
@@ -492,5 +517,5 @@ Tuplet_bracket::add_column (Grob*me, Item*n)
 
 ADD_INTERFACE (Tuplet_bracket,"tuplet-bracket-interface",
   "A bracket with a number in the middle, used for tuplets.",
-  "note-columns edge-widen edge-height shorten-pair padding gap left-position right-position bracket-visibility number-visibility thickness direction");
+  "note-columns bracket-flare edge-height shorten-pair padding gap left-position right-position bracket-visibility number-visibility thickness direction");