]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/grob.cc
Web-ja: update introduction
[lilypond.git] / lily / grob.cc
index 660a34d07243c7d5296cfcb73a3f9a9d51d9f7c1..924c80e500221b2d7bcfc2a8fab0102fea2a7c3c 100644 (file)
@@ -38,6 +38,7 @@
 #include "system.hh"
 #include "unpure-pure-container.hh"
 #include "warn.hh"
+#include "lily-imports.hh"
 
 
 Grob *
@@ -75,17 +76,17 @@ Grob::Grob (SCM basicprops)
         }
     }
 
-  if (get_property_data ("X-extent") == SCM_EOL)
+  if (scm_is_null (get_property_data ("X-extent")))
     set_property ("X-extent", Grob::stencil_width_proc);
-  if (get_property_data ("Y-extent") == SCM_EOL)
+  if (scm_is_null (get_property_data ("Y-extent")))
     set_property ("Y-extent",
                   Unpure_pure_container::make_smob (Grob::stencil_height_proc,
                                                     Grob::pure_stencil_height_proc));
-  if (get_property_data ("vertical-skylines") == SCM_EOL)
+  if (scm_is_null (get_property_data ("vertical-skylines")))
     set_property ("vertical-skylines",
                   Unpure_pure_container::make_smob (Grob::simple_vertical_skylines_from_extents_proc,
                                                     Grob::pure_simple_vertical_skylines_from_extents_proc));
-  if (get_property_data ("horizontal-skylines") == SCM_EOL)
+  if (scm_is_null (get_property_data ("horizontal-skylines")))
     set_property ("horizontal-skylines",
                   Unpure_pure_container::make_smob (Grob::simple_horizontal_skylines_from_extents_proc,
                                                     Grob::pure_simple_horizontal_skylines_from_extents_proc));
@@ -127,7 +128,7 @@ Grob::get_stencil () const
     return 0;
 
   SCM stil = get_property ("stencil");
-  return Stencil::unsmob (stil);
+  return unsmob<Stencil> (stil);
 }
 
 Stencil
@@ -136,20 +137,35 @@ Grob::get_print_stencil () const
   SCM stil = get_property ("stencil");
 
   Stencil retval;
-  if (Stencil *m = Stencil::unsmob (stil))
+  if (Stencil *m = unsmob<Stencil> (stil))
     {
       retval = *m;
       bool transparent = to_boolean (get_property ("transparent"));
 
+      /* Process whiteout before color and grob-cause to prevent colored */
+      /* whiteout background and larger file sizes with \pointAndClickOn. */
+      /* A grob has to be visible, otherwise the whiteout property has no effect. */
+      /* Calls the scheme procedure stencil-whiteout in scm/stencils.scm */
+      if (!transparent && (scm_is_number (get_property ("whiteout"))
+                           || to_boolean (get_property ("whiteout"))))
+        {
+          Real line_thickness = layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
+          retval = *unsmob<Stencil>
+            (Lily::stencil_whiteout (retval.smobbed_copy (),
+                                     get_property ("whiteout-style"),
+                                     get_property ("whiteout"),
+                                     scm_from_double (line_thickness)));
+        }
+
       if (transparent)
         retval = Stencil (m->extent_box (), SCM_EOL);
       else
         {
-          SCM expr = m->expr ();
-          expr = scm_list_3 (ly_symbol2scm ("grob-cause"),
-                             self_scm (), expr);
+          SCM expr = scm_list_3 (ly_symbol2scm ("grob-cause"),
+                                 self_scm (),
+                                 retval.expr ());
 
-          retval = Stencil (m->extent_box (), expr);
+          retval = Stencil (retval.extent_box (), expr);
         }
 
       SCM rot = get_property ("rotation");
@@ -173,22 +189,11 @@ Grob::get_print_stencil () const
           retval = Stencil (retval.extent_box (), expr);
         }
 
