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);
82 a.dim_[X_AXIS] *= 1 / 1000.0;
83 a.dim_[Y_AXIS] *= 1 / 1000.0;
84 a.str_ = String_convert::form_str (str.ch_C (), m.code ());
90 Lookup::ball (int j) const
95 return afm_find (String ("balls") + String ("-") + to_str (j));
99 Lookup::bar (String str, Real h) const
102 a.push (print_dimen (h));
103 Atom s = (*symtables_p_) ("bars")->lookup (str);
104 s.str_ = substitute_args (s.str_, a);
105 s.dim_.y () = Interval (-h/2, h/2);
111 Lookup::beam (Real slope, Real width, Real thick) const
113 Atom a (ps_beam (slope, width, thick));
114 Real height = slope * width;
115 Real min_y = (0 <? height) - thick/2;
116 Real max_y = (0 >? height) + thick/2;
118 a.dim_[X_AXIS] = Interval (0, width);
119 a.dim_[Y_AXIS] = Interval (min_y, max_y);
124 Lookup::clef (String st) const
126 return afm_find (String ("clefs") + String ("-") + st);
130 Lookup::dots () const
132 return afm_find (String ("dots") + String ("-") + String ("dot"));
136 Lookup::dynamic (String st) const
138 return (*symtables_p_) ("dynamics")->lookup (st);
142 Lookup::fill (Box b) const
150 Lookup::flag (int j, Direction d) const
152 char c = (d == UP) ? 'u' : 'd';
153 return afm_find (String ("flags") + String ("-") + to_str (c) + to_str (j));
157 Lookup::print () const
160 DOUT << "Lookup {\n";
161 symtables_p_->print ();
167 Lookup::rest (int j, bool o) const
169 return afm_find (String ("rests")
170 + String ("-") + to_str (j) + (o ? "o" : ""));
174 Lookup::rule_symbol (Real height, Real width) const
176 Atom bs= (*symtables_p_) ("param")->lookup ("rule");
178 args.push (print_dimen (height));
179 args.push (print_dimen (width));
180 bs.str_ = substitute_args (bs.str_,args);
181 bs.dim_.x () = Interval (0,width);
182 bs.dim_.y () = Interval (0,height);
187 Lookup::script (String str) const
189 return afm_find (String ("scripts") + String ("-") + str);
193 Lookup::special_time_signature (String s) const
195 Atom a (afm_find ("timesig-"+ s));
200 Lookup::stem (Real y1, Real y2, String str) const
210 s.dim_.x () = Interval (0,0);
211 s.dim_.y () = Interval (y1,y2);
215 Real stem_width = paper_l_->get_var ("stemthickness");
216 a.push (print_dimen (-stem_width /2));
217 a.push (print_dimen (stem_width));
218 a.push (print_dimen (y2));
219 a.push (print_dimen (-y1));
221 s.str_ = substitute_args (str, a);
227 Lookup::streepje (int type) const
232 return afm_find ("balls" + String ("-") +to_str (type) + "l");
236 Lookup::text (String style, String text) const
241 Atom s = (*symtables_p_) ("style")->lookup (style);
242 s.str_ = substitute_args (s.str_,a);
249 Lookup::time_signature (Array<Scalar> a) const
251 Atom s ((*symtables_p_) ("param")->lookup ("time_signature"));
252 s.str_ = substitute_args (s.str_, a);
258 should be handled via Tex_ code and Lookup::bar ()
261 Lookup::vbrace (Real &y) const
263 Atom brace = (*symtables_p_) ("param")->lookup ( "brace");
264 Interval ydims = brace.dim_[Y_AXIS];
265 Real min_y = ydims[LEFT];
266 Real max_y = ydims[RIGHT];
271 warning (_ ("piano brace")
272 + " " + _ ("too small") + " (" + print_dimen (y) + ")");
277 warning (_ ("piano brace")
278 + " " + _ ("too big") + " (" + print_dimen (y) + ")");
283 int idx = int (rint ( (y- min_y)/step)) + 1;
287 a.push (to_str (idx));
288 brace.str_ = substitute_args (brace.str_,a);
289 brace.dim_[Y_AXIS] = Interval (-y/2,y/2);