]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix DynamicTextSpanner left alignment.
authorNeil Puttock <n.puttock@gmail.com>
Fri, 15 Jan 2010 00:02:23 +0000 (00:02 +0000)
committerNeil Puttock <n.puttock@gmail.com>
Fri, 15 Jan 2010 00:02:23 +0000 (00:02 +0000)
When a DynamicTextSpanner directly follows a DynamicScript, padding is
required to ensure the 'left 'text doesn't collide with the
dynamic sign.  Unfortunately, this default value skews the
spanner's left bound to the right when no dynamic script is present.

This patch caters for both situations by resetting 'left 'padding
and 'left 'attach-dir as required, adding extra padding read from the
property 'right-padding to fine-tune the space between the text elements.

* add regtests demonstrating 'right-padding and correct alignment

* remove hard-coded 'bound-details setting in New_dynamic_engraver, which
  prevented user override

* add dynamic-text-interface with user property 'right-padding

* add 'before-line-breaking callback dynamic-text-spanner::before-line-breaking
  which checks whether the left bound is a DynamicText; if this is true,
  set nested properties 'left 'attach-dir/'padding to prevent collision

input/regression/dynamics-text-left-text-alignment.ly [new file with mode: 0644]
input/regression/dynamics-text-right-padding.ly [new file with mode: 0644]
lily/new-dynamic-engraver.cc
scm/define-grob-interfaces.scm
scm/define-grobs.scm
scm/output-lib.scm

diff --git a/input/regression/dynamics-text-left-text-alignment.ly b/input/regression/dynamics-text-left-text-alignment.ly
new file mode 100644 (file)
index 0000000..03893c0
--- /dev/null
@@ -0,0 +1,13 @@
+\version "2.13.11"
+\header {
+  texidoc = "The left text of a @code{DynamicTextSpanner} is
+left-aligned to its anchor note.
+"
+}
+
+\relative c' {
+  \crescTextCresc
+  \dimTextDim
+  c4\< c c c\!
+  c4\> c c c\!
+}
diff --git a/input/regression/dynamics-text-right-padding.ly b/input/regression/dynamics-text-right-padding.ly
new file mode 100644 (file)
index 0000000..e3c8a09
--- /dev/null
@@ -0,0 +1,12 @@
+\version "2.13.11"
+\header {
+  texidoc = "The space between an absolute dynamic and a dynamic text
+span can be changed using @code{'right-padding}.
+"
+}
+
+\relative c' {
+  \dimTextDim
+  \once \override DynamicText #'right-padding = #0
+  c4\fff\> c c c\!
+}
index ea4c99d22ad59f4b7267fcd06914d3286f286221..af943c4aa8583c7d64965de3dab8c6d01a800e9c 100644 (file)
@@ -166,16 +166,7 @@ New_dynamic_engraver::process_music ()
       if (finished_spanner_)
        finished_spanner_->set_bound (RIGHT, script_);
       if (current_spanner_)
-       {
-         current_spanner_->set_bound (LEFT, script_);
-
-         if (!Hairpin::has_interface (current_spanner_))
-           set_nested_property (current_spanner_,
-                                scm_list_3 (ly_symbol2scm ("bound-details"),
-                                            ly_symbol2scm ("left"),
-                                            ly_symbol2scm ("attach-dir")),
-                                scm_from_int (RIGHT));
-       }
+       current_spanner_->set_bound (LEFT, script_);
     }
 }
 
index d0abebed7bb753585bbf018f3de3e5a90324f0eb..b068da91adf7c19e02c75484b4d7e60eff74d690 100644 (file)
@@ -56,6 +56,11 @@ note)."
  "Dynamic line spanner."
  '(avoid-slur))
 
+(ly:add-interface
+ 'dynamic-text-interface
+ "An absolute text dynamic."
+ '(right-padding))
+
 (ly:add-interface
  'dynamic-text-spanner-interface
  "Dynamic text spanner."
index 7c459a0bca6ed52c278723bd15c5e65fa0ff8b01..781d3e0b0322e4964869cf621ea85b60e7abf05f 100644 (file)
        (font-shape . italic)
        (outside-staff-priority . 250)
        (positioning-done . ,ly:script-interface::calc-positioning-done)
+       (right-padding . 0.5)
        (self-alignment-X . ,CENTER)
        (self-alignment-Y . ,CENTER)
        (stencil . ,ly:text-interface::print)
        (Y-offset . ,ly:self-alignment-interface::y-aligned-on-self)
        (meta . ((class . Item)
                 (interfaces . (dynamic-interface
+                               dynamic-text-interface
                                font-interface
                                script-interface
                                self-alignment-interface
 
     (DynamicTextSpanner
      . (
+       (before-line-breaking . ,dynamic-text-spanner::before-line-breaking)
        (bound-details . ((right . ((attach-dir .  ,LEFT)
                                    (Y . 0)
                                    (padding . 0.75)
 
                          (left . ((attach-dir .  ,LEFT)
                                   (Y . 0)
-                                  (stencil-offset . (0 . -0.5))
-                                  (padding . 0.5)
+                                  (stencil-offset . (-0.75 . -0.5))
+                                  (padding . 0.75)
                                   ))
                          (left-broken . ((attach-dir .  ,RIGHT)
                                   ))
index a7ba96b58916f32fb7e3fcbbe27f46013562368c..e98937e821ea762d332d7907376c43567f07d5e0 100644 (file)
@@ -644,6 +644,27 @@ and duration-log @var{log}."
       START
       STOP))
 
+(define-public (dynamic-text-spanner::before-line-breaking grob)
+  "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
+If found, ensure @code{DynamicText} does not collide with spanner text by
+changing @code{'attach-dir} and @code{'padding}.  Reads the
+@code{'right-padding} property of @code{DynamicText} to fine tune space
+between the two text elements."
+  (let ((left-bound (ly:spanner-bound grob LEFT)))
+    (if (grob::has-interface left-bound 'dynamic-text-interface)
+       (let* ((details (ly:grob-property grob 'bound-details))
+              (left-details (ly:assoc-get 'left details))
+              (my-padding (ly:assoc-get 'padding left-details))
+              (script-padding (ly:grob-property left-bound 'right-padding 0)))
+
+         (and (number? my-padding)
+              (ly:grob-set-nested-property! grob
+                                            '(bound-details left attach-dir)
+                                            RIGHT)
+              (ly:grob-set-nested-property! grob
+                                            '(bound-details left padding)
+                                            (+ my-padding script-padding)))))))
+
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; lyrics