summaryrefslogtreecommitdiff
path: root/symtable.cc
blob: 5d295d0be5aafacf5eb41d5f015b2385198e8d39 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "misc.hh"
#include "debug.hh"
#include "real.hh"
#include "symbol.hh"
#include "assoc.hh"
#include "symtable.hh"
#include "const.hh"

static Symbol unknown;


// scary! What if Symtable resizes on the fly...?
const Symbol *
Symtable::lookup(String s) const
{
    if (elt_query(s))
	return &(*this)[s];
    else {
	WARN<<"Unknown symbol " << s <<'\n';
	return &unknown;
    }
}

Symtable* 
Symtables::operator()(String s) 
{
    if (!done_reading){	// read on demand
	*mlog << '(' << fname ;
	read();
	done_reading = true;
	*mlog << ")\n";
    }
    return Assoc<String, Symtable*>::operator[](s);
} 

void
Symtables::read()
{
     Text_db symini(fname);
     while (!symini.eof()) {
	 Text_record  r(  symini++);
	 assert (r[0] == "table");
	 
	 String tabnam = r[1];
	 Symtable * sp = new Symtable;
	 while (!symini.eof()){
	     r = symini++;
	     if (r[0] == "end")
		 break;
	     
	     assert(r.sz() == 6);
	     int i=0;
	     String id=r[i++];
	     String tex=r[i++];
	     svec<Real> dims;
	     for (int j=0; j < 4; j++)
		 dims.add( r[i++].fvalue() *1.0/CM_TO_PT);
	     
	     Symbol s(tex, Box(dims));
	     (*sp)[id] = s;
	 }
	 (*this)[tabnam] = sp;	 	 
     }
}

Symtables the_sym_tables("symbol.ini");


const Symbol*
Symbol::find_ball(int j)
{
    if (j > 4) j = 4;
    Symtable * st = the_sym_tables("balls");
    return st->lookup(String(j));
}

const Symbol*
Symbol::find_rest(int j)
{
    return the_sym_tables("rests")->lookup(String(j));
}
const Symbol*
Symbol::find_bar(String s)
{
    return the_sym_tables("bars")->lookup(s);
}
/****************************************************************/
// bare bones.

struct Linestaf_symbol : Stretchable_symbol {
    int lines;
    String operator ()(Real w);
    Linestaf_symbol(int n) { lines = n;}
    Interval height(Real) const { return Interval(0,lines*1/CM_TO_PT); }
};



// should be done in TeX
String
Linestaf_symbol::operator()(Real w)
{
    String s;
    s += "\\hbox to 0pt{";
    s+= "\\vbox to 0pt{";
    for (int i=0; i<lines; i++) {
	if (i) s+= "\\vskip1pt";
	s+= "\\hrule width " + String(w* HOR_TO_PT) +"pt";
    }
    s+="\\vss}\\hss}";
    return s;
}

const Stretchable_symbol *
Stretchable_symbol::get_linestaff(int n)
{
    return new Linestaf_symbol(n);
}