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 "symtable.hh"
18 #include "dimension.hh"
21 #include "paper-def.hh"
22 #include "string-convert.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::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::clef (String st) const
129 return afm_find (String ("clefs") + String ("-") + st);
133 Lookup::dots () const
135 return afm_find (String ("dots") + String ("-") + String ("dot"));
139 Lookup::dynamic (String st) const
141 return (*symtables_p_) ("dynamics")->lookup (st);
145 Lookup::fill (Box b) const
153 Lookup::flag (int j, Direction d) const
155 char c = (d == UP) ? 'u' : 'd';
156 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
160 Lookup::print () const
163 DOUT << "Lookup {\n";
164 symtables_p_->print ();
170 Lookup::rest (int j, bool o) const
172 return afm_find (String ("rests")
173 + String ("-") + to_str (j) + (o ? "o" : ""));
177 Lookup::rule_symbol (Real height, Real width) const
179 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
181 args.push (print_dimen (height));
182 args.push (print_dimen (width));
183 bs.str_ = substitute_args (bs.str_,args);
184 bs.dim_.x () = Interval (0,width);
185 bs.dim_.y () = Interval (0,height);
190 Lookup::script (String str) const
192 return afm_find (String ("scripts") + String ("-") + str);
196 Lookup::special_time_signature (String s, Array<Scalar> arr) const
198 String symbolname="timesig-"+s+"%/%";
199 Atom a (afm_find (substitute_args(symbolname,arr)));
202 // Try if the full name was given
203 a=afm_find ("timesig-"+s);
206 // Resort to default layout with numbers
207 return time_signature(arr);
211 Lookup::stem (Real y1, Real y2, String str) const
221 s.dim_.x () = Interval (0,0);
222 s.dim_.y () = Interval (y1,y2);
226 Real stem_width = paper_l_->get_var ("stemthickness");
227 a.push (print_dimen (-stem_width /2));
228 a.push (print_dimen (stem_width));
229 a.push (print_dimen (y2));
230 a.push (print_dimen (-y1));
232 s.str_ = substitute_args (str, a);
238 Lookup::streepje (int type) const
243 return afm_find ("balls" + String ("-") +to_str (type) + "l");
247 Lookup::text (String style, String text) const
252 Atom s = (*symtables_p_) ("style")->lookup (style);
253 s.str_ = substitute_args (s.str_,a);
260 Lookup::time_signature (Array<Scalar> a) const
262 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
263 s.str_ = substitute_args (s.str_, a);
269 should be handled via Tex_ code and Lookup::bar ()
272 Lookup::vbrace (Real &y) const
274 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
275 Interval ydims = brace.dim_[Y_AXIS];
276 Real min_y = ydims[LEFT];
277 Real max_y = ydims[RIGHT];
282 warning (_ ("piano brace")
283 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
288 warning (_ ("piano brace")
289 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
294 int idx = int (rint ( (y- min_y)/step)) + 1;
298 a.push (to_str (idx));
299 brace.str_ = substitute_args (brace.str_,a);
300 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);