]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/bar.cc
release: 1.3.44
[lilypond.git] / lily / bar.cc
index f21d68fbac833ccd7ef1201f14d43c94fd59a401..99f65c026ecabd64f111efc1d4efdeed0ca5a658 100644 (file)
@@ -3,9 +3,12 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
+#include <math.h>
 
+#include "main.hh"
+#include "dimensions.hh"
 #include "dimension-cache.hh"
 #include "bar.hh"
 #include "string.hh"
 #include "paper-def.hh"
 #include "lookup.hh"
 #include "debug.hh"
-
+#include "all-font-metrics.hh"
 
 Bar::Bar ()
 {
-  set_elt_property (breakable_scm_sym, SCM_BOOL_T);
-  type_str_ = "|";
+  set_elt_property ("breakable", SCM_BOOL_T);
 }
 
-void
-Bar::do_print () const
-{
-#ifndef NPRINT
-  String s = type_str_;
-  DEBUG_OUT << "type = " << s;
-#endif
-}
 
 Real
 Bar::get_bar_size () const
@@ -38,51 +32,122 @@ Bar::get_bar_size () const
 }
 
 
-Molecule*
-Bar::do_brew_molecule_p () const
-{    
-  Molecule *output = new Molecule (lookup_l ()->bar (type_str_, get_bar_size (), paper_l ()));
+Molecule 
+Bar::do_brew_molecule () const
+{
+  SCM s = get_elt_property ("glyph");
+  if (gh_string_p (s))
+    {
+      String str  =ly_scm2string (s);
+      return compound_barline (str, get_bar_size ());
+    }
+  return Molecule ();
+}
+
+
+Molecule
+Bar::compound_barline (String str, Real h) const
+{
+  Real kern = paper_l()->get_var ("bar_kern");
+  Real thinkern = paper_l()->get_var ("bar_thinkern");
+
+  Molecule thin = simple_barline (paper_l()->get_var ("barthick_thin"), h);
+  Molecule thick = simple_barline (paper_l()->get_var ("barthick_thick"), h);
+  Molecule colon = lookup_l ()->afm_find ("dots-repeatcolon");  
+
+  Molecule m;
   
-  return output;
+  if (str == "")
+    {
+      return lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
+    }
+  if (str == "scorepostbreak")
+    {
+      return simple_barline (paper_l ()->get_var ("barthick_score"), h);
+    }
+  else if (str == "|")
+    {
+      return thin;
+    }
+  else if (str == "|.")
+    {
+      m.add_at_edge (X_AXIS, LEFT, thick, 0);      
+      m.add_at_edge (X_AXIS, LEFT, thin, kern);
+    }
+  else if (str == ".|")
+    {
+      m.add_at_edge (X_AXIS, RIGHT, thick, 0);
+      m.add_at_edge (X_AXIS, RIGHT, thin, kern);
+    }
+  else if (str == ":|")
+    {
+      m.add_at_edge (X_AXIS, LEFT, thick, 0);
+      m.add_at_edge (X_AXIS, LEFT, thin, kern);
+      m.add_at_edge (X_AXIS, LEFT, colon, kern);      
+    }
+  else if (str == "|:")
+    {
+      m.add_at_edge (X_AXIS, RIGHT, thick, 0);
+      m.add_at_edge (X_AXIS, RIGHT, thin, kern);
+      m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
+    }
+  else if (str == ":|:")
+    {
+      m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
+      m.add_at_edge (X_AXIS, LEFT, colon, kern);      
+      m.add_at_edge (X_AXIS, RIGHT, thick, kern);
+      m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
+    }
+  else if (str == ".|.")
+    {
+      m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
+      m.add_at_edge (X_AXIS, RIGHT, thick, kern);      
+    }
+  else if (str == "||")
+    {
+      m.add_at_edge (X_AXIS, RIGHT, thin, 0);
+      m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);      
+    }
+
+  return m;
+}
+
+
+Molecule
+Bar::simple_barline (Real w, Real h) const
+{
+  return lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
 }
 
-/**
-  Prescriptions for splitting bars.
-  TODO: put this in SCM.
- */
-static char const *bar_breaks[][3] ={
-  {":|", ":|:", "|:"},
-  {"|", "|", ""},
-  {"", "|s", "|"},
-  {"|", "|:", "|:"},
-  {"|.", "|.", ""},
-  {":|", ":|", ""},
-  {"||", "||", ""},
-  {".|.", ".|.", ""},
-  {"", "scorebar", "scorepostbreak"},
-  {"", "brace", "brace"},
-  {"", "bracket", "bracket"},  
-  {0,0,0}
-};
 
 void
-Bar::do_pre_processing ()
+Bar::before_line_breaking ()
 {
-  for (int i=0; bar_breaks[i][0]; i++) 
+  SCM g = get_elt_property ("glyph");
+  Direction bsd = break_status_dir ();
+  if (gh_string_p (g))
     {
-      if (bar_breaks[i][1] == type_str_)
+      if (bsd)
        {
-         type_str_ = bar_breaks[i][break_status_dir ()+1];
-         break;
+         SCM breakdir = gh_int2scm (bsd);
+         g = scm_eval (gh_list (ly_symbol2scm ("break-barline"),
+                                g,
+                                breakdir,
+                                SCM_UNDEFINED));
        }
     }
-  if (remove_elt_property (at_line_start_scm_sym) != SCM_BOOL_F        // UGR.
-      && (break_status_dir () == RIGHT) && (type_str_ == ""))
+  else
     {
-      type_str_ = "|";
+      g = SCM_UNDEFINED;
     }
-
-  if (type_str_ =="")
-    set_empty (true, X_AXIS);
+  
+  if (!gh_string_p (g))
+    {
+      set_elt_property ("transparent", SCM_BOOL_T);
+      set_extent_callback (0, X_AXIS);      
+    }
+  else
+    set_elt_property ("glyph", g);
 }
   
+