]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tex-beam.cc
release: 1.0.1
[lilypond.git] / lily / tex-beam.cc
index c16a0e9c02a722e0b65da52327b4072a75926be1..002154acc452e2ae2cd33c08c2621fd66cf17219 100644 (file)
@@ -1,9 +1,9 @@
 /*
-  tex-beam.cc -- implement Lookup::{beam_element, beam, rule_symbol}
+  tex-beam.cc -- implement Lookup::beam
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 /*
   */
 
 #include <math.h>
-#include "symbol.hh"
+#include "atom.hh"
 #include "molecule.hh"
 #include "tex.hh"
 #include "symtable.hh"
-#include "dimen.hh"
+#include "dimension.hh"
 #include "debug.hh"
 #include "lookup.hh"
+#include "misc.hh"
+#include "paper-def.hh"
+#include "string-convert.hh"
+#include "main.hh"
 
-Symbol
-Lookup::beam_element (int sidx, int widx, Real slope) const
-{
-  Symbol bs=(*symtables_)("beamslopes")->lookup ("slope");
-  
-  Array<String> args;
-  args.push (sidx);
-  args.push (widx);
-  bs.tex = substitute_args (bs.tex,args);
-  int w = 2 << widx;
-  Real width = w PT;
-  bs.dim.x() = Interval (0,width);
-  bs.dim.y() = Interval (0,width*slope);
-  return bs;
-}
-
-// ugh.. hard wired tex-code.
-static int
-slope_index (Real &s)
-{
-  if (abs (s) > 0.5) 
-    {
-      WARN << "beam steeper than 0.5 (" << s << ")\n";
-      s = sign (s) * 0.5;
-    }
-
-  int i = int (rint (s *  20.0));
 
-  s = i/20.0;
-  if (s>0)
-    return 6*i +122;
-  else
-    return -6 * i+ 186;
-}
-
-Symbol
+Atom
 Lookup::rule_symbol (Real height, Real width) const
 {
-  Symbol bs=(*symtables_)("beamslopes")->lookup ("horizontal");    
+  Atom bs=(*symtables_p_)("param")->lookup ("rule");
   Array<String> args;
   args.push (print_dimen (height));
   args.push (print_dimen (width));
-  bs.tex = substitute_args (bs.tex,args);
-  bs.dim.x() = Interval (0,width);
-  bs.dim.y() = Interval (0,height);
+  bs.tex_ = substitute_args (bs.tex_,args);
+  bs.dim_.x() = Interval (0,width);
+  bs.dim_.y() = Interval (0,height);
   return bs;
 }
 
-Symbol
-Lookup::beam (Real &slope, Real width) const
-{        
-  int sidx = slope_index (slope);
-  if (!slope)
-    return rule_symbol (2 PT, width);
-  if (width < 2 PT) 
-    {
-      WARN<<"Beam too narrow. (" << print_dimen (width) <<")\n";
-      width = 2 PT;
-    }
-  Real elemwidth = 64 PT;
-  int widx = 5;
-
-  Molecule m;
-  
-  while (elemwidth > width) 
-    {
-      widx --;
-      elemwidth /= 2.0;
-    }
-  Real overlap = elemwidth/4;
-  Real last_x = width - elemwidth;
-  Real x = overlap;
-  Atom elem (beam_element (sidx, widx, slope));
-  Atom a (elem);
-  m.add (a);
-  while (x < last_x) 
-    {
-      a=elem;
-      a.translate (Offset (x-overlap, (x-overlap)*slope));
-      m.add (a);
-      x += elemwidth - overlap;
-    }
-  a=elem;
-  a.translate (Offset (last_x, (last_x) * slope));
-  m.add (a);
+Atom 
+Lookup::beam(Real slope, Real width, Real thick) const
+{
   
-  Symbol ret;
-  ret.tex = m.TeX_string();
-  ret.dim.y() = Interval (0,width*slope);
-  ret.dim.x() = Interval (0,width);
+  Atom a (ps_beam (slope, width, thick));
+  Real height = slope * width; 
+  Real min_y = (0 <? height) - thick/2;
+  Real max_y = (0 >? height) + thick/2;
   
-  return ret;
+  a.dim_[X_AXIS] = Interval(0, width);
+  a.dim_[Y_AXIS] = Interval(min_y, max_y);
+  return a;
 }
 
+Atom
+Lookup::ps_beam (Real slope, Real width, Real thick) const
+{
+  String ps = "\\embeddedps{\n";
+  ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick)
+    + " draw_beam}";
+
+  Atom s;
+  s.tex_ = ps;
+  return s;
+}