]> git.donarmstrong.com Git - lilypond.git/blob - symtable.cc
release: 0.0.1
[lilypond.git] / symtable.cc
1 #include "misc.hh"
2 #include "debug.hh"
3 #include "real.hh"
4 #include "tex.hh"
5 #include "assoc.hh"
6 #include "symtable.hh"
7 #include "const.hh"
8
9 Symtable* 
10 Symtables::operator()(String s) 
11 {
12     if (!done_reading){ // read on demand
13         *mlog << '(' << fname ;
14         read();
15         done_reading = true;
16         *mlog << ")\n";
17     }
18     return Assoc<String, Symtable*>::operator[](s);
19
20
21 void
22 Symtables::read()
23 {
24      Text_db symini(fname);
25      while (1) {
26          if (symini.eof())
27              break;
28          Text_record  r(  symini++);
29          if (!r.sz())
30              continue;
31
32          assert (r[0] == "table");
33          
34          String tabnam = r[1];
35          Symtable * sp = new Symtable;
36          while (1) {
37              r = symini++;
38              if (!r.sz())
39                  continue;
40              if (r[0] == "end")
41                  break;
42              
43              assert(r.sz() == 6);
44              int i=0;
45              String id=r[i++];
46              String tex=r[i++];
47              svec<Real> dims;
48              for (int j=0; j < 4; j++)
49                  dims.add( r[i++].fvalue() *1.0/CM_TO_PT);
50              
51              Symbol s(tex, Box(dims));
52              (*sp)[id] = s;
53          }
54          (*this)[tabnam] = sp;           
55      }
56 }
57
58 Symtables the_sym_tables("symbol.ini");
59
60
61 const Symbol*
62 Symbol::find_ball(int i)
63 {
64     int j = intlog2(i);
65     if (j > 4) j = 4;
66     Symtable * st = the_sym_tables("balls");
67     return &(*st)[String(j)];
68
69 }
70
71 const Symbol*
72 Symbol::find_rest(int i)
73 {
74     int j = intlog2(i);
75     return &(*the_sym_tables("rests"))[String(j)];
76 }
77 const Symbol*
78 Symbol::find_bar(String s)
79 {
80     return &(*the_sym_tables("bars"))[s];  
81 }
82 /****************************************************************/
83 // bare bones.
84
85 struct Linestaf_symbol : Stretchable_symbol {
86     int lines;
87     String operator ()(Real w);
88     Linestaf_symbol(int n) { lines = n;}
89 };
90 // should be done in TeX
91 String
92 Linestaf_symbol::operator()(Real w)
93 {
94     String s;
95     s += "\\hbox to 0pt{";
96     s+= "\\vbox to 0pt{";
97     for (int i=0; i<lines; i++) {
98         if (i) s+= "\\vskip1pt";
99         s+= "\\hrule width " + String(w* HOR_TO_PT) +"pt";
100     }
101     s+="\\vss}\\hss}";
102     return s;
103 }
104
105 const Stretchable_symbol *
106 Stretchable_symbol::get_linestaff(int n)
107 {
108     return new Linestaf_symbol(n);
109 }