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"
29 symtables_p_ = new Symtables;
33 Lookup::Lookup (Lookup const& s)
36 font_path_ = s.font_path_;
37 paper_l_ = s.paper_l_;
38 symtables_p_ = new Symtables (*s.symtables_p_);
42 Lookup::Lookup (Symtables const& s)
45 font_path_ = s.font_path_;
47 symtables_p_ = new Symtables (s);
58 Lookup::accidental (int j, bool cautionary) const
60 Molecule m(afm_find (String ("accidentals") + String ("-") + to_str (j)));
63 m.add_at_edge(X_AXIS, LEFT,
64 Molecule(afm_find (String ("accidentals") + String ("-("))))
66 m.add_at_edge(X_AXIS, RIGHT,
67 Molecule(afm_find (String ("accidentals") + String ("-)"))))
74 Lookup::add (String s, Symtable*p)
76 symtables_p_->add (s, p);
80 Lookup::afm_find (String s, bool warn) const
84 *mlog << "[" << font_path_;
85 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
86 *mlog << "]" << flush ;
87 DOUT << this->afm_p_->str ();
89 Adobe_font_char_metric m = afm_p_->find_char (s, warn);
96 a.dim_[X_AXIS] *= 1 / 1000.0;
97 a.dim_[Y_AXIS] *= 1 / 1000.0;
100 a.lambda_ = (lambda_scm ("char", arr));
101 a.str_ = "afm_find: " + s;
107 Lookup::ball (int j) const
112 return afm_find (String ("balls") + String ("-") + to_str (j));
116 Lookup::bar (String str, Real h) const
120 Atom a = (*symtables_p_) ("bars")->lookup (str);
121 a.lambda_ = (lambda_scm (a.str_, arr));
123 a.dim_.y () = Interval (-h/2, h/2);
129 Lookup::beam (Real slope, Real width, Real thick) const
131 Real height = slope * width;
132 Real min_y = (0 <? height) - thick/2;
133 Real max_y = (0 >? height) + thick/2;
141 a.lambda_ = (lambda_scm ("beam", arr));
143 a.dim_[X_AXIS] = Interval (0, width);
144 a.dim_[Y_AXIS] = Interval (min_y, max_y);
149 Lookup::clef (String st) const
151 return afm_find (String ("clefs") + String ("-") + st);
155 offset2scm (Offset o)
157 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]), SCM_UNDEFINED);
161 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
163 assert (controls.size () == 8);
164 Offset d = controls[3] - controls[0];
171 a.dim_[X_AXIS] = Interval (0, dx);
172 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
175 for (int i=0; i< 4; i++)
177 sc[i] = offset2scm (controls[i]);
180 // (lambda (o) (dashed-slur o thick dash '(stuff))
181 a.lambda_ = gh_list (gh_append3 (ly_lambda_o (),
182 ly_func_o ("dashed-slur"),
183 gh_list (gh_double2scm (thick),
184 gh_double2scm (dash),
185 ly_quote_scm (gh_list (sc[0], sc[1], sc[2], sc[3], SCM_UNDEFINED)),
189 a.str_ = "dashed_slur";
194 Lookup::dots () const
196 return afm_find (String ("dots") + String ("-") + String ("dot"));
200 Lookup::dynamic (String st) const
202 return (*symtables_p_) ("dynamics")->lookup (st);
206 Lookup::fill (Box b) const
214 Lookup::flag (int j, Direction d) const
216 char c = (d == UP) ? 'u' : 'd';
217 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
222 Lookup::print () const
225 DOUT << "Lookup {\n";
226 symtables_p_->print ();
232 Lookup::rest (int j, bool o) const
234 return afm_find (String ("rests")
235 + String ("-") + to_str (j) + (o ? "o" : ""));
239 Lookup::rule_symbol (Real height, Real width) const
241 Atom a = (*symtables_p_) ("param")->lookup ("rule");
245 a.lambda_ = (lambda_scm (a.str_, arr));
246 a.str_ = "rule_symbol";
247 a.dim_.x () = Interval (0, width);
248 a.dim_.y () = Interval (0, height);
253 Lookup::script (String str) const
255 return afm_find (String ("scripts") + String ("-") + str);
259 Lookup::special_time_signature (String s, Array<int> arr) const
261 // First guess: s contains only the signature style
262 assert (arr.size () >1);
263 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
265 Atom a = afm_find (symbolname, false);
269 // Second guess: s contains the full signature name
270 a = afm_find ("timesig-"+s, false);
274 // Resort to default layout with numbers
275 return time_signature (arr);
279 Lookup::stem (Real y1, Real y2) const
289 a.dim_.x () = Interval (0,0);
290 a.dim_.y () = Interval (y1,y2);
294 Real stem_width = paper_l_->get_var ("stemthickness");
295 arr.push (-stem_width /2);
296 arr.push (stem_width);
300 a.lambda_ = (lambda_scm ("stem", arr));
307 Lookup::streepje (int type) const
312 return afm_find ("balls" + String ("-") +to_str (type) + "l");
316 Lookup::text (String style, String text) const
321 Atom a = (*symtables_p_) ("style")->lookup (style);
322 a.lambda_ = lambda_scm (a.str_, arr);
331 Lookup::time_signature (Array<int> a) const
333 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
334 s.lambda_ = (lambda_scm (s.str_, a));
340 should be handled via Tex_ code and Lookup::bar ()
343 Lookup::vbrace (Real &y) const
345 Atom a = (*symtables_p_) ("param")->lookup ( "brace");
346 Interval ydims = a.dim_[Y_AXIS];
347 Real min_y = ydims[LEFT];
348 Real max_y = ydims[RIGHT];
353 warning (_ ("piano brace")
354 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
359 warning (_ ("piano brace")
360 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
365 int idx = int (rint ( (y- min_y)/step)) + 1;
369 a.lambda_ = (lambda_scm (a.str_, arr));
371 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
377 Lookup::hairpin (Real width, bool decresc, bool continued) const
380 Real height = paper_l_->staffheight_f () / 6;
382 ps += to_str (width) + " "
383 + to_str (height) + " "
384 + to_str (continued ? height/2 : 0) +
385 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
387 a.dim_.x () = Interval (0, width);
388 a.dim_.y () = Interval (-2*height, 2*height);
394 Lookup::plet (Real dy , Real dx, Direction dir) const
398 ps += String_convert::double_str (dx) + " "
399 + String_convert::double_str (dy) + " "
400 + String_convert::int_str ( (int)dir) +
409 Lookup::slur (Array<Offset> controls) const
411 assert (controls.size () == 8);
415 Real dx = controls[3].x () - controls[0].x ();
416 Real dy = controls[3].y () - controls[0].y ();
420 int indices[] = {5,6,7,4,1,2,3,0};
422 for (int i= 0; i < 8; i++)
423 scontrols[i] = offset2scm (controls[indices[i]]);
427 gh_append2 (ly_lambda_o (),
428 gh_list (gh_append2 (ly_func_o ("slur"),
429 gh_list (ly_quote_scm (gh_list (scontrols[0],
446 a.dim_[X_AXIS] = Interval (0, dx);
447 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
453 Lookup::vbracket (Real &y) const
456 Real min_y = paper_l_->staffheight_f ();
459 warning (_ ("bracket")
460 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
465 a.lambda_ = (lambda_scm ("bracket", arr));
467 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
468 a.dim_[X_AXIS] = Interval (0,4 PT);