2 lookup.cc -- implement simple Lookup methods.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 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"
29 #include "lily-guile.hh"
32 array_to_list (SCM *a , int l)
37 list = gh_cons (a[i], list);
49 Lookup::Lookup (Lookup const& s)
51 font_name_ = s.font_name_;
58 Lookup::ledger_line (Interval xwid) const
60 Molecule end (afm_find ("noteheads-ledgerending"));
61 Interval ed = end.dim_[X_AXIS];
62 xwid = Interval (xwid[LEFT] - ed[LEFT],
63 xwid[RIGHT] - ed[RIGHT]);
64 Molecule mid = filledbox (Box (xwid, end.dim_[Y_AXIS]));
69 e1.translate_axis (xwid[RIGHT], X_AXIS);
70 e2.translate_axis (xwid[LEFT], X_AXIS);
79 Lookup::accidental (int j, bool cautionary) const
81 Molecule m(afm_find (String ("accidentals-") + to_str (j)));
84 Molecule open = afm_find (String ("accidentals-("));
85 Molecule close = afm_find (String ("accidentals-)"));
86 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
87 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
95 Lookup::afm_find (String s, bool warn) const
99 Lookup * me = (Lookup*)(this);
100 me->afm_l_ = all_fonts_global_p->find_afm (font_name_);
103 warning (_f("Can't open `%s'\n", font_name_));
104 warning (_f("Search path %s\n", global_path.str ().ch_C()));
105 error (_f("Aborting"));
108 Adobe_font_char_metric cm = afm_l_->find_char (s, warn);
113 Atom at (gh_list (char_scm_sym,
114 gh_int2scm (cm.code ()),
116 at.font_ = ly_symbol (font_name_.ch_C());
117 m.dim_ = cm.dimensions();
123 Lookup::notehead (int j, String type) const
128 return afm_find (String ("noteheads-") + to_str (j) + type);
132 Lookup::simple_bar (String type, Real h) const
134 SCM thick = ly_symbol ("barthick_" + type);
136 if (paper_l_->scope_p_->elem_b (thick))
138 w = paper_l_->get_realvar (thick);
141 return filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
146 Lookup::bar (String str, Real h) const
149 return staff_bracket (h);
151 return staff_brace (h);
153 Real kern = paper_l_->get_var ("bar_kern");
154 Real thinkern = paper_l_->get_var ("bar_thinkern");
155 Molecule thin = simple_bar ("thin", h);
156 Molecule thick = simple_bar ("thick", h);
157 Molecule colon = afm_find ("dots-repeatcolon");
163 return fill (Box (Interval(0, 0), Interval (-h/2, h/2)));
165 if (str == "scorepostbreak")
167 return simple_bar ("score", h);
173 else if (str == "|.")
175 m.add_at_edge (X_AXIS, LEFT, thick, 0);
176 m.add_at_edge (X_AXIS, LEFT, thin, kern);
178 else if (str == ".|")
180 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
181 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
183 else if (str == ":|")
185 m.add_at_edge (X_AXIS, LEFT, thick, 0);
186 m.add_at_edge (X_AXIS, LEFT, thin, kern);
187 m.add_at_edge (X_AXIS, LEFT, colon, kern);
189 else if (str == "|:")
191 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
192 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
193 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
195 else if (str == ":|:")
197 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
198 m.add_at_edge (X_AXIS, LEFT, colon, kern);
199 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
200 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
202 else if (str == ".|.")
204 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
205 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
207 else if (str == "||")
209 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
210 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);
217 Lookup::beam (Real slope, Real width, Real thick) const
219 Real height = slope * width;
220 Real min_y = (0 <? height) - thick/2;
221 Real max_y = (0 >? height) + thick/2;
226 (gh_list (beam_scm_sym,
227 gh_double2scm (width),
228 gh_double2scm (slope),
229 gh_double2scm (thick),
232 m.dim_[X_AXIS] = Interval (0, width);
233 m.dim_[Y_AXIS] = Interval (min_y, max_y);
239 Lookup::clef (String st) const
241 return afm_find (String ("clefs-" + st));
245 offset2scm (Offset o)
247 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
252 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
254 assert (controls.size () == 8);
255 Offset d = controls[3] - controls[0];
263 m.dim_[X_AXIS] = Interval (0, dx);
264 m.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
267 for (int i=0; i< 4; i++)
269 sc[i] = offset2scm (controls[i]);
273 (gh_list (ly_symbol ("dashed-slur"),
274 gh_double2scm (thick),
275 gh_double2scm (dash),
276 ly_quote_scm (array_to_list (sc, 4)),
285 Lookup::dots () const
287 return afm_find (String ("dots-dot"));
293 Lookup::fill (Box b) const
301 Lookup::flag (int j, Direction d) const
303 char c = (d == UP) ? 'u' : 'd';
304 return afm_find (String ("flags-") + to_str (c) + to_str (j));
308 Lookup::rest (int j, bool o) const
310 return afm_find (String ("rests-") + to_str (j) + (o ? "o" : ""));
314 Lookup::rule_symbol (Real height, Real width) const
316 Atom at (gh_list (rulesym_scm_sym,
317 gh_double2scm (height),
318 gh_double2scm (width),
322 m.dim_.x () = Interval (0, width);
323 m.dim_.y () = Interval (0, height);
331 Lookup::script (String str) const
333 return afm_find (String ("scripts-") + str);
337 Lookup::special_time_signature (String s, int n, int d) const
339 // First guess: s contains only the signature style
340 String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
342 Molecule m = afm_find (symbolname, false);
346 // Second guess: s contains the full signature name
347 m = afm_find ("timesig-"+s, false);
351 // Resort to default layout with numbers
352 return time_signature (n,d);
356 Lookup::filledbox (Box b ) const
360 Atom at (gh_list (filledbox_scm_sym,
361 gh_double2scm (-b[X_AXIS][LEFT]),
362 gh_double2scm (b[X_AXIS][RIGHT]),
363 gh_double2scm (-b[Y_AXIS][DOWN]),
364 gh_double2scm (b[Y_AXIS][UP]),
373 Lookup::stem (Real y1, Real y2) const
381 Real stem_width = paper_l_->get_var ("stemthickness");
382 return filledbox (Box (Interval (-stem_width/2,stem_width/2),
389 Magnification steps. These are powers of 1.2. The numbers are
390 taken from Knuth's plain.tex: */
391 static Real mag_steps[] = {1, 1, 1.200, 1.440, 1.7280, 2.074, 2.488};
396 Lookup::text (String style, String text) const
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 (paper_l_->scope_p_->elem_b ("magnification_" + style))
409 font_mag = (int)paper_l_->get_var ("magnification_" + style);
412 SCM l = gh_eval_str (("(style-to-cmr \"" + style + "\")").ch_C());
415 style = ly_scm2string (SCM_CDR(l)) +to_str ((int)font_h);
419 Interval ydims (0,0);
421 Font_metric* afm_l = all_fonts_global_p->find_font (style);
424 for (int i = 0; i < text.length_i (); i++)
427 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
431 Character_metric *c = afm_l->get_char ((unsigned char)text[i],false);
433 w += c->dimensions()[X_AXIS].length ();
434 ydims.unite (c->dimensions()[Y_AXIS]);
438 if (font_mag > 1 && font_mag < 7 )
441 style = style + String(" scaled \\magstep ") + to_str (font_mag);
442 w *= mag_steps[font_mag];
443 ydims *= mag_steps[font_mag];
446 DOUT << "\n" << to_str (w) << "\n";
447 m.dim_.x () = Interval (0, w);
451 Atom at (gh_list (text_scm_sym,
452 gh_str02scm (text.ch_C()),
454 at.font_ = ly_symbol (style);
464 Lookup::time_signature (int num, int den) const
466 String sty = "number";
467 Molecule n (text (sty, to_str (num)));
468 Molecule d (text (sty, to_str (den)));
469 n.do_center (X_AXIS);
470 d.do_center (X_AXIS);
474 m.add_at_edge (Y_AXIS, UP, n, 0.0);
475 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
480 m.do_center (Y_AXIS);
486 Lookup::staff_brace (Real y) const
490 Atom at (gh_list (pianobrace_scm_sym,
495 m.dim_[Y_AXIS] = Interval (-y/2,y/2);
496 m.dim_[X_AXIS] = Interval (0,0);
502 Lookup::hairpin (Real width, bool decresc, bool continued) const
505 Real height = paper_l_->staffheight_f () / 6;
507 String hairpin = String (decresc ? "de" : "") + "crescendo";
508 Atom at (gh_list (ly_symbol (hairpin),
509 gh_double2scm (width),
510 gh_double2scm (height),
511 gh_double2scm (continued ? height/2 : 0.0),
513 m.dim_.x () = Interval (0, width);
514 m.dim_.y () = Interval (-2*height, 2*height);
521 Lookup::plet (Real dy , Real dx, Direction dir) const
524 SCM thick = tuplet_thick_scm_sym;
526 if (paper_l_->scope_p_->elem_b (thick))
528 t = paper_l_->get_realvar (thick);
531 Atom at (gh_list(tuplet_scm_sym,
543 Make a smooth curve along the points
546 Lookup::slur (Array<Offset> controls) const
548 Offset delta_off = controls[3]- controls[0];
552 int indices[] = {5,6,7,4,1,2,3,0};
554 for (int i= 0; i < 8; i++)
555 scontrols[i] = offset2scm (controls[indices[i]]);
558 Atom at (gh_list (ly_symbol ("bezier-sandwich"),
559 ly_quote_scm (array_to_list (scontrols, 8)),
562 m.dim_[X_AXIS] = Interval (0, delta_off[X_AXIS]);
563 m.dim_[Y_AXIS] = Interval (0 <? delta_off[Y_AXIS], 0 >? delta_off[Y_AXIS]);
569 Lookup::staff_bracket (Real y) const
572 Atom at ( gh_list (bracket_scm_sym,
576 m.dim_[Y_AXIS] = Interval (-y/2,y/2);
577 m.dim_[X_AXIS] = Interval (0,4 PT);
579 m.translate_axis (- 4. / 3. * m.dim_[X_AXIS].length (), X_AXIS);
584 Lookup::volta (Real w, bool last_b) const
587 SCM thick = volta_thick_scm_sym;
589 if (paper_l_->scope_p_->elem_b (thick))
591 t = paper_l_->get_realvar (thick);
593 Atom at (gh_list (volta_scm_sym,
599 Real interline_f = paper_l_->get_realvar (interline_scm_sym);
601 m.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
602 m.dim_[X_AXIS] = Interval (0, w);