]> git.donarmstrong.com Git - lilypond.git/blob - lily/separation-item.cc
* lily/include/translator.icc: new file.
[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 "pointer-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   extract_grob_set (me, "conditional-elements", elts);
43   for (int i = 0; i < elts.size (); i++)
44     {
45       Item *il = dynamic_cast<Item*> (elts[i]);
46       if (pc != il->get_column ())
47         {
48           /* this shouldn't happen, but let's continue anyway. */
49           programming_error ("Separation_item:  I've been drinking too much");
50           continue;             /*UGH UGH*/
51         }
52
53       if (to_boolean (il->get_property ("no-spacing-rods")))
54         {
55           continue;
56         }
57
58       if (Accidental_placement::has_interface (il))
59         {
60           w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
61         }
62     }
63
64   SCM pad = me->get_property ("padding");
65
66   w.widen (robust_scm2double (pad, 0.0));
67   return w;
68 }
69
70 Interval
71 Separation_item::width (Grob *me)
72 {
73   SCM sw = me->get_property ("X-extent");
74   if (is_number_pair (sw))
75     {
76       return ly_scm2interval (sw);
77     }
78
79   Item *item = dynamic_cast<Item *> (me);
80   Paper_column *pc = item->get_column ();
81   Interval w;
82
83   extract_grob_set (me, "elements", elts);
84   for (int i = 0; i < elts.size (); i++)
85     {
86       Item *il = dynamic_cast<Item*> (elts[i]);
87       if (pc != il->get_column ())
88         {
89           /* this shouldn't happen, but let's continue anyway. */
90           programming_error ("Separation_item:  I've been drinking too much");
91           continue;             /*UGH UGH*/
92         }
93
94       if (to_boolean (il->get_property ("no-spacing-rods")))
95         {
96           continue;
97         }
98
99       Interval iv (il->extent (pc, X_AXIS));
100       if (!iv.is_empty ())
101         {
102           w.unite (iv);
103         }
104     }
105
106   SCM pad = me->get_property ("padding");
107
108   w.widen (robust_scm2double (pad, 0.0));
109
110   me->set_property ("X-extent", ly_interval2scm (w));
111
112   return w;
113 }
114
115 Interval
116 Separation_item::relative_width (Grob *me, Grob *common)
117 {
118   Interval iv = width (me);
119
120   return dynamic_cast<Item *> (me)->get_column ()->relative_coordinate (common, X_AXIS) + iv;
121 }
122
123 /*
124   Try to find the break-aligned symbol in SEPARATION_ITEM that is
125   sticking out at direction D. The x size is put in LAST_EXT
126 */
127 Grob *
128 Separation_item::extremal_break_aligned_grob (Grob *me,
129                                               Direction d,
130                                               Interval *last_ext)
131 {
132   Grob *col = dynamic_cast<Item *> (me)->get_column ();
133   last_ext->set_empty ();
134   Grob *last_grob = 0;
135   
136   extract_grob_set (me, "elements", elts);
137   for (int i = elts.size (); i--; )
138     {
139       Grob *break_item = elts[i];
140       if (!scm_is_symbol (break_item->get_property ("break-align-symbol")))
141         continue;
142
143       Interval ext = break_item->extent (col, X_AXIS);
144
145       if (ext.is_empty ())
146         continue;
147
148       if (!last_grob
149           || (last_grob && d * (ext[d]- (*last_ext)[d]) > 0))
150         {
151           *last_ext = ext;
152           last_grob = break_item;
153         }
154     }
155
156   return last_grob;
157 }
158
159 ADD_INTERFACE (Separation_item, "separation-item-interface",
160                "Item that computes widths to generate spacing rods. "
161                "This is done in concert with @ref{separation-spanner-interface}.",
162                "padding X-extent conditional-elements elements");