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"
19 #include "paper-def.hh"
20 #include "string-convert.hh"
21 #include "file-path.hh"
23 #include "lily-guile.hh"
24 #include "all-fonts.hh"
27 #include "molecule.hh"
30 array_to_list (SCM *a , int l)
35 list = gh_cons (a[i], list);
47 Lookup::Lookup (Lookup const& s)
49 font_name_ = s.font_name_;
57 Lookup::accidental (int j, bool cautionary) const
59 Molecule m(afm_find (String ("accidentals") + String ("-") + to_str (j)));
62 Atom open = afm_find (String ("accidentals") + String ("-("));
63 Atom close = afm_find (String ("accidentals") + String ("-)"));
64 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
65 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
73 Lookup::afm_find (String s, bool warn) const
77 Lookup * me = ((Lookup*)this);
78 me->afm_l_ = all_fonts_global_p->find_afm (font_name_);
81 warning (_f("Can't open `%s'\n", font_name_));
82 warning (_f("Search path %s\n", global_path.str ().ch_C()));
85 Adobe_font_char_metric m = afm_l_->find_char (s, warn);
91 a.dim_ = m.dimensions();
93 a.lambda_ = gh_list (ly_symbol ("char"),
94 gh_int2scm (m.code ()),
101 Lookup::ball (int j) const
106 return afm_find (String ("balls") + String ("-") + to_str (j));
110 Lookup::simple_bar (String type, Real h) const
112 SCM thick = ly_symbol ("barthick_" + type);
114 if (paper_l_->scope_p_->elem_b (thick))
116 w = paper_l_->get_realvar (thick);
120 a.lambda_ = gh_list (ly_symbol ("filledbox"),
127 a.dim_[X_AXIS] = Interval(0,w);
128 a.dim_[Y_AXIS] = Interval (-h/2, h/2);
134 Lookup::bar (String str, Real h) const
136 Real kern = paper_l_->get_var ("bar_kern");
137 Real thinkern = paper_l_->get_var ("bar_thinkern");
138 Atom thin = simple_bar ("thin", h);
139 Atom thick = simple_bar ("thick", h);
140 Atom colon = afm_find ("dots-repeatcolon");
146 return fill (Box (Interval(0,0),Interval (-h/2, h/2)));
152 else if (str == "|.")
154 m.add_at_edge (X_AXIS, LEFT, thick, 0);
155 m.add_at_edge (X_AXIS, LEFT, thin,kern);
157 else if (str == ".|")
159 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
160 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
162 else if (str == ":|")
164 m.add_at_edge (X_AXIS, LEFT, thick, 0);
165 m.add_at_edge (X_AXIS, LEFT, thin, kern);
166 m.add_at_edge (X_AXIS, LEFT, colon, kern);
168 else if (str == "|:")
170 m.add_at_edge (X_AXIS, RIGHT, thick,0);
171 m.add_at_edge (X_AXIS, RIGHT, thin,kern);
172 m.add_at_edge (X_AXIS, RIGHT, colon,kern);
174 else if (str == ":|:")
176 m.add_at_edge (X_AXIS, LEFT, thick,thinkern);
177 m.add_at_edge (X_AXIS, LEFT, colon,kern);
178 m.add_at_edge (X_AXIS, RIGHT, thick,kern);
179 m.add_at_edge (X_AXIS, RIGHT, colon,kern);
181 else if (str == "||")
183 m.add_at_edge (X_AXIS, RIGHT, thin,0);
184 m.add_at_edge (X_AXIS, RIGHT, thin,thinkern);
187 else if (str == ".|.")
189 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
190 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
197 Lookup::beam (Real slope, Real width, Real thick) const
199 Real height = slope * width;
200 Real min_y = (0 <? height) - thick/2;
201 Real max_y = (0 >? height) + thick/2;
204 a.lambda_ = gh_list (ly_symbol ("beam"),
205 gh_double2scm (width),
206 gh_double2scm (slope),
207 gh_double2scm (thick),
210 a.dim_[X_AXIS] = Interval (0, width);
211 a.dim_[Y_AXIS] = Interval (min_y, max_y);
216 Lookup::clef (String st) const
218 return afm_find (String ("clefs") + String ("-") + st);
222 offset2scm (Offset o)
224 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
229 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
231 assert (controls.size () == 8);
232 Offset d = controls[3] - controls[0];
238 a.font_ = font_name_;
239 a.dim_[X_AXIS] = Interval (0, dx);
240 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
243 for (int i=0; i< 4; i++)
245 sc[i] = offset2scm (controls[i]);
249 gh_list (ly_symbol ("dashed-slur"),
250 gh_double2scm (thick),
251 gh_double2scm (dash),
252 ly_quote_scm (array_to_list (sc, 4)),
259 Lookup::dots () const
261 return afm_find (String ("dots") + String ("-") + String ("dot"));
266 Lookup::extender (Real width) const
269 a.lambda_ = gh_list (ly_symbol ("extender"),
270 gh_double2scm (width),
273 a.dim_[X_AXIS] = Interval (0, width);
274 a.dim_[Y_AXIS] = Interval (0,0);
276 a.font_ = font_name_;
281 Lookup::fill (Box b) const
289 Lookup::flag (int j, Direction d) const
291 char c = (d == UP) ? 'u' : 'd';
292 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
297 Lookup::rest (int j, bool o) const
299 return afm_find (String ("rests")
300 + String ("-") + to_str (j) + (o ? "o" : ""));
304 Lookup::rule_symbol (Real height, Real width) const
307 a.lambda_ = gh_list (ly_symbol ("rulesym"),
308 gh_double2scm (height),
309 gh_double2scm (width),
311 a.dim_.x () = Interval (0, width);
312 a.dim_.y () = Interval (0, height);
317 Lookup::script (String str) const
319 return afm_find (String ("scripts") + String ("-") + str);
323 Lookup::special_time_signature (String s, Array<int> arr) const
325 // First guess: s contains only the signature style
326 assert (arr.size () >1);
327 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
329 Atom a = afm_find (symbolname, false);
333 // Second guess: s contains the full signature name
334 a = afm_find ("timesig-"+s, false);
338 // Resort to default layout with numbers
339 return time_signature (arr);
343 Lookup::stem (Real y1, Real y2) const
353 a.dim_.x () = Interval (0,0);
354 a.dim_.y () = Interval (y1,y2);
356 Real stem_width = paper_l_->get_var ("stemthickness");
358 a.lambda_ = gh_list (ly_symbol ("filledbox"),
359 gh_double2scm(stem_width /2),
360 gh_double2scm(stem_width/2),
365 a.font_ = font_name_;
370 Lookup::streepje (int type) const
375 return afm_find ("balls" + String ("-") +to_str (type) + "l");
378 static Dict_initialiser<char const*> cmr_init[] = {
380 {"dynamic", "feta-din"},
381 {"finger", "feta-nummer"},
386 {"mark", "feta-nummer"},
387 {"nummer", "feta-nummer"},
391 static Dictionary<char const *> cmr_dict (cmr_init);
394 Lookup::text (String style, String text) const
397 a.lambda_ = gh_list(ly_symbol ("set" + style),
398 gh_str02scm (text.ch_C()),
401 Real font_h = paper_l_->get_var ("font_normal");
402 if (paper_l_->scope_p_->elem_b ("font_" + style))
404 font_h = paper_l_->get_var ("font_" + style);
407 if (cmr_dict.elem_b (style))
409 style = String (cmr_dict [style]) + to_str ((int)font_h); // ugh
413 Interval ydims (0,0);
415 Font_metric* afm_l = all_fonts_global_p->find_font (style);
418 for (int i = 0; i < text.length_i (); i++)
421 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
425 Character_metric *c = afm_l->get_char (text[i],false);
426 w += c->dimensions()[X_AXIS].length ();
427 ydims.unite (c->dimensions()[Y_AXIS]);
431 DOUT << "\n" << to_str (w) << "\n";
432 a.dim_.x () = Interval (0, w);
434 a.font_ = font_name_;
440 TODO: should return a molecule with 2 stacked nums.
443 Lookup::time_signature (Array<int> a) const
446 s.lambda_ = gh_list (ly_symbol ("generalmeter"),
451 Real r = paper_l_->interline_f () ;
452 s.dim_[Y_AXIS] = Interval (-2*r, 2*r);
453 s.dim_[X_AXIS] = Interval (0, 2*r);
458 Lookup::vbrace (Real &y) const
461 a.lambda_ = gh_list (ly_symbol ("pianobrace"),
465 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
466 a.dim_[X_AXIS] = Interval (0,0);
467 a.font_ = font_name_;
472 Lookup::hairpin (Real width, bool decresc, bool continued) const
475 Real height = paper_l_->staffheight_f () / 6;
477 String hairpin = String (decresc ? "de" : "") + "crescendo";
478 a.lambda_ = gh_list (ly_symbol (hairpin),
479 gh_double2scm (width),
480 gh_double2scm (height),
481 gh_double2scm (continued ? height/2 : 0.0),
483 a.dim_.x () = Interval (0, width);
484 a.dim_.y () = Interval (-2*height, 2*height);
485 a.font_ = font_name_;
490 Lookup::plet (Real dy , Real dx, Direction dir) const
493 SCM thick = ly_symbol ("tuplet_thick");
495 if (paper_l_->scope_p_->elem_b (thick))
497 t = paper_l_->get_realvar (thick);
499 a.lambda_ = gh_list(ly_symbol ("tuplet"),
510 Lookup::slur (Array<Offset> controls) const
512 assert (controls.size () == 8);
513 Real dx = controls[3].x () - controls[0].x ();
514 Real dy = controls[3].y () - controls[0].y ();
518 int indices[] = {5,6,7,4,1,2,3,0};
520 for (int i= 0; i < 8; i++)
521 scontrols[i] = offset2scm (controls[indices[i]]);
524 a.lambda_ =gh_list (ly_symbol ("slur"),
525 ly_quote_scm (array_to_list (scontrols, 8)),
528 a.dim_[X_AXIS] = Interval (0, dx);
529 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
530 a.font_ = font_name_;
535 Lookup::vbracket (Real &y) const
538 a.lambda_ = gh_list (ly_symbol ("bracket"),
541 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
542 a.dim_[X_AXIS] = Interval (0,4 PT);
547 Lookup::volta (Real w, bool last_b) const
550 SCM thick = ly_symbol ("volta_thick");
552 if (paper_l_->scope_p_->elem_b (thick))
554 t = paper_l_->get_realvar (thick);
556 a.lambda_ = gh_list (ly_symbol ("volta"),
562 Real interline_f = paper_l_->interline_f ();
564 a.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
565 a.dim_[X_AXIS] = Interval (0, w);
571 Lookup::special_ball (int j, String kind_of_ball) const
576 return afm_find (String ("balls") + String ("-") + kind_of_ball);