]> git.donarmstrong.com Git - lilypond.git/blob - lily/separating-group-spanner.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[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       if (Separation_item::set_distance (Drul_array<Item *> (l, r), padding))
41         break;
42
43       /*
44         this grob doesn't cause a constraint. We look further until we
45         find one that does.
46       */
47     }
48 }
49
50 MAKE_SCHEME_CALLBACK (Separating_group_spanner, set_spacing_rods, 1);
51 SCM
52 Separating_group_spanner::set_spacing_rods (SCM smob)
53 {
54   Grob *me = unsmob_grob (smob);
55
56   /*
57     Ugh: padding is added doubly, also for SeparationItem
58   */
59   Real padding = robust_scm2double (me->get_property ("padding"), 0.1);
60
61   extract_grob_set (me, "elements", elts);
62   for (vsize i = elts.size (); i-- > 1;)
63     {
64       Item *r = dynamic_cast<Item *> (elts[i]);
65       if (!r)
66         continue;
67
68       if (Separation_item::width (r).is_empty ())
69         continue;
70
71       Item *rb
72         = dynamic_cast<Item *> (r->find_prebroken_piece (LEFT));
73
74       find_rods (r, elts, i - 1, padding);
75       if (rb)
76         find_rods (rb, elts, i - 1, padding);
77     }
78
79   return SCM_UNSPECIFIED;
80 }
81
82 void
83 Separating_group_spanner::add_spacing_unit (Grob *me, Item *i)
84 {
85   Pointer_group_interface::add_unordered_grob (me, ly_symbol2scm ("elements"), i);
86 }
87
88 ADD_INTERFACE (Separating_group_spanner,
89                "A spanner that calculates spacing constraints (\"rods\") "
90                "using the @code{separation-item-interface} grobs in @code{elements}.",
91
92                /* properties */
93                "elements "
94                "padding ");