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>
11 Read spacing info from AFMs
17 #include "dimensions.hh"
18 #include "symtable.hh"
20 #include "paper-def.hh"
21 #include "string-convert.hh"
23 #include "lily-guile.hh"
28 symtables_p_ = new Symtables;
32 Lookup::Lookup (Lookup const& s)
35 font_path_ = s.font_path_;
36 paper_l_ = s.paper_l_;
37 symtables_p_ = new Symtables (*s.symtables_p_);
41 Lookup::Lookup (Symtables const& s)
44 font_path_ = s.font_path_;
46 symtables_p_ = new Symtables (s);
57 Lookup::accidental (int j, bool cautionary) const
59 Molecule m(afm_find (String ("accidentals") + String ("-") + to_str (j)));
62 m.add_at_edge(X_AXIS, LEFT,
63 Molecule(afm_find (String ("accidentals") + String ("-("))))
65 m.add_at_edge(X_AXIS, RIGHT,
66 Molecule(afm_find (String ("accidentals") + String ("-)"))))
73 Lookup::add (String s, Symtable*p)
75 symtables_p_->add (s, p);
79 Lookup::afm_find (String s, bool warn) const
83 *mlog << "[" << font_path_;
84 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
85 *mlog << "]" << flush ;
86 DOUT << this->afm_p_->str ();
88 Adobe_font_char_metric m = afm_p_->find_char (s, warn);
95 a.dim_[X_AXIS] *= 1 / 1000.0;
96 a.dim_[Y_AXIS] *= 1 / 1000.0;
99 a.lambda_ = (lambda_scm ("char", arr));
100 a.str_ = "afm_find: " + s;
106 Lookup::ball (int j) const
111 return afm_find (String ("balls") + String ("-") + to_str (j));
115 Lookup::bar (String str, Real h) const
119 Atom a = (*symtables_p_) ("bars")->lookup (str);
120 a.lambda_ = (lambda_scm (a.str_, arr));
122 a.dim_.y () = Interval (-h/2, h/2);
128 Lookup::beam (Real slope, Real width, Real thick) const
130 Real height = slope * width;
131 Real min_y = (0 <? height) - thick/2;
132 Real max_y = (0 >? height) + thick/2;
140 a.lambda_ = (lambda_scm ("beam", arr));
142 a.dim_[X_AXIS] = Interval (0, width);
143 a.dim_[Y_AXIS] = Interval (min_y, max_y);
148 Lookup::clef (String st) const
150 return afm_find (String ("clefs") + String ("-") + st);
154 offset2scm (Offset o)
156 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]), SCM_UNDEFINED);
160 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
162 assert (controls.size () == 8);
163 Offset d = controls[3] - controls[0];
170 a.dim_[X_AXIS] = Interval (0, dx);
171 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
174 for (int i=0; i< 4; i++)
176 sc[i] = offset2scm (controls[i]);
179 // (lambda (o) (dashed-slur o thick dash '(stuff))
180 a.lambda_ = gh_list (gh_append3 (ly_lambda_o (),
181 ly_func_o ("dashed-slur"),
182 gh_list (gh_double2scm (thick),
183 gh_double2scm (dash),
184 ly_quote_scm (gh_list (sc[0], sc[1], sc[2], sc[3], SCM_UNDEFINED)),
188 a.str_ = "dashed_slur";
193 Lookup::dots () const
195 return afm_find (String ("dots") + String ("-") + String ("dot"));
199 Lookup::dynamic (String st) const
201 return (*symtables_p_) ("dynamics")->lookup (st);
205 Lookup::fill (Box b) const
213 Lookup::flag (int j, Direction d) const
215 char c = (d == UP) ? 'u' : 'd';
216 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
221 Lookup::print () const
224 DOUT << "Lookup {\n";
225 symtables_p_->print ();
231 Lookup::rest (int j, bool o) const
233 return afm_find (String ("rests")
234 + String ("-") + to_str (j) + (o ? "o" : ""));
238 Lookup::rule_symbol (Real height, Real width) const
240 Atom a = (*symtables_p_) ("param")->lookup ("rule");
244 a.lambda_ = (lambda_scm (a.str_, arr));
245 a.str_ = "rule_symbol";
246 a.dim_.x () = Interval (0, width);
247 a.dim_.y () = Interval (0, height);
252 Lookup::script (String str) const
254 return afm_find (String ("scripts") + String ("-") + str);
258 Lookup::special_time_signature (String s, Array<int> arr) const
260 // First guess: s contains only the signature style
261 assert (arr.size () >1);
262 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
264 Atom a = afm_find (symbolname, false);
268 // Second guess: s contains the full signature name
269 a = afm_find ("timesig-"+s, false);
273 // Resort to default layout with numbers
274 return time_signature (arr);
278 Lookup::stem (Real y1, Real y2) const
288 a.dim_.x () = Interval (0,0);
289 a.dim_.y () = Interval (y1,y2);
293 Real stem_width = paper_l_->get_var ("stemthickness");
294 arr.push (-stem_width /2);
295 arr.push (stem_width);
299 a.lambda_ = (lambda_scm ("stem", arr));
306 Lookup::streepje (int type) const
311 return afm_find ("balls" + String ("-") +to_str (type) + "l");
315 Lookup::text (String style, String text) const
320 Atom a = (*symtables_p_) ("style")->lookup (style);
321 a.lambda_ = lambda_scm (a.str_, arr);
330 Lookup::time_signature (Array<int> a) const
332 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
333 s.lambda_ = (lambda_scm (s.str_, a));
339 should be handled via Tex_ code and Lookup::bar ()
342 Lookup::vbrace (Real &y) const
344 Atom a = (*symtables_p_) ("param")->lookup ( "brace");
345 Interval ydims = a.dim_[Y_AXIS];
346 Real min_y = ydims[LEFT];
347 Real max_y = ydims[RIGHT];
352 warning (_ ("piano brace")
353 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
358 warning (_ ("piano brace")
359 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
364 int idx = int (rint ( (y- min_y)/step)) + 1;
368 a.lambda_ = (lambda_scm (a.str_, arr));
370 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
376 Lookup::hairpin (Real width, bool decresc, bool continued) const
379 Real height = paper_l_->staffheight_f () / 6;
381 ps += to_str (width) + " "
382 + to_str (height) + " "
383 + to_str (continued ? height/2 : 0) +
384 + " draw_" + String (decresc ? "de" : "") + "cresc\n";
386 a.dim_.x () = Interval (0, width);
387 a.dim_.y () = Interval (-2*height, 2*height);
393 Lookup::plet (Real dy , Real dx, Direction dir) const
397 ps += String_convert::double_str (dx) + " "
398 + String_convert::double_str (dy) + " "
399 + String_convert::int_str ( (int)dir) +
408 Lookup::slur (Array<Offset> controls) const
410 assert (controls.size () == 8);
414 Real dx = controls[3].x () - controls[0].x ();
415 Real dy = controls[3].y () - controls[0].y ();
419 int indices[] = {5,6,7,4,1,2,3,0};
421 for (int i= 0; i < 8; i++)
422 scontrols[i] = offset2scm (controls[indices[i]]);
426 gh_append2 (ly_lambda_o (),
427 gh_list (gh_append2 (ly_func_o ("slur"),
428 gh_list (ly_quote_scm (gh_list (scontrols[0],
445 a.dim_[X_AXIS] = Interval (0, dx);
446 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
452 Lookup::vbracket (Real &y) const
455 Real min_y = paper_l_->staffheight_f ();
458 warning (_ ("bracket")
459 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
464 a.lambda_ = (lambda_scm ("bracket", arr));
466 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
467 a.dim_[X_AXIS] = Interval (0,4 PT);