From b80fd169a769326b32b3b1fb42467a84c9a19189 Mon Sep 17 00:00:00 2001 From: Nicolas Sceaux Date: Fri, 15 Feb 2008 22:01:31 +0100 Subject: [PATCH] Instrument names: horizontal aligment. - define a short-indent scaled layout variable; - using indent or short-indent, and the value of the self-alignment-X grob property, horizontally align the instrument name; - by default, center instrument names. --- Documentation/user/staff.itely | 34 +++++----------- input/regression/instrument-name-x-align.ly | 45 +++++++++++++++++++++ lily/system-start-text.cc | 19 ++++++++- scm/define-grobs.scm | 1 + scm/paper.scm | 3 +- 5 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 input/regression/instrument-name-x-align.ly diff --git a/Documentation/user/staff.itely b/Documentation/user/staff.itely index b1d47765da..ee40671d52 100644 --- a/Documentation/user/staff.itely +++ b/Documentation/user/staff.itely @@ -439,20 +439,20 @@ c''1 @cindex instrument names, centering -If you wish to center the instrument names, you must center all of -them individually: +As instrument names are centered by default, multi line names +are better entered using @code{\center-align}: @lilypond[quote,verbatim,ragged-right] { << \new Staff { - \set Staff.instrumentName = \markup { - \center-align { "Clarinetti" - \line { "in B" \smaller \flat } } } + \set Staff.instrumentName = \markup \center-align { + Clarinetti + \line { "in B" \smaller \flat } + } c''1 } \new Staff { - \set Staff.instrumentName = - \markup{ \center-align { Vibraphone }} + \set Staff.instrumentName = "Vibraphone" c''1 } >> @@ -462,23 +462,9 @@ them individually: For longer instrument names, it may be useful to increase the @code{indent} setting in the @code{\layout} block. -To center instrument names while leaving extra space to the right, - -@lilypond[quote,verbatim,ragged-right] -\new StaffGroup \relative -<< - \new Staff { - \set Staff.instrumentName = - \markup { \hcenter-in #10 "blabla" } - c1 c1 - } - \new Staff { - \set Staff.instrumentName = - \markup { \hcenter-in #10 "blo" } - c1 c1 - } ->> -@end lilypond +Short instrument names, printed before the systems following the first +one, are also centered by default, in a space which width is given by +the @code{short-indent} variable of the @code{\layout} block. To add instrument names to other contexts (such as @code{GrandStaff}, @code{ChoirStaff}, or @code{StaffGroup}), the diff --git a/input/regression/instrument-name-x-align.ly b/input/regression/instrument-name-x-align.ly new file mode 100644 index 0000000000..bfdd50f02e --- /dev/null +++ b/input/regression/instrument-name-x-align.ly @@ -0,0 +1,45 @@ +\header { + + texidoc = "Instrument names horizontal alignment is tweaked by +changing the @code{Staff.Instrument #'self-alignment-X} property. The +@code{\layout} variables @code{indent} and @code{short-indent} define +the space where the instrument names are aligned before the first and +the following systems, respectively." + +} + +\version "2.11.39" +\paper { left-margin = 3\cm } +\score { + \new StaffGroup << + \new Staff { + \override Staff . InstrumentName #'self-alignment-X = #LEFT + \set Staff . instrumentName = \markup \column { + "Left aligned" "instrument name" + } + \set Staff . shortInstrumentName = "Left" + c''1 \break c'' + } + \new Staff { + \override Staff . InstrumentName #'self-alignment-X = #CENTER + \set Staff . instrumentName = \markup \center-align { + "Centered" "instrument name" + } + \set Staff . shortInstrumentName = "Centered" + g'1 g' + } + \new Staff { + \override Staff . InstrumentName #'self-alignment-X = #RIGHT + \set Staff . instrumentName = \markup \column \right-align { + "Right aligned" "instrument name" + } + \set Staff . shortInstrumentName = "Right" + e' \break e' + } + >> + \layout { + ragged-right = ##t + indent = 4\cm + short-indent = 2\cm + } +} diff --git a/lily/system-start-text.cc b/lily/system-start-text.cc index 494ab149b8..c99f150fed 100644 --- a/lily/system-start-text.cc +++ b/lily/system-start-text.cc @@ -45,7 +45,23 @@ System_start_text::get_stencil (Grob *me_grob) SCM align_y = me_grob->get_property ("self-alignment-Y"); if (scm_is_number (align_y)) p->align_to (Y_AXIS, robust_scm2double (align_y, 0.0)); - return *p; + + /* Horizontal alignment according to the self-alignment-X property + * and indent value. */ + Output_def *layout = me_grob->layout (); + Real indent; + if (me->get_break_index () == 0) + indent = robust_scm2double (layout->c_variable ("indent"), 0); + else + indent = robust_scm2double (layout->c_variable ("short-indent"), 0); + Real align_x = robust_scm2double (me->get_property ("self-alignment-X"), 0); + Interval p_extent_x = p->extent (X_AXIS); + Interval padding (0.0, max (0.0, indent - p_extent_x.length ())); + Real right_padding = padding.length () - padding.linear_combination (align_x); + Box box (Interval (p_extent_x[LEFT], p_extent_x[RIGHT] + right_padding), + p->extent (Y_AXIS)); + Stencil *aligned_p = new Stencil (box, p->expr ()); + return *aligned_p; } return Stencil (); } @@ -101,4 +117,5 @@ ADD_INTERFACE (System_start_text, "text " "long-text " "self-alignment-Y " + "self-alignment-X " ); diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index c8b1c5f085..2ef83b3d30 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -820,6 +820,7 @@ (X-offset . ,ly:side-position-interface::x-aligned-side) (direction . ,LEFT) (self-alignment-Y . ,CENTER) + (self-alignment-X . ,CENTER) (meta . ((class . Spanner) (interfaces . (system-start-text-interface side-position-interface diff --git a/scm/paper.scm b/scm/paper.scm index be15759f7a..8c2b5dc710 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -9,7 +9,7 @@ '(pt mm cm in staff-height staff-space page-top-space between-system-space between-system-padding - line-width indent paper-width paper-height horizontal-shift + line-width indent short-indent paper-width paper-height horizontal-shift staff-space line-thickness ledgerline-thickness blot-diameter left-margin right-margin))) @@ -115,6 +115,7 @@ size. SZ is in points" (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) (module-define! m 'indent (/ w 14)) + (module-define! m 'short-indent (* 5 mm)) ;; page layout - what to do with (printer specific!) margin settings? -- 2.39.5