flower-1.0.1
[lilypond.git] / symtable.cc
bloba63bc195c8984867d68a49d29bf1671dad1510af
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"
9 Symtable*
10 Symtables::operator()(String s)
12 if (!done_reading){ // read on demand
13 *mlog << '(' << fname ;
14 read();
15 done_reading = true;
16 *mlog << ")\n";
18 return Assoc<String, Symtable*>::operator[](s);
21 void
22 Symtables::read()
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;
32 assert (r[0] == "table");
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;
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);
51 Symbol s(tex, Box(dims));
52 (*sp)[id] = s;
54 (*this)[tabnam] = sp;
58 Symtables the_sym_tables("symbol.ini");
61 const Symbol*
62 Symbol::find_ball(int i)
64 int j = intlog2(i);
65 if (j > 4) j = 4;
66 Symtable * st = the_sym_tables("balls");
67 return &(*st)[String(j)];
71 const Symbol*
72 Symbol::find_rest(int i)
74 int j = intlog2(i);
75 return &(*the_sym_tables("rests"))[String(j)];
77 const Symbol*
78 Symbol::find_bar(String s)
80 return &(*the_sym_tables("bars"))[s];
82 /****************************************************************/
83 // bare bones.
85 struct Linestaf_symbol : Stretchable_symbol {
86 int lines;
87 String operator ()(Real w);
88 Linestaf_symbol(int n) { lines = n;}
90 // should be done in TeX
91 String
92 Linestaf_symbol::operator()(Real w)
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";
101 s+="\\vss}\\hss}";
102 return s;
105 const Stretchable_symbol *
106 Stretchable_symbol::get_linestaff(int n)
108 return new Linestaf_symbol(n);