lilypond-1.3.21
[lilypond.git] / src / lookup.cc
blobffd668e75d33e72e80f676ebd497bdb35313da24
1 /*
2 lookup.cc -- implement simple Lookup methods.
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "lookup.hh"
10 #include "debug.hh"
11 #include "symtable.hh"
12 #include "dimen.hh"
13 #include "tex.hh"
14 #include "scalar.hh"
16 Lookup::Lookup()
18 texsetting = "\\unknowntexsetting";
19 symtables_ = new Symtables;
22 Lookup::Lookup(Lookup const &s)
24 texsetting = s.texsetting;
25 symtables_ = new Symtables(*s.symtables_);
27 Lookup::~Lookup()
29 delete symtables_;
32 void
33 Lookup::add(String s, Symtable*p)
35 symtables_->add(s, p);
38 void
39 Lookup::print()const
41 mtor << "Lookup: " << texsetting << " {\n";
42 symtables_->print();
43 mtor << "}\n";
46 Symbol
47 Lookup::text(String style, String text, int dir)
49 Array<String> a;
51 a.push(text);
52 Symbol tsym = (*symtables_)("style")->lookup(style);
53 a[0] = substitute_args(tsym.tex,a);
55 Symbol s = (*symtables_)("align")->lookup(dir);
56 s.tex = substitute_args(s.tex,a);
57 s.dim.y = tsym.dim.y;
58 return s;
62 Real
63 Lookup::internote()
65 return ball(4).dim.y.length()/2;
68 Symbol
69 Lookup::ball(int j)
71 if (j > 4)
72 j = 4;
74 Symtable * st = (*symtables_)("balls");
75 return st->lookup(String(j));
78 Symbol
79 Lookup::rest(int j)
81 return (*symtables_)("rests")->lookup(String(j));
84 Symbol
85 Lookup::fill(Box b)
87 Symbol s( (*symtables_)("param")->lookup("fill"));
88 s.dim = b;
89 return s;
92 Symbol
93 Lookup::accidental(int j)
95 return (*symtables_)("accidentals")->lookup(String(j));
99 Symbol
100 Lookup::bar(String s)
102 return (*symtables_)("bars")->lookup(s);
105 Symbol
106 Lookup::script(String s)
108 return (*symtables_)("scripts")->lookup(s);
111 Symbol
112 Lookup::clef(String s)
114 return (*symtables_)("clefs")->lookup(s);
117 Symbol
118 Lookup::dots(int j)
120 if (j>3)
121 error("max 3 dots"); // todo
122 return (*symtables_)("dots")->lookup(j);
125 Symbol
126 Lookup::flag(int j)
128 return (*symtables_)("flags")->lookup(j);
131 Symbol
132 Lookup::streepjes(int i)
134 assert(i);
136 int arg;
137 String idx;
139 if (i < 0) {
140 idx = "botlines";
141 arg = -i;
142 } else {
143 arg = i;
144 idx = "toplines";
146 Symbol ret = (*symtables_)("streepjes")->lookup(idx);
148 Array<String> a;
149 a.push(arg);
150 ret.tex = substitute_args(ret.tex, a);
152 return ret;
155 Symbol
156 Lookup::hairpin(Real &wid, bool decresc)
158 int idx = int(rint(wid / 6 PT));
159 if(!idx) idx ++;
160 wid = idx*6 PT;
161 String idxstr = (decresc)? "decrescendosym" : "crescendosym";
162 Symbol ret=(*symtables_)("param")->lookup(idxstr);
164 Array<String> a;
165 a.push(idx);
166 ret.tex = substitute_args(ret.tex, a);
167 ret.dim.x = Interval(0,wid);
168 return ret;
171 Symbol
172 Lookup::linestaff(int lines, Real wid)
174 Symbol s;
175 s.dim.x = Interval(0,wid);
176 Real dy = (lines >0) ? (lines-1)*internote()*2 : 0;
177 s.dim.y = Interval(0,dy);
179 Array<String> a;
180 a.push(lines);
181 a.push(print_dimen(wid));
183 s.tex = (*symtables_)("param")->lookup("linestaf").tex;
184 s.tex = substitute_args(s.tex, a);
186 return s;
190 Symbol
191 Lookup::meter(Array<Scalar> a)
193 Symbol s;
194 s.dim.x = Interval( 0 PT, 10 PT);
195 s.dim.y = Interval(0, 20 PT); // todo
196 String src = (*symtables_)("param")->lookup("meter").tex;
197 s.tex = substitute_args(src,a);
198 return s;
202 Symbol
203 Lookup::stem(Real y1,Real y2)
205 if (y1 > y2) {
206 Real t = y1;
207 y1 = y2;
208 y2 = t;
210 Symbol s;
212 s.dim.x = Interval(0,0);
213 s.dim.y = Interval(y1,y2);
215 Array<String> a;
216 a.push(print_dimen(y1));
217 a.push(print_dimen(y2));
219 String src = (*symtables_)("param")->lookup("stem").tex;
220 s.tex = substitute_args(src,a);
221 return s;