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) const
59 Atom a = afm_find (String ("accidentals") + String ("-") + to_str (j));
64 Lookup::add (String s, Symtable*p)
66 symtables_p_->add (s, p);
70 Lookup::afm_find (String s) const
74 *mlog << "[" << font_path_;
75 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
76 *mlog << "]" << flush ;
77 DOUT << this->afm_p_->str ();
79 Adobe_font_char_metric m = afm_p_->find_char (s);
86 a.dim_[X_AXIS] *= 1 / 1000.0;
87 a.dim_[Y_AXIS] *= 1 / 1000.0;
90 a.lambda_ = (lambda_scm ("char", arr));
91 a.str_ = "afm_find: " + s;
97 Lookup::ball (int j) const
102 return afm_find (String ("balls") + String ("-") + to_str (j));
106 Lookup::bar (String str, Real h) const
110 Atom a = (*symtables_p_) ("bars")->lookup (str);
111 a.lambda_ = (lambda_scm (a.str_, arr));
113 a.dim_.y () = Interval (-h/2, h/2);
119 Lookup::beam (Real slope, Real width, Real thick) const
121 Real height = slope * width;
122 Real min_y = (0 <? height) - thick/2;
123 Real max_y = (0 >? height) + thick/2;
131 a.lambda_ = (lambda_scm ("beam", arr));
133 a.dim_[X_AXIS] = Interval (0, width);
134 a.dim_[Y_AXIS] = Interval (min_y, max_y);
139 Lookup::clef (String st) const
141 return afm_find (String ("clefs") + String ("-") + st);
145 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
147 assert (controls.size () == 8);
149 Real dx = controls[3].x () - controls[0].x ();
150 Real dy = controls[3].y () - controls[0].y ();
154 a.dim_[X_AXIS] = Interval (0, dx);
155 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
157 // (lambda (o) (dashed-slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2))))
159 ly_append (ly_lambda_o (),
160 ly_list1 (ly_append (ly_func_o ("dashed-slur"),
161 gh_cons (gh_double2scm (thick), gh_cons (gh_double2scm (dash),
162 ly_list1 (ly_list2 (ly_quote (),
163 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
164 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
165 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
166 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
169 a.str_ = "dashed_slur";
174 Lookup::dots () const
176 return afm_find (String ("dots") + String ("-") + String ("dot"));
180 Lookup::dynamic (String st) const
182 return (*symtables_p_) ("dynamics")->lookup (st);
186 Lookup::fill (Box b) const
194 Lookup::flag (int j, Direction d) const
196 char c = (d == UP) ? 'u' : 'd';
197 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
202 Lookup::print () const
205 DOUT << "Lookup {\n";
206 symtables_p_->print ();
212 Lookup::rest (int j, bool o) const
214 return afm_find (String ("rests")
215 + String ("-") + to_str (j) + (o ? "o" : ""));
219 Lookup::rule_symbol (Real height, Real width) const
221 Atom a = (*symtables_p_) ("param")->lookup ("rule");
225 a.lambda_ = lambda_scm (a.str_, arr);
226 a.str_ = "rule_symbol";
227 a.dim_.x () = Interval (0, width);
228 a.dim_.y () = Interval (0, height);
232 Lookup::script (String str) const
234 return afm_find (String ("scripts") + String ("-") + str);
238 Lookup::special_time_signature (String s, Array<Real> arr) const
240 String symbolname = "timesig-" + s;
242 symbolname += to_str (arr[0]);
244 symbolname += "/" + to_str (arr[1]);
246 Atom a = afm_find (symbolname);
250 #if 0 //guess we covered this
251 // Try if the full name was given
252 a = afm_find ("timesig-"+s);
257 // Resort to default layout with numbers
258 return time_signature (arr);
262 Lookup::stem (Real y1, Real y2) const
272 a.dim_.x () = Interval (0,0);
273 a.dim_.y () = Interval (y1,y2);
277 Real stem_width = paper_l_->get_var ("stemthickness");
278 arr.push (-stem_width /2);
279 arr.push (stem_width);
283 a.lambda_ = lambda_scm ("stem", arr);
289 Lookup::streepje (int type) const
294 Atom a = afm_find ("balls" + String ("-") + to_str (type) + "l");
299 Lookup::text (String style, String text) const
304 Atom a = (*symtables_p_) ("style")->lookup (style);
305 a.lambda_ = lambda_scm (a.str_, arr);
311 Lookup::time_signature (Array<Real> a) const
313 Atom a ((*symtables_p_) ("param")->lookup ("time_signature"));
314 a.lambda_ = lambda_scm (a.str_, arr);
315 a.str_ = "time_signature";
319 should be handled via Tex_ code and Lookup::bar ()
322 Lookup::vbrace (Real &y) const
324 Atom a = (*symtables_p_) ("param")->lookup ( "brace");
325 Interval ydims = a.dim_[Y_AXIS];
326 Real min_y = ydims[LEFT];
327 Real max_y = ydims[RIGHT];
332 warning (_ ("piano brace")
333 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
338 warning (_ ("piano brace")
339 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
344 int idx = int (rint ( (y- min_y)/step)) + 1;
348 a.lambda_ = lambda_scm (a.str_, arr);
350 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
356 Lookup::hairpin (Real width, bool decresc, bool continued) const
359 Real height = paper_l_->staffheight_f () / 6;
361 ps += to_str (width) + " "
362 + to_str (height) + " "
363 + to_str (continued ? height/2 : 0) +
364 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
368 a.dim_.x () = Interval (0, width);
369 a.dim_.y () = Interval (-2*height, 2*height);
375 Lookup::plet (Real dy , Real dx, Direction dir) const
380 ps += String_convert::double_str (dx) + " "
381 + String_convert::double_str (dy) + " "
382 + String_convert::int_str ( (int)dir) +
391 Lookup::slur (Array<Offset> controls) const
393 assert (controls.size () == 8);
397 Real dx = controls[3].x () - controls[0].x ();
398 Real dy = controls[3].y () - controls[0].y ();
401 // (lambda (o) (slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2) .. )))
403 ly_append (ly_lambda_o (),
404 ly_list1 (ly_append (ly_func_o ("slur"),
405 ly_list1 (ly_list2 (ly_quote (),
406 gh_cons (ly_list2 (gh_double2scm (controls[5].x ()), gh_double2scm (controls[5].y ())),
407 gh_cons (ly_list2 (gh_double2scm (controls[6].x ()), gh_double2scm (controls[6].y ())),
408 gh_cons (ly_list2 (gh_double2scm (controls[7].x ()), gh_double2scm (controls[7].y ())),
409 gh_cons (ly_list2 (gh_double2scm (controls[4].x ()), gh_double2scm (controls[4].y ())),
410 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
411 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
412 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
413 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
414 SCM_EOL))))))))))))));
417 a.dim_[X_AXIS] = Interval (0, dx);
418 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
424 Lookup::vbracket (Real &y) const
427 Real min_y = paper_l_->staffheight_f ();
430 warning (_ ("bracket")
431 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
436 a.lambda_ = (lambda_scm ("bracket", arr));
438 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
439 a.dim_[X_AXIS] = Interval (0,4 PT);