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);
84 a.dim_ = m.dimensions();
86 a.lambda_ = gh_list (ly_symbol ("char"),
87 gh_int2scm (m.code ()),
94 Lookup::ball (int j) const
99 return afm_find (String ("balls") + String ("-") + to_str (j));
103 Lookup::simple_bar (String type, Real h) const
105 SCM thick = ly_symbol ("barthick_" + type);
107 if (paper_l_->scope_p_->elem_b (thick))
109 w = paper_l_->get_realvar (thick);
113 a.lambda_ = gh_list (ly_symbol ("filledbox"),
120 a.dim_[X_AXIS] = Interval(0,w);
121 a.dim_[Y_AXIS] = Interval (-h/2, h/2);
127 Lookup::bar (String str, Real h) const
129 Real kern = paper_l_->get_var ("bar_kern");
130 Real thinkern = paper_l_->get_var ("bar_thinkern");
131 Atom thin = simple_bar ("thin", h);
132 Atom thick = simple_bar ("thick", h);
133 Atom colon = afm_find ("dots-repeatcolon");
139 return fill (Box (Interval(0,0),Interval (-h/2, h/2)));
145 else if (str == "|.")
147 m.add_at_edge (X_AXIS, LEFT, thick, 0);
148 m.add_at_edge (X_AXIS, LEFT, thin,kern);
150 else if (str == ".|")
152 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
153 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
155 else if (str == ":|")
157 m.add_at_edge (X_AXIS, LEFT, thick, 0);
158 m.add_at_edge (X_AXIS, LEFT, thin, kern);
159 m.add_at_edge (X_AXIS, LEFT, colon, kern);
161 else if (str == "|:")
163 m.add_at_edge (X_AXIS, RIGHT, thick,0);
164 m.add_at_edge (X_AXIS, RIGHT, thin,kern);
165 m.add_at_edge (X_AXIS, RIGHT, colon,kern);
167 else if (str == ":|:")
169 m.add_at_edge (X_AXIS, LEFT, thick,kern/2);
170 m.add_at_edge (X_AXIS, LEFT, colon,kern);
171 m.add_at_edge (X_AXIS, RIGHT, thick,kern);
172 m.add_at_edge (X_AXIS, RIGHT, colon,kern);
174 else if (str == "||")
176 m.add_at_edge (X_AXIS, RIGHT, thin,0);
177 m.add_at_edge (X_AXIS, RIGHT, thin,thinkern);
180 else if (str == ".|.")
182 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
183 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
190 Lookup::beam (Real slope, Real width, Real thick) const
192 Real height = slope * width;
193 Real min_y = (0 <? height) - thick/2;
194 Real max_y = (0 >? height) + thick/2;
197 a.lambda_ = gh_list (ly_symbol ("beam"),
198 gh_double2scm (width),
199 gh_double2scm (slope),
200 gh_double2scm (thick),
203 a.dim_[X_AXIS] = Interval (0, width);
204 a.dim_[Y_AXIS] = Interval (min_y, max_y);
209 Lookup::clef (String st) const
211 return afm_find (String ("clefs") + String ("-") + st);
215 offset2scm (Offset o)
217 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
222 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
224 assert (controls.size () == 8);
225 Offset d = controls[3] - controls[0];
231 a.font_ = font_name_;
232 a.dim_[X_AXIS] = Interval (0, dx);
233 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
236 for (int i=0; i< 4; i++)
238 sc[i] = offset2scm (controls[i]);
242 gh_list (ly_symbol ("dashed-slur"),
243 gh_double2scm (thick),
244 gh_double2scm (dash),
245 ly_quote_scm (array_to_list (sc, 4)),
252 Lookup::dots () const
254 return afm_find (String ("dots") + String ("-") + String ("dot"));
259 Lookup::extender (Real width) const
262 a.lambda_ = gh_list (ly_symbol ("extender"),
263 gh_double2scm (width),
266 a.dim_[X_AXIS] = Interval (0, width);
267 a.dim_[Y_AXIS] = Interval (0,0);
269 a.font_ = font_name_;
274 Lookup::fill (Box b) const
282 Lookup::flag (int j, Direction d) const
284 char c = (d == UP) ? 'u' : 'd';
285 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
290 Lookup::rest (int j, bool o) const
292 return afm_find (String ("rests")
293 + String ("-") + to_str (j) + (o ? "o" : ""));
297 Lookup::rule_symbol (Real height, Real width) const
300 a.lambda_ = gh_list (ly_symbol ("rulesym"),
301 gh_double2scm (height),
302 gh_double2scm (width),
304 a.dim_.x () = Interval (0, width);
305 a.dim_.y () = Interval (0, height);
310 Lookup::script (String str) const
312 return afm_find (String ("scripts") + String ("-") + str);
316 Lookup::special_time_signature (String s, Array<int> arr) const
318 // First guess: s contains only the signature style
319 assert (arr.size () >1);
320 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
322 Atom a = afm_find (symbolname, false);
326 // Second guess: s contains the full signature name
327 a = afm_find ("timesig-"+s, false);
331 // Resort to default layout with numbers
332 return time_signature (arr);
336 Lookup::stem (Real y1, Real y2) const
346 a.dim_.x () = Interval (0,0);
347 a.dim_.y () = Interval (y1,y2);
349 Real stem_width = paper_l_->get_var ("stemthickness");
351 a.lambda_ = gh_list (ly_symbol ("filledbox"),
352 gh_double2scm(stem_width /2),
353 gh_double2scm(stem_width/2),
358 a.font_ = font_name_;
363 Lookup::streepje (int type) const
368 return afm_find ("balls" + String ("-") +to_str (type) + "l");
371 static Dict_initialiser<char const*> cmr_init[] = {
373 {"dynamic", "feta-din"},
374 {"finger", "feta-nummer"},
379 {"mark", "feta-nummer"},
380 {"nummer", "feta-nummer"},
384 static Dictionary<char const *> cmr_dict (cmr_init);
387 Lookup::text (String style, String text) const
390 a.lambda_ = gh_list(ly_symbol ("set" + style),
391 gh_str02scm (text.ch_C()),
394 Real font_h = paper_l_->get_var ("font_normal");
395 if (paper_l_->scope_p_->elem_b ("font_" + style))
397 font_h = paper_l_->get_var ("font_" + style);
400 if (cmr_dict.elem_b (style))
402 style = String (cmr_dict [style]) + to_str ((int)font_h); // ugh
409 Font_metric* afm_l = all_fonts_global_p->find_font (style);
412 for (int i = 0; i < text.length_i (); i++)
415 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
419 Character_metric *c = afm_l->get_char (text[i],false);
420 w += c->dimensions()[X_AXIS].length ();
421 h = h >? c->dimensions()[Y_AXIS].max ();
422 d = d <? c->dimensions()[Y_AXIS].min ();
426 DOUT << "\n" << to_str (w) << "\n";
427 a.dim_.x () = Interval (0, w);
428 a.dim_.y () = Interval (d, h);
429 a.font_ = font_name_;
435 TODO: should return a molecule with 2 stacked nums.
438 Lookup::time_signature (Array<int> a) const
441 s.lambda_ = gh_list (ly_symbol ("generalmeter"),
446 Real r = paper_l_->interline_f () ;
447 s.dim_[Y_AXIS] = Interval (-2*r, 2*r);
448 s.dim_[X_AXIS] = Interval (0, 2*r);
453 Lookup::vbrace (Real &y) const
456 a.lambda_ = gh_list (ly_symbol ("pianobrace"),
460 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
461 a.dim_[X_AXIS] = Interval (0,0);
462 a.font_ = font_name_;
467 Lookup::hairpin (Real width, bool decresc, bool continued) const
470 Real height = paper_l_->staffheight_f () / 6;
472 String hairpin = String (decresc ? "de" : "") + "crescendo";
473 a.lambda_ = gh_list (ly_symbol (hairpin),
474 gh_double2scm (width),
475 gh_double2scm (height),
476 gh_double2scm (continued ? height/2 : 0.0),
478 a.dim_.x () = Interval (0, width);
479 a.dim_.y () = Interval (-2*height, 2*height);
480 a.font_ = font_name_;
485 Lookup::plet (Real dy , Real dx, Direction dir) const
488 a.lambda_ = gh_list(ly_symbol ("tuplet"),
491 gh_int2scm (dir), SCM_UNDEFINED);
497 Lookup::slur (Array<Offset> controls) const
499 assert (controls.size () == 8);
500 Real dx = controls[3].x () - controls[0].x ();
501 Real dy = controls[3].y () - controls[0].y ();
505 int indices[] = {5,6,7,4,1,2,3,0};
507 for (int i= 0; i < 8; i++)
508 scontrols[i] = offset2scm (controls[indices[i]]);
511 a.lambda_ =gh_list (ly_symbol ("slur"),
512 ly_quote_scm (array_to_list (scontrols, 8)),
515 a.dim_[X_AXIS] = Interval (0, dx);
516 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
517 a.font_ = font_name_;
522 Lookup::vbracket (Real &y) const
525 a.lambda_ = gh_list (ly_symbol ("bracket"),
528 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
529 a.dim_[X_AXIS] = Interval (0,4 PT);
534 Lookup::volta (Real w, bool last_b) const
537 a.lambda_ = gh_list (ly_symbol ("volta"),
542 Real interline_f = paper_l_->interline_f ();
544 a.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
545 a.dim_[X_AXIS] = Interval (0, w);