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"
27 symtables_p_ = new Symtables;
31 Lookup::Lookup (Lookup const& s)
34 font_path_ = s.font_path_;
35 paper_l_ = s.paper_l_;
36 symtables_p_ = new Symtables (*s.symtables_p_);
40 Lookup::Lookup (Symtables const& s)
43 font_path_ = s.font_path_;
45 symtables_p_ = new Symtables (s);
56 Lookup::accidental (int j) const
58 return afm_find (String ("accidentals") + String ("-") + to_str (j));
62 Lookup::add (String s, Symtable*p)
64 symtables_p_->add (s, p);
68 Lookup::afm_find (String s, String str) const
72 *mlog << "[" << font_path_;
73 ( (Lookup*)this)->afm_p_ = new Adobe_font_metric (read_afm (font_path_));
74 *mlog << "]" << flush ;
75 DOUT << this->afm_p_->str ();
77 Adobe_font_char_metric m = afm_p_->find_char (s);
84 a.dim_[X_AXIS] *= 1 / 1000.0;
85 a.dim_[Y_AXIS] *= 1 / 1000.0;
86 a.str_ = String_convert::form_str (str.ch_C (), m.code ());
92 Lookup::ball (int j) const
97 return afm_find (String ("balls") + String ("-") + to_str (j));
101 Lookup::bar (String str, Real h) const
104 a.push (print_dimen (h));
105 Atom s = (*symtables_p_) ("bars")->lookup (str);
106 s.str_ = substitute_args (s.str_, a);
107 s.dim_.y () = Interval (-h/2, h/2);
113 Lookup::base_output_str () const
116 String str = paper_l_->get_default_output ();
120 str = default_outname_base_global;
121 int def = paper_l_->get_next_default_count ();
123 str += "-" + to_str (def);
129 Lookup::beam (Real slope, Real width, Real thick) const
131 Atom a (ps_beam (slope, width, thick));
132 Real height = slope * width;
133 Real min_y = (0 <? height) - thick/2;
134 Real max_y = (0 >? height) + thick/2;
136 a.dim_[X_AXIS] = Interval (0, width);
137 a.dim_[Y_AXIS] = Interval (min_y, max_y);
142 Lookup::character_str (int i) const
148 Lookup::clef (String st) const
150 return afm_find (String ("clefs") + String ("-") + st);
154 Lookup::dots () const
156 return afm_find (String ("dots") + String ("-") + String ("dot"));
160 Lookup::dynamic (String st) const
162 return (*symtables_p_) ("dynamics")->lookup (st);
166 Lookup::fill (Box b) const
174 Lookup::flag (int j, Direction d) const
176 char c = (d == UP) ? 'u' : 'd';
177 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
181 Lookup::print () const
184 DOUT << "Lookup {\n";
185 symtables_p_->print ();
191 Lookup::print_dimen (Real r) const
193 String s = to_str (r, "%.3f");
194 if (s.index_i ("NaN") != -1)
203 Lookup::rest (int j, bool o) const
205 return afm_find (String ("rests")
206 + String ("-") + to_str (j) + (o ? "o" : ""));
210 Lookup::rule_symbol (Real height, Real width) const
212 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
214 args.push (print_dimen (height));
215 args.push (print_dimen (width));
216 bs.str_ = substitute_args (bs.str_, args);
217 bs.dim_.x () = Interval (0, width);
218 bs.dim_.y () = Interval (0, height);
223 Lookup::script (String str) const
225 return afm_find (String ("scripts") + String ("-") + str);
229 Lookup::special_time_signature (String s, Array<Scalar> arr) const
231 String symbolname = "timesig-"+s+"%/%";
232 Atom a (afm_find (substitute_args (symbolname, arr)));
235 // Try if the full name was given
236 a = afm_find ("timesig-"+s);
239 // Resort to default layout with numbers
240 return time_signature (arr);
244 substitute_arg (String& r, String arg)
246 int p = r.index_i ('%');
250 r = r.left_str (p) + arg + r.right_str (r.length_i () - p - 1);
254 Lookup::substitute_args (String source, Array<String> args) const
257 for (int i = 0 ; i < args.size (); i++)
258 substitute_arg (str, args[i]);
263 Lookup::substitute_args (String source, Array<Scalar> args) const
266 for (int i = 0 ; i < args.size (); i++)
268 return substitute_args (source, sv);
272 Lookup::stem (Real y1, Real y2, String str) const
282 s.dim_.x () = Interval (0,0);
283 s.dim_.y () = Interval (y1,y2);
287 Real stem_width = paper_l_->get_var ("stemthickness");
288 a.push (print_dimen (-stem_width /2));
289 a.push (print_dimen (stem_width));
290 a.push (print_dimen (y2));
291 a.push (print_dimen (-y1));
293 s.str_ = substitute_args (str, a);
299 Lookup::streepje (int type) const
304 return afm_find ("balls" + String ("-") +to_str (type) + "l");
308 Lookup::text (String style, String text) const
313 Atom s = (*symtables_p_) ("style")->lookup (style);
314 s.str_ = substitute_args (s.str_,a);
321 Lookup::time_signature (Array<Scalar> a) const
323 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
324 s.str_ = substitute_args (s.str_, a);
330 should be handled via Tex_ code and Lookup::bar ()
333 Lookup::vbrace (Real &y) const
335 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
336 Interval ydims = brace.dim_[Y_AXIS];
337 Real min_y = ydims[LEFT];
338 Real max_y = ydims[RIGHT];
343 warning (_ ("piano brace")
344 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
349 warning (_ ("piano brace")
350 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
355 int idx = int (rint ( (y- min_y)/step)) + 1;
359 a.push (character_str (idx));
360 brace.str_ = substitute_args (brace.str_,a);
361 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);