]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-group-spanner.cc
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / separating-group-spanner.cc
1 /*
2   separating-group-spanner.cc -- implement Separating_group_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "separating-group-spanner.hh"
10
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "output-def.hh"
14 #include "dimensions.hh"
15 #include "pointer-group-interface.hh"
16
17 void
18 Separating_group_spanner::find_rods (Item *r,
19                                      vector<Grob*> const &separators,
20                                      vsize idx,
21                                      Real padding)
22 {
23
24   /*
25     This is an inner loop: look for the first normal (unbroken) Left
26     grob.  This looks like an inner loop (ie. quadratic total), but in
27     most cases, the interesting L will just be the first entry of
28     NEXT, making it linear in most of the cases.
29   */
30   for (; idx != VPOS; idx--)
31     {
32       Item *l = dynamic_cast<Item *> (separators[idx]);
33       Item *lb = l->find_prebroken_piece (RIGHT);
34
35       if (lb)
36         {
37           Separation_item::set_distance (Drul_array<Item*> (lb, r), padding);
38         }
39
40       Separation_item::set_distance (Drul_array<Item *> (l, r), padding);
41
42       /*
43         this grob doesn't cause a constraint. We look further until we
44         find one that does.
45       */
46     }
47 }
48
49 MAKE_SCHEME_CALLBACK (Separating_group_spanner, set_spacing_rods, 1);
50 SCM
51 Separating_group_spanner::set_spacing_rods (SCM smob)
52 {
53   Grob *me = unsmob_grob (smob);
54
55   /*
56     Ugh: padding is added doubly, also for SeparationItem
57   */
58   Real padding = robust_scm2double (me->get_property ("padding"), 0.1);
59
60   extract_grob_set (me, "elements", elts);
61   for (vsize i = elts.size (); i-- > 1;)
62     {
63       Item *r = dynamic_cast<Item *> (elts[i]);
64       if (!r)
65         continue;
66
67       if (Separation_item::width (r).is_empty ())
68         continue;
69
70       Item *rb
71         = dynamic_cast<Item *> (r->find_prebroken_piece (LEFT));
72
73       find_rods (r, elts, i - 1, padding);
74       if (rb)
75         find_rods (rb, elts, i - 1, padding);
76     }
77
78   return SCM_UNSPECIFIED;
79 }
80
81 void
82 Separating_group_spanner::add_spacing_unit (Grob *me, Item *i)
83 {
84   Pointer_group_interface::add_unordered_grob (me, ly_symbol2scm ("elements"), i);
85 }
86
87 ADD_INTERFACE (Separating_group_spanner,
88                "A spanner that calculates spacing constraints (\"rods\") "
89                "using the @code{separation-item-interface} grobs in @code{elements}.",
90
91                /* properties */
92                "elements "
93                "padding ");