]> git.donarmstrong.com Git - lilypond.git/blob - lily/tex-beam.cc
release: 0.1.59
[lilypond.git] / lily / tex-beam.cc
1 /*
2   tex-beam.cc -- implement Lookup::{beam_element, beam, rule_symbol}
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 /*
10   Code to generate beams for TeX
11   */
12
13 #include <math.h>
14 #include "atom.hh"
15 #include "molecule.hh"
16 #include "tex.hh"
17 #include "symtable.hh"
18 #include "dimen.hh"
19 #include "debug.hh"
20 #include "lookup.hh"
21 #include "misc.hh"
22 #include "paper-def.hh"
23 #include "string-convert.hh"
24 #include "main.hh"
25
26
27 Atom
28 Lookup::rule_symbol (Real height, Real width) const
29 {
30   Atom bs=(*symtables_p_)("param")->lookup ("rule");
31   Array<String> args;
32   args.push (print_dimen (height));
33   args.push (print_dimen (width));
34   bs.tex_ = substitute_args (bs.tex_,args);
35   bs.dim_.x() = Interval (0,width);
36   bs.dim_.y() = Interval (0,height);
37   return bs;
38 }
39
40 Atom 
41 Lookup::beam(Real &slope, Real width, Real y_thick) const
42 {
43   
44   Atom a( ps_beam (slope, width, y_thick));
45   Real slope_y =slope * width; 
46   Real min_y = (0 <? slope_y )- y_thick/2;
47   Real max_y = (0 >? slope_y) + y_thick/2;
48   
49   a.dim_[X_AXIS] = Interval(0, width);
50   a.dim_[Y_AXIS] = Interval(min_y, max_y);
51   return a;
52 }
53
54 Atom
55 Lookup::ps_beam (Real slope, Real width, Real y_thickness)const
56 {
57   String ps = "\\embeddedps{\n";
58   ps += String (width) + " "+ String (slope) + " " + String (y_thickness)
59     + " draw_beam}";
60
61   /* 
62    beam parts are rarely wider than 100pt: 
63    precision of 4 yields maximum (half beam spanning half a page)
64    error of: 1%% * 3*72pt === 0.2pt = 0.07mm
65    */
66   String width_str = String_convert::precision_str (width, 4);
67   String slope_str = String_convert::precision_str (slope, 4);
68   String thick_str = String_convert::precision_str (y_thickness, 3);
69   String name = "feta-beum-" + width_str + "-" + slope_str + "-" + thick_str;
70
71   int i;
72   while ((i = name.index_i ('.')) != -1)
73     name[i]=  'x';
74
75
76
77   Atom s;
78   s.tex_ = ps;
79   return s;
80 }