]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix 97.
authorJoe Neeman <joeneeman@gmail.com>
Wed, 25 Apr 2007 01:36:48 +0000 (11:36 +1000)
committerJoe Neeman <joeneeman@gmail.com>
Wed, 25 Apr 2007 01:36:48 +0000 (11:36 +1000)
Add break-align-anchor property and use it for barlines.

lily/bar-line.cc
lily/break-alignment-interface.cc
lily/include/bar-line.hh
lily/include/break-align-interface.hh
scm/define-grob-properties.scm
scm/define-grobs.scm

index 78012a55a1a5d6630416b327daa2c5ecc71fa20e..7a1e92de376f3b576b91443e48b7ed1fb88f89b0 100644 (file)
@@ -237,6 +237,30 @@ Bar_line::dashed_bar_line (Grob *me, Real h, Real thick)
   return Stencil ();
 }
 
+MAKE_SCHEME_CALLBACK (Bar_line, calc_anchor, 1)
+SCM
+Bar_line::calc_anchor (SCM smob)
+{
+  Grob *me = unsmob_grob (smob);
+  Real kern = robust_scm2double (me->get_property ("kern"), 1);
+  Real staffline = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
+  string str = robust_scm2string (me->get_property ("glyph-name"), "");
+
+  /* we put the anchor in the center of the barline, unless we are
+     a repeat bar, in which case we put the anchor in the center of
+     the barline without the dots. */
+  Interval ext = me->extent (me, X_AXIS);
+  Real anchor = ext.center ();
+
+  Stencil dot = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
+  Real dot_width = dot.extent (X_AXIS).length () + kern * staffline;
+  if (str == "|:")
+    anchor -= dot_width / 2;
+  else if (str == ":|")
+    anchor += dot_width / 2;
+
+  return scm_from_double (anchor);
+}
 
 ADD_INTERFACE (Bar_line,
 
index 4a2ab62cb73868a083a66170198ad339a953bb84..7e866a551ffcc4bc7b6ad0892ea95bb7ca254f0b 100644 (file)
@@ -296,10 +296,36 @@ Break_alignable_interface::self_align_callback (SCM grob)
   else
     which_edge = RIGHT;
   
-  Grob *common = me->common_refpoint (elements[last_idx_found], X_AXIS);
+  Grob *alignment_parent = elements[last_idx_found];
+  Grob *common = me->common_refpoint (alignment_parent, X_AXIS);
+  Real anchor = robust_scm2double (alignment_parent->get_property ("break-align-anchor"), 0);
 
-  return scm_from_double (robust_relative_extent (elements[last_idx_found], common, X_AXIS)[which_edge]
-                         - me->relative_coordinate (common, X_AXIS));
+  return scm_from_double (alignment_parent->relative_coordinate (common, X_AXIS)
+                         - me->relative_coordinate (common, X_AXIS)
+                         + anchor);
+}
+
+MAKE_SCHEME_CALLBACK (Break_aligned_interface, calc_anchor, 1)
+SCM
+Break_aligned_interface::calc_anchor (SCM grob)
+{
+  Grob *me = unsmob_grob (grob);
+  Real avg = 0.0;
+  int count = 0;
+
+  /* average the anchors of those children that have it set */
+  extract_grob_set (me, "elements", elts);
+  for (vsize i = 0; i < elts.size (); i++)
+    {
+      SCM anchor = elts[i]->get_property ("break-align-anchor");
+      if (scm_is_number (anchor))
+       {
+         count++;
+         avg += scm_to_double (anchor);
+       }
+    }
+
+  return scm_from_double (count > 0 ? avg / count : 0);
 }
 
 ADD_INTERFACE (Break_alignable_interface,
@@ -336,6 +362,7 @@ ADD_INTERFACE (Break_aligned_interface,
               "See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147\n",
 
               /* properties */ 
+              "break-align-anchor "
               "break-align-symbol "
               "space-alist "
               );
index d1b2625ae680df35e9cefe1291b7d82908aed0a2..d85905d72e79d6cad32a30db89ae7c55eb2c33f6 100644 (file)
@@ -20,6 +20,7 @@ public:
   static Stencil simple_barline (Grob *, Real wid, Real height, bool rounded);
   DECLARE_SCHEME_CALLBACK (calc_bar_size, (SCM));
   DECLARE_SCHEME_CALLBACK (print, (SCM));
+  DECLARE_SCHEME_CALLBACK (calc_anchor, (SCM));
 };
 #endif // BAR_HH
 
index ba68a874af481cfbb592f90a6e4eed838693b0e6..211ad0da8b1dba98931d74abbd36627f5d2be7b3 100644 (file)
@@ -25,6 +25,7 @@ public:
 
 struct Break_aligned_interface
 {
+  DECLARE_SCHEME_CALLBACK (calc_anchor, (SCM element));
   DECLARE_GROB_INTERFACE();
 };
 
index d00d2875b5d3bd92a40c4792d1c4a97073488ffa..992b7f098dbe67476e37e9bbb659eb92db8dc68e 100644 (file)
@@ -93,6 +93,10 @@ visibility of the tuplet bracket.  Setting it to false prevents
 printing of the bracket.  Setting the property to @code{if-no-beam}
 makes it print only if there is no beam associated with this tuplet
 bracket.")
+     (break-align-anchor ,number? "Grobs aligned to this break-align
+grob will have their X-offsets shifted by this number. In barlines,
+for example, this is used to position grobs relative to the (visual)
+center of the barline.")
      (break-align-symbol ,symbol? "This key is used for aligning and
 spacing breakable items.")
      (break-align-orders ,vector? "Defines the order in which
index 9b75b09afe1cb8c3048fb512542c6a1ac025139d..8b32b4c6b956659a4ebf36f6de73b39253e73f38 100644 (file)
     (BarLine
      . (
        (break-align-symbol . staff-bar)
+       (break-align-anchor . ,ly:bar-line::calc-anchor)
        (glyph . "|")
        (gap . 0.4)
        (layer . 0)
      . (
        (axes . (0))
        (X-extent . ,ly:axis-group-interface::width)
+       (break-align-anchor . ,ly:break-aligned-interface::calc-anchor)
        (meta . ((class . Item)
                 (interfaces . (break-aligned-interface
                                axis-group-interface))))))