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 return afm_find (String ("accidentals") + String ("-") + to_str (j));
63 Lookup::add (String s, Symtable*p)
65 symtables_p_->add (s, p);
69 Lookup::afm_find (String s) const
73 *mlog << "[" << font_path_;
74 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
75 *mlog << "]" << flush ;
76 DOUT << this->afm_p_->str ();
78 Adobe_font_char_metric m = afm_p_->find_char (s);
85 a.dim_[X_AXIS] *= 1 / 1000.0;
86 a.dim_[Y_AXIS] *= 1 / 1000.0;
89 a.lambda_ = lambda_scm ("char", arr);
95 Lookup::ball (int j) const
100 return afm_find (String ("balls") + String ("-") + to_str (j));
104 Lookup::bar (String str, Real h) const
108 Atom a = (*symtables_p_) ("bars")->lookup (str);
109 a.lambda_ = lambda_scm (a.str_, arr);
110 a.dim_.y () = Interval (-h/2, h/2);
116 Lookup::beam (Real slope, Real width, Real thick) const
118 Real height = slope * width;
119 Real min_y = (0 <? height) - thick/2;
120 Real max_y = (0 >? height) + thick/2;
128 a.lambda_ = lambda_scm ("beam", arr);
129 a.dim_[X_AXIS] = Interval (0, width);
130 a.dim_[Y_AXIS] = Interval (min_y, max_y);
135 Lookup::clef (String st) const
137 return afm_find (String ("clefs") + String ("-") + st);
141 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
143 assert (controls.size () == 8);
145 Real dx = controls[3].x () - controls[0].x ();
146 Real dy = controls[3].y () - controls[0].y ();
150 a.dim_[X_AXIS] = Interval (0, dx);
151 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
153 // (lambda (o) (dashed-slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2))))
155 ly_append (ly_lambda_o (),
156 ly_list1 (ly_append (ly_func_o ("dashed-slur"),
157 gh_cons (gh_double2scm (thick), gh_cons (gh_double2scm (dash),
158 ly_list1 (ly_list2 (ly_quote (),
159 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
160 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
161 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
162 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
169 Lookup::dots () const
171 return afm_find (String ("dots") + String ("-") + String ("dot"));
175 Lookup::dynamic (String st) const
177 return (*symtables_p_) ("dynamics")->lookup (st);
181 Lookup::fill (Box b) const
189 Lookup::flag (int j, Direction d) const
191 char c = (d == UP) ? 'u' : 'd';
192 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
196 Lookup::print () const
199 DOUT << "Lookup {\n";
200 symtables_p_->print ();
206 Lookup::rest (int j, bool o) const
208 return afm_find (String ("rests")
209 + String ("-") + to_str (j) + (o ? "o" : ""));
213 Lookup::rule_symbol (Real height, Real width) const
215 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
219 bs.lambda_ = lambda_scm (bs.str_, args);
220 bs.dim_.x () = Interval (0, width);
221 bs.dim_.y () = Interval (0, height);
226 Lookup::script (String str) const
228 return afm_find (String ("scripts") + String ("-") + str);
232 Lookup::special_time_signature (String s, Array<Real> arr) const
234 String symbolname = "timesig-" + s;
236 symbolname += to_str (arr[0]);
238 symbolname += "/" + to_str (arr[1]);
240 Atom a = afm_find (symbolname);
244 #if 0 //guess we covered this
245 // Try if the full name was given
246 a = afm_find ("timesig-"+s);
251 // Resort to default layout with numbers
252 return time_signature (arr);
256 Lookup::stem (Real y1, Real y2) const
266 s.dim_.x () = Interval (0,0);
267 s.dim_.y () = Interval (y1,y2);
271 Real stem_width = paper_l_->get_var ("stemthickness");
272 a.push (-stem_width /2);
277 s.lambda_ = lambda_scm ("stem", a);
283 Lookup::streepje (int type) const
288 return afm_find ("balls" + String ("-") +to_str (type) + "l");
292 Lookup::text (String style, String text) const
297 Atom s = (*symtables_p_) ("style")->lookup (style);
298 s.lambda_ = lambda_scm (s.str_, a);
305 Lookup::time_signature (Array<Real> a) const
307 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
308 s.lambda_ = lambda_scm (s.str_, a);
314 should be handled via Tex_ code and Lookup::bar ()
317 Lookup::vbrace (Real &y) const
319 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
320 Interval ydims = brace.dim_[Y_AXIS];
321 Real min_y = ydims[LEFT];
322 Real max_y = ydims[RIGHT];
327 warning (_ ("piano brace")
328 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
333 warning (_ ("piano brace")
334 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
339 int idx = int (rint ( (y- min_y)/step)) + 1;
343 brace.lambda_ = lambda_scm (brace.str_, a);
344 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
352 Lookup::hairpin (Real width, bool decresc, bool continued) const
355 Real height = paper_l_->staffheight_f () / 6;
357 ps += to_str (width) + " "
358 + to_str (height) + " "
359 + to_str (continued ? height/2 : 0) +
360 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
364 a.dim_.x () = Interval (0, width);
365 a.dim_.y () = Interval (-2*height, 2*height);
371 Lookup::plet (Real dy , Real dx, Direction dir) const
376 ps += String_convert::double_str (dx) + " "
377 + String_convert::double_str (dy) + " "
378 + String_convert::int_str ( (int)dir) +
387 Lookup::slur (Array<Offset> controls) const
389 assert (controls.size () == 8);
393 Real dx = controls[3].x () - controls[0].x ();
394 Real dy = controls[3].y () - controls[0].y ();
397 // (lambda (o) (slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2) .. )))
399 ly_append (ly_lambda_o (),
400 ly_list1 (ly_append (ly_func_o ("slur"),
401 ly_list1 (ly_list2 (ly_quote (),
402 gh_cons (ly_list2 (gh_double2scm (controls[5].x ()), gh_double2scm (controls[5].y ())),
403 gh_cons (ly_list2 (gh_double2scm (controls[6].x ()), gh_double2scm (controls[6].y ())),
404 gh_cons (ly_list2 (gh_double2scm (controls[7].x ()), gh_double2scm (controls[7].y ())),
405 gh_cons (ly_list2 (gh_double2scm (controls[4].x ()), gh_double2scm (controls[4].y ())),
406 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
407 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
408 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
409 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
410 SCM_EOL)))))))))))));
412 a.dim_[X_AXIS] = Interval (0, dx);
413 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
419 Lookup::vbracket (Real &y) const
422 Real min_y = paper_l_->staffheight_f ();
425 warning (_ ("bracket")
426 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
431 a.lambda_ = lambda_scm ("bracket", arr);
432 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
433 a.dim_[X_AXIS] = Interval (0,4 PT);