2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 This doth suck. We should have PS output, and read spacing info from AFMs
17 #include "symtable.hh"
18 #include "dimension.hh"
21 #include "paper-def.hh"
22 #include "string-convert.hh"
28 symtables_p_ = new Symtables;
32 Lookup::Lookup (Lookup const &s)
35 font_path_ = s.font_path_;
36 paper_l_ = s.paper_l_;
37 symtables_p_ = new Symtables (*s.symtables_p_);
48 Lookup::afm_find (String s) const
52 *mlog << "[" << font_path_;
53 ((Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
54 *mlog << "]" << flush ;
55 DOUT << this->afm_p_->str ();
57 Adobe_font_char_metric m = afm_p_->find_char (s);
60 a.tex_ = String_convert::form_str ("\\char%d", m.code ());
62 a.dim_[X_AXIS] *= 1 / 1000.0;
63 a.dim_[Y_AXIS] *= 1 / 1000.0;
69 Lookup::add (String s, Symtable*p)
71 symtables_p_->add (s, p);
79 symtables_p_->print();
85 Lookup::text (String style, String text) const
90 Atom tsym = (*symtables_p_)("style")->lookup (style);
91 tsym.tex_ = substitute_args (tsym.tex_,a);
100 Lookup::ball (int j) const
105 Atom s = afm_find (String ("balls") + String ("-") + to_str (j));
110 Lookup::rest (int j, bool o) const
112 Atom s =afm_find (String ("rests")
113 + String ("-") + to_str (j) + (o ? "o" : ""));
119 Lookup::fill (Box b) const
129 Lookup::accidental (int j) const
131 Atom s= afm_find (String ("accidentals") + String ("-") + to_str (j));
137 Lookup::bar (String s, Real h) const
140 a.push (print_dimen (h));
141 Atom ret=(*symtables_p_)("bars")->lookup (s);
142 ret.tex_ = substitute_args (ret.tex_, a);
143 ret.dim_.y() = Interval (-h/2, h/2);
149 Lookup::script (String st) const
151 Atom s= afm_find (String ("scripts") + String ("-") + st);
157 Lookup::dynamic (String st) const
159 return (*symtables_p_) ("dynamics")->lookup (st);
163 Lookup::clef (String st) const
165 Atom s=afm_find (String ("clefs") + String ("-") + st);
171 Lookup::dots () const
173 Atom s=afm_find (String ("dots") + String ("-") + String("dot"));
179 Lookup::flag (int j, Direction d) const
181 char c = (d == UP) ? 'u' : 'd';
182 Atom s=afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
188 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
190 assert (controls.size () == 8);
192 String ps = "\\embeddedps{\n";
194 Real dx = controls[3].x () - controls[0].x ();
195 Real dy = controls[3].y () - controls[0].y ();
197 for (int i = 1; i < 4; i++)
198 ps += String_convert::double_str (controls[i].x ()) + " "
199 + String_convert::double_str (controls[i].y ()) + " ";
201 ps += String_convert::double_str (controls[0].x ()) + " "
202 + String_convert::double_str (controls[0].y ()) + " ";
204 ps += String_convert::double_str (thick) + " ";
205 Real on = dash > 1? thick * dash - thick : 0;
206 Real off = 2 * thick;
207 ps += "[" + String_convert::double_str (on) + " ";
208 ps += String_convert::double_str (off) + "] ";
209 ps += String_convert::int_str (0) + " ";
210 ps += " draw_dashed_slur}";
215 s.dim_[X_AXIS] = Interval (0, dx);
216 s.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
222 Lookup::slur (Array<Offset> controls) const
224 assert (controls.size () == 8);
226 String ps = "\\embeddedps{\n";
228 Real dx = controls[3].x () - controls[0].x ();
229 Real dy = controls[3].y () - controls[0].y ();
231 for (int i = 5; i < 8; i++)
232 ps += String_convert::double_str (controls[i].x ()) + " "
233 + String_convert::double_str (controls[i].y ()) + " ";
235 ps += String_convert::double_str (controls[4].x ()) + " "
236 + String_convert::double_str (controls[4].y ()) + " ";
238 for (int i = 1; i < 4; i++)
239 ps += String_convert::double_str (controls[i].x ()) + " "
240 + String_convert::double_str (controls[i].y ()) + " ";
242 ps += String_convert::double_str (controls[0].x ()) + " "
243 + String_convert::double_str (controls[0].y ()) + " ";
250 s.dim_[X_AXIS] = Interval (0, dx);
251 s.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
258 Lookup::streepje (int type) const
263 return afm_find ("balls" + String ("-") +to_str (type) + "l");
267 Lookup::hairpin (Real width, bool decresc, bool continued) const
271 Real height = paper_l_->staffheight_f () / 6;
272 embed = "\\embeddedps{\n" ;
273 embed += to_str (width) + " "
274 + to_str (height) + " "
275 + to_str (continued ? height/2 : 0) +
276 + " draw_" + String(decresc ? "de" : "") + "cresc}\n";
280 ret.dim_.x () = Interval (0, width);
281 ret.dim_.y () = Interval (-2*height, 2*height);
287 Lookup::time_signature (Array<Scalar> a) const
289 Atom s((*symtables_p_)("param")->lookup ("time_signature"));
290 s.tex_ = substitute_args (s.tex_,a);
297 Lookup::stem (Real y1,Real y2) const
307 s.dim_.x() = Interval (0,0);
308 s.dim_.y() = Interval (y1,y2);
313 Real stem_width = paper_l_->get_var ("stemthickness");
314 a.push (print_dimen (-stem_width /2));
315 a.push (print_dimen (stem_width));
316 a.push (print_dimen (y2));
317 a.push (print_dimen (-y1));
319 String src = "\\kern %\\vrule width % height % depth %";
320 s.tex_ = substitute_args (src,a);
326 should be handled via Tex_ code and Lookup::bar()
329 Lookup::vbrace (Real &y) const
331 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
332 Interval ydims = brace.dim_[Y_AXIS];
333 Real min_y = ydims[LEFT];
334 Real max_y = ydims[RIGHT];
339 warning (_ ("piano brace")
340 + " " + _ ("too small") + "(" + print_dimen (y) + ")");
345 warning (_ ("piano brace")
346 + " " + _ ("too big") + "(" + print_dimen (y)+ ")");
351 int idx = int (rint ((y- min_y)/step)) + 1;
355 a.push (to_str (idx));
356 brace.tex_ = substitute_args (brace.tex_,a);
357 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
366 Lookup::vbracket (Real &y) const
369 Real min_y = paper_l_->staffheight_f ();
372 warning (_ ("bracket")
373 + " " + _ ("too small") + "(" + print_dimen (y) + ")");
376 psbracket.tex_ = String ("\\embeddedps{ ") + to_str (y) + " draw_bracket}";
377 psbracket.dim_[Y_AXIS] = Interval (-y/2,y/2);
378 psbracket.dim_[X_AXIS] = Interval (0,4 PT);
381 Atom bracket = afm_find (String ("param") + "bracket");
382 Interval ydims = bracket.dim_[Y_AXIS];
384 Real min_y = ydims[LEFT];
385 Real max_y = ydims[RIGHT];
390 warning (_ ("bracket")
391 + " " + _ ("too small") + "(" + print_dimen (y) + ")");
396 warning (_ ("bracket")
397 + " " + _ ("too big") + "(" + print_dimen (y)+ ")");
402 int idx = int (rint ((y- min_y)/step)) + 1;
406 a.push (to_str (idx));
407 bracket.tex_ = substitute_args (bracket.tex_,a);
408 bracket.dim_[Y_AXIS] = Interval (-y/2,y/2);