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