]> git.donarmstrong.com Git - lilypond.git/commitdiff
Adds a numbering-assertion-function property to the footnote grob.
authorMike Solomon <mike@apollinemike.com>
Fri, 2 Dec 2011 07:06:13 +0000 (08:06 +0100)
committerMike Solomon <mike@apollinemike.com>
Fri, 2 Dec 2011 07:06:13 +0000 (08:06 +0100)
This allows the footnote regtests to verify that the footnotes are
being numbered in the correct order.

input/regression/footnote-auto-numbering-vertical-order.ly [new file with mode: 0644]
input/regression/footnote-auto-numbering.ly
lily/include/page-layout-problem.hh
lily/page-layout-problem.cc
scm/define-grob-interfaces.scm
scm/define-grob-properties.scm

diff --git a/input/regression/footnote-auto-numbering-vertical-order.ly b/input/regression/footnote-auto-numbering-vertical-order.ly
new file mode 100644 (file)
index 0000000..c7862a9
--- /dev/null
@@ -0,0 +1,97 @@
+\version "2.15.21"
+\header {
+  texidoc = "This regtest makes sure that footnote numbers are laid out
+in the correct vertical order.
+"
+}
+
+#(define (make-footnote-numbering-assertion-function n)
+  (lambda (x)
+    (if (not (= n x))
+      (ly:error (_ "Expecting number ~a, got ~a") n x))))
+
+#(define (simultaneous-footnote-numbering-assertion-function x y)
+  (lambda (grob)
+    (let ((n (if (grob::has-interface (ly:grob-parent grob Y)
+                                      'beam-interface)
+                 x
+                 y)))
+      (lambda (x)
+        (if (not (= n x))
+          (ly:error (_ "Expecting number ~a, got ~a") n x))))))
+
+\paper {
+  reset-footnotes-on-new-page = ##f
+}
+
+#(set-default-paper-size "a6")
+\book {
+  \score {
+    <<
+      \new Staff \relative c' {
+        d4 e
+        \once \override FootnoteItem #'numbering-assertion-function =
+          #(lambda (grob) (make-footnote-numbering-assertion-function 0))
+        < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+        \once \override FootnoteSpanner #'numbering-assertion-function =
+          #(simultaneous-footnote-numbering-assertion-function 2 4)
+        \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
+        \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
+        a8\< [ b c d ] a4 b c\f |
+        d a b c |\break
+        d,4 e
+        \once \override FootnoteItem #'numbering-assertion-function =
+          #(lambda (grob) (make-footnote-numbering-assertion-function 6))
+        < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+        \once \override FootnoteSpanner #'numbering-assertion-function =
+          #(simultaneous-footnote-numbering-assertion-function 8 10)
+        \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
+        \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
+        a8\< [ b c d ] a4 b c |
+        d a b c\f |\pageBreak
+        d,4 e
+        \once \override FootnoteItem #'numbering-assertion-function =
+          #(lambda (grob) (make-footnote-numbering-assertion-function 12))
+        < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+        \once \override FootnoteSpanner #'numbering-assertion-function =
+          #(simultaneous-footnote-numbering-assertion-function 14 16)
+        \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
+        \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
+        a8\< [ b c d ] a4 b c |
+        d a b c\! |\break
+      }
+      \new Staff \relative c' {
+        d4 e
+        \once \override FootnoteItem #'numbering-assertion-function =
+          #(lambda (grob) (make-footnote-numbering-assertion-function 1))
+        < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+        \once \override FootnoteSpanner #'numbering-assertion-function =
+          #(simultaneous-footnote-numbering-assertion-function 3 5)
+        \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
+        \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
+        a8\< [ b c d ] a4 b c\f |
+        d a b c |\break
+        d,4 e
+        \once \override FootnoteItem #'numbering-assertion-function =
+          #(lambda (grob) (make-footnote-numbering-assertion-function 7))
+        < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+        \once \override FootnoteSpanner #'numbering-assertion-function =
+          #(simultaneous-footnote-numbering-assertion-function 9 11)
+        \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
+        \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
+        a8\< [ b c d ] a4 b c |
+        d a b c\f |\pageBreak
+        d,4 e
+        \once \override FootnoteItem #'numbering-assertion-function =
+          #(lambda (grob) (make-footnote-numbering-assertion-function 13))
+        < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+        \once \override FootnoteSpanner #'numbering-assertion-function =
+          #(simultaneous-footnote-numbering-assertion-function 15 17)
+        \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
+        \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
+        a8\< [ b c d ] a4 b c |
+        d a b c\! |\break
+      }
+    >>
+  }
+}
index 790278288b3f21a99f2b167aca8b55caa12648e2..0461597eac67de3a2977bd414c9eda4638663f70 100644 (file)
@@ -1,4 +1,4 @@
-\version "2.15.7"
+\version "2.15.21"
 \header {
   texidoc = "This is an example of automatic footnote numbering
 where the number is not reset on each page.  It uses the default
@@ -7,6 +7,21 @@ footnotes.
 "
 }
 
