Bump version.
[lilypond.git] / lily / spaceable-grob.cc
blob0412edcf02a2b537d7172e0fffd9aa015f3ba6ff
1 /*
2 spaceable-grob.cc -- implement Spaceable_grob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "spaceable-grob.hh"
11 #include <cstdio>
13 #include "warn.hh"
14 #include "spring.hh"
15 #include "pointer-group-interface.hh"
16 #include "grob.hh"
17 #include "paper-column.hh"
18 #include "international.hh"
20 SCM
21 Spaceable_grob::get_minimum_distances (Grob *me)
23 return me->get_object ("minimum-distances");
26 /*todo: merge code of spring & rod?
28 void
29 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
31 // printf ("rod %lf\n", d);
32 if (d < 0)
33 return;
35 if (isinf (d))
36 programming_error ("infinite rod");
38 SCM mins = get_minimum_distances (me);
39 SCM newdist = scm_from_double (d);
40 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
42 SCM dist = scm_car (s);
43 if (scm_car (dist) == p->self_scm ())
45 scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
46 newdist));
47 return;
51 if (Paper_column::get_rank (p) < Paper_column::get_rank (me))
52 programming_error ("Adding reverse rod");
54 mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
55 me->set_object ("minimum-distances", mins);
58 void
59 Spaceable_grob::add_spring (Grob *me, Grob *other, Spring sp)
61 SCM ideal = me->get_object ("ideal-distances");
63 ideal = scm_cons (scm_cons (sp.smobbed_copy (), other->self_scm ()), ideal);
64 me->set_object ("ideal-distances", ideal);
67 Spring
68 Spaceable_grob::get_spring (Grob *this_col, Grob *next_col)
70 Spring *spring = 0;
72 for (SCM s = this_col->get_object ("ideal-distances");
73 !spring && scm_is_pair (s);
74 s = scm_cdr (s))
76 if (scm_is_pair (scm_car (s))
77 && unsmob_grob (scm_cdar (s)) == next_col
78 && unsmob_spring (scm_caar (s)))
79 spring = unsmob_spring (scm_caar (s));
82 if (!spring)
83 programming_error (_f ("No spring between column %d and next one",
84 Paper_column::get_rank (this_col)));
86 return spring ? *spring : Spring ();
91 ADD_INTERFACE (Spaceable_grob,
92 "A layout object that takes part in the spacing problem.",
94 /* properties */
95 "allow-loose-spacing "
96 "ideal-distances "
97 "keep-inside-line "
98 "left-neighbors "
99 "measure-length "
100 "minimum-distances "
101 "right-neighbors "
102 "spacing-wishes "