2 tex-beam.cc -- implement Lookup::{beam_element, beam, rule_symbol}
4 source file of the GNU LilyPond music typesetter
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
10 Code to generate beams for TeX
15 #include "molecule.hh"
17 #include "symtable.hh"
24 Lookup::beam_element (int sidx, int widx, Real slope) const
26 String name = String("slope");
27 Atom bs=(*symtables_p_)("beamslopes")->lookup (name);
32 bs.tex_ = substitute_args (bs.tex_,args);
35 bs.dim_.x() = Interval (0,width);
36 bs.dim_.y() = Interval (0,width*slope);
42 Lookup::rule_symbol (Real height, Real width) const
44 Atom bs=(*symtables_p_)("beamslopes")->lookup ("horizontal");
46 args.push (print_dimen (height));
47 args.push (print_dimen (width));
48 bs.tex_ = substitute_args (bs.tex_,args);
49 bs.dim_.x() = Interval (0,width);
50 bs.dim_.y() = Interval (0,height);
55 Lookup::beam (Real &slope, Real width) const
57 const Real MAX_SLOPE = 0.6;
58 const Real SLOPES = 20.0;
60 if (abs (slope) > MAX_SLOPE)
62 WARN << _("beam too steep (") << slope << ")\n";
63 slope = sign (slope) * MAX_SLOPE;
66 sidx = int (rint (slope / MAX_SLOPE * SLOPES));
67 slope = MAX_SLOPE * sidx / SLOPES;
69 Interval xdims = (*symtables_p_)("beamslopes")->lookup ("slope").dim_[X_AXIS];
70 Real min_wid = xdims[LEFT];
71 Real max_wid = xdims[RIGHT];
73 int widths = intlog2 (int (max_wid/min_wid)) + 1;
77 WARN<<_("Beam too narrow. (") << print_dimen (width) <<")\n";
81 Real elemwidth = max_wid;
85 while (elemwidth > width)
90 Real overlap = elemwidth/4;
91 Real last_x = width - elemwidth;
93 Atom elem (beam_element (sidx * widths, widx, slope));
98 a.translate (Offset (x-overlap, (x-overlap)*slope));
100 x += elemwidth - overlap;
103 a.translate (Offset (last_x, (last_x) * slope));
107 ret.tex_ = m.TeX_string();
108 ret.dim_.y() = Interval (0,width*slope);
109 ret.dim_.x() = Interval (0,width);