+#(define (make-footnote-numbering-assertion-function n)
+  (lambda (x)
+    (if (not (= n x))
+      (ly:error (_ "Expecting number ~a, got ~a") n x))))
+
+#(define (simultaneous-footnote-numbering-assertion-function x y)
+  (lambda (grob)
+    (let ((n (if (grob::has-interface (ly:grob-parent grob Y)
+                                      'beam-interface)
+                 x
+                 y)))
+      (lambda (x)
+        (if (not (= n x))
+          (ly:error (_ "Expecting number ~a, got ~a") n x))))))
+
 \paper {
   reset-footnotes-on-new-page = ##f
 }
@@ -23,8 +38,11 @@ footnotes.
 \markup { h i }
 
 \relative c' {
-\autoFootnoteGrob #'NoteHead #'(1 . -1) \markup { j }
-a b c d }
+  \once \override FootnoteItem #'numbering-assertion-function =
+    #(lambda (grob) (make-footnote-numbering-assertion-function 3))
+  \autoFootnoteGrob #'NoteHead #'(1 . -1) \markup { j }
+  a b c d
+}
 
 \pageBreak
 
@@ -34,7 +52,11 @@ a b c d }
 
 \relative c' {
   d4 e
+  \once \override FootnoteItem #'numbering-assertion-function =
+    #(lambda (grob) (make-footnote-numbering-assertion-function 5))
   < f  a-\autoFootnote #'(1 . -1) \markup { n } c >
+  \once \override FootnoteSpanner #'numbering-assertion-function =
+    #(simultaneous-footnote-numbering-assertion-function 6 7)
   \autoFootnoteGrob #'Beam #'(1 . 1) \markup { o }
   \autoFootnoteGrob #'Hairpin #'(1 . 1) \markup { p }
   a8\< [ b c d ] a4 b c |
index 665f15396bf311a32f1d981ad492a87feb5e1e84..c0577b9ab072b37e4d1a9a996d9415d92b2d9c0c 100644 (file)
@@ -34,6 +34,7 @@ public:
   static bool read_spacing_spec (SCM spec, Real *dest, SCM sym);
   static bool is_spaceable (Grob *g);
   static SCM get_details (Grob *g);
+  static vector<Grob *> get_footnote_grobs (SCM lines);
   static vsize get_footnote_count (SCM lines);
   static SCM get_footnotes_from_lines (SCM lines);
   static void add_footnotes_to_lines (SCM lines, int counter, Paper_book *pb);
index 319ba396f14a5d087e6e64938f53623a2136cfd4..f4e208521859f945a6e3591547b90e0178763128 100644 (file)
  Returns the number of footntoes associated with a given line.
 */
 
