]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
Run grand replace for 2015.
[lilypond.git] / lily / lookup.cc
index 7b63b83111e4ccf9000710f087d526453c2d1176..9bef343fedd5625714c1e6846ef1b7ee64a41c1d 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   Jan Nieuwenhuizen <janneke@gnu.org>
 
@@ -27,6 +27,7 @@ using namespace std;
 
 #include "line-interface.hh"
 #include "warn.hh"
+#include "international.hh"
 #include "dimensions.hh"
 #include "bezier.hh"
 #include "file-path.hh"
@@ -169,10 +170,18 @@ Lookup::filled_box (Box b)
 Stencil
 Lookup::round_filled_box (Box b, Real blotdiameter)
 {
-  if (b.x ().length () < blotdiameter)
-    blotdiameter = b.x ().length ();
-  if (b.y ().length () < blotdiameter)
-    blotdiameter = b.y ().length ();
+  Real width = b.x ().delta ();
+  blotdiameter = min (blotdiameter, width);
+  Real height = b.y ().delta ();
+  blotdiameter = min (blotdiameter, height);
+
+  if (blotdiameter < 0.0)
+    {
+      if (!isinf (blotdiameter))
+        warning (_f ("Not drawing a box with negative dimension, %.2f by %.2f.",
+                     width, height));
+      return Stencil (b, SCM_EOL);
+    }
 
   SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
                         scm_from_double (-b[X_AXIS][LEFT]),
@@ -333,11 +342,10 @@ Stencil
 Lookup::frame (Box b, Real thick, Real blot)
 {
   Stencil m;
-  Direction d = LEFT;
   for (Axis a = X_AXIS; a < NO_AXES; a = Axis (a + 1))
     {
       Axis o = Axis ((a + 1) % NO_AXES);
-      do
+      for (LEFT_and_RIGHT (d))
         {
           Box edges;
           edges[a] = b[a][d] + 0.5 * thick * Interval (-1, 1);
@@ -346,7 +354,6 @@ Lookup::frame (Box b, Real thick, Real blot)
 
           m.add_stencil (round_filled_box (edges, blot));
         }
-      while (flip (&d) != LEFT);
     }
   return m;
 }
@@ -449,25 +456,28 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick,
 Stencil
 Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve, Real thickness)
 {
-  SCM commands  = scm_list_n (ly_symbol2scm ("moveto"),
-                              scm_from_double (top_curve.control_[0][X_AXIS]),
-                              scm_from_double (top_curve.control_[0][Y_AXIS]),
-                              ly_symbol2scm ("curveto"),
-                              scm_from_double (top_curve.control_[1][X_AXIS]),
-                              scm_from_double (top_curve.control_[1][Y_AXIS]),
-                              scm_from_double (top_curve.control_[2][X_AXIS]),
-                              scm_from_double (top_curve.control_[2][Y_AXIS]),
-                              scm_from_double (top_curve.control_[3][X_AXIS]),
-                              scm_from_double (top_curve.control_[3][Y_AXIS]),
-                              ly_symbol2scm ("curveto"),
-                              scm_from_double (bottom_curve.control_[2][X_AXIS]),
-                              scm_from_double (bottom_curve.control_[2][Y_AXIS]),
-                              scm_from_double (bottom_curve.control_[1][X_AXIS]),
-                              scm_from_double (bottom_curve.control_[1][Y_AXIS]),
-                              scm_from_double (bottom_curve.control_[0][X_AXIS]),
-                              scm_from_double (bottom_curve.control_[0][Y_AXIS]),
-                              ly_symbol2scm ("closepath"),
-                              SCM_UNDEFINED);
+  SCM commands = scm_list_n (ly_symbol2scm ("moveto"),
+                             scm_from_double (top_curve.control_[0][X_AXIS]),
+                             scm_from_double (top_curve.control_[0][Y_AXIS]),
+                             ly_symbol2scm ("curveto"),
+                             scm_from_double (top_curve.control_[1][X_AXIS]),
+                             scm_from_double (top_curve.control_[1][Y_AXIS]),
+                             scm_from_double (top_curve.control_[2][X_AXIS]),
+                             scm_from_double (top_curve.control_[2][Y_AXIS]),
+                             scm_from_double (top_curve.control_[3][X_AXIS]),
+                             scm_from_double (top_curve.control_[3][Y_AXIS]),
+                             ly_symbol2scm ("lineto"),
+                             scm_from_double (bottom_curve.control_[3][X_AXIS]),
+                             scm_from_double (bottom_curve.control_[3][Y_AXIS]),
+                             ly_symbol2scm ("curveto"),
+                             scm_from_double (bottom_curve.control_[2][X_AXIS]),
+                             scm_from_double (bottom_curve.control_[2][Y_AXIS]),
+                             scm_from_double (bottom_curve.control_[1][X_AXIS]),
+                             scm_from_double (bottom_curve.control_[1][Y_AXIS]),
+                             scm_from_double (bottom_curve.control_[0][X_AXIS]),
+                             scm_from_double (bottom_curve.control_[0][Y_AXIS]),
+                             ly_symbol2scm ("closepath"),
+                             SCM_UNDEFINED);
 
   SCM horizontal_bend = scm_list_n (ly_symbol2scm ("path"),
                                     scm_from_double (thickness),
@@ -490,21 +500,32 @@ Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve, Real thickness)
 Stencil
 Lookup::repeat_slash (Real w, Real s, Real t)
 {
-#if 0 /*  TODO */
-  vector<Offset> points;
-  Real blotdiameter = 0.0;
-
-  Offset p1 (0, 0);
-  Offset p2 (w, w * s);
-
-  return Lookup::round_filled_polygon (points, blotdiameter);
-#endif
 
-  SCM wid = scm_from_double (w);
-  SCM sl = scm_from_double (s);
-  SCM thick = scm_from_double (t);
-  SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
-                               wid, sl, thick, SCM_UNDEFINED);
+  Real x_width = sqrt ((t * t) + ((t / s) * (t / s)));
+  Real height = w * s;
+
+  SCM controls = scm_list_n (ly_symbol2scm ("moveto"),
+                             scm_from_double (0),
+                             scm_from_double (0),
+                             ly_symbol2scm ("rlineto"),
+                             scm_from_double (x_width),
+                             scm_from_double (0),
+                             ly_symbol2scm ("rlineto"),
+                             scm_from_double (w),
+                             scm_from_double (height),
+                             ly_symbol2scm ("rlineto"),
+                             scm_from_double (-x_width),
+                             scm_from_double (0),
+                             ly_symbol2scm ("closepath"),
+                             SCM_UNDEFINED);
+
+  SCM slashnodot = scm_list_n (ly_symbol2scm ("path"),
+                               scm_from_double (0),
+                               ly_quote_scm (controls),
+                               ly_quote_scm (ly_symbol2scm ("round")),
+                               ly_quote_scm (ly_symbol2scm ("round")),
+                               SCM_BOOL_T,
+                               SCM_UNDEFINED);
 
   Box b (Interval (0, w + sqrt (sqr (t / s) + sqr (t))),
          Interval (0, w * s));