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 Atom a (ps_beam (slope, width, thick));
119 Real height = slope * width;
120 Real min_y = (0 <? height) - thick/2;
121 Real max_y = (0 >? height) + thick/2;
123 a.dim_[X_AXIS] = Interval (0, width);
124 a.dim_[Y_AXIS] = Interval (min_y, max_y);
129 Lookup::clef (String st) const
131 return afm_find (String ("clefs") + String ("-") + st);
135 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
137 assert (controls.size () == 8);
139 Real dx = controls[3].x () - controls[0].x ();
140 Real dy = controls[3].y () - controls[0].y ();
144 a.dim_[X_AXIS] = Interval (0, dx);
145 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
147 // (lambda (o) (dashed-slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2))))
149 ly_append (ly_lambda_o (),
150 ly_list1 (ly_append (ly_func_o ("dashed-slur"),
151 gh_cons (gh_double2scm (thick), gh_cons (gh_double2scm (dash),
152 ly_list1 (ly_list2 (ly_quote (),
153 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
154 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
155 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
156 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
163 Lookup::dots () const
165 return afm_find (String ("dots") + String ("-") + String ("dot"));
169 Lookup::dynamic (String st) const
171 return (*symtables_p_) ("dynamics")->lookup (st);
175 Lookup::fill (Box b) const
183 Lookup::flag (int j, Direction d) const
185 char c = (d == UP) ? 'u' : 'd';
186 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
190 Lookup::print () const
193 DOUT << "Lookup {\n";
194 symtables_p_->print ();
200 Lookup::rest (int j, bool o) const
202 return afm_find (String ("rests")
203 + String ("-") + to_str (j) + (o ? "o" : ""));
207 Lookup::rule_symbol (Real height, Real width) const
209 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
213 bs.lambda_ = lambda_scm (bs.str_, args);
214 bs.dim_.x () = Interval (0, width);
215 bs.dim_.y () = Interval (0, height);
220 Lookup::script (String str) const
222 return afm_find (String ("scripts") + String ("-") + str);
226 Lookup::special_time_signature (String s, Array<Scalar> arr) const
229 String symbolname = "timesig-"+s+"%/%";
230 Atom a (afm_find (lambda_scm (symbolname, arr)));
233 // Try if the full name was given
234 a = afm_find ("timesig-"+s);
237 // Resort to default layout with numbers
239 return time_signature (arr);
243 Lookup::stem (Real y1, Real y2) const
253 s.dim_.x () = Interval (0,0);
254 s.dim_.y () = Interval (y1,y2);
258 Real stem_width = paper_l_->get_var ("stemthickness");
259 a.push (-stem_width /2);
264 s.lambda_ = lambda_scm ("stem", a);
270 Lookup::streepje (int type) const
275 return afm_find ("balls" + String ("-") +to_str (type) + "l");
279 Lookup::text (String style, String text) const
284 Atom s = (*symtables_p_) ("style")->lookup (style);
285 s.lambda_ = lambda_scm (s.str_, a);
292 Lookup::time_signature (Array<Scalar> a) const
294 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
295 s.lambda_ = lambda_scm (s.str_, a);
301 should be handled via Tex_ code and Lookup::bar ()
304 Lookup::vbrace (Real &y) const
306 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
307 Interval ydims = brace.dim_[Y_AXIS];
308 Real min_y = ydims[LEFT];
309 Real max_y = ydims[RIGHT];
314 warning (_ ("piano brace")
315 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
320 warning (_ ("piano brace")
321 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
326 int idx = int (rint ( (y- min_y)/step)) + 1;
330 brace.lambda_ = lambda_scm (brace.str_, a);
331 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
339 Lookup::hairpin (Real width, bool decresc, bool continued) const
342 Real height = paper_l_->staffheight_f () / 6;
344 ps += to_str (width) + " "
345 + to_str (height) + " "
346 + to_str (continued ? height/2 : 0) +
347 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
351 a.dim_.x () = Interval (0, width);
352 a.dim_.y () = Interval (-2*height, 2*height);
358 Lookup::plet (Real dy , Real dx, Direction dir) const
363 ps += String_convert::double_str (dx) + " "
364 + String_convert::double_str (dy) + " "
365 + String_convert::int_str ( (int)dir) +
374 Lookup::ps_beam (Real slope, Real width, Real thick) const
377 ps += to_str (width) + " "+ to_str (slope) + " " + to_str (thick)
386 Lookup::slur (Array<Offset> controls) const
388 assert (controls.size () == 8);
392 Real dx = controls[3].x () - controls[0].x ();
393 Real dy = controls[3].y () - controls[0].y ();
396 // (lambda (o) (slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2) .. )))
398 ly_append (ly_lambda_o (),
399 ly_list1 (ly_append (ly_func_o ("slur"),
400 ly_list1 (ly_list2 (ly_quote (),
401 gh_cons (ly_list2 (gh_double2scm (controls[5].x ()), gh_double2scm (controls[5].y ())),
402 gh_cons (ly_list2 (gh_double2scm (controls[6].x ()), gh_double2scm (controls[6].y ())),
403 gh_cons (ly_list2 (gh_double2scm (controls[7].x ()), gh_double2scm (controls[7].y ())),
404 gh_cons (ly_list2 (gh_double2scm (controls[4].x ()), gh_double2scm (controls[4].y ())),
405 gh_cons (ly_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
406 gh_cons (ly_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
407 gh_cons (ly_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
408 gh_cons (ly_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
409 SCM_EOL)))))))))))));
411 a.dim_[X_AXIS] = Interval (0, dx);
412 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
418 Lookup::vbracket (Real &y) const
421 Real min_y = paper_l_->staffheight_f ();
424 warning (_ ("bracket")
425 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
430 a.lambda_ = lambda_scm ("bracket", arr);
431 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
432 a.dim_[X_AXIS] = Interval (0,4 PT);