X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhara-kiri-group-spanner.cc;h=ce06c40ee1bfc723f05cdbdf29ce27997b004ef4;hb=058370efc7e9710f149d0f444328bb1fcd7bdec1;hp=859ae78df4d98c18dbf9df3cf2813bfe68fd1c4b;hpb=62f221b6b3861ff055dc0384ec3c48cc665688cd;p=lilypond.git diff --git a/lily/hara-kiri-group-spanner.cc b/lily/hara-kiri-group-spanner.cc index 859ae78df4..ce06c40ee1 100644 --- a/lily/hara-kiri-group-spanner.cc +++ b/lily/hara-kiri-group-spanner.cc @@ -1,10 +1,21 @@ /* - hara-kiri-vertical-group-spanner.cc -- implement Hara_kiri_group_spanner + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter - - (c) 1998--2008 Jan Nieuwenhuizen + Copyright (C) 1998--2014 Jan Nieuwenhuizen Han-Wen Nienhuys + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "hara-kiri-group-spanner.hh" @@ -59,12 +70,26 @@ bool find_in_range (SCM vector, int low, int hi, int min, int max) if (val >= min && val <= max) return true; else if (val < min) - return find_in_range (vector, mid+1, hi, min, max); + return find_in_range (vector, mid + 1, hi, min, max); return find_in_range (vector, low, mid, min, max); } bool Hara_kiri_group_spanner::request_suicide (Grob *me, int start, int end) +{ + if (!request_suicide_alone (me, start, end)) + return false; + + extract_grob_set (me, "keep-alive-with", friends); + for (vsize i = 0; i < friends.size (); ++i) + if (friends[i]->is_live () && !request_suicide_alone (friends[i], start, end)) + return false; + + return true; +} + +bool +Hara_kiri_group_spanner::request_suicide_alone (Grob *me, int start, int end) { if (!to_boolean (me->get_property ("remove-empty"))) return false; @@ -78,7 +103,7 @@ Hara_kiri_group_spanner::request_suicide (Grob *me, int start, int end) { int len = scm_c_vector_length (important); if (find_in_range (important, 0, len, start, end)) - return false; + return false; } else /* build the important-columns-cache */ { @@ -86,17 +111,17 @@ Hara_kiri_group_spanner::request_suicide (Grob *me, int start, int end) vector ranks; for (vsize i = 0; i < worth.size (); i++) - { - Interval_t iv = worth[i]->spanned_rank_interval (); - for (int j = iv[LEFT]; j <= iv[RIGHT]; j++) - ranks.push_back (j); - } + { + Interval_t iv = worth[i]->spanned_rank_interval (); + for (int j = iv[LEFT]; j <= iv[RIGHT]; j++) + ranks.push_back (j); + } vector_sort (ranks, less ()); uniq (ranks); SCM scm_vec = scm_c_make_vector (ranks.size (), SCM_EOL); for (vsize i = 0; i < ranks.size (); i++) - scm_vector_set_x (scm_vec, scm_from_int (i), scm_from_int (ranks[i])); + scm_vector_set_x (scm_vec, scm_from_int (i), scm_from_int (ranks[i])); me->set_property ("important-column-ranks", scm_vec); return request_suicide (me, start, end); @@ -108,13 +133,17 @@ Hara_kiri_group_spanner::request_suicide (Grob *me, int start, int end) void Hara_kiri_group_spanner::consider_suicide (Grob *me) { - Spanner *sp = dynamic_cast (me); - int left = sp->get_bound (LEFT)->get_column ()->get_rank (); - int right = sp->get_bound (RIGHT)->get_column ()->get_rank (); + Spanner *sp = dynamic_cast (me); + int left = 0; + int right = INT_MAX; + if (Item *l = sp->get_bound (LEFT)) + left = l->get_column ()->get_rank (); + if (Item *r = sp->get_bound (RIGHT)) + right = r->get_column ()->get_rank (); if (!request_suicide (me, left, right)) return; - vector childs; + vector childs; Axis_group_interface::get_children (me, &childs); for (vsize i = 0; i < childs.size (); i++) childs[i]->suicide (); @@ -154,15 +183,15 @@ Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n) } ADD_INTERFACE (Hara_kiri_group_spanner, - "A group spanner that keeps track of interesting items. If it" - " doesn't contain any after line breaking, it removes itself" - " and all its children.", - - /* properties */ - "items-worth-living " - "important-column-ranks " - "remove-empty " - "remove-first " - ); - + "A group spanner that keeps track of interesting items. If it" + " doesn't contain any after line breaking, it removes itself" + " and all its children.", + + /* properties */ + "items-worth-living " + "important-column-ranks " + "keep-alive-with " + "remove-empty " + "remove-first " + );