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>
17 #include "dimensions.hh"
18 #include "symtable.hh"
20 #include "paper-def.hh"
21 #include "string-convert.hh"
22 #include "file-path.hh"
24 #include "lily-guile.hh"
25 #include "all-fonts.hh"
29 array_to_list (SCM *a , int l)
34 list = gh_cons (a[i], list);
43 symtables_p_ = new Symtables;
47 Lookup::Lookup (Lookup const& s)
49 font_name_ = s.font_name_;
50 paper_l_ = s.paper_l_;
51 symtables_p_ = new Symtables (*s.symtables_p_);
55 Lookup::Lookup (Symtables const& s)
57 font_name_ = s.font_name_;
59 symtables_p_ = new Symtables (s);
69 Lookup::accidental (int j, bool cautionary) const
71 Molecule m(afm_find (String ("accidentals") + String ("-") + to_str (j)));
74 m.add_at_edge(X_AXIS, LEFT,
75 Molecule(afm_find (String ("accidentals") + String ("-("))))
77 m.add_at_edge(X_AXIS, RIGHT,
78 Molecule(afm_find (String ("accidentals") + String ("-)"))))
85 Lookup::add (String s, Symtable*p)
87 symtables_p_->add (s, p);
92 Lookup::afm_find (String s, bool warn) const
95 ((Lookup*)this)->afm_l_ = all_fonts_global_p->find_font (font_name_);
97 Adobe_font_char_metric m = afm_l_->find_char (s, warn);
104 // a.dim_[X_AXIS] *= 1 / 1000.0;
105 // a.dim_[Y_AXIS] *= 1 / 1000.0;
108 a.lambda_ = gh_list (ly_symbol ("char"),
109 gh_int2scm (m.code ()),
111 a.str_ = "afm_find: " + s;
112 a.font_ = font_name_;
117 Lookup::ball (int j) const
122 return afm_find (String ("balls") + String ("-") + to_str (j));
126 Lookup::special_ball (int j, String kind_of_ball) const
131 return afm_find (String ("balls") + String ("-") + kind_of_ball);
135 Lookup::bar (String str, Real h) const
138 Atom a = (*symtables_p_) ("bars")->lookup (str);
141 a.lambda_ = gh_list (ly_symbol (a.str_.ch_C()),
146 a.dim_.y () = Interval (-h/2, h/2);
147 a.font_ = font_name_;
152 Lookup::beam (Real slope, Real width, Real thick) const
154 Real height = slope * width;
155 Real min_y = (0 <? height) - thick/2;
156 Real max_y = (0 >? height) + thick/2;
159 a.lambda_ = gh_list (ly_symbol ("beam"),
160 gh_double2scm (width),
161 gh_double2scm (slope),
162 gh_double2scm (thick),
165 a.dim_[X_AXIS] = Interval (0, width);
166 a.dim_[Y_AXIS] = Interval (min_y, max_y);
171 Lookup::clef (String st) const
173 return afm_find (String ("clefs") + String ("-") + st);
177 offset2scm (Offset o)
179 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
184 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
186 assert (controls.size () == 8);
187 Offset d = controls[3] - controls[0];
193 a.font_ = font_name_;
194 a.dim_[X_AXIS] = Interval (0, dx);
195 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
198 for (int i=0; i< 4; i++)
200 sc[i] = offset2scm (controls[i]);
204 gh_list (ly_symbol ("dashed-slur"),
205 gh_double2scm (thick),
206 gh_double2scm (dash),
207 ly_quote_scm (array_to_list (sc, 4)),
210 a.str_ = "dashed_slur";
215 Lookup::dots () const
217 return afm_find (String ("dots") + String ("-") + String ("dot"));
221 Lookup::dynamic (String st) const
223 return (*symtables_p_) ("dynamics")->lookup (st);
227 Lookup::extender (Real width) const
229 Atom a = (*symtables_p_) ("param")->lookup ("extender");
230 a.lambda_ = gh_list (ly_symbol (a.str_),
231 gh_double2scm (width),
234 a.font_ = font_name_;
239 Lookup::fill (Box b) const
247 Lookup::flag (int j, Direction d) const
249 char c = (d == UP) ? 'u' : 'd';
250 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
255 Lookup::print () const
258 DOUT << "Lookup {\n";
259 symtables_p_->print ();
265 Lookup::rest (int j, bool o) const
267 return afm_find (String ("rests")
268 + String ("-") + to_str (j) + (o ? "o" : ""));
272 Lookup::rule_symbol (Real height, Real width) const
275 a.lambda_ = gh_list (ly_symbol ("rulesym"),
276 gh_double2scm (height),
277 gh_double2scm (width),
279 a.dim_.x () = Interval (0, width);
280 a.dim_.y () = Interval (0, height);
285 Lookup::script (String str) const
287 return afm_find (String ("scripts") + String ("-") + str);
291 Lookup::special_time_signature (String s, Array<int> arr) const
293 // First guess: s contains only the signature style
294 assert (arr.size () >1);
295 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
297 Atom a = afm_find (symbolname, false);
301 // Second guess: s contains the full signature name
302 a = afm_find ("timesig-"+s, false);
306 // Resort to default layout with numbers
307 return time_signature (arr);
311 Lookup::stem (Real y1, Real y2) const
321 a.dim_.x () = Interval (0,0);
322 a.dim_.y () = Interval (y1,y2);
324 Real stem_width = paper_l_->get_var ("stemthickness");
326 a.lambda_ = gh_list (ly_symbol ("stem"),
327 gh_double2scm(-stem_width /2),
328 gh_double2scm(stem_width),
333 a.font_ = font_name_;
338 Lookup::streepje (int type) const
343 return afm_find ("balls" + String ("-") +to_str (type) + "l");
346 static Dict_initialiser<char const*> cmr_init[] = {
348 {"dynamic", "feta-din"},
349 {"finger", "feta-nummer"},
354 {"mark", "feta-nummer"},
355 {"nummer", "feta-nummer"},
359 static Dictionary<char const *> cmr_dict (cmr_init);
362 Lookup::text (String style, String text) const
364 Atom a = (*symtables_p_) ("style")->lookup (style);
366 a.lambda_ = gh_list(ly_symbol (a.str_),
367 gh_str02scm (text.ch_C()),
370 Real font_w = a.dim_.x ().length ();
371 Real font_h = a.dim_.y ().length ();
373 if (cmr_dict.elem_b (style))
375 style = String (cmr_dict [style]) + to_str ((int)font_h); // ugh
378 Adobe_font_metric* afm_l = all_fonts_global_p->find_font (style);
381 for (int i = 0; i < text.length_i (); i++)
384 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
389 int code = afm_l->ascii_to_metric_idx_[c];
392 Adobe_font_char_metric m = afm_l->char_metrics_[code];
393 w += m.B_.x ().length ();
394 DOUT << to_str (m.B_.x ().length ()) << " ";
398 DOUT << "\n" << to_str (w) << "\n";
399 a.dim_.x () = Interval (0, w);
400 a.font_ = font_name_;
406 Lookup::time_signature (Array<int> a) const
408 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
409 s.lambda_ = gh_list (ly_symbol (s.str_),
417 Lookup::vbrace (Real &y) const
420 a.lambda_ = gh_list (ly_symbol ("pianobrace"),
424 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
425 a.font_ = font_name_;
430 Lookup::hairpin (Real width, bool decresc, bool continued) const
433 Real height = paper_l_->staffheight_f () / 6;
435 String hairpin = String (decresc ? "de" : "") + "crescendo";
436 a.lambda_ = gh_list (ly_symbol (hairpin),
437 gh_double2scm (width),
438 gh_double2scm (height),
439 gh_double2scm (continued ? height/2 : 0.0),
441 a.dim_.x () = Interval (0, width);
442 a.dim_.y () = Interval (-2*height, 2*height);
443 a.font_ = font_name_;
448 Lookup::plet (Real dy , Real dx, Direction dir) const
451 a.lambda_ = gh_list(ly_symbol ("tuplet"),
454 gh_int2scm (dir), SCM_UNDEFINED);
460 Lookup::slur (Array<Offset> controls) const
462 assert (controls.size () == 8);
463 Real dx = controls[3].x () - controls[0].x ();
464 Real dy = controls[3].y () - controls[0].y ();
468 int indices[] = {5,6,7,4,1,2,3,0};
470 for (int i= 0; i < 8; i++)
471 scontrols[i] = offset2scm (controls[indices[i]]);
474 a.lambda_ =gh_list (ly_symbol ("slur"),
475 ly_quote_scm (array_to_list (scontrols, 8)),
478 a.dim_[X_AXIS] = Interval (0, dx);
479 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
480 a.font_ = font_name_;
485 Lookup::vbracket (Real &y) const
488 a.lambda_ = gh_list (ly_symbol ("bracket"),
492 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
493 a.dim_[X_AXIS] = Interval (0,4 PT);
498 Lookup::volta (Real w, bool last_b) const
501 a.lambda_ = gh_list (ly_symbol ("volta"),
506 Real interline_f = paper_l_->interline_f ();
508 a.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
509 a.dim_[X_AXIS] = Interval (0, w);