]> git.donarmstrong.com Git - lilypond.git/blob - lily/tex-beam.cc
release: 0.1.18
[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
23 Atom
24 Lookup::beam_element (int sidx, int widx, Real slope) const
25 {
26   String name = String("slope");
27   Atom bs=(*symtables_)("beamslopes")->lookup (name);
28   
29   Array<String> args;
30   args.push (sidx);
31   args.push (widx);
32   bs.tex_ = substitute_args (bs.tex_,args);
33   int w = 2 << widx;
34   Real width = w PT;
35   bs.dim_.x() = Interval (0,width);
36   bs.dim_.y() = Interval (0,width*slope);
37   return bs;
38 }
39
40
41 Atom
42 Lookup::rule_symbol (Real height, Real width) const
43 {
44   Atom bs=(*symtables_)("beamslopes")->lookup ("horizontal");    
45   Array<String> args;
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);
51   return bs;
52 }
53
54 Atom
55 Lookup::beam (Real &slope, Real width) const
56 {        
57   int sidx = 0;
58   if (abs (slope) > 1.0)
59     {
60       WARN << "beam steeper than 1.0 (" << slope << ")\n";
61       slope = sign (slope);
62     }
63
64   sidx = int (rint (slope *  20.0));
65   slope = sidx / 20.0;
66   
67   Interval xdims = (*symtables_)("beamslopes")->lookup ("slope").dim_[X_AXIS];
68   Real min_wid = xdims[LEFT];
69   Real max_wid = xdims[RIGHT];
70   assert(max_wid > 0);
71   int widths = intlog2 (int (max_wid/min_wid)) + 1;
72   
73   if (width < min_wid) 
74     {
75       WARN<<"Beam too narrow. (" << print_dimen (width) <<")\n";
76       width = min_wid;
77     }
78   
79   Real elemwidth = max_wid;
80   
81   int widx  =widths - 1;
82   Molecule m;
83   while (elemwidth > width) 
84     {
85       widx --;
86       elemwidth /= 2.0;
87     }
88   Real overlap = elemwidth/4;
89   Real last_x = width - elemwidth;
90   Real x = overlap;
91   Atom elem (beam_element (sidx * widths, widx, slope));
92   m.add (elem);
93   while (x < last_x) 
94     {
95       Atom a(elem);
96       a.translate (Offset (x-overlap, (x-overlap)*slope));
97       m.add (a);
98       x += elemwidth - overlap;
99     }
100   Atom a(elem);
101   a.translate (Offset (last_x, (last_x) * slope));
102   m.add (a);
103   
104   Atom ret;
105   ret.tex_ = m.TeX_string();
106   ret.dim_.y() = Interval (0,width*slope);
107   ret.dim_.x() = Interval (0,width);
108   
109   return ret;
110 }
111
112