-vsize
-Page_layout_problem::get_footnote_count (SCM lines)
+vector<Grob *>
+Page_layout_problem::get_footnote_grobs (SCM lines)
 {
-  vsize fn_count = 0;
+  vector<Grob *> footnotes;
   for (SCM s = lines; scm_is_pair (s); s = scm_cdr (s))
     {
       if (Grob *g = unsmob_grob (scm_car (s)))
@@ -52,7 +52,8 @@ Page_layout_problem::get_footnote_count (SCM lines)
               programming_error ("got a grob for footnotes that wasn't a System");
               continue;
             }
-          fn_count += sys->num_footnotes ();
+          extract_grob_set (sys, "footnotes-after-line-breaking", footnote_grobs);
+          footnotes.insert (footnotes.end (), footnote_grobs.begin (), footnote_grobs.end ());
         }
       else if (Prob *p = unsmob_prob (scm_car (s)))
         {
@@ -60,11 +61,18 @@ Page_layout_problem::get_footnote_count (SCM lines)
           if (stencils == SCM_EOL)
             continue;
           for (SCM st = stencils; scm_is_pair (st); st = scm_cdr (st))
-            fn_count++;
+            footnotes.push_back (0);
         }
     }
 
-  return fn_count;
+  return footnotes;
+}
+
+vsize
+Page_layout_problem::get_footnote_count (SCM lines)
+{
+  vector<Grob *> notes = get_footnote_grobs (lines);
+  return notes.size ();
 }
 
 SCM
@@ -137,7 +145,8 @@ Page_layout_problem::add_footnotes_to_lines (SCM lines, int counter, Paper_book
   Real padding = robust_scm2double (paper->c_variable ("footnote-padding"), 0.0);
   Real number_raise = robust_scm2double (paper->c_variable ("footnote-number-raise"), 0.0);
 
-  vsize fn_count = get_footnote_count (lines);
+  vector<Grob *> fn_grobs = get_footnote_grobs (lines);
+  vsize fn_count = fn_grobs.size ();
 
   // now, make the footnote stencils with the numbering function
   SCM numbers = SCM_EOL;
@@ -156,6 +165,12 @@ Page_layout_problem::add_footnotes_to_lines (SCM lines, int counter, Paper_book
   vector<Stencil *> footnote_number_stencils; // Holds translated versions of the stencilized numbering markups.
   for (vsize i = 0; i < fn_count; i++)
     {
+      if (fn_grobs[i])
+        {
+          SCM assertion_function = fn_grobs[i]->get_property ("numbering-assertion-function");
+          if (ly_is_procedure (assertion_function))
+            (void) scm_call_1 (assertion_function, scm_from_int (counter));
+        }
       SCM markup = scm_call_1 (numbering_function, scm_from_int (counter));
       Stencil *s = unsmob_stencil (Text_interface::interpret_markup (layout, props, markup));
       if (!s)
index 2047d6c63083b8213dd006159825e4bad59f1b1f..b17a6a995dea7754c6c0ec2bcd45b7361fa1413f 100644 (file)
@@ -84,7 +84,10 @@ note)."
 (ly:add-interface
  'footnote-interface
  "Make a footnote."
- '(automatically-numbered footnote footnote-text))
+ '(automatically-numbered
+   footnote
+   footnote-text
+   numbering-assertion-function))
 
 (ly:add-interface
  'footnote-spanner-interface
index 2b67674fb11c15590f30f29a12bfdfdee042173f..c26bd3cae19a503c10ee9e3eb7c586e8498adc9a 100644 (file)
@@ -1153,6 +1153,8 @@ entries @code{name} and @code{interfaces}.")
 
      (note-collision ,ly:grob? "The @code{NoteCollision} object of a
 dot column.")
+     (numbering-assertion-function ,scheme? "The function used to assert
+that footnotes are receiving correct automatic numbers.")
 
      (positioning-done ,boolean? "Used to signal that a positioning element
 did its job.  This ensures that a positioning is only done once.")