From 09412c25cce3fdffce7cefe491cb3849ece0ae3e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Janek=20Warcho=C5=82?= Date: Sat, 30 Mar 2013 00:11:28 +0100 Subject: [PATCH] Clean up DynamicText horizontal alignment. Until now, DynamicText alignment was messy, as there were 3 different callbacks involved - some of them interacting in a confusing way: - in define-grobs.scm, X-offset property was initialized to ly:self-alignment-interface::x-aligned-on-self, - Dynamic_engraver called set_center_parent on every DynamicText attached to a note, so that half a NoteHead width was always added to its X-offset (producing confusing results for example when user requested dynamics to be left-aligned), - DynamicTexts living in a Dynamics context used a completely different offset callback, which aligned them on NoteColumns. Since aligned_on_parent is now able to correctly align grobs with PaperColumn parents (issue 3254), we can use it for all DynamicTexts and have a single interface for the job. Expected changes in output: DynamicTexts in Dynamics context aligned to suspended noteheads may be placed up to 1/4 NoteHead width further to the right. This shouldn't be a problem. --- lily/dynamic-engraver.cc | 5 +---- lily/include/self-alignment-interface.hh | 1 - lily/self-alignment-interface.cc | 21 --------------------- ly/engraver-init.ly | 7 ------- scm/define-grobs.scm | 2 +- 5 files changed, 2 insertions(+), 34 deletions(-) diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index d1b8cf00b5..a91d742ee8 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -268,10 +268,7 @@ Dynamic_engraver::acknowledge_note_column (Grob_info info) ? heads[0] : unsmob_grob (info.grob ()->get_object ("rest"))); if (x_parent) - { - script_->set_parent (x_parent, X_AXIS); - Self_alignment_interface::set_center_parent (script_, X_AXIS); - } + script_->set_parent (x_parent, X_AXIS); } if (current_spanner_ && !current_spanner_->get_bound (LEFT)) diff --git a/lily/include/self-alignment-interface.hh b/lily/include/self-alignment-interface.hh index 823556a4c2..dfec0670a4 100644 --- a/lily/include/self-alignment-interface.hh +++ b/lily/include/self-alignment-interface.hh @@ -38,7 +38,6 @@ struct Self_alignment_interface DECLARE_SCHEME_CALLBACK (pure_y_aligned_on_self, (SCM element, SCM start, SCM end)); - DECLARE_SCHEME_CALLBACK (centered_on_note_columns, (SCM element)); DECLARE_SCHEME_CALLBACK (centered_on_x_parent, (SCM element)); DECLARE_SCHEME_CALLBACK (centered_on_y_parent, (SCM element)); DECLARE_SCHEME_CALLBACK (aligned_on_x_parent, (SCM element)); diff --git a/lily/self-alignment-interface.cc b/lily/self-alignment-interface.cc index eb51dc7f1b..a23d7b99cc 100644 --- a/lily/self-alignment-interface.cc +++ b/lily/self-alignment-interface.cc @@ -79,27 +79,6 @@ Self_alignment_interface::centered_on_x_parent (SCM smob) return centered_on_object (unsmob_grob (smob)->get_parent (X_AXIS), X_AXIS); } -MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_note_columns, 1); -SCM -Self_alignment_interface::centered_on_note_columns (SCM smob) -{ - Item *it = unsmob_item (smob)->get_column (); - if (!it) - return scm_from_double (0.0); - - extract_grob_set (it, "elements", elts); - vector ncs; - Interval centers; - for (vsize i = 0; i < elts.size (); i++) - if (Note_column::has_interface (elts[i])) - centers.add_point (scm_to_double (centered_on_object (elts[i], X_AXIS))); - - if (centers.is_empty ()) - return scm_from_double (0.0); - - return scm_from_double (centers.center ()); -} - MAKE_SCHEME_CALLBACK (Self_alignment_interface, centered_on_y_parent, 1); SCM Self_alignment_interface::centered_on_y_parent (SCM smob) diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index ebfff6a2fc..ec34cd64c3 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -420,13 +420,6 @@ a collection of staves, with a bracket in front and spanning bar lines." \override DynamicLineSpanner.outside-staff-priority = ##f \override DynamicText.outside-staff-priority = ##f \override Hairpin.outside-staff-priority = ##f - \override DynamicText.X-offset = - #(ly:make-simple-closure - `(,+ - ,(ly:make-simple-closure - (list ly:self-alignment-interface::centered-on-note-columns)) - ,(ly:make-simple-closure - (list ly:self-alignment-interface::x-aligned-on-self)))) \description "Holds a single line of dynamics, which will be centered between the staves surrounding this context." diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index aa3e605aeb..9d894be3e3 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -857,7 +857,7 @@ (stencil . ,ly:text-interface::print) (vertical-skylines . ,grob::always-vertical-skylines-from-stencil) (Y-extent . ,grob::always-Y-extent-from-stencil) - (X-offset . ,ly:self-alignment-interface::x-aligned-on-self) + (X-offset . ,ly:self-alignment-interface::aligned-on-x-parent) (Y-offset . ,(scale-by-font-size -0.6)) ; center on an 'm' (meta . ((class . Item) (interfaces . (dynamic-interface -- 2.39.2