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);
114 Lookup::beam (Real slope, Real width, Real thick) const
116 Atom a (ps_beam (slope, width, thick));
117 Real height = slope * width;
118 Real min_y = (0 <? height) - thick/2;
119 Real max_y = (0 >? height) + thick/2;
121 a.dim_[X_AXIS] = Interval (0, width);
122 a.dim_[Y_AXIS] = Interval (min_y, max_y);
127 Lookup::character_str (int i) const
133 Lookup::clef (String st) const
135 return afm_find (String ("clefs") + String ("-") + st);
139 Lookup::dots () const
141 return afm_find (String ("dots") + String ("-") + String ("dot"));
145 Lookup::dynamic (String st) const
147 return (*symtables_p_) ("dynamics")->lookup (st);
151 Lookup::fill (Box b) const
159 Lookup::flag (int j, Direction d) const
161 char c = (d == UP) ? 'u' : 'd';
162 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
166 Lookup::print () const
169 DOUT << "Lookup {\n";
170 symtables_p_->print ();
176 Lookup::print_dimen (Real r) const
178 return paper_l_->dimension_str (r);
182 Lookup::rest (int j, bool o) const
184 return afm_find (String ("rests")
185 + String ("-") + to_str (j) + (o ? "o" : ""));
189 Lookup::rule_symbol (Real height, Real width) const
191 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
193 args.push (print_dimen (height));
194 args.push (print_dimen (width));
195 bs.str_ = substitute_args (bs.str_, args);
196 bs.dim_.x () = Interval (0, width);
197 bs.dim_.y () = Interval (0, height);
202 Lookup::script (String str) const
204 return afm_find (String ("scripts") + String ("-") + str);
208 Lookup::special_time_signature (String s, Array<Scalar> arr) const
210 String symbolname = "timesig-"+s+"%/%";
211 Atom a (afm_find (substitute_args (symbolname, arr)));
214 // Try if the full name was given
215 a = afm_find ("timesig-"+s);
218 // Resort to default layout with numbers
219 return time_signature (arr);
223 substitute_arg (String& r, String arg)
225 int p = r.index_i ('%');
229 r = r.left_str (p) + arg + r.right_str (r.length_i () - p - 1);
233 Lookup::substitute_args (String source, Array<String> args) const
236 for (int i = 0 ; i < args.size (); i++)
237 substitute_arg (str, args[i]);
242 Lookup::substitute_args (String source, Array<Scalar> args) const
245 for (int i = 0 ; i < args.size (); i++)
247 return substitute_args (source, sv);
251 Lookup::stem (Real y1, Real y2, String str) const
261 s.dim_.x () = Interval (0,0);
262 s.dim_.y () = Interval (y1,y2);
266 Real stem_width = paper_l_->get_var ("stemthickness");
267 a.push (print_dimen (-stem_width /2));
268 a.push (print_dimen (stem_width));
269 a.push (print_dimen (y2));
270 a.push (print_dimen (-y1));
272 s.str_ = substitute_args (str, a);
278 Lookup::streepje (int type) const
283 return afm_find ("balls" + String ("-") +to_str (type) + "l");
287 Lookup::text (String style, String text) const
292 Atom s = (*symtables_p_) ("style")->lookup (style);
293 s.str_ = substitute_args (s.str_,a);
300 Lookup::time_signature (Array<Scalar> a) const
302 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
303 s.str_ = substitute_args (s.str_, a);
309 should be handled via Tex_ code and Lookup::bar ()
312 Lookup::vbrace (Real &y) const
314 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
315 Interval ydims = brace.dim_[Y_AXIS];
316 Real min_y = ydims[LEFT];
317 Real max_y = ydims[RIGHT];
322 warning (_ ("piano brace")
323 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
328 warning (_ ("piano brace")
329 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
334 int idx = int (rint ( (y- min_y)/step)) + 1;
338 a.push (character_str (idx));
339 brace.str_ = substitute_args (brace.str_,a);
340 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);