From c3a27377112760f52fdfa05c8ea0bfa304f3abd1 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 5 Nov 2006 13:45:00 +0100 Subject: [PATCH] Center harmonic heads if stem is invisible. Fixes #140 --- input/regression/note-head-harmonic-whole.ly | 19 +++++++++++++++++++ input/regression/note-head-harmonic.ly | 3 ++- lily/stem.cc | 19 ++++++++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 input/regression/note-head-harmonic-whole.ly diff --git a/input/regression/note-head-harmonic-whole.ly b/input/regression/note-head-harmonic-whole.ly new file mode 100644 index 0000000000..259608ac07 --- /dev/null +++ b/input/regression/note-head-harmonic-whole.ly @@ -0,0 +1,19 @@ +\header { + + texidoc = "A harmonic note head must be centered if the base note + is a whole note." + +} + + +\version "2.9.29" + +\paper { + ragged-right = ##t +} + +\relative c' { + 1 + 1 +} + diff --git a/input/regression/note-head-harmonic.ly b/input/regression/note-head-harmonic.ly index b76d29687e..ae49e1bfd3 100644 --- a/input/regression/note-head-harmonic.ly +++ b/input/regression/note-head-harmonic.ly @@ -3,7 +3,8 @@ texidoc = " The handling of stems for harmonic notes must be completely identical to normal note heads. - Harmonic heads do not get dots. If @code{harmonicAccidentals} is unset, they also don't get accidentals." + Harmonic heads do not get dots. If @code{harmonicAccidentals} is + unset, they also don't get accidentals." } diff --git a/lily/stem.cc b/lily/stem.cc index 6a0fb43485..69e7a15ce6 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -419,12 +419,25 @@ Stem::calc_positioning_done (SCM smob) dir = UP; set_grob_direction (me, dir); } - + + bool is_harmonic_centered = false; + for (vsize i = 0; i < heads.size (); i++) + is_harmonic_centered = is_harmonic_centered + || heads[i]->get_property ("style") == ly_symbol2scm ("harmonic"); + is_harmonic_centered = is_harmonic_centered && is_invisible (me); + Real w = hed->extent (hed, X_AXIS)[dir]; for (vsize i = 0; i < heads.size (); i++) - heads[i]->translate_axis (w - heads[i]->extent (heads[i], X_AXIS)[dir], - X_AXIS); + { + Real amount = w - heads[i]->extent (heads[i], X_AXIS)[dir]; + if (is_harmonic_centered) + amount = + hed->extent (hed, X_AXIS).linear_combination (CENTER) + - heads[i]->extent (heads[i], X_AXIS).linear_combination (CENTER); + + heads[i]->translate_axis (amount, X_AXIS); + } bool parity = true; Real lastpos = Real (Staff_symbol_referencer::get_position (heads[0])); for (vsize i = 1; i < heads.size (); i++) -- 2.39.5