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::bar (String str, Real h) const
129 Atom a = (*symtables_p_) ("bars")->lookup (str);
132 a.lambda_ = gh_list (ly_symbol (a.str_.ch_C()),
137 a.dim_.y () = Interval (-h/2, h/2);
138 a.font_ = font_name_;
143 Lookup::beam (Real slope, Real width, Real thick) const
145 Real height = slope * width;
146 Real min_y = (0 <? height) - thick/2;
147 Real max_y = (0 >? height) + thick/2;
150 a.lambda_ = gh_list (ly_symbol ("beam"),
151 gh_double2scm (width),
152 gh_double2scm (slope),
153 gh_double2scm (thick),
156 a.dim_[X_AXIS] = Interval (0, width);
157 a.dim_[Y_AXIS] = Interval (min_y, max_y);
162 Lookup::clef (String st) const
164 return afm_find (String ("clefs") + String ("-") + st);
168 offset2scm (Offset o)
170 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
175 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
177 assert (controls.size () == 8);
178 Offset d = controls[3] - controls[0];
184 a.font_ = font_name_;
185 a.dim_[X_AXIS] = Interval (0, dx);
186 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
189 for (int i=0; i< 4; i++)
191 sc[i] = offset2scm (controls[i]);
195 gh_list (ly_symbol ("dashed-slur"),
196 gh_double2scm (thick),
197 gh_double2scm (dash),
198 ly_quote_scm (array_to_list (sc, 4)),
201 a.str_ = "dashed_slur";
206 Lookup::dots () const
208 return afm_find (String ("dots") + String ("-") + String ("dot"));
212 Lookup::dynamic (String st) const
214 return (*symtables_p_) ("dynamics")->lookup (st);
218 Lookup::extender (Real width) const
220 Atom a = (*symtables_p_) ("param")->lookup ("extender");
221 a.lambda_ = gh_list (ly_symbol (a.str_),
222 gh_double2scm (width),
225 a.font_ = font_name_;
230 Lookup::fill (Box b) const
238 Lookup::flag (int j, Direction d) const
240 char c = (d == UP) ? 'u' : 'd';
241 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
246 Lookup::print () const
249 DOUT << "Lookup {\n";
250 symtables_p_->print ();
256 Lookup::rest (int j, bool o) const
258 return afm_find (String ("rests")
259 + String ("-") + to_str (j) + (o ? "o" : ""));
263 Lookup::rule_symbol (Real height, Real width) const
266 a.lambda_ = gh_list (ly_symbol ("rulesym"),
267 gh_double2scm (height),
268 gh_double2scm (width),
270 a.dim_.x () = Interval (0, width);
271 a.dim_.y () = Interval (0, height);
276 Lookup::script (String str) const
278 return afm_find (String ("scripts") + String ("-") + str);
282 Lookup::special_time_signature (String s, Array<int> arr) const
284 // First guess: s contains only the signature style
285 assert (arr.size () >1);
286 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
288 Atom a = afm_find (symbolname, false);
292 // Second guess: s contains the full signature name
293 a = afm_find ("timesig-"+s, false);
297 // Resort to default layout with numbers
298 return time_signature (arr);
302 Lookup::stem (Real y1, Real y2) const
312 a.dim_.x () = Interval (0,0);
313 a.dim_.y () = Interval (y1,y2);
315 Real stem_width = paper_l_->get_var ("stemthickness");
317 a.lambda_ = gh_list (ly_symbol ("stem"),
318 gh_double2scm(-stem_width /2),
319 gh_double2scm(stem_width),
324 a.font_ = font_name_;
329 Lookup::streepje (int type) const
334 return afm_find ("balls" + String ("-") +to_str (type) + "l");
337 static Dict_initialiser<char const*> cmr_init[] = {
339 {"dynamic", "feta-din"},
340 {"finger", "feta-nummer"},
345 {"mark", "feta-nummer"},
346 {"nummer", "feta-nummer"},
350 static Dictionary<char const *> cmr_dict (cmr_init);
353 Lookup::text (String style, String text) const
355 Atom a = (*symtables_p_) ("style")->lookup (style);
357 a.lambda_ = gh_list(ly_symbol (a.str_),
358 gh_str02scm (text.ch_C()),
361 Real font_w = a.dim_.x ().length ();
362 Real font_h = a.dim_.y ().length ();
364 if (cmr_dict.elem_b (style))
366 style = String (cmr_dict [style]) + to_str ((int)font_h); // ugh
369 Adobe_font_metric* afm_l = all_fonts_global_p->find_font (style);
372 for (int i = 0; i < text.length_i (); i++)
375 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
380 int code = afm_l->ascii_to_metric_idx_[c];
383 Adobe_font_char_metric m = afm_l->char_metrics_[code];
384 w += m.B_.x ().length ();
385 DOUT << to_str (m.B_.x ().length ()) << " ";
389 DOUT << "\n" << to_str (w) << "\n";
390 a.dim_.x () = Interval (0, w);
391 a.font_ = font_name_;
397 Lookup::time_signature (Array<int> a) const
399 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
400 s.lambda_ = gh_list (ly_symbol (s.str_),
408 Lookup::vbrace (Real &y) const
411 a.lambda_ = gh_list (ly_symbol ("pianobrace"),
415 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
416 a.font_ = font_name_;
421 Lookup::hairpin (Real width, bool decresc, bool continued) const
424 Real height = paper_l_->staffheight_f () / 6;
426 String hairpin = String (decresc ? "de" : "") + "crescendo";
427 a.lambda_ = gh_list (ly_symbol (hairpin),
428 gh_double2scm (width),
429 gh_double2scm (height),
430 gh_double2scm (continued ? height/2 : 0.0),
432 a.dim_.x () = Interval (0, width);
433 a.dim_.y () = Interval (-2*height, 2*height);
434 a.font_ = font_name_;
439 Lookup::plet (Real dy , Real dx, Direction dir) const
442 a.lambda_ = gh_list(ly_symbol ("tuplet"),
445 gh_int2scm (dir), SCM_UNDEFINED);
451 Lookup::slur (Array<Offset> controls) const
453 assert (controls.size () == 8);
454 Real dx = controls[3].x () - controls[0].x ();
455 Real dy = controls[3].y () - controls[0].y ();
459 int indices[] = {5,6,7,4,1,2,3,0};
461 for (int i= 0; i < 8; i++)
462 scontrols[i] = offset2scm (controls[indices[i]]);
465 a.lambda_ =gh_list (ly_symbol ("slur"),
466 ly_quote_scm (array_to_list (scontrols, 8)),
469 a.dim_[X_AXIS] = Interval (0, dx);
470 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
471 a.font_ = font_name_;
476 Lookup::vbracket (Real &y) const
479 a.lambda_ = gh_list (ly_symbol ("bracket"),
483 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
484 a.dim_[X_AXIS] = Interval (0,4 PT);
489 Lookup::volta (Real w, bool last_b) const
492 a.lambda_ = gh_list (ly_symbol ("volta"),
497 Real interline_f = paper_l_->interline_f ();
499 a.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
500 a.dim_[X_AXIS] = Interval (0, w);