]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/grob-scheme.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / grob-scheme.cc
index ee88f2ac48e52571b7c62b4a6d306c0a9c12ac88..c8bdc2c828d9d36a864e91c32504ea60fb5f0c6e 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "grob.hh"
 
-#include "warn.hh"
+#include "warn.hh"             // error()
 #include "item.hh"
 #include "output-def.hh"
 #include "system.hh"
@@ -47,17 +47,23 @@ LY_DEFINE (ly_grob_set_property_x, "ly:grob-set-property!",
 }
 
 LY_DEFINE (ly_grob_property, "ly:grob-property",
-          2, 0, 0, (SCM grob, SCM sym),
+          2, 1, 0, (SCM grob, SCM sym, SCM deflt),
           "Return the value of a value in grob @var{g} of property @var{sym}. "
-          "It will return @code{'()} (end-of-list) "
+          "It will return @code{'()} or @var{deflt} (if specified) "
           "if  @var{sym} is undefined in @var{g}."
           "\n\n")
 {
   Grob *sc = unsmob_grob (grob);
   SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
   SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
+  if (deflt == SCM_UNDEFINED)
+    deflt = SCM_EOL;
 
-  return sc->internal_get_property (sym);
+  SCM retval = sc->internal_get_property (sym);
+  if (retval == SCM_EOL)
+    retval = deflt;
+  
+  return retval;
 }
 
 
@@ -134,13 +140,48 @@ LY_DEFINE (ly_get_extent, "ly:grob-extent",
 {
   Grob *sc = unsmob_grob (grob);
   Grob *ref = unsmob_grob (refp);
+  
   SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
   SCM_ASSERT_TYPE (ref, refp, SCM_ARG2, __FUNCTION__, "grob");
   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
 
-  return ly_interval2scm (sc->extent (ref, Axis (scm_to_int (axis))));
+  Axis a = Axis (scm_to_int (axis));
+
+    
+  if (ref->common_refpoint (sc, a) != ref)
+    {
+      // ugh. should use other error message
+      SCM_ASSERT_TYPE (false, refp, SCM_ARG2, __FUNCTION__, "common refpoint");
+    }
+  return ly_interval2scm (sc->extent (ref, a));
+}
+
+
+LY_DEFINE (ly_grob_relative_coordinate, "ly:grob-relative-coordinate",
+          3, 0, 0, (SCM grob, SCM refp, SCM axis),
+          "Get the coordinate in @var{axis} direction of @var{grob} relative to "
+          "the grob @var{refp}")
+{
+  Grob *sc = unsmob_grob (grob);
+  Grob *ref = unsmob_grob (refp);
+  
+  SCM_ASSERT_TYPE (sc, grob, SCM_ARG1, __FUNCTION__, "grob");
+  SCM_ASSERT_TYPE (ref, refp, SCM_ARG2, __FUNCTION__, "grob");
+  SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
+
+  Axis a = Axis (scm_to_int (axis));
+
+    
+  if (ref->common_refpoint (sc, a) != ref)
+    {
+      // ugh. should use other error message
+      SCM_ASSERT_TYPE (false, refp, SCM_ARG2, __FUNCTION__, "common refpoint");
+    }
+
+  return scm_from_double (sc->relative_coordinate (ref,a));
 }
 
+
 LY_DEFINE (ly_grob_parent, "ly:grob-parent",
           2, 0, 0, (SCM grob, SCM axis),
           "Get the parent of @var{grob}.  @var{axis} is 0 for the X-axis, "
@@ -208,7 +249,7 @@ LY_DEFINE (ly_spanner_broken_into, "ly:spanner-broken-into",
   SCM_ASSERT_TYPE (me, spanner, SCM_ARG1, __FUNCTION__, "spanner");
 
   SCM s = SCM_EOL;
-  for (int i = me->broken_intos_.size (); i--;)
+  for (vsize i = me->broken_intos_.size (); i--;)
     s = scm_cons (me->broken_intos_[i]->self_scm (), s);
   return s;
 }
@@ -267,3 +308,38 @@ LY_DEFINE (ly_grob_default_font, "ly:grob-default-font",
 
   return Font_interface::get_default_font (gr)->self_scm ();
 }
+
+LY_DEFINE (ly_grob_common_refpoint, "ly:grob-common-refpoint",
+          3, 0, 0,  (SCM grob, SCM other, SCM axis),
+          "Find the common refpoint of @var{grob} and @var{other} for @var{axis}."
+          )
+{
+  
+  Grob *gr = unsmob_grob (grob);
+  SCM_ASSERT_TYPE (gr, grob, SCM_ARG1, __FUNCTION__, "grob");
+
+  Grob *o = unsmob_grob (other);
+  SCM_ASSERT_TYPE (o, other, SCM_ARG2, __FUNCTION__, "grob");
+
+  SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
+
+  Grob *refp = gr->common_refpoint (o,  Axis (scm_to_int (axis)));
+  return refp ? refp->self_scm () : SCM_BOOL_F;
+}
+
+LY_DEFINE (ly_grob_common_refpoint_of_array, "ly:grob-common-refpoint-of-array",
+          3, 0, 0,  (SCM grob, SCM others, SCM axis),
+          "Find the common refpoint of @var{grob} and @var{others} "
+          "(a grob-array) for @var{axis}."
+          )
+{
+  Grob *gr = unsmob_grob (grob);
+  SCM_ASSERT_TYPE (gr, grob, SCM_ARG1, __FUNCTION__, "grob");
+
+  Grob_array *ga = unsmob_grob_array (others);
+  SCM_ASSERT_TYPE (ga, others, SCM_ARG2, __FUNCTION__, "grob array");
+  SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
+
+  Grob *refp = common_refpoint_of_array (ga->array (), gr, Axis (scm_to_int (axis)));
+  return refp ? refp->self_scm () : SCM_BOOL_F;
+}