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"
22 #include "paper-def.hh"
23 #include "string-convert.hh"
27 Lookup::beam_element (int sidx, int widx, Real slope) const
29 String name = String("slope");
30 Atom bs=(*symtables_p_)("beamslopes")->lookup (name);
35 bs.tex_ = substitute_args (bs.tex_,args);
38 bs.dim_.x() = Interval (0,width);
39 bs.dim_.y() = Interval (0,width*slope);
45 Lookup::rule_symbol (Real height, Real width) const
47 Atom bs=(*symtables_p_)("param")->lookup ("rule");
49 args.push (print_dimen (height));
50 args.push (print_dimen (width));
51 bs.tex_ = substitute_args (bs.tex_,args);
52 bs.dim_.x() = Interval (0,width);
53 bs.dim_.y() = Interval (0,height);
58 Lookup::beam(Real &slope, Real width, Real y_thick) const
60 Atom a( postscript_global_b
61 ? ps_beam (slope, width, y_thick)
62 : tex_beam (slope, width));
64 Real slope_y =slope * width;
65 Real min_y = (0 <? slope_y )- y_thick/2;
66 Real max_y = (0 >? slope_y) + y_thick/2;
68 a.dim_[X_AXIS] = Interval(0, width);
69 a.dim_[Y_AXIS] = Interval(min_y, max_y);
74 Lookup::ps_beam (Real slope, Real width, Real y_thickness)const
76 String ps = "\\embeddedps{\n";
77 ps += String (width) + " "+ String (slope) + " " + String (y_thickness)
81 beam parts are rarely wider than 100pt:
82 precision of 4 yields maximum (half beam spanning half a page)
83 error of: 1%% * 3*72pt === 0.2pt = 0.07mm
85 String width_str = String_convert::precision_str (width, 4);
86 String slope_str = String_convert::precision_str (slope, 4);
87 String thick_str = String_convert::precision_str (y_thickness, 3);
88 String name = "feta-beum-" + width_str + "-" + slope_str + "-" + thick_str;
91 while ((i = name.index_i ('.')) != -1)
95 String mf = "\\embeddedmf{" + name + "}{\n";
96 mf += "input feta-beum;\n";
97 mf += "drawbeam(" + width_str + "," + slope_str + "," + thick_str + ");\n";
108 Lookup::tex_beam (Real &slope, Real width) const
110 const Real MAX_SLOPE = 0.6;
111 const Real SLOPES = 20.0;
113 if (abs (slope) > MAX_SLOPE)
115 WARN << _("beam too steep (") << slope << ")\n";
116 slope = sign (slope) * MAX_SLOPE;
119 sidx = int (rint (slope / MAX_SLOPE * SLOPES));
120 slope = MAX_SLOPE * sidx / SLOPES;
122 Interval xdims = (*symtables_p_)("beamslopes")->lookup ("slope").dim_[X_AXIS];
123 Real min_wid = xdims[LEFT];
124 Real max_wid = xdims[RIGHT];
126 int widths = intlog2 (int (max_wid/min_wid)) + 1;
130 WARN<<_("Beam too narrow. (") << print_dimen (width) <<")\n";
134 Real elemwidth = max_wid;
136 int widx =widths - 1;
138 while (elemwidth > width)
143 Real overlap = elemwidth/4;
144 Real last_x = width - elemwidth;
146 Atom elem (beam_element (sidx * widths, widx, slope));
151 a.translate (Offset (x-overlap, (x-overlap)*slope));
153 x += elemwidth - overlap;
156 a.translate (Offset (last_x, (last_x) * slope));
160 ret.tex_ = m.TeX_string();