-      /* process whiteout */
-      /* a grob has to be visible, otherwise the whiteout property has no effect */
-      if (!transparent && to_boolean (get_property ("whiteout")))
-        {
-          /* Call the scheme procedure stencil-whiteout in scm/stencils.scm */
-          /* to add a round-filled-box stencil to the stencil list */
-          retval
-            = *Stencil::unsmob (scm_call_1 (ly_lily_module_constant ("stencil-whiteout"),
-                                           retval.smobbed_copy ()));
-        }
-
-      SCM id = get_property ("id");
-      if (scm_is_string (id))
+      SCM attributes = get_property ("output-attributes");
+      if (scm_is_pair (attributes))
         {
-          SCM expr = scm_list_3 (ly_symbol2scm ("id"),
-                                 id,
+          SCM expr = scm_list_3 (ly_symbol2scm ("output-attributes"),
+                                 attributes,
                                  retval.expr ());
 
           retval = Stencil (retval.extent_box (), expr);
@@ -328,18 +333,21 @@ Real
 Grob::relative_coordinate (Grob const *refp, Axis a) const
 {
   /* eaa - hmmm, should we do a programming_error() here? */
-  if ((this == NULL) || (refp == this))
+  if (refp == this)
     return 0.0;
 
   /* We catch PARENT_L_ == nil case with this, but we crash if we did
      not ask for the absolute coordinate (ie. REFP == nil.)  */
-  Real off = get_offset (a);
-  if (refp == dim_cache_[a].parent_)
-    return off;
 
-  off += dim_cache_[a].parent_->relative_coordinate (refp, a);
+  return get_offset (a) + parent_relative (refp, a);
+}
 
-  return off;
+Real
+Grob::parent_relative (Grob const *refp, Axis a) const
+{
+  if (Grob *p = get_parent (a))
+    return p->relative_coordinate (refp, a);
+  return 0.0;
 }
 
 Real
@@ -380,7 +388,7 @@ Grob::pure_relative_y_coordinate (Grob const *refp, int start, int end)
   if (Grob *p = get_parent (Y_AXIS))
     {
       Real trans = 0;
-      if (Align_interface::has_interface (p) && !dim_cache_[Y_AXIS].offset_)
+      if (has_interface<Align_interface> (p) && !dim_cache_[Y_AXIS].offset_)
         trans = Align_interface::get_pure_child_y_translation (p, this, start, end);
 
       return off + trans + p->pure_relative_y_coordinate (refp, start, end);
@@ -478,14 +486,14 @@ Grob::extent (Grob *refp, Axis a) const
     if(!isinf (offset))
       real_ext.translate(offset);
     else
-      this->warning(_f ("ignored infinite %s-offset",
+      warning(_f ("ignored infinite %s-offset",
                         a == X_AXIS ? "X" : "Y"));
 
   return real_ext;
 }
 
 Interval
-Grob::pure_height (Grob *refp, int start, int end)
+Grob::pure_y_extent (Grob *refp, int start, int end)
 {
   SCM iv_scm = get_pure_property ("Y-extent", start, end);
   Interval iv = robust_scm2interval (iv_scm, Interval ());
@@ -507,7 +515,7 @@ Grob::pure_height (Grob *refp, int start, int end)
 Interval
 Grob::maybe_pure_extent (Grob *refp, Axis a, bool pure, int start, int end)
 {
-  return (pure && a == Y_AXIS) ? pure_height (refp, start, end) : extent (refp, a);
+  return (pure && a == Y_AXIS) ? pure_y_extent (refp, start, end) : extent (refp, a);
 }
 
 Interval_t<int>
@@ -627,7 +635,7 @@ get_maybe_root_vertical_alignment (Grob *g, Grob *maybe)
 {
   if (!g)
     return maybe;
-  if (Align_interface::has_interface (g))
+  if (has_interface<Align_interface> (g))
     return get_maybe_root_vertical_alignment (g->get_parent (Y_AXIS), g);
   return get_maybe_root_vertical_alignment (g->get_parent (Y_AXIS), maybe);
 
@@ -646,8 +654,8 @@ Grob::get_vertical_axis_group (Grob *g)
     return 0;
   if (!g->get_parent (Y_AXIS))
     return 0;
-  if (Axis_group_interface::has_interface (g)
-      && Align_interface::has_interface (g->get_parent (Y_AXIS)))
+  if (has_interface<Axis_group_interface> (g)
+      && has_interface<Align_interface> (g->get_parent (Y_AXIS)))
     return g;
   return get_vertical_axis_group (g->get_parent (Y_AXIS));
 
@@ -720,13 +728,13 @@ void
 Grob::programming_error (const string &s) const
 {
   SCM cause = self_scm ();
-  while (Grob *g = Grob::unsmob (cause))
+  while (Grob *g = unsmob<Grob> (cause))
     cause = g->get_property ("cause");
 
   /* ES TODO: cause can't be Music*/
-  if (Music *m = Music::unsmob (cause))
+  if (Music *m = unsmob<Music> (cause))
     m->origin ()->programming_error (s);
-  else if (Stream_event *ev = Stream_event::unsmob (cause))
+  else if (Stream_event *ev = unsmob<Stream_event> (cause))
     ev->origin ()->programming_error (s);
   else
     ::programming_error (s);
@@ -736,13 +744,13 @@ void
 Grob::warning (const string &s) const
 {
   SCM cause = self_scm ();
-  while (Grob *g = Grob::unsmob (cause))
+  while (Grob *g = unsmob<Grob> (cause))
     cause = g->get_property ("cause");
 
   /* ES TODO: cause can't be Music*/
-  if (Music *m = Music::unsmob (cause))
+  if (Music *m = unsmob<Music> (cause))
     m->origin ()->warning (s);
-  else if (Stream_event *ev = Stream_event::unsmob (cause))
+  else if (Stream_event *ev = unsmob<Stream_event> (cause))
     ev->origin ()->warning (s);
   else
     ::warning (s);
@@ -754,7 +762,7 @@ Grob::name () const
   SCM meta = get_property ("meta");
   SCM nm = scm_assq (ly_symbol2scm ("name"), meta);
   nm = (scm_is_pair (nm)) ? scm_cdr (nm) : SCM_EOL;
-  return scm_is_symbol (nm) ? ly_symbol2string (nm) : this->class_name ();
+  return scm_is_symbol (nm) ? ly_symbol2string (nm) : class_name ();
 }
 
 ADD_INTERFACE (Grob,
@@ -808,16 +816,18 @@ ADD_INTERFACE (Grob,
                "cause "
                "color "
                "cross-staff "
-               "id "
                "extra-offset "
                "footnote-music "
                "forced-spacing "
                "horizontal-skylines "
+               "id "
                "interfaces "
                "layer "
                "meta "
                "minimum-X-extent "
                "minimum-Y-extent "
+               "output-attributes "
+               "parenthesis-friends "
                "pure-Y-offset-in-progress "
                "rotation "
                "skyline-horizontal-padding "
@@ -827,6 +837,7 @@ ADD_INTERFACE (Grob,
                "transparent "
                "vertical-skylines "
                "whiteout "
+               "whiteout-style "
               );
 
 /****************************************************************
@@ -847,7 +858,7 @@ MAKE_SCHEME_CALLBACK (Grob, stencil_height, 1);
 SCM
 Grob::stencil_height (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
   return grob_stencil_extent (me, Y_AXIS);
 }
 
@@ -855,8 +866,8 @@ MAKE_SCHEME_CALLBACK (Grob, pure_stencil_height, 3);
 SCM
 Grob::pure_stencil_height (SCM smob, SCM /* beg */, SCM /* end */)
 {
-  Grob *me = Grob::unsmob (smob);
-  if (Stencil::is_smob (me->get_property_data ("stencil")))
+  Grob *me = unsmob<Grob> (smob);
+  if (unsmob<Stencil> (me->get_property_data ("stencil")))
     return grob_stencil_extent (me, Y_AXIS);
 
   return ly_interval2scm (Interval ());
@@ -867,7 +878,7 @@ MAKE_SCHEME_CALLBACK (Grob, y_parent_positioning, 1);
 SCM
 Grob::y_parent_positioning (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
   Grob *par = me->get_parent (Y_AXIS);
   if (par)
     (void) par->get_property ("positioning-done");
@@ -879,7 +890,7 @@ MAKE_SCHEME_CALLBACK (Grob, x_parent_positioning, 1);
 SCM
 Grob::x_parent_positioning (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
 
   Grob *par = me->get_parent (X_AXIS);
   if (par)
@@ -892,7 +903,7 @@ MAKE_SCHEME_CALLBACK (Grob, stencil_width, 1);
 SCM
 Grob::stencil_width (SCM smob)
 {
-  Grob *me = Grob::unsmob (smob);
+  Grob *me = unsmob<Grob> (smob);
   return grob_stencil_extent (me, X_AXIS);
 }
 
@@ -900,7 +911,7 @@ Grob *
 common_refpoint_of_list (SCM elist, Grob *common, Axis a)
 {
   for (; scm_is_pair (elist); elist = scm_cdr (elist))
-    if (Grob *s = Grob::unsmob (scm_car (elist)))
+    if (Grob *s = unsmob<Grob> (scm_car (elist)))
       {
         if (common)
           common = common->common_refpoint (s, a);
@@ -952,11 +963,11 @@ robust_relative_extent (Grob *me, Grob *refpoint, Axis a)
 bool
 Grob::check_cross_staff (Grob *commony)
 {
-  if (Align_interface::has_interface (commony))
+  if (has_interface<Align_interface> (commony))
     return true;
 
   for (Grob *g = this; g && g != commony; g = g->get_parent (Y_AXIS))
-    if (Align_interface::has_interface (g))
+    if (has_interface<Align_interface> (g))
       return true;
 
   return false;