]> git.donarmstrong.com Git - lilypond.git/blob - lily/separation-item.cc
* flower
[lilypond.git] / lily / separation-item.cc
1 /*
2   separation-item.cc -- implement Separation_item
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "separation-item.hh"
10
11 #include "paper-column.hh"
12 #include "warn.hh"
13 #include "group-interface.hh"
14 #include "accidental-placement.hh"
15
16 void
17 Separation_item::add_item (Grob *s, Item *i)
18 {
19   assert (i);
20   Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"), i);
21   s->add_dependency (i);
22 }
23
24 void
25 Separation_item::add_conditional_item (Grob *me, Grob *e)
26 {
27   Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
28 }
29
30 /*
31   Return the width of ME given that we are considering the object on
32   the LEFT.
33 */
34 Interval
35 Separation_item::conditional_width (Grob *me, Grob *left)
36 {
37   Interval w = width (me);
38
39   Item *item = dynamic_cast<Item *> (me);
40   Paper_column *pc = item->get_column ();
41
42   for (SCM s = me->get_property ("conditional-elements"); scm_is_pair (s); s = scm_cdr (s))
43     {
44       SCM elt = scm_car (s);
45       if (!unsmob_grob (elt))
46         continue;
47
48       Item *il = unsmob_item (elt);
49       if (pc != il->get_column ())
50         {
51           /* this shouldn't happen, but let's continue anyway. */
52           programming_error (_ ("Separation_item:  I've been drinking too much"));
53           continue;             /*UGH UGH*/
54         }
55
56       if (to_boolean (il->get_property ("no-spacing-rods")))
57         {
58           continue;
59         }
60
61       if (Accidental_placement::has_interface (il))
62         {
63           w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
64         }
65     }
66
67   SCM pad = me->get_property ("padding");
68
69   w.widen (robust_scm2double (pad, 0.0));
70   return w;
71 }
72
73 Interval
74 Separation_item::width (Grob *me)
75 {
76   SCM sw = me->get_property ("X-extent");
77   if (is_number_pair (sw))
78     {
79       return ly_scm2interval (sw);
80     }
81
82   Item *item = dynamic_cast<Item *> (me);
83   Paper_column *pc = item->get_column ();
84   Interval w;
85
86   for (SCM s = me->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
87     {
88       SCM elt = scm_car (s);
89       if (!unsmob_grob (elt))
90         continue;
91
92       Item *il = unsmob_item (elt);
93       if (pc != il->get_column ())
94         {
95           /* this shouldn't happen, but let's continue anyway. */
96           programming_error (_ ("Separation_item:  I've been drinking too much"));
97           continue;             /*UGH UGH*/
98         }
99
100       if (to_boolean (il->get_property ("no-spacing-rods")))
101         {
102           continue;
103         }
104
105       Interval iv (il->extent (pc, X_AXIS));
106       if (!iv.is_empty ())
107         {
108           w.unite (iv);
109         }
110     }
111
112   SCM pad = me->get_property ("padding");
113
114   w.widen (robust_scm2double (pad, 0.0));
115
116   me->set_property ("X-extent", ly_interval2scm (w));
117
118   return w;
119 }
120
121 Interval
122 Separation_item::relative_width (Grob *me, Grob *common)
123 {
124   Interval iv = width (me);
125
126   return dynamic_cast<Item *> (me)->get_column ()->relative_coordinate (common, X_AXIS) + iv;
127 }
128
129 /*
130   Try to find the break-aligned symbol in SEPARATION_ITEM that is
131   sticking out at direction D. The x size is put in LAST_EXT
132 */
133 Grob *
134 Separation_item::extremal_break_aligned_grob (Grob *separation_item, Direction d,
135                                               Interval *last_ext)
136 {
137   Grob *col = dynamic_cast<Item *> (separation_item)->get_column ();
138   last_ext->set_empty ();
139   Grob *last_grob = 0;
140   for (SCM s = separation_item->get_property ("elements");
141        scm_is_pair (s); s = scm_cdr (s))
142     {
143       Grob *break_item = unsmob_grob (scm_car (s));
144
145       if (!scm_is_symbol (break_item->get_property ("break-align-symbol")))
146         continue;
147
148       Interval ext = break_item->extent (col, X_AXIS);
149
150       if (ext.is_empty ())
151         continue;
152       if (!last_grob
153           || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0))
154         {
155           *last_ext = ext;
156           last_grob = break_item;
157         }
158     }
159
160   return last_grob;
161 }
162
163
164 ADD_INTERFACE (Separation_item, "separation-item-interface",
165                "Item that computes widths to generate spacing rods. "
166                "This is done in concert with @ref{separation-spanner-interface}.",
167                "padding X-extent conditional-elements elements");