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
76 ((Lookup*)this)->afm_l_ = all_fonts_global_p->find_afm (font_name_);
78 Adobe_font_char_metric m = afm_l_->find_char (s, warn);
85 a.dim_[X_AXIS] *= 1 / 1000.0;
86 a.dim_[Y_AXIS] *= 1 / 1000.0;
89 a.lambda_ = gh_list (ly_symbol ("char"),
90 gh_int2scm (m.code ()),
97 Lookup::ball (int j) const
102 return afm_find (String ("balls") + String ("-") + to_str (j));
106 Lookup::simple_bar (String type, Real h) const
108 SCM thick = ly_symbol ("barthick_" + type);
110 if (paper_l_->scope_p_->elem_b (thick))
112 w = paper_l_->get_realvar (thick);
116 a.lambda_ = gh_list (ly_symbol ("filledbox"),
123 a.dim_[X_AXIS] = Interval(0,w);
124 a.dim_[Y_AXIS] = Interval (-h/2, h/2);
130 Lookup::bar (String str, Real h) const
132 Real kern = paper_l_->get_var ("bar_kern");
133 Real thinkern = paper_l_->get_var ("bar_thinkern");
134 Atom thin = simple_bar ("thin", h);
135 Atom thick = simple_bar ("thick", h);
136 Atom colon = afm_find ("dots-repeatcolon");
142 return fill (Box (Interval(0,0),Interval (-h/2, h/2)));
148 else if (str == "|.")
150 m.add_at_edge (X_AXIS, LEFT, thick, 0);
151 m.add_at_edge (X_AXIS, LEFT, thin,kern);
153 else if (str == ".|")
155 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
156 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
158 else if (str == ":|")
160 m.add_at_edge (X_AXIS, LEFT, thick, 0);
161 m.add_at_edge (X_AXIS, LEFT, thin, kern);
162 m.add_at_edge (X_AXIS, LEFT, colon, kern);
164 else if (str == "|:")
166 m.add_at_edge (X_AXIS, RIGHT, thick,0);
167 m.add_at_edge (X_AXIS, RIGHT, thin,kern);
168 m.add_at_edge (X_AXIS, RIGHT, colon,kern);
170 else if (str == ":|:")
172 m.add_at_edge (X_AXIS, LEFT, thick,kern/2);
173 m.add_at_edge (X_AXIS, LEFT, thin,kern);
174 m.add_at_edge (X_AXIS, LEFT, colon,kern);
175 m.add_at_edge (X_AXIS, RIGHT, thick,kern);
176 m.add_at_edge (X_AXIS, RIGHT, thin,kern);
177 m.add_at_edge (X_AXIS, RIGHT, colon,kern);
179 else if (str == "||")
181 m.add_at_edge (X_AXIS, RIGHT, thin,0);
182 m.add_at_edge (X_AXIS, RIGHT, thin,thinkern);
185 else if (str == ".|.")
187 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
188 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
195 Lookup::beam (Real slope, Real width, Real thick) const
197 Real height = slope * width;
198 Real min_y = (0 <? height) - thick/2;
199 Real max_y = (0 >? height) + thick/2;
202 a.lambda_ = gh_list (ly_symbol ("beam"),
203 gh_double2scm (width),
204 gh_double2scm (slope),
205 gh_double2scm (thick),
208 a.dim_[X_AXIS] = Interval (0, width);
209 a.dim_[Y_AXIS] = Interval (min_y, max_y);
214 Lookup::clef (String st) const
216 return afm_find (String ("clefs") + String ("-") + st);
220 offset2scm (Offset o)
222 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
227 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
229 assert (controls.size () == 8);
230 Offset d = controls[3] - controls[0];
236 a.font_ = font_name_;
237 a.dim_[X_AXIS] = Interval (0, dx);
238 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
241 for (int i=0; i< 4; i++)
243 sc[i] = offset2scm (controls[i]);
247 gh_list (ly_symbol ("dashed-slur"),
248 gh_double2scm (thick),
249 gh_double2scm (dash),
250 ly_quote_scm (array_to_list (sc, 4)),
257 Lookup::dots () const
259 return afm_find (String ("dots") + String ("-") + String ("dot"));
264 Lookup::extender (Real width) const
267 a.lambda_ = gh_list (ly_symbol ("extender"),
268 gh_double2scm (width),
271 a.dim_[X_AXIS] = Interval (0, width);
272 a.dim_[Y_AXIS] = Interval (0,0);
274 a.font_ = font_name_;
279 Lookup::fill (Box b) const
287 Lookup::flag (int j, Direction d) const
289 char c = (d == UP) ? 'u' : 'd';
290 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
295 Lookup::rest (int j, bool o) const
297 return afm_find (String ("rests")
298 + String ("-") + to_str (j) + (o ? "o" : ""));
302 Lookup::rule_symbol (Real height, Real width) const
305 a.lambda_ = gh_list (ly_symbol ("rulesym"),
306 gh_double2scm (height),
307 gh_double2scm (width),
309 a.dim_.x () = Interval (0, width);
310 a.dim_.y () = Interval (0, height);
315 Lookup::script (String str) const
317 return afm_find (String ("scripts") + String ("-") + str);
321 Lookup::special_time_signature (String s, Array<int> arr) const
323 // First guess: s contains only the signature style
324 assert (arr.size () >1);
325 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
327 Atom a = afm_find (symbolname, false);
331 // Second guess: s contains the full signature name
332 a = afm_find ("timesig-"+s, false);
336 // Resort to default layout with numbers
337 return time_signature (arr);
341 Lookup::stem (Real y1, Real y2) const
351 a.dim_.x () = Interval (0,0);
352 a.dim_.y () = Interval (y1,y2);
354 Real stem_width = paper_l_->get_var ("stemthickness");
356 a.lambda_ = gh_list (ly_symbol ("filledbox"),
357 gh_double2scm(stem_width /2),
358 gh_double2scm(stem_width/2),
363 a.font_ = font_name_;
368 Lookup::streepje (int type) const
373 return afm_find ("balls" + String ("-") +to_str (type) + "l");
376 static Dict_initialiser<char const*> cmr_init[] = {
378 {"dynamic", "feta-din"},
379 {"finger", "feta-nummer"},
384 {"mark", "feta-nummer"},
385 {"nummer", "feta-nummer"},
389 static Dictionary<char const *> cmr_dict (cmr_init);
392 Lookup::text (String style, String text) const
395 a.lambda_ = gh_list(ly_symbol ("set" + style),
396 gh_str02scm (text.ch_C()),
399 Real font_h = paper_l_->get_var ("font_normal");
400 if (paper_l_->scope_p_->elem_b ("font_" + style))
402 font_h = paper_l_->get_var ("font_" + style);
405 if (cmr_dict.elem_b (style))
407 style = String (cmr_dict [style]) + to_str ((int)font_h); // ugh
410 Font_metric* afm_l = all_fonts_global_p->find_font (style);
413 for (int i = 0; i < text.length_i (); i++)
416 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
420 Character_metric *c = afm_l->get_char (text[i],false);
421 w += c->dimensions()[X_AXIS].length ();
425 DOUT << "\n" << to_str (w) << "\n";
426 a.dim_.x () = Interval (0, w);
427 a.font_ = font_name_;
433 TODO: should return a molecule with 2 stacked nums.
436 Lookup::time_signature (Array<int> a) const
439 s.lambda_ = gh_list (ly_symbol ("generalmeter"),
444 Real r = paper_l_->interline_f () ;
445 s.dim_[Y_AXIS] = Interval (-2*r, 2*r);
446 s.dim_[X_AXIS] = Interval (0, 2*r);
451 Lookup::vbrace (Real &y) const
454 a.lambda_ = gh_list (ly_symbol ("pianobrace"),
458 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
459 a.dim_[X_AXIS] = Interval (0,0);
460 a.font_ = font_name_;
465 Lookup::hairpin (Real width, bool decresc, bool continued) const
468 Real height = paper_l_->staffheight_f () / 6;
470 String hairpin = String (decresc ? "de" : "") + "crescendo";
471 a.lambda_ = gh_list (ly_symbol (hairpin),
472 gh_double2scm (width),
473 gh_double2scm (height),
474 gh_double2scm (continued ? height/2 : 0.0),
476 a.dim_.x () = Interval (0, width);
477 a.dim_.y () = Interval (-2*height, 2*height);
478 a.font_ = font_name_;
483 Lookup::plet (Real dy , Real dx, Direction dir) const
486 a.lambda_ = gh_list(ly_symbol ("tuplet"),
489 gh_int2scm (dir), SCM_UNDEFINED);
495 Lookup::slur (Array<Offset> controls) const
497 assert (controls.size () == 8);
498 Real dx = controls[3].x () - controls[0].x ();
499 Real dy = controls[3].y () - controls[0].y ();
503 int indices[] = {5,6,7,4,1,2,3,0};
505 for (int i= 0; i < 8; i++)
506 scontrols[i] = offset2scm (controls[indices[i]]);
509 a.lambda_ =gh_list (ly_symbol ("slur"),
510 ly_quote_scm (array_to_list (scontrols, 8)),
513 a.dim_[X_AXIS] = Interval (0, dx);
514 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
515 a.font_ = font_name_;
520 Lookup::vbracket (Real &y) const
523 a.lambda_ = gh_list (ly_symbol ("bracket"),
526 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
527 a.dim_[X_AXIS] = Interval (0,4 PT);
532 Lookup::volta (Real w, bool last_b) const
535 a.lambda_ = gh_list (ly_symbol ("volta"),
540 Real interline_f = paper_l_->interline_f ();
542 a.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
543 a.dim_[X_AXIS] = Interval (0, w);