2 tex-slur.cc -- implement Lookup::*slur
4 source file of the GNU LilyPond music typesetter
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
13 #include "molecule.hh"
16 #include "paper-def.hh"
17 #include "string-convert.hh"
21 direction_char (Direction y_sign)
42 Lookup::half_slur_middlepart (Real &dx, Direction dir) const
47 WARN<<_("halfslur too large") <<print_dimen (dx)<< _("shrinking (ugh)\n");
50 int widx = int (floor (dx / 4.0));
55 WARN << _("slur too narrow\n");
60 s.dim_[Y_AXIS] = Interval (min (0, 0), max (0, 0)); // todo
61 s.dim_[X_AXIS] = Interval (-dx/2, dx/2);
63 String f = String ("\\hslurchar");
64 f += direction_char (CENTER);
72 f +=String ("{") + String (idx) + "}";
74 s.translate_axis (dx/2, X_AXIS);
80 The halfslurs have their center at the end pointing away from the notehead.
81 This lookup translates so that width() == [0, w]
85 Lookup::half_slur (int dy, Real &dx, Direction dir, int xpart) const
89 return half_slur_middlepart (dx, dir);
95 WARN << _("Slur half too wide.") << print_dimen (orig_dx) << _(" shrinking (ugh)\n");
99 widx = int (rint (dx/12.0));
105 WARN << _("slur too narrow ") << print_dimen (orig_dx)<<"\n";
109 s.dim_[X_AXIS] = Interval (0, dx);
110 s.dim_[Y_AXIS] = Interval (min (0, dy), max (0, dy));
113 String f = String ("\\hslurchar");
115 f+= direction_char (dir);
123 idx = widx * 16 + hidx;
128 f+=String ("{") + String (idx) + "}";
137 Lookup::ps_slur (Real dy , Real dx, Real dir) const
139 String ps = "\\embeddedps{\n";
141 ps += String_convert::double_str (dx) + " "
142 + String_convert::double_str (dy) + " "
143 + String_convert::double_str (dir) +
146 String mf = "\\embeddedmf{\n";
147 mf += "input feta-sleur;\n";
148 mf += "draw_slur((0,0),";
149 mf += "(" + String_convert::double_str (dx) + ","
150 + String_convert::double_str (dy) + "),";
151 mf += String_convert::double_str (dir) + ");\n";
161 Lookup::tex_slur (int dy , Real &dx, Direction dir) const
163 assert (abs (dir) <= 1);
165 Direction y_sign = (Direction) sign (dy);
167 bool large = abs (dy) > 8;
171 large |= dx>= 4*16 PT;
174 large |= dx>= 4*54 PT;
178 s = big_slur (dy, dx, dir);
182 int widx = int (floor (dx/4.0)); // slurs better too small..
188 WARN << _("slur too narrow: ") << print_dimen (orig_dx) << "\n";
197 WARN<<_("slur to steep: ") << dy << _(" shrinking (ugh)\n");
200 String f = String ("\\slurchar") + String (direction_char (y_sign));
205 idx = hidx * 16 + widx;
213 WARN << _("slur too wide: ") << print_dimen (dx) <<
214 _(" shrinking (ugh)\n");
223 f+=String ("{") + String (idx) + "}";
225 s.translate_axis (dx/2, X_AXIS);
230 Lookup::big_slur (int dy , Real &dx, Direction dir) const
234 warning (_("big_slur too small ") + print_dimen (dx) + _(" (stretching)"));
238 Real slur_extra =abs (dy) /2.0 + 2;
239 int l_dy = int (Real (dy)/2 + slur_extra*dir);
240 int r_dy = dy - l_dy;
242 Real internote_f = paper_l_->internote_f();
243 Real left_wid = dx/4.0;
244 Real right_wid = left_wid;
246 Atom l = half_slur (l_dy, left_wid, dir, -1);
249 Atom r = half_slur (r_dy, right_wid, dir, 1);
250 Real mid_wid = dx - left_wid - right_wid;
254 Atom a (half_slur (0, mid_wid, dir, 0));
255 mol.add_at_edge (X_AXIS, RIGHT, a);
256 mol.add_at_edge (X_AXIS, RIGHT, r);
258 mol.translate_axis (l_dy * internote_f, Y_AXIS);
260 s.tex_ = mol.TeX_string();
261 s.dim_ = mol.extent();
267 Lookup::slur (Real &dy_f , Real &dx, Direction dir) const
271 warning (_("Negative slur/tie length: ") + print_dimen (dx));
276 if (postscript_global_b)
277 s = ps_slur (dy_f, dx, dir);
280 Real nh = paper_l_->internote_f ();
281 int dy_i = (int) rint(dy_f / nh);
283 s = tex_slur (dy_i, dx, dir);
287 s.dim_[X_AXIS] = Interval (0, dx);
288 s.dim_[Y_AXIS] = Interval (0 <? dy_f, 0 >? dy_f);