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) const
59 return afm_find (String ("accidentals") + String ("-") + to_str (j));
63 Lookup::add (String s, Symtable*p)
65 symtables_p_->add (s, p);
69 Lookup::afm_find (String s, String str) const
73 *mlog << "[" << font_path_;
74 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
75 *mlog << "]" << flush ;
76 DOUT << this->afm_p_->str ();
78 Adobe_font_char_metric m = afm_p_->find_char (s);
85 a.dim_[X_AXIS] *= 1 / 1000.0;
86 a.dim_[Y_AXIS] *= 1 / 1000.0;
87 a.str_ = String_convert::form_str (str.ch_C (), m.code ());
93 Lookup::ball (int j) const
98 return afm_find (String ("balls") + String ("-") + to_str (j));
102 Lookup::bar (String str, Real h) const
105 a.push (print_dimen (h));
106 Atom s = (*symtables_p_) ("bars")->lookup (str);
107 s.str_ = substitute_args (s.str_, a);
108 s.dim_.y () = Interval (-h/2, h/2);
114 Lookup::base_output_str () const
117 String str = paper_l_->get_default_output ();
121 str = default_outname_base_global;
122 int def = paper_l_->get_next_default_count ();
124 str += "-" + to_str (def);
130 Lookup::beam (Real slope, Real width, Real thick) const
132 Atom a (ps_beam (slope, width, thick));
133 Real height = slope * width;
134 Real min_y = (0 <? height) - thick/2;
135 Real max_y = (0 >? height) + thick/2;
137 a.dim_[X_AXIS] = Interval (0, width);
138 a.dim_[Y_AXIS] = Interval (min_y, max_y);
143 Lookup::character_str (int i) const
149 Lookup::clef (String st) const
151 return afm_find (String ("clefs") + String ("-") + st);
155 Lookup::dashed_slur (Array<Offset> controls, Real thick, Real dash) const
157 assert (controls.size () == 8);
159 Real dx = controls[3].x () - controls[0].x ();
160 Real dy = controls[3].y () - controls[0].y ();
164 a.dim_[X_AXIS] = Interval (0, dx);
165 a.dim_[Y_AXIS] = Interval (0 <? dy, 0 >? dy);
167 #ifndef HAVE_LIBGUILE
170 for (int i = 1; i < 4; i++)
171 ps += String_convert::double_str (controls[i].x ()) + " "
172 + String_convert::double_str (controls[i].y ()) + " ";
174 ps += String_convert::double_str (controls[0].x ()) + " "
175 + String_convert::double_str (controls[0].y ()) + " ";
177 ps += String_convert::double_str (thick) + " ";
178 Real on = dash > 1? thick * dash - thick : 0;
179 Real off = 2 * thick;
180 ps += "[" + String_convert::double_str (on) + " ";
181 ps += String_convert::double_str (off) + "] ";
182 ps += String_convert::int_str (0) + " ";
183 ps += "draw_dashed_slur ";
187 #else // HAVE_LIBGUILE
189 // (lambda (o) (dashed-slur o '((0.1 0.2) (1.1 1.2) (2.1 2.2) (3.1 3.2))))
191 gh_append (gh_lambda_o (),
192 gh_list1 (gh_append (gh_func_o ("dashed-slur"),
193 gh_cons (gh_double2scm (thick), gh_cons (gh_double2scm (dash),
194 gh_list1 (gh_list2 (gh_quote (),
195 gh_cons (gh_list2 (gh_double2scm (controls[0].x ()), gh_double2scm (controls[0].y ())),
196 gh_cons (gh_list2 (gh_double2scm (controls[1].x ()), gh_double2scm (controls[1].y ())),
197 gh_cons (gh_list2 (gh_double2scm (controls[2].x ()), gh_double2scm (controls[2].y ())),
198 gh_cons (gh_list2 (gh_double2scm (controls[3].x ()), gh_double2scm (controls[3].y ())),
201 #endif // HAVE_LIBGUILE
207 Lookup::dots () const
209 return afm_find (String ("dots") + String ("-") + String ("dot"));
213 Lookup::dynamic (String st) const
215 return (*symtables_p_) ("dynamics")->lookup (st);
219 Lookup::fill (Box b) const
227 Lookup::flag (int j, Direction d) const
229 char c = (d == UP) ? 'u' : 'd';
230 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
234 Lookup::print () const
237 DOUT << "Lookup {\n";
238 symtables_p_->print ();
244 Lookup::print_dimen (Real r) const
246 String s = to_str (r, "%.3f");
247 if (s.index_i ("NaN") != -1)
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
265 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
267 args.push (print_dimen (height));
268 args.push (print_dimen (width));
269 bs.str_ = substitute_args (bs.str_, args);
270 bs.dim_.x () = Interval (0, width);
271 bs.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<Scalar> arr) const
284 String symbolname = "timesig-"+s+"%/%";
285 Atom a (afm_find (substitute_args (symbolname, arr)));
288 // Try if the full name was given
289 a = afm_find ("timesig-"+s);
292 // Resort to default layout with numbers
293 return time_signature (arr);
297 substitute_arg (String& r, String arg)
299 int p = r.index_i ('%');
303 r = r.left_str (p) + arg + r.right_str (r.length_i () - p - 1);
307 Lookup::substitute_args (String source, Array<String> args) const
310 for (int i = 0 ; i < args.size (); i++)
311 substitute_arg (str, args[i]);
316 Lookup::substitute_args (String source, Array<Scalar> args) const
319 for (int i = 0 ; i < args.size (); i++)
321 return substitute_args (source, sv);
325 Lookup::stem (Real y1, Real y2, String str) const
335 s.dim_.x () = Interval (0,0);
336 s.dim_.y () = Interval (y1,y2);
340 Real stem_width = paper_l_->get_var ("stemthickness");
341 a.push (print_dimen (-stem_width /2));
342 a.push (print_dimen (stem_width));
343 a.push (print_dimen (y2));
344 a.push (print_dimen (-y1));
346 s.str_ = substitute_args (str, a);
352 Lookup::streepje (int type) const
357 return afm_find ("balls" + String ("-") +to_str (type) + "l");
361 Lookup::text (String style, String text) const
366 Atom s = (*symtables_p_) ("style")->lookup (style);
367 s.str_ = substitute_args (s.str_,a);
374 Lookup::time_signature (Array<Scalar> a) const
376 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
377 s.str_ = substitute_args (s.str_, a);
383 should be handled via Tex_ code and Lookup::bar ()
386 Lookup::vbrace (Real &y) const
388 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
389 Interval ydims = brace.dim_[Y_AXIS];
390 Real min_y = ydims[LEFT];
391 Real max_y = ydims[RIGHT];
396 warning (_ ("piano brace")
397 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
402 warning (_ ("piano brace")
403 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
408 int idx = int (rint ( (y- min_y)/step)) + 1;
412 a.push (character_str (idx));
413 brace.str_ = substitute_args (brace.str_,a);
414 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);