2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 This doth suck. We should have PS output, and read spacing info from TFMs
17 #include "symtable.hh"
21 #include "paper-def.hh"
22 #include "string-convert.hh"
28 texsetting = "\\unknowntexsetting";
29 symtables_p_ = new Symtables;
32 Lookup::Lookup (Lookup const &s)
34 paper_l_ = s.paper_l_;
35 texsetting = s.texsetting;
36 symtables_p_ = new Symtables (*s.symtables_p_);
44 Lookup::add (String s, Symtable*p)
46 symtables_p_->add (s, p);
53 DOUT << "Lookup: " << texsetting << " {\n";
54 symtables_p_->print();
60 Lookup::text (String style, String text, int dir) const
65 Atom tsym = (*symtables_p_)("style")->lookup (style);
66 a[0] = substitute_args (tsym.tex_,a);
68 Atom s = (*symtables_p_)("align")->lookup (dir);
69 s.tex_ = substitute_args (s.tex_,a);
77 Lookup::ball (int j) const
82 Symtable * st = (*symtables_p_)("balls");
83 return st->lookup (String (j));
87 Lookup::rest (int j, bool o) const
89 return (*symtables_p_)("rests")->lookup (String (j) + (o ? "o" : ""));
93 Lookup::fill (Box b) const
95 Atom s ((*symtables_p_)("param")->lookup ("fill"));
101 Lookup::accidental (int j) const
103 return (*symtables_p_)("accidentals")->lookup (String (j));
108 Lookup::bar (String s, Real h) const
111 a.push (print_dimen (h));
112 Atom ret=(*symtables_p_)("bars")->lookup (s);
113 ret.tex_ = substitute_args (ret.tex_, a);
114 ret.dim_.y() = Interval (-h/2, h/2);
119 Lookup::script (String s) const
121 return (*symtables_p_)("scripts")->lookup (s);
125 Lookup::dynamic (String s) const
127 return (*symtables_p_)("dynamics")->lookup (s);
131 Lookup::clef (String s) const
133 return (*symtables_p_)("clefs")->lookup (s);
137 Lookup::dots () const
139 return (*symtables_p_)("dots")->lookup ("dot");
143 Lookup::flag (int j, Direction d) const
145 char c = (d == UP) ? 'u' : 'd';
146 return (*symtables_p_)("flags")->lookup (c + String (j));
150 Lookup::slur (Array<Offset> controls) const
152 assert (controls.size () == 8);
154 String ps = "\\embeddedps{\n";
156 Real dx = controls[3].x () - controls[0].x ();
157 Real dy = controls[3].y () - controls[0].y ();
159 for (int i = 5; i < 8; i++)
160 ps += String_convert::double_str (controls[i].x ()) + " "
161 + String_convert::double_str (controls[i].y ()) + " ";
163 ps += String_convert::double_str (controls[4].x ()) + " "
164 + String_convert::double_str (controls[4].y ()) + " ";
166 for (int i = 1; i < 4; i++)
167 ps += String_convert::double_str (controls[i].x ()) + " "
168 + String_convert::double_str (controls[i].y ()) + " ";
170 ps += String_convert::double_str (controls[0].x ()) + " "
171 + String_convert::double_str (controls[0].y ()) + " ";
178 s.dim_[X_AXIS] = Interval (0, dx);
179 s.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
184 Lookup::streepje (int type) const
189 Symtable * st = (*symtables_p_)("balls");
191 return st->lookup (String (type) + 'l');
195 Lookup::hairpin (Real &wid, bool decresc, bool continued) const
199 Real height = paper_l_->get_var ("barsize") / 6;
200 embed = "\\embeddedps{\n" ;
201 embed += String (wid) + " "
202 + String (height) + " "
203 + String (continued ? height/2 : 0) +
204 + " draw_" + String(decresc ? "de" : "") + "cresc}\n";
208 ret.dim_.x () = Interval (0,wid);
209 ret.dim_.y () = Interval (-2*height,2*height);
215 Lookup::meter (Array<Scalar> a) const
217 Atom s((*symtables_p_)("param")->lookup ("meter"));
218 s.tex_ = substitute_args (s.tex_,a);
224 Lookup::stem (Real y1,Real y2) const
234 s.dim_.x() = Interval (0,0);
235 s.dim_.y() = Interval (y1,y2);
238 a.push (print_dimen (y1));
239 a.push (print_dimen (y2));
241 String src = (*symtables_p_)("param")->lookup ("stem").tex_;
242 s.tex_ = substitute_args (src,a);
247 should be handled via Tex_ code and Lookup::bar()
250 Lookup::vbrace (Real &y) const
252 Atom brace = (*symtables_p_)("param")->lookup ("brace");
253 Interval ydims = brace.dim_[Y_AXIS];
254 Real min_y = ydims[LEFT];
255 Real max_y = ydims[RIGHT];
260 warning (_("piano brace too small (") + print_dimen (y)+ ")");
265 warning (_("piano brace too big (") + print_dimen (y)+ ")");
270 int idx = int (rint ((y- min_y)/step)) + 1;
275 brace.tex_ = substitute_args (brace.tex_,a);
276 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
283 Lookup::vbracket (Real &y) const
286 psbracket.tex_ = String ("\\embeddedps{ ") + y + " draw_bracket}";
287 psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2);
288 psbracket.dim_[X_AXIS] = Interval (0,4 PT);
290 Atom bracket = (*symtables_p_)("param")->lookup ("bracket");
291 Interval ydims = bracket.dim_[Y_AXIS];
294 Real min_y = ydims[LEFT];
295 Real max_y = ydims[RIGHT];
300 warning (_("bracket too small (") + print_dimen (y)+ ")");
305 warning (_("bracket too big (") + print_dimen (y)+ ")");
310 int idx = int (rint ((y- min_y)/step)) + 1;
315 bracket.tex_ = substitute_args (bracket.tex_,a);
316 bracket.dim_[Y_AXIS] = Interval (-y/2,y/2);