]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tex-slur.cc
release: 0.1.52
[lilypond.git] / lily / tex-slur.cc
index 05ff03a0891e8d8ca5d7278bf2baf54259ec360f..9e116df08ee99c1a93ebb9a4ebb01e35a0b5de1d 100644 (file)
@@ -127,53 +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));
+  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";
 
-  // duh
-  // let's try the embedded stuff
-  bool embedded_b = experimental_features_global_b;
-  String embed;
-  if (embedded_b)
-    {
-      Real fdy = dy*paper_l_->internote_f ();
-      Real fdx = dx;
-      String ps = "\\embeddedps{\n";
-      // ugh, how bout " /draw_slur { ... } def "
-      ps += String_convert::double_str (fdx) + " " 
-       + String_convert::double_str (fdy) + " "
-       + String_convert::double_str (dir) +
-       " draw_slur}";
-
-      String mf = "\\embeddedmf{\n";
-      mf += "input feta-sleur;\n";
-      mf += "draw_slur((0,0),";
-      mf += "(" + String_convert::double_str (fdx) + "," 
-       + String_convert::double_str (fdy) + "),";
-      mf += String_convert::double_str (dir) + ");\n";
-      mf += "end.\n";
-      mf += "}\n";
-
-      embed = ps + mf;
-    }
+  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;
@@ -188,11 +195,6 @@ Lookup::slur (int dy , Real &dx, Direction dir) const
   if (large)
     {
       s = big_slur (dy, dx, dir);
-      if (embedded_b)
-        {
-         s.tex_ = "\\embeddedtex{\n" + s.tex_ + "\n}\n";
-         s.tex_ += embed;
-        }
       return s;
     }
   Real orig_dx = dx;
@@ -239,12 +241,6 @@ Lookup::slur (int dy , Real &dx, Direction dir) const
   assert (idx < 256);
   f+=String ("{") + String (idx) + "}";
   s.tex_ = f;
-  if (embedded_b)
-    { 
-      s.tex_ = "\\embeddedtex{\n" + s.tex_ + "\n}\n";
-      s.tex_ += embed;
-    }
-
   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;
+}