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 (postscript_global_b);
153 assert (controls.size () == 8);
155 String ps = "\\embeddedps{\n";
158 for (int i = 1; i < 4; i++)
159 ps += String_convert::double_str (controls[i].x ()) + " "
160 + String_convert::double_str (controls[i].y ()) + " ";
162 Real dx = controls[3].x ();
163 Real dy = controls[3].y ();
164 for (int i = 5; i < 8; i++)
165 ps += String_convert::double_str (controls[i].x () - dx) + " "
166 + String_convert::double_str (controls[i].y () - dy) + " ";
168 // this would be nice
169 for (int i = 1; i < 4; i++)
170 ps += String_convert::double_str (controls[i].x ()) + " "
171 + String_convert::double_str (controls[i].y ()) + " ";
173 for (int i = 5; i < 8; i++)
174 ps += String_convert::double_str (controls[i].x ()) + " "
175 + String_convert::double_str (controls[i].y ()) + " ";
183 s.dim_[X_AXIS] = Interval (0, dx);
184 s.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
189 Lookup::streepje (int type) const
194 Symtable * st = (*symtables_p_)("balls");
196 return st->lookup (String (type) + 'l');
200 Lookup::hairpin (Real &wid, bool decresc, bool continued) const
202 bool embedded_b = postscript_global_b;
205 Real height = paper_l_->get_var ("barsize") / 6;
208 embed = "\\embeddedps{\n" ;
209 embed += String (wid) + " "
210 + String (height) + " "
211 + String (continued ? height/2 : 0) +
212 + " draw_" + String(decresc ? "de" : "") + "cresc}\n";
219 warning (_("Crescendo too long (") + print_dimen (wid)
220 +_( ") shrinking (ugh)"));
223 int idx = int (rint (wid / 6 PT));
226 String idxstr = (decresc)? "decrescendosym" : "crescendosym";
227 ret=(*symtables_p_)("param")->lookup (idxstr);
231 ret.tex_ = substitute_args (ret.tex_, a);
234 ret.dim_.x () = Interval (0,wid);
235 ret.dim_.y () = Interval (-2*height,2*height);
236 // ret.translate_axis (ret.dim_[Y_AXIS][DOWN], Y_AXIS);
241 Lookup::meter (Array<Scalar> a) const
243 Atom s((*symtables_p_)("param")->lookup ("meter"));
244 s.tex_ = substitute_args (s.tex_,a);
250 Lookup::stem (Real y1,Real y2) const
260 s.dim_.x() = Interval (0,0);
261 s.dim_.y() = Interval (y1,y2);
264 a.push (print_dimen (y1));
265 a.push (print_dimen (y2));
267 String src = (*symtables_p_)("param")->lookup ("stem").tex_;
268 s.tex_ = substitute_args (src,a);
273 should be handled via Tex_ code and Lookup::bar()
276 Lookup::vbrace (Real &y) const
278 Atom brace = (*symtables_p_)("param")->lookup ("brace");
279 Interval ydims = brace.dim_[Y_AXIS];
280 Real min_y = ydims[LEFT];
281 Real max_y = ydims[RIGHT];
286 warning (_("piano brace too small (") + print_dimen (y)+ ")");
291 warning (_("piano brace too big (") + print_dimen (y)+ ")");
296 int idx = int (rint ((y- min_y)/step)) + 1;
301 brace.tex_ = substitute_args (brace.tex_,a);
302 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
309 Lookup::vbracket (Real &y) const
311 Atom bracket = (*symtables_p_)("param")->lookup ("bracket");
312 Interval ydims = bracket.dim_[Y_AXIS];
313 Real min_y = ydims[LEFT];
314 Real max_y = ydims[RIGHT];
319 warning (_("bracket too small (") + print_dimen (y)+ ")");
324 warning (_("bracket too big (") + print_dimen (y)+ ")");
329 int idx = int (rint ((y- min_y)/step)) + 1;
334 bracket.tex_ = substitute_args (bracket.tex_,a);
335 bracket.dim_[Y_AXIS] = Interval (-y/2,y/2);