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"
25 Lookup::beam_element (int sidx, int widx, Real slope) const
27 String name = String("slope");
28 Atom bs=(*symtables_p_)("beamslopes")->lookup (name);
33 bs.tex_ = substitute_args (bs.tex_,args);
36 bs.dim_.x() = Interval (0,width);
37 bs.dim_.y() = Interval (0,width*slope);
43 Lookup::rule_symbol (Real height, Real width) const
45 Atom bs=(*symtables_p_)("beamslopes")->lookup ("horizontal");
47 args.push (print_dimen (height));
48 args.push (print_dimen (width));
49 bs.tex_ = substitute_args (bs.tex_,args);
50 bs.dim_.x() = Interval (0,width);
51 bs.dim_.y() = Interval (0,height);
56 Lookup::beam(Real &slope, Real width, Real y_thick) const
58 if (postscript_global_b)
60 return ps_beam (slope, width, y_thick);
63 return tex_beam(slope, width);
67 Lookup::ps_beam (Real slope, Real width, Real y_thickness)const
70 String ps(String (width) + " "+ String(slope)
71 + " " + String(y_thickness) + " draw_beam");
72 ret.tex_ = String("\\embeddedps{" + ps + "}");
73 ret.dim_[X_AXIS] = Interval(0, width);
74 ret.dim_[Y_AXIS] = Interval(0, slope * width + y_thickness);
79 Lookup::tex_beam (Real &slope, Real width) const
81 const Real MAX_SLOPE = 0.6;
82 const Real SLOPES = 20.0;
84 if (abs (slope) > MAX_SLOPE)
86 WARN << _("beam too steep (") << slope << ")\n";
87 slope = sign (slope) * MAX_SLOPE;
90 sidx = int (rint (slope / MAX_SLOPE * SLOPES));
91 slope = MAX_SLOPE * sidx / SLOPES;
93 Interval xdims = (*symtables_p_)("beamslopes")->lookup ("slope").dim_[X_AXIS];
94 Real min_wid = xdims[LEFT];
95 Real max_wid = xdims[RIGHT];
97 int widths = intlog2 (int (max_wid/min_wid)) + 1;
101 WARN<<_("Beam too narrow. (") << print_dimen (width) <<")\n";
105 Real elemwidth = max_wid;
107 int widx =widths - 1;
109 while (elemwidth > width)
114 Real overlap = elemwidth/4;
115 Real last_x = width - elemwidth;
117 Atom elem (beam_element (sidx * widths, widx, slope));
122 a.translate (Offset (x-overlap, (x-overlap)*slope));
124 x += elemwidth - overlap;
127 a.translate (Offset (last_x, (last_x) * slope));
131 ret.tex_ = m.TeX_string();
132 ret.dim_.y() = Interval (0,width*slope);
133 ret.dim_.x() = Interval (0,width);