]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
Fix repeatCommands context property docstring
[lilypond.git] / lily / lookup.cc
index 4ed1226b4ce3938fc95fd38685c933c6e48ebab2..dfda5f73e4eab63d06a4bd454a953549a3690662 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   Jan Nieuwenhuizen <janneke@gnu.org>
 */
@@ -106,10 +106,26 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction)
                        ly_quote_scm (l),
                        SCM_UNDEFINED));
 
-  Box box (Interval (0, 0), Interval (0, 0));
+  Box box (b.extent (X_AXIS), b.extent (Y_AXIS));
   return Stencil (box, at);
 }
 
+Stencil
+Lookup::rotated_box (Real slope, Real width, Real thick, Real blot)
+{
+  vector<Offset> pts;
+  Offset rot (1, slope);
+
+  thick -= 2*blot;
+  width -= 2*blot;
+  rot /= sqrt (1 + slope*slope);
+  pts.push_back (Offset (0, -thick / 2) * rot);
+  pts.push_back (Offset (width, -thick / 2) * rot);
+  pts.push_back (Offset (width, thick / 2) * rot);
+  pts.push_back (Offset (0, thick / 2) * rot);
+  return Lookup::round_filled_polygon (pts, blot);
+}
+
 Stencil
 Lookup::horizontal_line (Interval w, Real th)
 {
@@ -131,7 +147,7 @@ Lookup::horizontal_line (Interval w, Real th)
 Stencil
 Lookup::blank (Box b)
 {
-  return Stencil (b, scm_makfrom0str (""));
+  return Stencil (b, scm_from_locale_string (""));
 }
 
 Stencil
@@ -227,7 +243,7 @@ Lookup::round_filled_box (Box b, Real blotdiameter)
  * shrinked polygon). --jr
  */
 Stencil
-Lookup::round_filled_polygon (Array<Offset> const &points,
+Lookup::round_filled_polygon (vector<Offset> const &points,
                              Real blotdiameter)
 {
   /* TODO: Maybe print a warning if one of the above limitations
@@ -238,10 +254,10 @@ Lookup::round_filled_polygon (Array<Offset> const &points,
 
 #ifndef NDEBUG
   /* remove consecutive duplicate points */
-  for (int i = 0; i < points.size (); i++)
+  for (vsize i = 0; i < points.size (); i++)
     {
-      int next_i = (i + 1) % points.size ();
-      Real d = (points[i] - points[next_i]).length ();
+      int next = (i + 1) % points.size ();
+      Real d = (points[i] - points[next]).length ();
       if (d < epsilon)
        programming_error ("Polygon should not have duplicate points");
     }
@@ -256,10 +272,10 @@ Lookup::round_filled_polygon (Array<Offset> const &points,
     return Line_interface::make_line (blotdiameter, points[0], points[1]);
 
   /* shrink polygon in size by 0.5 * blotdiameter */
-  Array<Offset> shrunk_points;
-  shrunk_points.set_size (points.size ());
+  vector<Offset> shrunk_points;
+  shrunk_points.resize (points.size ());
   bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
-  for (int i = 0; i < points.size (); i++)
+  for (vsize i = 0; i < points.size (); i++)
     {
       int i0 = i;
       int i1 = (i + 1) % points.size ();
@@ -304,7 +320,7 @@ Lookup::round_filled_polygon (Array<Offset> const &points,
   /* build scm expression and bounding box */
   SCM shrunk_points_scm = SCM_EOL;
   Box box;
-  for (int i = 0; i < shrunk_points.size (); i++)
+  for (vsize i = 0; i < shrunk_points.size (); i++)
     {
       SCM x = scm_from_double (shrunk_points[i][X_AXIS]);
       SCM y = scm_from_double (shrunk_points[i][Y_AXIS]);
@@ -388,6 +404,7 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick)
   b[X_AXIS].unite (back.extent (X_AXIS));
   b[Y_AXIS].unite (back.extent (Y_AXIS));
 
+  b.widen (0.5 * linethick, 0.5 * linethick);
   return Stencil (b, at);
 }
 
@@ -451,8 +468,8 @@ Stencil
 Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
 {
   Stencil m;
-  std::string sym = ly_scm2string (scm_car (s));
-  std::string reg = ly_scm2string (scm_car (scm_cdr (s)));
+  string sym = ly_scm2string (scm_car (s));
+  string reg = ly_scm2string (scm_car (scm_cdr (s)));
 
   if (sym == "Discant")
     {
@@ -649,7 +666,7 @@ Stencil
 Lookup::repeat_slash (Real w, Real s, Real t)
 {
 #if 0 /*  TODO */
-  Array<Offset> points;
+  vector<Offset> points;
   Real blotdiameter = 0.0;
 
   Offset p1 (0, 0);
@@ -698,17 +715,29 @@ Lookup::triangle (Interval iv, Real thick, Real protude)
   b[X_AXIS] = Interval (0, iv.length ());
   b[Y_AXIS] = Interval (min (0., protude), max (0.0, protude));
 
-  Offset z1 (iv[LEFT], 0);
-  Offset z2 (iv[RIGHT], 0);
-  Offset z3 ((z1 + z2)[X_AXIS] / 2, protude);
+  vector<Offset> points;
+  points.push_back (Offset (iv[LEFT], 0));
+  points.push_back (Offset (iv[RIGHT], 0));
+  points.push_back (Offset (iv.center (), protude));
 
-  /*
-    TODO: move Triangle to Line_interface ?
-  */
-  Stencil tri = Line_interface::make_line (thick, z1, z2);
-  tri.add_stencil (Line_interface::make_line (thick, z2, z3));
-  tri.add_stencil (Line_interface::make_line (thick, z3, z1));
+  return points_to_line_stencil (thick, points);
 
-  return tri;
 }
 
+
+
+Stencil
+Lookup::points_to_line_stencil (Real thick, vector<Offset> const &points)
+{
+  Stencil ret;
+  for (vsize i = 1; i < points.size (); i++)
+    {
+      if (points[i-1].is_sane () && points[i].is_sane ())
+       {
+         Stencil line
+           = Line_interface::make_line (thick, points[i-1], points[i]);
+         ret.add_stencil (line);
+       }
+    }
+  return ret;
+}