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
18 #include "dimensions.hh"
19 #include "symtable.hh"
21 #include "paper-def.hh"
22 #include "string-convert.hh"
23 #include "file-path.hh"
25 #include "lily-guile.hh"
28 array_to_list (SCM *a , int l)
33 list = gh_cons (a[i], list);
42 symtables_p_ = new Symtables;
46 Lookup::Lookup (Lookup const& s)
49 font_path_ = s.font_path_;
50 paper_l_ = s.paper_l_;
51 symtables_p_ = new Symtables (*s.symtables_p_);
55 Lookup::Lookup (Symtables const& s)
58 font_path_ = s.font_path_;
60 symtables_p_ = new Symtables (s);
71 Lookup::accidental (int j, bool cautionary) const
73 Molecule m(afm_find (String ("accidentals") + String ("-") + to_str (j)));
76 m.add_at_edge(X_AXIS, LEFT,
77 Molecule(afm_find (String ("accidentals") + String ("-("))))
79 m.add_at_edge(X_AXIS, RIGHT,
80 Molecule(afm_find (String ("accidentals") + String ("-)"))))
87 Lookup::add (String s, Symtable*p)
89 symtables_p_->add (s, p);
93 Lookup::afm_find (String s, bool warn) const
97 *mlog << "[" << font_path_;
98 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
99 *mlog << "]" << flush ;
100 DOUT << this->afm_p_->str ();
102 Adobe_font_char_metric m = afm_p_->find_char (s, warn);
109 a.dim_[X_AXIS] *= 1 / 1000.0;
110 a.dim_[Y_AXIS] *= 1 / 1000.0;
113 a.lambda_ = gh_list (ly_symbol ("char"),
114 gh_int2scm (m.code ()),
116 a.str_ = "afm_find: " + s;
122 Lookup::ball (int j) const
127 return afm_find (String ("balls") + String ("-") + to_str (j));
131 Lookup::bar (String str, Real h) const
134 Atom a = (*symtables_p_) ("bars")->lookup (str);
137 a.lambda_ = gh_list (ly_symbol (a.str_.ch_C()),
142 a.dim_.y () = Interval (-h/2, h/2);
148 Lookup::beam (Real slope, Real width, Real thick) const
150 Real height = slope * width;
151 Real min_y = (0 <? height) - thick/2;
152 Real max_y = (0 >? height) + thick/2;
155 a.lambda_ = gh_list (ly_symbol ("beam"),
156 gh_double2scm (width),
157 gh_double2scm (slope),
158 gh_double2scm (thick),
161 a.dim_[X_AXIS] = Interval (0, width);
162 a.dim_[Y_AXIS] = Interval (min_y, max_y);
167 Lookup::clef (String st) const
169 return afm_find (String ("clefs") + String ("-") + st);
173 offset2scm (Offset o)
175 return gh_list (gh_double2scm (o[X_AXIS]), gh_double2scm(o[Y_AXIS]),
180 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
182 assert (controls.size () == 8);
183 Offset d = controls[3] - controls[0];
190 a.dim_[X_AXIS] = Interval (0, dx);
191 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
194 for (int i=0; i< 4; i++)
196 sc[i] = offset2scm (controls[i]);
200 gh_list (ly_symbol ("dashed-slur"),
201 gh_double2scm (thick),
202 gh_double2scm (dash),
203 ly_quote_scm (array_to_list (sc, 4)),
206 a.str_ = "dashed_slur";
211 Lookup::dots () const
213 return afm_find (String ("dots") + String ("-") + String ("dot"));
217 Lookup::dynamic (String st) const
219 return (*symtables_p_) ("dynamics")->lookup (st);
223 Lookup::extender (Real width) const
225 Atom a = (*symtables_p_) ("param")->lookup ("extender");
226 a.lambda_ = gh_list (ly_symbol (a.str_),
227 gh_double2scm (width),
235 Lookup::fill (Box b) const
243 Lookup::flag (int j, Direction d) const
245 char c = (d == UP) ? 'u' : 'd';
246 Atom a = afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
251 Lookup::print () const
254 DOUT << "Lookup {\n";
255 symtables_p_->print ();
261 Lookup::rest (int j, bool o) const
263 return afm_find (String ("rests")
264 + String ("-") + to_str (j) + (o ? "o" : ""));
268 Lookup::rule_symbol (Real height, Real width) const
271 a.lambda_ = gh_list (ly_symbol ("rulesym"),
272 gh_double2scm (height),
273 gh_double2scm (width),
275 a.dim_.x () = Interval (0, width);
276 a.dim_.y () = Interval (0, height);
281 Lookup::script (String str) const
283 return afm_find (String ("scripts") + String ("-") + str);
287 Lookup::special_time_signature (String s, Array<int> arr) const
289 // First guess: s contains only the signature style
290 assert (arr.size () >1);
291 String symbolname = "timesig-" + s + to_str (arr[0]) + "/" + to_str (arr[1]);
293 Atom a = afm_find (symbolname, false);
297 // Second guess: s contains the full signature name
298 a = afm_find ("timesig-"+s, false);
302 // Resort to default layout with numbers
303 return time_signature (arr);
307 Lookup::stem (Real y1, Real y2) const
317 a.dim_.x () = Interval (0,0);
318 a.dim_.y () = Interval (y1,y2);
320 Real stem_width = paper_l_->get_var ("stemthickness");
322 a.lambda_ = gh_list (ly_symbol ("stem"),
323 gh_double2scm(-stem_width /2),
324 gh_double2scm(stem_width),
334 Lookup::streepje (int type) const
339 return afm_find ("balls" + String ("-") +to_str (type) + "l");
342 Dictionary<String> cmr_dict;
343 Dictionary<Adobe_font_metric*> afm_p_dict;
346 Lookup::text (String style, String text) const
348 Atom a = (*symtables_p_) ("style")->lookup (style);
350 a.lambda_ = gh_list(ly_symbol (a.str_),
351 gh_str02scm (text.ch_C()),
354 Real font_w = a.dim_.x ().length ();
355 Real font_h = a.dim_.y ().length ();
357 if (!cmr_dict.elem_b ("roman"))
360 cmr_dict.elem ("bold") = "cmbx";
361 cmr_dict.elem ("dynamic") = "feta-din";
362 cmr_dict.elem ("finger") = "feta-nummer";
363 cmr_dict.elem ("italic") = "cmti";
364 cmr_dict.elem ("roman") = "cmr";
367 if (!afm_p_dict.elem_b (style))
369 Adobe_font_metric* afm_p = 0;
370 String cmr_str = cmr_dict.elem (style) + to_str ((int) font_h) + ".afm";
371 String font_path = global_path.find (cmr_str);
372 if (!font_path.length_i ())
374 warning (_f("can't open file: `%s'", cmr_str.ch_C ()));
375 warning (_f("guessing dimensions for font style: `%s'", style.ch_C ()));
379 *mlog << "[" << font_path;
380 afm_p = new Adobe_font_metric (read_afm (font_path));
381 DOUT << afm_p->str ();
382 *mlog << "]" << flush ;
384 afm_p_dict.elem (style) = afm_p;
387 Adobe_font_metric* afm_p = afm_p_dict.elem (style);
389 for (int i = 0; i < text.length_i (); i++)
392 for (i++; (i < text.length_i ()) && isalpha(text[i]); i++)
397 if (afm_p && ((c >= 0) && (c < afm_p->char_metrics_.size ())))
399 Adobe_font_char_metric m = afm_p->char_metrics_[c];
400 w += m.B_.x ().length ();
401 DOUT << to_str (m.B_.x ().length ()) << " ";
407 DOUT << "\n" << to_str (w) << "\n";
408 a.dim_.x () = Interval (0, w);
415 Lookup::time_signature (Array<int> a) const
417 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
418 s.lambda_ = gh_list (ly_symbol (s.str_),
426 Lookup::vbrace (Real &y) const
429 a.lambda_ = gh_list (ly_symbol ("pianobrace"),
433 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
439 Lookup::hairpin (Real width, bool decresc, bool continued) const
442 Real height = paper_l_->staffheight_f () / 6;
444 String hairpin = String (decresc ? "de" : "") + "crescendo";
445 a.lambda_ = gh_list (ly_symbol (hairpin),
446 gh_double2scm (width),
447 gh_double2scm (height),
448 gh_double2scm (continued ? height/2 : 0.0),
450 a.dim_.x () = Interval (0, width);
451 a.dim_.y () = Interval (-2*height, 2*height);
457 Lookup::plet (Real dy , Real dx, Direction dir) const
460 a.lambda_ = gh_list(ly_symbol ("tuplet"),
463 gh_int2scm (dir), SCM_UNDEFINED);
469 Lookup::slur (Array<Offset> controls) const
471 assert (controls.size () == 8);
472 Real dx = controls[3].x () - controls[0].x ();
473 Real dy = controls[3].y () - controls[0].y ();
477 int indices[] = {5,6,7,4,1,2,3,0};
479 for (int i= 0; i < 8; i++)
480 scontrols[i] = offset2scm (controls[indices[i]]);
483 a.lambda_ =gh_list (ly_symbol ("slur"),
484 ly_quote_scm (array_to_list (scontrols, 8)),
487 a.dim_[X_AXIS] = Interval (0, dx);
488 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
494 Lookup::vbracket (Real &y) const
497 Real min_y = paper_l_->staffheight_f ();
500 warning (_ ("bracket")
501 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
505 a.lambda_ = gh_list (ly_symbol ("bracket"),
509 a.dim_[Y_AXIS] = Interval (-y/2,y/2);
510 a.dim_[X_AXIS] = Interval (0,4 PT);
515 Lookup::volta (Real w, bool last_b) const
518 a.lambda_ = gh_list (ly_symbol ("volta"),
523 Real interline_f = paper_l_->interline_f ();
524 // a.dim_[Y_AXIS] = Interval (0, 2 * interline_f);
525 a.dim_[Y_AXIS] = Interval (-interline_f, interline_f);
526 a.dim_[X_AXIS] = Interval (0, w);