]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/grob.cc
Fix issue 542: Harden Grob::relative_coordinate()
[lilypond.git] / lily / grob.cc
index 01b2c7f3e313b33fdeb12e35de11ee33082752fe..7f78b5ff60112937bc5745106da7e2b96535fcab 100644 (file)
@@ -128,7 +128,7 @@ Grob::get_print_stencil () const
          Real x = scm_to_double (scm_cadr (rot));
          Real y = scm_to_double (scm_caddr (rot));
 
-         retval.rotate (angle, Offset (x, y));
+         retval.rotate_degrees (angle, Offset (x, y));
        }
 
       /* color support... see interpret_stencil_expression () for more... */
@@ -265,7 +265,8 @@ Grob::translate_axis (Real y, Axis a)
 Real
 Grob::relative_coordinate (Grob const *refp, Axis a) const
 {
-  if (refp == this)
+  /* eaa - hmmm, should we do a programming_error() here? */
+  if ((this == NULL) || (refp == this))
     return 0.0;
 
   /* We catch PARENT_L_ == nil case with this, but we crash if we did
@@ -288,16 +289,23 @@ Grob::pure_relative_y_coordinate (Grob const *refp, int start, int end)
   Real off = 0;
 
   if (dim_cache_[Y_AXIS].offset_)
-    off = *dim_cache_[Y_AXIS].offset_;
+    {
+      if (to_boolean (get_property ("pure-Y-offset-in-progress")))
+       programming_error ("cyclic chain in pure-Y-offset callbacks");
+
+      off = *dim_cache_[Y_AXIS].offset_;
+    }
   else
     {
       SCM proc = get_property_data ("Y-offset");
 
       dim_cache_[Y_AXIS].offset_ = new Real (0.0);
+      set_property ("pure-Y-offset-in-progress", SCM_BOOL_T);
       off = robust_scm2double (call_pure_function (proc,
                                                   scm_list_1 (self_scm ()),
                                                   start, end),
                               0.0);
+      del_property ("pure-Y-offset-in-progress");
       delete dim_cache_[Y_AXIS].offset_;
       dim_cache_[Y_AXIS].offset_ = 0;
     }
@@ -394,7 +402,7 @@ Grob::extent (Grob *refp, Axis a) const
        (a == X_AXIS)
        ? ly_symbol2scm ("X-extent")
        : ly_symbol2scm ("Y-extent");
-
+       
       SCM ext = internal_get_property (ext_sym);
       if (is_number_pair (ext))
        real_ext.unite (ly_scm2interval (ext));
@@ -433,7 +441,8 @@ Grob::pure_height (Grob *refp, int start, int end)
   if (!iv.is_empty () && is_number_pair (min_ext))
     iv.unite (ly_scm2interval (min_ext));
 
-  iv.translate (offset);
+  if (!iv.is_empty ())
+    iv.translate (offset);
   return iv;
 }
 
@@ -446,7 +455,7 @@ Grob::maybe_pure_extent (Grob *refp, Axis a, bool pure, int start, int end)
 }
 
 Interval_t<int>
-Grob::spanned_rank_iv ()
+Grob::spanned_rank_interval () const
 {
   return Interval_t<int> (-1, 0);
 }
@@ -613,6 +622,7 @@ ADD_INTERFACE (Grob,
               "before-line-breaking "
               "cause "
               "color "
+              "cross-staff "
               "extra-X-extent "
               "extra-Y-extent "
               "extra-offset "
@@ -624,6 +634,7 @@ ADD_INTERFACE (Grob,
               "outside-staff-horizontal-padding "
               "outside-staff-padding "
               "outside-staff-priority "
+              "pure-Y-offset-in-progress "
               "rotation "
               "springs-and-rods "
               "staff-symbol "
@@ -654,7 +665,7 @@ Grob::stencil_height (SCM smob)
   return grob_stencil_extent (me, Y_AXIS);
 }
 
-MAKE_SCHEME_CALLBACK(Grob, y_parent_positioning, 1);
+MAKE_SCHEME_CALLBACK (Grob, y_parent_positioning, 1);
 SCM
 Grob::y_parent_positioning (SCM smob)
 {
@@ -667,7 +678,7 @@ Grob::y_parent_positioning (SCM smob)
 }
 
 
-MAKE_SCHEME_CALLBACK(Grob, x_parent_positioning, 1);
+MAKE_SCHEME_CALLBACK (Grob, x_parent_positioning, 1);
 SCM
 Grob::x_parent_positioning (SCM smob)
 {