From d8fce1e1ea2aca1a82e25e47805aef0f70f511b9 Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Thu, 24 Nov 2011 10:29:00 +0100 Subject: [PATCH] Gets vertical ordering of footnotes correct. Now, when there are two footnotes that have the same vertical position on the system, the higher one will receive a lower number. This is implemented by changing the footnotes_ vector in the system class to a grob array and sorting it via grob_2D_less in system.cc --- lily/footnote-engraver.cc | 8 +++ lily/grob.cc | 18 +++++ lily/include/grob.hh | 2 + lily/include/system.hh | 8 +-- lily/page-layout-problem.cc | 5 +- lily/span-bar-engraver.cc | 2 +- lily/system.cc | 119 +++++++++++++++++++++++---------- scm/define-grob-properties.scm | 4 ++ scm/define-grobs.scm | 4 +- 9 files changed, 127 insertions(+), 43 deletions(-) diff --git a/lily/footnote-engraver.cc b/lily/footnote-engraver.cc index 6b62af0d47..89cecc3a00 100644 --- a/lily/footnote-engraver.cc +++ b/lily/footnote-engraver.cc @@ -23,6 +23,7 @@ #include "item.hh" #include "pointer-group-interface.hh" #include "spanner.hh" +#include "system.hh" #include "translator.icc" @@ -37,6 +38,7 @@ class Footnote_engraver : public Engraver vector > annotated_spanners_; void stop_translation_timestep (); + void finalize (); void footnotify (Grob *, Stream_event *); }; @@ -54,6 +56,12 @@ Footnote_engraver::stop_translation_timestep () events_.clear (); } +void +Footnote_engraver::finalize () +{ + annotated_spanners_.resize (0); +} + Footnote_engraver::Footnote_engraver () { } diff --git a/lily/grob.cc b/lily/grob.cc index a21ab9c5d9..13dd9c7b39 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -644,6 +644,18 @@ Grob::get_vertical_axis_group_index (Grob *g) bool Grob::vertical_less (Grob *g1, Grob *g2) +{ + return internal_vertical_less (g1, g2, false); +} + +bool +Grob::pure_vertical_less (Grob *g1, Grob *g2) +{ + return internal_vertical_less (g1, g2, true); +} + +bool +Grob::internal_vertical_less (Grob *g1, Grob *g2, bool pure) { Grob *vag = get_root_vertical_alignment (g1); if (!vag) @@ -658,6 +670,12 @@ Grob::vertical_less (Grob *g1, Grob *g2) extract_grob_set (vag, "elements", elts); + if (ag1 == ag2 && !pure) + { + Grob *common = g1->common_refpoint (g2, Y_AXIS); + return g1->relative_coordinate (common, Y_AXIS) > g2->relative_coordinate (common, Y_AXIS); + } + for (vsize i = 0; i < elts.size (); i++) { if (elts[i] == ag1) diff --git a/lily/include/grob.hh b/lily/include/grob.hh index 36f912a289..681e4be290 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -144,6 +144,8 @@ public: static Grob *get_root_vertical_alignment (Grob *g); static Grob *get_vertical_axis_group (Grob *g); static bool vertical_less (Grob *g1, Grob *g2); + static bool pure_vertical_less (Grob *g1, Grob *g2); + static bool internal_vertical_less (Grob *g1, Grob *g2, bool pure); static int get_vertical_axis_group_index (Grob *g); virtual Interval_t spanned_rank_interval () const; diff --git a/lily/include/system.hh b/lily/include/system.hh index 165b589c37..5ce98171b8 100644 --- a/lily/include/system.hh +++ b/lily/include/system.hh @@ -37,8 +37,6 @@ class System : public Spanner void init_elements (); friend class Paper_score; // ugh. Paper_score *pscore_; // ugh. - bool checked_footnotes_; - vector footnote_grobs_; // TODO: make this a grob array public: Paper_score *paper_score () const; @@ -52,17 +50,17 @@ public: vector get_footnote_heights_in_range (vsize st, vsize end); vector get_in_note_heights_in_range (vsize st, vsize end); vector internal_get_note_heights_in_range (vsize st, vsize end, bool foot); - void get_footnote_grobs_in_range (vector &out, vsize st, vsize end); - vector *footnote_grobs (); + vector get_footnote_grobs_in_range (vsize st, vsize end); vsize num_footnotes (); void do_break_substitution_and_fixup_refpoints (); void post_processing (); - void populate_footnote_grob_vector (); SCM get_paper_system (); SCM get_paper_systems (); SCM get_broken_system_grobs (); SCM get_broken_footnote_stencils (); + DECLARE_SCHEME_CALLBACK (footnotes_before_line_breaking, (SCM)); + DECLARE_SCHEME_CALLBACK (footnotes_after_line_breaking, (SCM)); DECLARE_SCHEME_CALLBACK (calc_pure_relevant_grobs, (SCM)); DECLARE_SCHEME_CALLBACK (height, (SCM)); DECLARE_SCHEME_CALLBACK (calc_pure_height, (SCM, SCM, SCM)); diff --git a/lily/page-layout-problem.cc b/lily/page-layout-problem.cc index 562f0aeb90..319ba396f1 100644 --- a/lily/page-layout-problem.cc +++ b/lily/page-layout-problem.cc @@ -206,9 +206,10 @@ Page_layout_problem::add_footnotes_to_lines (SCM lines, int counter, Paper_book } Stencil mol; Stencil in_note_mol; - for (vsize i = 0; i < sys->footnote_grobs ()->size (); i++) + extract_grob_set (sys, "footnotes-after-line-breaking", footnote_grobs); + for (vsize i = 0; i < footnote_grobs.size (); i++) { - Grob *footnote = sys->footnote_grobs ()->at (i); + Grob *footnote = footnote_grobs[i]; SCM footnote_markup = footnote->get_property ("footnote-text"); if (Spanner *orig = dynamic_cast(footnote)) if (orig->is_broken ()) diff --git a/lily/span-bar-engraver.cc b/lily/span-bar-engraver.cc index 4addffcac6..8a673f15bf 100644 --- a/lily/span-bar-engraver.cc +++ b/lily/span-bar-engraver.cc @@ -71,7 +71,7 @@ Span_bar_engraver::process_acknowledged () { Grob *vag = Grob::get_root_vertical_alignment (bars_[0]); if (vag) - vector_sort (bars_, Grob::vertical_less); + vector_sort (bars_, Grob::pure_vertical_less); spanbar_ = make_item ("SpanBar", SCM_EOL); spanbar_->set_parent (bars_[0], X_AXIS); diff --git a/lily/system.cc b/lily/system.cc index 176e338a54..cc4cbda549 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -47,7 +47,6 @@ System::System (System const &src) all_elements_ = 0; pscore_ = 0; rank_ = 0; - checked_footnotes_ = false; init_elements (); } @@ -56,7 +55,6 @@ System::System (SCM s) { all_elements_ = 0; rank_ = 0; - checked_footnotes_ = false; init_elements (); } @@ -191,6 +189,7 @@ System::do_break_substitution_and_fixup_refpoints () { System *child = dynamic_cast (broken_intos_[i]); child->all_elements_->remove_duplicates (); + for (vsize j = 0; j < child->all_elements_->size (); j++) { Grob *g = child->all_elements_->grob (j); @@ -229,37 +228,32 @@ System::get_paper_systems () return lines; } -void -System::populate_footnote_grob_vector () -{ - extract_grob_set (this, "all-elements", all_elts); - for (vsize i = 0; i < all_elts.size (); i++) - if (all_elts[i]->internal_has_interface (ly_symbol2scm ("footnote-interface"))) - footnote_grobs_.push_back (all_elts[i]); - - sort (footnote_grobs_.begin (), footnote_grobs_.end (), Grob::less); - checked_footnotes_ = true; -} - -void -System::get_footnote_grobs_in_range (vector &out, vsize start, vsize end) +vector +System::get_footnote_grobs_in_range (vsize start, vsize end) { - if (!checked_footnotes_) - populate_footnote_grob_vector (); - - for (vsize i = 0; i < footnote_grobs_.size (); i++) + vector out; + extract_grob_set (this, "footnotes-before-line-breaking", footnote_grobs); + for (vsize i = 0; i < footnote_grobs.size (); i++) { - int pos = footnote_grobs_[i]->spanned_rank_interval ()[LEFT]; - if (Spanner *s = dynamic_cast(footnote_grobs_[i])) + Grob *at_bat = footnote_grobs[i]; + int pos = at_bat->spanned_rank_interval ()[LEFT]; + bool end_of_line_visible = true; + if (Spanner *s = dynamic_cast(at_bat)) { Direction spanner_placement = robust_scm2dir (s->get_property ("spanner-placement"), LEFT); if (spanner_placement == CENTER) spanner_placement = LEFT; pos = s->spanned_rank_interval ()[spanner_placement]; + if (s->original ()) + { + Spanner *orig = dynamic_cast(s->original ()); + at_bat = spanner_placement == LEFT ? orig->broken_intos_[0] : orig->broken_intos_.back (); + pos = at_bat->spanned_rank_interval ()[RIGHT]; + } } - if (Item *item = dynamic_cast(footnote_grobs_[i])) + if (Item *item = dynamic_cast(at_bat)) { if (!Item::break_visible (item)) continue; @@ -275,12 +269,17 @@ System::get_footnote_grobs_in_range (vector &out, vsize start, vsize end if (pos < int (start)) continue; if (pos > int (end)) - break; - if (!footnote_grobs_[i]->is_live ()) + continue; + if (pos == int (start) && end_of_line_visible) + continue; + if (pos == int (end) && !end_of_line_visible) + continue; + if (!at_bat->is_live ()) continue; - out.push_back (footnote_grobs_[i]); + out.push_back (at_bat); } + return out; } vector @@ -298,8 +297,7 @@ System::get_in_note_heights_in_range (vsize start, vsize end) vector System::internal_get_note_heights_in_range (vsize start, vsize end, bool foot) { - vector footnote_grobs; - get_footnote_grobs_in_range (footnote_grobs, start, end); + vector footnote_grobs = get_footnote_grobs_in_range (start, end); vector out; for (vsize i = footnote_grobs.size (); i--;) @@ -331,13 +329,66 @@ System::internal_get_note_heights_in_range (vsize start, vsize end, bool foot) vsize System::num_footnotes () { - return footnote_grobs_.size (); + extract_grob_set (this, "footnotes-after-line-breaking", footnote_grobs); + return footnote_grobs.size (); +} + +bool +grob_2D_less (Grob *g1, Grob *g2) +{ + int sri[] = {0,0}; + Grob *gs[] = {g1, g2}; + + for (int i = 0; i < 2; i++) + { + sri[i] = gs[i]->spanned_rank_interval ()[LEFT]; + if (Spanner *s = dynamic_cast (gs[i])) + { + if (s->broken_intos_.size ()) + s = (scm_to_int (s->broken_intos_[0]->get_property ("spanner-placement")) == LEFT + ? s->broken_intos_[0] + : s->broken_intos_.back ()); + gs[i] = s; + if (robust_scm2double (s->get_property ("X-offset"), 0.0) > 0) + sri[i] = s->spanned_rank_interval ()[RIGHT]; + } + } + + if (sri[0] == sri[1]) + return Grob::vertical_less (gs[0], gs[1]); + + return sri[0] < sri[1]; } -vector* -System::footnote_grobs () +MAKE_SCHEME_CALLBACK (System, footnotes_before_line_breaking, 1); +SCM +System::footnotes_before_line_breaking (SCM smob) { - return &footnote_grobs_; + Grob *me = unsmob_grob (smob); + vector footnotes; + SCM grobs_scm = Grob_array::make_array (); + extract_grob_set (me, "all-elements", elts); + for (vsize i = 0; i < elts.size (); i++) + if (elts[i]->internal_has_interface (ly_symbol2scm ("footnote-interface"))) + footnotes.push_back (elts[i]); + + unsmob_grob_array (grobs_scm)->set_array (footnotes); + return grobs_scm; +} + +MAKE_SCHEME_CALLBACK (System, footnotes_after_line_breaking, 1); +SCM +System::footnotes_after_line_breaking (SCM smob) +{ + Spanner *sys_span = unsmob_spanner (smob); + System *sys = dynamic_cast (sys_span); + Interval_t sri = sys->spanned_rank_interval (); + vector footnote_grobs = sys->get_footnote_grobs_in_range (sri[LEFT], sri[RIGHT]); + vector_sort (footnote_grobs, grob_2D_less); + + SCM grobs_scm = Grob_array::make_array (); + unsmob_grob_array (grobs_scm)->set_array (footnote_grobs); + return grobs_scm; } void @@ -356,8 +407,6 @@ System::break_into_pieces (vector const &breaking) Interval iv (pure_height (this, st, end)); system->set_property ("pure-Y-extent", ly_interval2scm (iv)); - get_footnote_grobs_in_range (system->footnote_grobs_, st, end); - system->set_bound (LEFT, c[0]); system->set_bound (RIGHT, c.back ()); SCM system_labels = SCM_EOL; @@ -1001,6 +1050,8 @@ ADD_INTERFACE (System, "all-elements " "columns " "footnote-stencil " + "footnotes-before-line-breaking " + "footnotes-after-line-breaking " "in-note-direction " "in-note-padding " "in-note-stencil " diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index c7960fe76a..e71848e422 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -1031,6 +1031,10 @@ in addition to notes and stems.") (figures ,ly:grob-array? "Figured bass objects for continuation line.") (flag ,ly:grob? "A pointer to a @code{Flag} object.") (footnote-stencil ,ly:stencil? "The stencil of a system's footnotes.") + (footnotes-before-line-breaking ,ly:grob-array? "Footnote grobs of +a whole system.") + (footnotes-after-line-breaking ,ly:grob-array? "Footnote grobs of +a broken system.") (full-score-pure-minimum-translations ,list? "A list of translations for a full score's worth of grobs.") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 85dd188f51..1702585b2e 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -2048,7 +2048,9 @@ (X-extent . ,ly:axis-group-interface::width) (Y-extent . ,ly:system::height) (meta . ((class . System) - (object-callbacks . ((pure-relevant-grobs . ,ly:system::calc-pure-relevant-grobs) + (object-callbacks . ((footnotes-before-line-breaking . ,ly:system::footnotes-before-line-breaking) + (footnotes-after-line-breaking . ,ly:system::footnotes-after-line-breaking) + (pure-relevant-grobs . ,ly:system::calc-pure-relevant-grobs) (pure-Y-common . ,ly:axis-group-interface::calc-pure-y-common))) (interfaces . (axis-group-interface system-interface)))))) -- 2.39.5