From 0a029b8dccc5d0253a849f915584e12a58f9335e Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Wed, 25 Apr 2007 11:36:48 +1000 Subject: [PATCH] Fix 97. Add break-align-anchor property and use it for barlines. --- lily/bar-line.cc | 24 +++++++++++++++++++ lily/break-alignment-interface.cc | 33 ++++++++++++++++++++++++--- lily/include/bar-line.hh | 1 + lily/include/break-align-interface.hh | 1 + scm/define-grob-properties.scm | 4 ++++ scm/define-grobs.scm | 2 ++ 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/lily/bar-line.cc b/lily/bar-line.cc index 78012a55a1..7a1e92de37 100644 --- a/lily/bar-line.cc +++ b/lily/bar-line.cc @@ -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, diff --git a/lily/break-alignment-interface.cc b/lily/break-alignment-interface.cc index 4a2ab62cb7..7e866a551f 100644 --- a/lily/break-alignment-interface.cc +++ b/lily/break-alignment-interface.cc @@ -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 " ); diff --git a/lily/include/bar-line.hh b/lily/include/bar-line.hh index d1b2625ae6..d85905d72e 100644 --- a/lily/include/bar-line.hh +++ b/lily/include/bar-line.hh @@ -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 diff --git a/lily/include/break-align-interface.hh b/lily/include/break-align-interface.hh index ba68a874af..211ad0da8b 100644 --- a/lily/include/break-align-interface.hh +++ b/lily/include/break-align-interface.hh @@ -25,6 +25,7 @@ public: struct Break_aligned_interface { + DECLARE_SCHEME_CALLBACK (calc_anchor, (SCM element)); DECLARE_GROB_INTERFACE(); }; diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index d00d2875b5..992b7f098d 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -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 diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 9b75b09afe..8b32b4c6b9 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -171,6 +171,7 @@ (BarLine . ( (break-align-symbol . staff-bar) + (break-align-anchor . ,ly:bar-line::calc-anchor) (glyph . "|") (gap . 0.4) (layer . 0) @@ -410,6 +411,7 @@ . ( (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)))))) -- 2.39.2