]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tex-slur.cc
release: 0.1.52
[lilypond.git] / lily / tex-slur.cc
index 2c362915146576c43f8b19f6ca95c34a71440058..9e116df08ee99c1a93ebb9a4ebb01e35a0b5de1d 100644 (file)
@@ -7,6 +7,7 @@
 */
 
 #include <math.h>
+#include "main.hh"
 #include "misc.hh"
 #include "lookup.hh"
 #include "molecule.hh"
@@ -126,65 +127,60 @@ Lookup::half_slur (int dy, Real &dx, Direction dir, int xpart) const
   assert (idx < 256);
   f+=String ("{") + String (idx) + "}";
 
-
   s.tex_ = f;
 
   return s;
 }
 
 Atom
-Lookup::slur (int dy , Real &dx, Direction dir) const
+Lookup::ps_slur (Real dy , Real dx, Real ht, Real dir) const
 {
-  assert (abs (dir) <= 1);
-  if  (dx < 0)
+  String ps = "\\embeddedps{\n";
+  
+  ps += String_convert::double_str (dx) + " " 
+    + String_convert::double_str (dy) + " "
+    + String_convert::double_str (ht) + " "
+    + String_convert::double_str (dir) +
+    " draw_slur}";
+
+  /*
+   slurs are rarely wider than 100pt: 
+   precision of 3 yields maximum (slur spanning page)
+   error of: 1%% * 6*72pt === 0.4pt = 0.14 mm
+   */
+  String dx_str = String_convert::precision_str (dx, 4);
+  String dy_str = String_convert::precision_str (dy, 3);
+  String dir_str = String_convert::int_str ((int)dir);
+  String name = "feta-sleur-" + dx_str + "-" + dy_str + "-" + dir_str;
+  int i = name.index_i ('.');
+  while (i != -1)
     {
-      warning (_("Negative slur/tie length: ") + print_dimen (dx));
-      dx = 4.0 PT;
+      *(name.ch_l () + i) = 'x';
+      i = name.index_i ('.');
     }
 
-  Atom s;
-  s.dim_[X_AXIS] = Interval (0, dx);
-  s.dim_[Y_AXIS] = Interval (min (0, dy), max (0, dy));
-
-  // duh
-  // let's try the embedded stuff
-  bool embedded_b = true;
-  if (embedded_b)
-    {
-      // huh, factor 8?
-      Real fdy = dy*paper_l_->interline_f ();
-      Real fdx = dx;
-      String ps = "\\embeddedps{\n";
-      // ugh, how bout " /draw_slur { ... } def "
-      ps += "0 0 moveto\n";
-      ps += String_convert::int_str (fdx/2) + " " 
-       + String_convert::int_str (fdy/2) + " "
-        + String_convert::int_str (fdx) + " " 
-       + String_convert::int_str (fdy) + " curveto\n";
-      ps += "closepath\n";
-      ps += "fill\n";
-      ps += "}\n";
-
-      String mf = "\\embeddedmf{\n";
-      mf += "input feta-sleur;\n";
-      mf += "draw_slur((0,0),";
-      mf += "(" + String_convert::int_str (fdx) + "," 
-       + String_convert::int_str (fdy) + "),";
-      mf += String_convert::int_str (dir) + ");\n";
-      mf += "end.\n";
-      ps += "}\n";
-
-      s.tex_ = ps + mf;
-      s.translate_axis (dx/2, X_AXIS);
-      // huh, extra translate?
-
-      s.translate_axis (-1.5*paper_l_->note_width (), X_AXIS);
-      // mmm, does embedded slur always start at y = 0?
-//      s.translate_axis (-1.5*paper_l_->note_width (), Y_AXIS);
+  String mf = "\\embeddedmf{" + name + "}{\n";
+  mf += "mode_setup;\n";
+  mf += "staffsize\\#:=" 
+    + String_convert::int_str ((int)paper_l_->get_var ("barsize"), "%d")
+    + "pt\\#;\n";
+  mf += "interline#:=staffsize#/4;\n";
+  mf += "stafflinethickness#:=0.1interline#;\n";
+  mf += "input feta-sleur;\n";
+  mf += "slurchar(" + dx_str + "," + dy_str + "," + dir_str + ");\n";
+  mf += "end.\n";
+  mf += "}\n";
 
-      return s;
-    }
+  Atom s;
+  s.tex_ = ps + mf;
+  return s;
+}
 
+Atom
+Lookup::tex_slur (int dy , Real &dx, Direction dir) const
+{
+  assert (abs ((int)dir) <= 1);
+  Atom s;
   Direction y_sign = (Direction) sign (dy);
 
   bool large = abs (dy) > 8;
@@ -198,7 +194,8 @@ Lookup::slur (int dy , Real &dx, Direction dir) const
 
   if (large)
     {
-      return big_slur (dy, dx, dir);
+      s = big_slur (dy, dx, dir);
+      return s;
     }
   Real orig_dx = dx;
   int widx = int (floor (dx/4.0)); // slurs better too small..
@@ -244,7 +241,6 @@ Lookup::slur (int dy , Real &dx, Direction dir) const
   assert (idx < 256);
   f+=String ("{") + String (idx) + "}";
   s.tex_ = f;
-
   s.translate_axis (dx/2, X_AXIS);
   return s;
 }
@@ -284,3 +280,30 @@ Lookup::big_slur (int dy , Real &dx, Direction dir) const
   s.dim_ = mol.extent();
   return s;
 }
+
+
+Atom
+Lookup::slur  (Real &dy_f , Real &dx, Real ht, Direction dir) const
+{
+  if  (dx < 0)
+    {
+      warning (_("Negative slur/tie length: ") + print_dimen (dx));
+      dx = 4.0 PT;
+    }
+  Atom s;
+  
+  if (postscript_global_b)
+    s = ps_slur (dy_f, dx, ht, dir);
+  else
+    {
+      Real nh =  paper_l_->internote_f ();
+      int dy_i = (int) rint(dy_f / nh);
+
+      s = tex_slur (dy_i, dx, dir);
+      dy_f = dy_i *  nh;
+    }
+  
+  s.dim_[X_AXIS] = Interval (0, dx);
+  s.dim_[Y_AXIS] = Interval (0 <? dy_f,  0 >? dy_f);
+  return s;
+}