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>
8 Jan Nieuwenhuizen <janneke@gnu.org>
11 Read spacing info from AFMs
17 #include "dimensions.hh"
18 #include "symtable.hh"
20 #include "paper-def.hh"
21 #include "string-convert.hh"
23 #include "lily-guile.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_);
41 Lookup::Lookup (Symtables const& s)
44 font_path_ = s.font_path_;
46 symtables_p_ = new Symtables (s);
57 Lookup::accidental (int j, bool cautionary) const
59 Molecule m(afm_find (String ("accidentals") + String ("-") + to_str (j)));
62 m.add_at_edge(X_AXIS, LEFT,
63 Molecule(afm_find (String ("accidentals") + String ("-("))))
65 m.add_at_edge(X_AXIS, RIGHT,
66 Molecule(afm_find (String ("accidentals") + String ("-)"))))
73 Lookup::add (String s, Symtable*p)
75 symtables_p_->add (s, p);
79 Lookup::afm_find (String s, bool warn) const
83 *mlog << "[" << font_path_;
84 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
85 *mlog << "]" << flush ;
86 DOUT << this->afm_p_->str ();
88 Adobe_font_char_metric m = afm_p_->find_char (s, warn);
95 a.dim_[X_AXIS] *= 1 / 1000.0;
96 a.dim_[Y_AXIS] *= 1 / 1000.0;
99 a.lambda_ = (lambda_scm ("char", arr));
100 a.str_ = "afm_find: " + s;
106 Lookup::ball (int j) const
111 return afm_find (String ("balls") + String ("-") + to_str (j));
115 Lookup::bar (String str, Real h) const
119 Atom a = (*symtables_p_) ("bars")->lookup (str);
120 a.lambda_ = (lambda_scm (a.str_, arr));
122 a.dim_.y () = Interval (-h/2, h/2);
128 Lookup::beam (Real slope, Real width, Real thick) const
130 Real height = slope * width;
131 Real min_y = (0 <? height) - thick/2;
132 Real max_y = (0 >? height) + thick/2;
140 a.lambda_ = (lambda_scm ("beam", arr));
142 a.dim_[X_AXIS] = Interval (0, width);
143 a.dim_[Y_AXIS] = Interval (min_y, max_y);
148 Lookup::clef (String st) const
150 return afm_find (String ("clefs") + String ("-") + st);
154 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
156 assert (controls.size () == 8);
158 Real dx = controls[3].x () - controls[0].x ();
159 Real dy = controls[3].y () - controls[0].y ();
163 a.dim_[X_AXIS] = Interval (0, dx);
164 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
166 // (lambda (o) (dashed-slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2))))
168 ly_append (ly_lambda_o (),
169 ly_list1 (ly_append (ly_func_o ("dashed-slur"),
170 gh_cons (gh_double2scm (thick), gh_cons (gh_double2scm (dash),
171 ly_list1 (ly_list2 (ly_quote (),
172 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
173 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
174 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
175 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
178 a.str_ = "dashed_slur";
183 Lookup::dots () const
185 return afm_find (String ("dots") + String ("-") + String ("dot"));
189 Lookup::dynamic (String st) const
191 return (*symtables_p_) ("dynamics")->lookup (st);
195 Lookup::fill (Box b) const
203 Lookup::flag (int j, Direction d) const
205 char c = (d == UP) ? 'u' : 'd';
206 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
211 Lookup::print () const
214 DOUT << "Lookup {\n";
215 symtables_p_->print ();
221 Lookup::rest (int j, bool o) const
223 return afm_find (String ("rests")
224 + String ("-") + to_str (j) + (o ? "o" : ""));
228 Lookup::rule_symbol (Real height, Real width) const
230 Atom a = (*symtables_p_) ("param")->lookup ("rule");
234 a.lambda_ = (lambda_scm (a.str_, arr));
235 a.str_ = "rule_symbol";
236 a.dim_.x () = Interval (0, width);
237 a.dim_.y () = Interval (0, height);
242 Lookup::script (String str) const
244 return afm_find (String ("scripts") + String ("-") + str);
248 Lookup::special_time_signature (String s, Array<int> arr) const
250 // First guess: s contains only the signature style
251 assert (arr.size () >1);
252 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
254 Atom a = afm_find (symbolname, false);
258 // Second guess: s contains the full signature name
259 a = afm_find ("timesig-"+s, false);
263 // Resort to default layout with numbers
264 return time_signature (arr);
268 Lookup::stem (Real y1, Real y2) const
278 a.dim_.x () = Interval (0,0);
279 a.dim_.y () = Interval (y1,y2);
283 Real stem_width = paper_l_->get_var ("stemthickness");
284 arr.push (-stem_width /2);
285 arr.push (stem_width);
289 a.lambda_ = (lambda_scm ("stem", arr));
296 Lookup::streepje (int type) const
301 return afm_find ("balls" + String ("-") +to_str (type) + "l");
305 Lookup::text (String style, String text) const
310 Atom a = (*symtables_p_) ("style")->lookup (style);
311 a.lambda_ = lambda_scm (a.str_, arr);
320 Lookup::time_signature (Array<int> a) const
322 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
323 s.lambda_ = (lambda_scm (s.str_, a));
329 should be handled via Tex_ code and Lookup::bar ()
332 Lookup::vbrace (Real &y) const
334 Atom a = (*symtables_p_) ("param")->lookup ( "brace");
335 Interval ydims = a.dim_[Y_AXIS];
336 Real min_y = ydims[LEFT];
337 Real max_y = ydims[RIGHT];
342 warning (_ ("piano brace")
343 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
348 warning (_ ("piano brace")
349 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
354 int idx = int (rint ( (y- min_y)/step)) + 1;
358 a.lambda_ = (lambda_scm (a.str_, arr));
360 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
366 Lookup::hairpin (Real width, bool decresc, bool continued) const
369 Real height = paper_l_->staffheight_f () / 6;
371 ps += to_str (width) + " "
372 + to_str (height) + " "
373 + to_str (continued ? height/2 : 0) +
374 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
378 a.dim_.x () = Interval (0, width);
379 a.dim_.y () = Interval (-2*height, 2*height);
385 Lookup::plet (Real dy , Real dx, Direction dir) const
390 ps += String_convert::double_str (dx) + " "
391 + String_convert::double_str (dy) + " "
392 + String_convert::int_str ( (int)dir) +
401 Lookup::slur (Array<Offset> controls) const
403 assert (controls.size () == 8);
407 Real dx = controls[3].x () - controls[0].x ();
408 Real dy = controls[3].y () - controls[0].y ();
411 // (lambda (o) (slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2) .. )))
413 ly_append (ly_lambda_o (),
414 ly_list1 (ly_append (ly_func_o ("slur"),
415 ly_list1 (ly_list2 (ly_quote (),
416 gh_cons (ly_list2 (gh_double2scm (controls[5].x ()), gh_double2scm (controls[5].y ())),
417 gh_cons (ly_list2 (gh_double2scm (controls[6].x ()), gh_double2scm (controls[6].y ())),
418 gh_cons (ly_list2 (gh_double2scm (controls[7].x ()), gh_double2scm (controls[7].y ())),
419 gh_cons (ly_list2 (gh_double2scm (controls[4].x ()), gh_double2scm (controls[4].y ())),
420 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
421 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
422 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
423 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
424 SCM_EOL))))))))))))));
427 a.dim_[X_AXIS] = Interval (0, dx);
428 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
434 Lookup::vbracket (Real &y) const
437 Real min_y = paper_l_->staffheight_f ();
440 warning (_ ("bracket")
441 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
446 a.lambda_ = (lambda_scm ("bracket", arr));
448 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
449 a.dim_[X_AXIS] = Interval (0,4 PT);