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"
31 array_to_list (SCM *a , int l)
36 list = gh_cons (a[i], list);
48 Lookup::Lookup (Lookup const& s)
50 font_name_ = s.font_name_;
57 Lookup::ledger_line (Interval xwid) const
59 Molecule end (afm_find ("noteheads-ledgerending"));
60 Interval ed = end.dim_[X_AXIS];
61 xwid = Interval (xwid[LEFT] - ed[LEFT],
62 xwid[RIGHT] - ed[RIGHT]);
63 Molecule mid = filledbox (Box (xwid, end.dim_[Y_AXIS]));
68 e1.translate_axis (xwid[RIGHT], X_AXIS);
69 e2.translate_axis (xwid[LEFT], X_AXIS);
78 Lookup::accidental (int j, bool cautionary) const
80 Molecule m(afm_find (String ("accidentals-") + to_str (j)));
83 Molecule open = afm_find (String ("accidentals-("));
84 Molecule close = afm_find (String ("accidentals-)"));
85 m.add_at_edge(X_AXIS, LEFT, Molecule(open), 0);
86 m.add_at_edge(X_AXIS, RIGHT, Molecule(close), 0);
94 Lookup::afm_find (String s, bool warn) const
98 Lookup * me = (Lookup*)(this);
99 me->afm_l_ = all_fonts_global_p->find_afm (font_name_);
102 warning (_f("Can't open `%s'\n", font_name_));
103 warning (_f("Search path %s\n", global_path.str ().ch_C()));
106 Adobe_font_char_metric cm = afm_l_->find_char (s, warn);
111 Atom at (gh_list (ly_symbol ("char"),
112 gh_int2scm (cm.code ()),
114 at.font_ = ly_symbol (font_name_.ch_C());
115 m.dim_ = cm.dimensions();
121 Lookup::ball (int j) const
126 return afm_find (String ("noteheads-") + to_str (j));
130 Lookup::simple_bar (String type, Real h) const
132 SCM thick = ly_symbol ("barthick_" + type);
134 if (paper_l_->scope_p_->elem_b (thick))
136 w = paper_l_->get_realvar (thick);
139 return filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
144 Lookup::bar (String str, Real h) const
147 return staff_bracket (h);
149 return staff_brace (h);
151 Real kern = paper_l_->get_var ("bar_kern");
152 Real thinkern = paper_l_->get_var ("bar_thinkern");
153 Molecule thin = simple_bar ("thin", h);
154 Molecule thick = simple_bar ("thick", h);
155 Molecule colon = afm_find ("dots-repeatcolon");
161 return fill (Box (Interval(0, 0), Interval (-h/2, h/2)));
167 else if (str == "|.")
169 m.add_at_edge (X_AXIS, LEFT, thick, 0);
170 m.add_at_edge (X_AXIS, LEFT, thin, kern);
172 else if (str == ".|")
174 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
175 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
177 else if (str == ":|")
179 m.add_at_edge (X_AXIS, LEFT, thick, 0);
180 m.add_at_edge (X_AXIS, LEFT, thin, kern);
181 m.add_at_edge (X_AXIS, LEFT, colon, kern);
183 else if (str == "|:")
185 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
186 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
187 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
189 else if (str == ":|:")
191 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
192 m.add_at_edge (X_AXIS, LEFT, colon, kern);
193 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
194 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
196 else if (str == ".|.")
198 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
199 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
201 else if (str == "||")
203 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
204 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);
211 Lookup::beam (Real slope, Real width, Real thick) const
213 Real height = slope * width;
214 Real min_y = (0 <? height) - thick/2;
215 Real max_y = (0 >? height) + thick/2;
220 (gh_list (ly_symbol ("beam"),
221 gh_double2scm (width),
222 gh_double2scm (slope),
223 gh_double2scm (thick),
226 m.dim_[X_AXIS] = Interval (0, width);
227 m.dim_[Y_AXIS] = Interval (min_y, max_y);
233 Lookup::clef (String st) const
235 return afm_find (String ("clefs-" + st));
239 offset2scm (Offset o)
241 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
246 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
248 assert (controls.size () == 8);
249 Offset d = controls[3] - controls[0];
257 m.dim_[X_AXIS] = Interval (0, dx);
258 m.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
261 for (int i=0; i< 4; i++)
263 sc[i] = offset2scm (controls[i]);
267 (gh_list (ly_symbol ("dashed-slur"),
268 gh_double2scm (thick),
269 gh_double2scm (dash),
270 ly_quote_scm (array_to_list (sc, 4)),
279 Lookup::dots () const
281 return afm_find (String ("dots-dot"));
287 Lookup::fill (Box b) const
295 Lookup::flag (int j, Direction d) const
297 char c = (d == UP) ? 'u' : 'd';
298 return afm_find (String ("flags-") + to_str (c) + to_str (j));
302 Lookup::rest (int j, bool o) const
304 return afm_find (String ("rests-") + to_str (j) + (o ? "o" : ""));
308 Lookup::rule_symbol (Real height, Real width) const
310 Atom at (gh_list (ly_symbol ("rulesym"),
311 gh_double2scm (height),
312 gh_double2scm (width),
316 m.dim_.x () = Interval (0, width);
317 m.dim_.y () = Interval (0, height);
325 Lookup::script (String str) const
327 return afm_find (String ("scripts-") + str);
331 Lookup::special_time_signature (String s, int n, int d) const
333 // First guess: s contains only the signature style
334 String symbolname = "timesig-" + s + to_str (n) + "/" + to_str (d);
336 Molecule m = afm_find (symbolname, false);
337 if (!m.dim_[X_AXIS].empty_b ())
340 // Second guess: s contains the full signature name
341 m = afm_find ("timesig-"+s, false);
342 if (!m.dim_[X_AXIS].empty_b ())
345 // Resort to default layout with numbers
346 return time_signature (n,d);
350 Lookup::filledbox (Box b ) const
354 Atom at (gh_list (ly_symbol ("filledbox"),
355 gh_double2scm (-b[X_AXIS][LEFT]),
356 gh_double2scm (b[X_AXIS][RIGHT]),
357 gh_double2scm (-b[Y_AXIS][DOWN]),
358 gh_double2scm (b[Y_AXIS][UP]),
367 Lookup::stem (Real y1, Real y2) const
375 Real stem_width = paper_l_->get_var ("stemthickness");
376 return filledbox (Box (Interval (-stem_width/2,stem_width/2),
381 static Dict_initialiser<char const*> cmr_init[] = {
383 {"dynamic", "feta-din"},
384 {"finger", "feta-nummer"},
389 {"mark", "feta-nummer"},
390 {"number", "feta-nummer"},
394 static Dictionary<char const *> cmr_dict (cmr_init);
397 Lookup::text (String style, String text) const
402 Real font_h = paper_l_->get_var ("font_normal");
403 if (paper_l_->scope_p_->elem_b ("font_" + style))
405 font_h = paper_l_->get_var ("font_" + style);
408 if (cmr_dict.elem_b (style))
410 style = String (cmr_dict [style]) + to_str ((int)font_h); // ugh
414 Interval ydims (0,0);
416 Font_metric* afm_l = all_fonts_global_p->find_font (style);
419 for (int i = 0; i < text.length_i (); i++)
422 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
426 Character_metric *c = afm_l->get_char (text[i],false);
427 w += c->dimensions()[X_AXIS].length ();
428 ydims.unite (c->dimensions()[Y_AXIS]);
432 DOUT << "\n" << to_str (w) << "\n";
433 m.dim_.x () = Interval (0, w);
435 Atom at (gh_list (ly_symbol ("text"),
436 gh_str02scm (text.ch_C()),
438 at.font_ = ly_symbol (style);
448 Lookup::time_signature (int num, int den) const
450 String sty = "number";
451 Molecule n (text (sty, to_str (num)));
452 Molecule d (text (sty, to_str (den)));
453 n.do_center (X_AXIS);
454 d.do_center (X_AXIS);
458 m.add_at_edge (Y_AXIS, UP, n, 0.0);
459 m.add_at_edge (Y_AXIS, DOWN, d, 0.0);
464 m.do_center (Y_AXIS);
470 Lookup::staff_brace (Real y) const
474 Atom at (gh_list (ly_symbol ("pianobrace"),
479 m.dim_[Y_AXIS] = Interval (-y/2,y/2);
480 m.dim_[X_AXIS] = Interval (0,0);
486 Lookup::hairpin (Real width, bool decresc, bool continued) const
489 Real height = paper_l_->staffheight_f () / 6;
491 String hairpin = String (decresc ? "de" : "") + "crescendo";
492 Atom at (gh_list (ly_symbol (hairpin),
493 gh_double2scm (width),
494 gh_double2scm (height),
495 gh_double2scm (continued ? height/2 : 0.0),
497 m.dim_.x () = Interval (0, width);
498 m.dim_.y () = Interval (-2*height, 2*height);
505 Lookup::plet (Real dy , Real dx, Direction dir) const
508 SCM thick = ly_symbol ("tuplet_thick");
510 if (paper_l_->scope_p_->elem_b (thick))
512 t = paper_l_->get_realvar (thick);
515 Atom at (gh_list(ly_symbol ("tuplet"),
527 Make a smooth curve along the points
530 Lookup::slur (Array<Offset> controls) const
532 Offset delta_off = controls[3]- controls[0];
536 int indices[] = {5,6,7,4,1,2,3,0};
538 for (int i= 0; i < 8; i++)
539 scontrols[i] = offset2scm (controls[indices[i]]);
542 Atom at (gh_list (ly_symbol ("bezier-sandwich"),
543 ly_quote_scm (array_to_list (scontrols, 8)),
546 m.dim_[X_AXIS] = Interval (0, delta_off[X_AXIS]);
547 m.dim_[Y_AXIS] = Interval (0 <? delta_off[Y_AXIS], 0 >? delta_off[Y_AXIS]);
553 Lookup::staff_bracket (Real y) const
556 Atom at ( gh_list (ly_symbol ("bracket"),
560 m.dim_[Y_AXIS] = Interval (-y/2,y/2);
561 m.dim_[X_AXIS] = Interval (0,4 PT);
563 m.translate_axis (- 4. / 3. * m.dim_[X_AXIS].length (), X_AXIS);
568 Lookup::volta (Real w, bool last_b) const
571 SCM thick = ly_symbol ("volta_thick");
573 if (paper_l_->scope_p_->elem_b (thick))
575 t = paper_l_->get_realvar (thick);
577 Atom at (gh_list (ly_symbol ("volta"),
583 Real interline_f = paper_l_->interline_f ();
585 m.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
586 m.dim_[X_AXIS] = Interval (0, w);
594 Lookup::special_ball (int j, String kind_of_ball) const
599 return afm_find (String ("noteheads-") + kind_of_ball);