]> git.donarmstrong.com Git - lilypond.git/blob - lily/page-layout-problem.cc
fb9e27d12bb95f8bf5faa1561af1a5acabf7334d
[lilypond.git] / lily / page-layout-problem.cc
1 /*
2   page-layout-problem.cc -- space systems nicely on a page. If systems can
3   be stretched, do that too.
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2009 Joe Neeman <joeneeman@gmail.com>
8 */
9
10 #include "page-layout-problem.hh"
11
12 #include "align-interface.hh"
13 #include "axis-group-interface.hh"
14 #include "hara-kiri-group-spanner.hh"
15 #include "international.hh"
16 #include "item.hh"
17 #include "output-def.hh"
18 #include "paper-book.hh"
19 #include "pointer-group-interface.hh"
20 #include "prob.hh"
21 #include "skyline-pair.hh"
22 #include "system.hh"
23
24 Page_layout_problem::Page_layout_problem (Paper_book *pb, SCM page_scm, SCM systems)
25   : bottom_skyline_ (DOWN)
26 {
27   Prob *page = unsmob_prob (page_scm);
28   header_height_ = 0;
29   footer_height_ = 0;
30   header_padding_ = 0;
31   footer_padding_ = 0;
32   page_height_ = 100;
33
34   if (page)
35     {
36       Stencil *head = unsmob_stencil (page->get_property ("head-stencil"));
37       Stencil *foot = unsmob_stencil (page->get_property ("foot-stencil"));
38
39       header_height_ = head ? head->extent (Y_AXIS).length () : 0;
40       footer_height_ = foot ? foot->extent (Y_AXIS).length () : 0;
41       page_height_ = robust_scm2double (page->get_property ("paper-height"), 100);
42     }
43
44   // Initially, bottom_skyline_ represents the top of the page. Make
45   // it solid, so that the top of the first system will be forced
46   // below the top of the printable area.
47   bottom_skyline_.set_minimum_height (-header_height_);
48
49   SCM between_system_spacing = SCM_EOL;
50   SCM after_title_spacing = SCM_EOL;
51   SCM before_title_spacing = SCM_EOL;
52   SCM between_title_spacing = SCM_EOL;
53
54   // first_system_spacing controls the spring from the top of the printable
55   // area to the first staff. It allows the user to control the offset of
56   // the first staff (as opposed to the top of the first system) from the
57   // top of the page. Similarly for last_system_spacing.
58   SCM first_system_spacing = SCM_EOL;
59   SCM last_system_spacing = SCM_EOL;
60   if (pb && pb->paper_)
61     {
62       Output_def *paper = pb->paper_;
63       between_system_spacing = paper->c_variable ("between-system-spacing");
64       after_title_spacing = paper->c_variable ("after-title-spacing");
65       before_title_spacing = paper->c_variable ("before-title-spacing");
66       between_title_spacing = paper->c_variable ("between-title-spacing");
67       last_system_spacing = paper->c_variable ("last-system-spacing");
68       first_system_spacing = paper->c_variable ("first-system-spacing");
69       if (scm_is_pair (systems) && unsmob_prob (scm_car (systems)))
70         first_system_spacing = paper->c_variable ("first-system-title-spacing");
71
72       // Note: the page height here does _not_ reserve space for headers and
73       // footers. This is because we want to anchor the first-system-spacing
74       // spring at the _top_ of the header.
75       page_height_ -= robust_scm2double (paper->c_variable ("top-margin"), 0)
76         + robust_scm2double (paper->c_variable ("bottom-margin"), 0);
77
78       read_spacing_spec (first_system_spacing, &header_padding_, ly_symbol2scm ("padding"));
79       read_spacing_spec (last_system_spacing, &footer_padding_, ly_symbol2scm ("padding"));
80     }
81   bool last_system_was_title = false;
82
83
84   for (SCM s = systems; scm_is_pair (s); s = scm_cdr (s))
85     {
86       bool first = (s == systems);
87
88       if (Grob *g = unsmob_grob (scm_car (s)))
89         {
90           System *sys = dynamic_cast<System*> (g);
91           if (!sys)
92             {
93               programming_error ("got a grob for vertical spacing that wasn't a System");
94               continue;
95             }
96
97           SCM spec = first ? first_system_spacing
98             : (last_system_was_title ? after_title_spacing : between_system_spacing);
99           Spring spring (first ? 0 : 1, 0.0);
100           Real padding = 0.0;
101           alter_spring_from_spacing_spec (spec, &spring);
102           read_spacing_spec (spec, &padding, ly_symbol2scm ("padding"));
103
104           append_system (sys, spring, padding);
105           last_system_was_title = false;
106         }
107       else if (Prob *p = unsmob_prob (scm_car (s)))
108         {
109           SCM spec = first ? first_system_spacing
110             : (last_system_was_title ? between_title_spacing : before_title_spacing);
111           Spring spring (first ? 0 : 1, 0.0);
112           Real padding = 0.0;
113           alter_spring_from_spacing_spec (spec, &spring);
114           read_spacing_spec (spec, &padding, ly_symbol2scm ("padding"));
115
116           append_prob (p, spring, padding);
117           last_system_was_title = true;
118         }
119       else
120         programming_error ("got a system that was neither a Grob nor a Prob");
121     }
122
123   Spring last_spring (0, 0);
124   Real last_padding = 0;
125   alter_spring_from_spacing_spec (last_system_spacing, &last_spring);
126   read_spacing_spec (last_system_spacing, &last_padding, ly_symbol2scm ("padding"));
127   last_spring.ensure_min_distance (last_padding - bottom_skyline_.max_height () + footer_height_);
128   springs_.push_back (last_spring);
129
130   if (elements_.size ())
131     {
132       Real bottom_padding;
133
134       // TODO: junk bottom-space now that we have last-system-spacing?
135       // bottom-space has the flexibility that one can do it per-system.
136       // NOTE: bottom-space is misnamed since it is not stretchable space.
137       if (Prob *p = elements_.back ().prob)
138         bottom_padding = robust_scm2double (p->get_property ("bottom-space"), 0);
139       else if (elements_.back ().staves.size ())
140         {
141           SCM details = get_details (elements_.back ());
142           bottom_padding = robust_scm2double (ly_assoc_get (ly_symbol2scm ("bottom-space"),
143                                                             details,
144                                                             SCM_BOOL_F),
145                                               0.0);
146         }
147       page_height_ -= bottom_padding;
148     }
149 }
150
151 void
152 Page_layout_problem::set_header_height (Real height)
153 {
154   header_height_ = height;
155 }
156
157 void
158 Page_layout_problem::set_footer_height (Real height)
159 {
160   footer_height_ = height;
161 }
162
163 void
164 Page_layout_problem::append_system (System *sys, Spring const& spring, Real padding)
165 {
166   Grob *align = sys->get_vertical_alignment ();
167   if (!align)
168     return;
169
170   align->set_property ("positioning-done", SCM_BOOL_T);
171
172   extract_grob_set (align, "elements", all_elts);
173   vector<Grob*> elts = filter_dead_elements (all_elts);
174   vector<Real> minimum_offsets = Align_interface::get_minimum_translations (align, elts, Y_AXIS,
175                                                                             false, 0, 0);
176
177   Skyline up_skyline (UP);
178   Skyline down_skyline (DOWN);
179   build_system_skyline (elts, minimum_offsets, &up_skyline, &down_skyline);
180
181   Real minimum_distance = up_skyline.distance (bottom_skyline_) + padding;
182
183   Spring spring_copy = spring;
184   spring_copy.ensure_min_distance (minimum_distance);
185   springs_.push_back (spring_copy);
186
187   bottom_skyline_ = down_skyline;
188   elements_.push_back (Element (elts, minimum_offsets));
189
190   // Add the springs for the VerticalAxisGroups in this system.
191
192   // If the user has specified the offsets of the individual staves, fix the
193   // springs at the given distances. Otherwise, use stretchable springs.
194   SCM details = get_details (elements_.back ());
195   SCM manual_dists = ly_assoc_get (ly_symbol2scm ("alignment-distances"), details, SCM_EOL);
196   vsize last_spaceable_staff = 0;
197   bool found_spaceable_staff = false;
198   for (vsize i = 0; i < elts.size (); ++i)
199     {
200       if (is_spaceable (elts[i]))
201         {
202           // We don't add a spring for the first staff, since
203           // we are only adding springs _between_ staves here.
204           if (!found_spaceable_staff)
205             {
206               found_spaceable_staff = true;
207               last_spaceable_staff = i;
208               continue;
209             }
210
211           Spring spring (0.5, 0.0);
212           SCM spec = elts[last_spaceable_staff]->get_property ("next-staff-spacing");
213           alter_spring_from_spacing_spec (spec, &spring);
214
215           springs_.push_back (spring);
216           Real min_distance = (found_spaceable_staff ? minimum_offsets[last_spaceable_staff] : 0) - minimum_offsets[i];
217           springs_.back ().ensure_min_distance (min_distance);
218
219           if (scm_is_pair (manual_dists))
220             {
221               if (scm_is_number (scm_car (manual_dists)))
222                 {
223                   Real dy = scm_to_double (scm_car (manual_dists));
224
225                   springs_.back ().set_distance (dy);
226                   springs_.back ().set_min_distance (dy);
227                   springs_.back ().set_inverse_stretch_strength (0);
228                 }
229               manual_dists = scm_cdr (manual_dists);
230             }
231           last_spaceable_staff = i;
232         }
233     }
234
235   // Corner case: there was only one staff, and it wasn't spaceable.
236   // Mark it spaceable, because we do not allow non-spaceable staves
237   // to be at the top or bottom of a system.
238   if (!found_spaceable_staff && elts.size ())
239     mark_as_spaceable (elts[0]);
240 }
241
242 void
243 Page_layout_problem::append_prob (Prob *prob, Spring const& spring, Real padding)
244 {
245   Skyline_pair *sky = Skyline_pair::unsmob (prob->get_property ("vertical-skylines"));
246   Real minimum_distance = 0;
247   if (sky)
248     {
249       minimum_distance = (*sky)[UP].distance (bottom_skyline_);
250       bottom_skyline_ = (*sky)[DOWN];
251     }
252   else if (Stencil *sten = unsmob_stencil (prob->get_property ("stencil")))
253     {
254       Interval iv = sten->extent (Y_AXIS);
255       minimum_distance = iv[UP] - bottom_skyline_.max_height ();
256
257       bottom_skyline_.clear ();
258       bottom_skyline_.set_minimum_height (iv[DOWN]);
259     }
260   minimum_distance += padding;
261
262   Spring spring_copy = spring;
263   spring_copy.ensure_min_distance (minimum_distance);
264   springs_.push_back (spring_copy);
265   elements_.push_back (Element (prob));
266 }
267
268 void
269 Page_layout_problem::solve_rod_spring_problem (bool ragged)
270 {
271   Simple_spacer spacer;
272
273   for (vsize i = 0; i < springs_.size (); ++i)
274     spacer.add_spring (springs_[i]);
275
276   spacer.solve (page_height_, ragged);
277   solution_ = spacer.spring_positions ();
278 }
279
280 // The solution_ vector stores the position of every live VerticalAxisGroup
281 // and every title. From that information,
282 // 1) within each system, stretch the staves so they land at the right position
283 // 2) find the offset of each system (relative to the printable area of the page).
284 // TODO: this function is getting too long, maybe split it up?
285 SCM
286 Page_layout_problem::find_system_offsets ()
287 {
288   SCM system_offsets = SCM_EOL;
289   SCM *tail = &system_offsets;
290
291   // spring_idx 0 is the top of the page. Interesting values start from 1.
292   vsize spring_idx = 1;
293   vector<Grob*> loose_lines;
294   vector<Real> loose_line_min_distances;
295   Grob *last_spaceable_line = 0;
296   Real last_spaceable_line_translation = 0;
297   for (vsize i = 0; i < elements_.size (); ++i)
298     {
299       if (elements_[i].prob)
300         {
301           *tail = scm_cons (scm_from_double (solution_[spring_idx]), SCM_EOL);
302           tail = SCM_CDRLOC (*tail);
303
304           // Lay out any non-spaceable lines between this line and
305           // the last one.
306           if (loose_lines.size ())
307             {
308               Interval loose_extent = loose_lines.back ()->extent (loose_lines.back (), Y_AXIS);
309               Interval prob_extent = unsmob_stencil (elements_[i].prob->get_property ("stencil"))->extent (Y_AXIS);
310               Real min_distance = -loose_extent[DOWN] + prob_extent[UP]; // TODO: include padding/minimum-distance
311
312               loose_line_min_distances.push_back (min_distance);
313               loose_lines.push_back (0);
314
315               distribute_loose_lines (loose_lines, loose_line_min_distances,
316                                       last_spaceable_line_translation, -solution_[spring_idx]);
317               loose_lines.clear ();
318               loose_line_min_distances.clear ();
319             }
320
321           last_spaceable_line = 0;
322           last_spaceable_line_translation = -solution_[spring_idx];
323           spring_idx++;
324         }
325       else
326         {
327           // Getting this signs right here is a little tricky. The configuration
328           // we return has zero at the top of the page and positive numbers further
329           // down, as does the solution_ vector.  Within a staff, however, positive
330           // numbers are up.
331           // TODO: perhaps change the way the page 'configuration variable works so
332           // that it is consistent with the usual up/down sign conventions in
333           // Lilypond. Then this would be less confusing.
334
335           // These two positions are relative to the page (with positive numbers being
336           // down).
337           Real first_staff_position = solution_[spring_idx];
338           Real first_staff_min_translation = elements_[i].min_offsets.size () ? elements_[i].min_offsets[0] : 0;
339           Real system_position = first_staff_position + first_staff_min_translation;
340
341           // Position the staves within this system.
342           Real translation = 0;
343           vector<Real> const& min_offsets = elements_[i].min_offsets;
344           bool found_spaceable_staff = false;
345           for (vsize staff_idx = 0; staff_idx < elements_[i].staves.size (); ++staff_idx)
346             {
347               Grob *staff = elements_[i].staves[staff_idx];
348               staff->set_property ("system-Y-offset", scm_from_double (-system_position));
349
350               if (is_spaceable (staff))
351                 {
352                   // this is relative to the system: negative numbers are down.
353                   translation = system_position - solution_[spring_idx];
354                   spring_idx++;
355
356                   // Lay out any non-spaceable lines between this line and
357                   // the last one.
358                   if (loose_lines.size ())
359                     {
360                       loose_line_min_distances.push_back (min_offsets[staff_idx-1] - min_offsets[staff_idx]);
361                       loose_lines.push_back (staff);
362
363                       distribute_loose_lines (loose_lines, loose_line_min_distances,
364                                               last_spaceable_line_translation, translation - system_position);
365                       loose_lines.clear ();
366                       loose_line_min_distances.clear ();
367                     }
368                   last_spaceable_line = staff;
369                   // Negative is down but the translation is relative to the whole page.
370                   last_spaceable_line_translation = -system_position + translation;
371
372                   staff->translate_axis (translation, Y_AXIS);
373                   found_spaceable_staff = true;
374                 }
375               else
376                 {
377                   if (loose_lines.empty ())
378                     loose_lines.push_back (last_spaceable_line);
379
380                   loose_lines.push_back (staff);
381                   if (staff_idx)
382                     loose_line_min_distances.push_back (min_offsets[staff_idx-1] - min_offsets[staff_idx]);
383                   else
384                     {
385                       Real min_dist = 0;
386                       if (last_spaceable_line)
387                         min_dist = Axis_group_interface::minimum_distance (last_spaceable_line,
388                                                                            staff,
389                                                                            Y_AXIS);
390                       else // distance to the top margin
391                         min_dist = header_padding_ + header_height_ + staff->extent (staff, Y_AXIS)[UP];
392
393                       loose_line_min_distances.push_back (min_dist);
394                     }
395                 }
396             }
397
398           // Corner case: even if a system has no live staves, it still takes up
399           // one spring (a system with one live staff also takes up one spring),
400           // which we need to increment past.
401           if (!found_spaceable_staff)
402             spring_idx++;
403
404           *tail = scm_cons (scm_from_double (system_position), SCM_EOL);
405           tail = SCM_CDRLOC (*tail);
406         }
407     }
408
409   if (loose_lines.size ())
410     {
411       Grob *last = loose_lines.back ();
412       Interval last_ext = last->extent (last, Y_AXIS);
413       loose_line_min_distances.push_back (-last_ext[DOWN] + footer_height_ + footer_padding_);
414       loose_lines.push_back (0);
415
416       distribute_loose_lines (loose_lines, loose_line_min_distances,
417                               last_spaceable_line_translation, -page_height_);
418
419     }
420
421   assert (spring_idx == solution_.size () - 1);
422   return system_offsets;
423 }
424
425 // Given two lines that are already spaced (the first and last
426 // elements of loose_lines), distribute some unspaced lines between
427 // them.
428 void
429 Page_layout_problem::distribute_loose_lines (vector<Grob*> const &loose_lines,
430                                              vector<Real> const &min_distances,
431                                              Real first_translation, Real last_translation)
432 {
433   Simple_spacer spacer;
434   for (vsize i = 0; i + 1 < loose_lines.size (); ++i)
435     {
436       SCM spec = get_spacing_spec (loose_lines[i], loose_lines[i+1]);
437       Spring spring (1.0, 0.0);
438       alter_spring_from_spacing_spec (spec, &spring);
439       spring.ensure_min_distance (min_distances[i]);
440
441       if ((spec == SCM_BOOL_F && loose_lines[0] && loose_lines.back ())
442           || !loose_lines[i]
443           || !loose_lines[i+1])
444         {
445           // Insert a very flexible spring, so it doesn't have much effect.
446           // TODO: set a default distance and a compress strength so that a
447           // lyrics line, for example, will stay closer to the top staff
448           // even in a compressed configuration.
449           spring.set_inverse_stretch_strength (100000);
450           spring.set_inverse_compress_strength (100000);
451         }
452
453       spacer.add_spring (spring);
454     }
455
456   // Remember: offsets are decreasing, since we're going from UP to DOWN!
457   spacer.solve (first_translation - last_translation, false);
458
459   vector<Real> solution = spacer.spring_positions ();
460   for (vsize i = 1; i + 1 < solution.size (); ++i)
461     {
462       Real system_offset = scm_to_double (loose_lines[i]->get_property ("system-Y-offset"));
463       loose_lines[i]->translate_axis (first_translation - solution[i] - system_offset, Y_AXIS);
464     }
465 }
466
467 SCM
468 Page_layout_problem::solution (bool ragged)
469 {
470   solve_rod_spring_problem (ragged);
471   return find_system_offsets ();
472 }
473
474 // Build upper and lower skylines for a system. We don't yet know the positions
475 // of the staves within the system, so we make the skyline as conservative as
476 // possible. That is, for the upper skyline, we pretend that all of the staves
477 // in the system are packed together close to the top system; for the lower
478 // skyline, we pretend that all of the staves are packed together close to
479 // the bottom system.
480 //
481 // The upper skyline is relative to the top staff; the lower skyline is relative to
482 // the bottom staff.
483 void
484 Page_layout_problem::build_system_skyline (vector<Grob*> const& staves,
485                                            vector<Real> const& minimum_translations,
486                                            Skyline *up,
487                                            Skyline *down)
488 {
489   if (minimum_translations.empty ())
490     return;
491
492   assert (staves.size () == minimum_translations.size ());
493   Real first_translation = minimum_translations[0];
494   Real last_spaceable_dy = 0;
495   Real first_spaceable_dy = 0;
496   bool found_spaceable_staff;
497
498   for (vsize i = 0; i < staves.size (); ++i)
499     {
500       Real dy = minimum_translations[i] - first_translation;
501       Grob *g = staves[i];
502       Skyline_pair *sky = Skyline_pair::unsmob (g->get_property ("vertical-skylines"));
503       if (sky)
504         {
505           up->raise (-dy);
506           up->merge ((*sky)[UP]);
507           up->raise (dy);
508
509           down->raise (-dy);
510           down->merge ((*sky)[DOWN]);
511           down->raise (dy);
512         }
513       if (is_spaceable (staves[i]))
514         {
515           if (!found_spaceable_staff)
516             {
517               found_spaceable_staff = true;
518               first_spaceable_dy = dy;
519             }
520           last_spaceable_dy = dy;
521         }
522     }
523
524   // Leave the up skyline at a position relative
525   // to the top spaceable staff.
526   up->raise (-first_spaceable_dy);
527
528   // Leave the down skyline at a position
529   // relative to the bottom spaceable staff.
530   down->raise (-last_spaceable_dy);
531 }
532
533 Interval
534 Page_layout_problem::prob_extent (Prob *p)
535 {
536   Stencil *sten = unsmob_stencil (p->get_property ("stencil"));
537   return sten ? sten->extent (Y_AXIS) : Interval (0, 0);
538 }
539
540 Interval
541 Page_layout_problem::first_staff_extent (Element const& e)
542 {
543   if (e.prob)
544     return prob_extent (e.prob);
545   else if (e.staves.size ())
546     return e.staves[0]->extent (e.staves[0], Y_AXIS);
547
548   return Interval (0, 0);
549 }
550
551 Interval
552 Page_layout_problem::last_staff_extent (Element const& e)
553 {
554   if (e.prob)
555     return prob_extent (e.prob);
556   else if (e.staves.size ())
557     return e.staves.back ()->extent (e.staves.back (), Y_AXIS);
558
559   return Interval (0, 0);
560 }
561
562 SCM
563 Page_layout_problem::get_details (Element const& elt)
564 {
565   if (elt.staves.empty ())
566     return SCM_EOL;
567
568   return get_details (elt.staves.back ()->get_system ());
569 }
570
571 SCM
572 Page_layout_problem::get_details (Grob *g)
573 {
574   Grob *left_bound = dynamic_cast<Spanner*> (g)->get_bound (LEFT);
575   return left_bound->get_property ("line-break-system-details");
576 }
577
578 bool
579 Page_layout_problem::is_spaceable (Grob *g)
580 {
581   return !scm_is_number (g->get_property ("staff-affinity"));
582 }
583
584 void
585 Page_layout_problem::mark_as_spaceable (Grob *g)
586 {
587   g->set_property ("staff-affinity", SCM_BOOL_F);
588 }
589
590 bool
591 Page_layout_problem::read_spacing_spec (SCM spec, Real* dest, SCM sym)
592 {
593   SCM pair = scm_sloppy_assq (sym, spec);
594   if (scm_is_pair (pair) && scm_is_number (scm_cdr (pair)))
595     {
596       *dest = scm_to_double (scm_cdr (pair));
597       return true;
598     }
599   return false;
600 }
601
602 // Returns the spacing spec connecting BEFORE to AFTER.  A return
603 // value of SCM_BOOL_F means that there should be no spring (in
604 // practice, this means that we use a very flexible spring).
605 SCM
606 Page_layout_problem::get_spacing_spec (Grob *before, Grob *after)
607 {
608   if (!before || !after)
609     return SCM_BOOL_F;
610
611   if (is_spaceable (before))
612     {
613       if (is_spaceable (after))
614         return before->get_property ("next-staff-spacing");
615       else
616         {
617           Direction affinity = to_dir (after->get_property ("staff-affinity"));
618           return (affinity == DOWN) ? SCM_BOOL_F : after->get_property ("inter-staff-spacing");
619         }
620     }
621   else
622     {
623       if (is_spaceable (after))
624         {
625           Direction affinity = to_dir (before->get_property ("staff-affinity"));
626           return (affinity == UP) ? SCM_BOOL_F : before->get_property ("inter-staff-spacing");
627         }
628       else
629         {
630           Direction before_affinity = to_dir (before->get_property ("staff-affinity"));
631           Direction after_affinity = to_dir (after->get_property ("staff-affinity"));
632           if (after_affinity > before_affinity)
633             {
634               warning (_ ("staff-affinities should only decrease"));
635               after_affinity = before_affinity;
636             }
637           if (before_affinity != UP)
638             return before->get_property ("inter-loose-line-spacing");
639           else if (after_affinity != DOWN)
640             return before->get_property ("inter-loose-line-spacing");
641         }
642     }
643   return SCM_BOOL_F;
644 }
645
646 void
647 Page_layout_problem::alter_spring_from_spacing_spec (SCM spec, Spring* spring)
648 {
649   Real space;
650   Real stretch;
651   Real min_dist;
652   if (read_spacing_spec (spec, &space, ly_symbol2scm ("space")))
653     spring->set_distance (space);
654   if (read_spacing_spec (spec, &min_dist, ly_symbol2scm ("minimum-distance")))
655     spring->set_min_distance (min_dist);
656   spring->set_default_strength ();
657
658   if (read_spacing_spec (spec, &stretch, ly_symbol2scm ("stretchability")))
659     {
660       spring->set_inverse_stretch_strength (stretch);
661       spring->set_inverse_compress_strength (stretch);
662     }
663 }
664
665 vector<Grob*>
666 Page_layout_problem::filter_dead_elements (vector<Grob*> const& input)
667 {
668   vector<Grob*> output;
669   for (vsize i = 0; i < input.size (); ++i)
670     {
671       if (Hara_kiri_group_spanner::has_interface (input[i]))
672         Hara_kiri_group_spanner::consider_suicide (input[i]);
673
674       if (input[i]->is_live ())
675         output.push_back (input[i]);
676     }
677
678   return output;
679 }