]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
* lily/spanner.cc (find_broken_piece):
[lilypond.git] / lily / paper-column.cc
1 /*
2   paper-column.cc -- implement Paper_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "paper-column.hh"
10
11 #include "moment.hh"
12 #include "paper-score.hh"
13 #include "warn.hh"
14 #include "axis-group-interface.hh"
15 #include "spaceable-grob.hh"
16 #include "text-interface.hh"
17 #include "lookup.hh"
18 #include "font-interface.hh"
19 #include "output-def.hh"
20 #include "pointer-group-interface.hh"
21 #include "grob-array.hh"
22
23 Grob *
24 Paper_column::clone (int count) const
25 {
26   return new Paper_column (*this, count);
27 }
28
29 void
30 Paper_column::do_break_processing ()
31 {
32   Spaceable_grob::remove_interface (this);
33   Item::do_break_processing ();
34 }
35
36 int
37 Paper_column::get_rank (Grob *me)
38 {
39   return dynamic_cast<Paper_column *> (me)->rank_;
40 }
41
42 System *
43 Paper_column::get_system () const
44 {
45   return system_;
46 }
47
48 void
49 Paper_column::set_system (System *s)
50 {
51   system_ = s;
52 }
53
54 Paper_column *
55 Paper_column::get_column () const
56 {
57   return (Paper_column *) (this);
58 }
59
60 Paper_column::Paper_column (SCM l, Object_key const *key)
61   : Item (l, key)               // guh.?
62 {
63   system_ = 0;
64   rank_ = -1;
65 }
66
67 Paper_column::Paper_column (Paper_column const &src, int count)
68   : Item (src, count)
69 {
70   system_ = 0;
71   rank_ = src.rank_;
72 }
73
74 int
75 Paper_column::compare (Grob * const &a,
76                        Grob * const &b)
77 {
78   return sign (dynamic_cast<Paper_column*> (a)->rank_
79                - dynamic_cast<Paper_column*> (b)->rank_);
80 }
81
82 bool
83 Paper_column::less_than (Grob *const &a,
84                          Grob *const &b)
85 {
86   return dynamic_cast<Paper_column*> (a)->rank_ < dynamic_cast<Paper_column*> (b)->rank_;
87 }
88
89 Moment
90 Paper_column::when_mom (Grob *me)
91 {
92   SCM m = me->get_property ("when");
93   if (Moment *when = unsmob_moment (m))
94     return *when;
95   return Moment (0);
96 }
97
98 bool
99 Paper_column::is_musical (Grob *me)
100 {
101   SCM m = me->get_property ("shortest-starter-duration");
102   Moment s (0);
103   if (unsmob_moment (m))
104     s = *unsmob_moment (m);
105   return s != Moment (0);
106 }
107
108 bool
109 Paper_column::is_used (Grob *me)
110 {
111   extract_grob_set (me, "elements", elts);
112   if (elts.size ())
113     return true;
114
115   extract_grob_set (me, "bounded-by-me", bbm);
116   if (bbm.size ())
117     return true;
118   
119   if (Paper_column::is_breakable (me))
120     return true;
121
122   if (to_boolean (me->get_property ("used")))
123     return true;
124   return false;
125 }
126
127 bool
128 Paper_column::is_breakable (Grob *me)
129 {
130   return scm_is_symbol (me->get_property ("line-break-permission"));
131 }
132
133 /*
134   Print a vertical line and  the rank number, to aid debugging.
135 */
136
137 MAKE_SCHEME_CALLBACK (Paper_column, print, 1);
138 SCM
139 Paper_column::print (SCM p)
140 {
141   Grob *me = unsmob_grob (p);
142
143   string r = to_string (Paper_column::get_rank (me));
144
145   Moment *mom = unsmob_moment (me->get_property ("when"));
146   string when = mom ? mom->to_string () : "?/?";
147
148   SCM properties = Font_interface::text_font_alist_chain (me);
149
150   SCM scm_mol = Text_interface::interpret_markup (me->layout ()->self_scm (),
151                                                   properties,
152                                                   scm_makfrom0str (r.c_str ()));
153   SCM when_mol = Text_interface::interpret_markup (me->layout ()->self_scm (),
154                                                    properties,
155                                                    scm_makfrom0str (when.c_str ()));
156   Stencil t = *unsmob_stencil (scm_mol);
157   t.add_at_edge (Y_AXIS, DOWN, *unsmob_stencil (when_mol), 0.1, 0.1);
158   t.align_to (X_AXIS, CENTER);
159   t.align_to (Y_AXIS, DOWN);
160
161   Stencil l = Lookup::filled_box (Box (Interval (-0.01, 0.01),
162                                        Interval (-2, -1)));
163
164   t.add_stencil (l);
165   return t.smobbed_copy ();
166 }
167
168 /*
169   This is all too hairy. We use bounded-by-me to make sure that some
170   columns are kept "alive". Unfortunately, when spanners are suicided,
171   this falls apart again, because suicided spanners are still in
172   bounded-by-me
173
174   THIS IS BROKEN KLUDGE. WE SHOULD INVENT SOMETHING BETTER.
175 */
176 MAKE_SCHEME_CALLBACK (Paper_column, before_line_breaking, 1);
177 SCM
178 Paper_column::before_line_breaking (SCM grob)
179 {
180   Grob *me = unsmob_grob (grob);
181
182   SCM bbm = me->get_object ("bounded-by-me");
183   Grob_array *ga = unsmob_grob_array (bbm);
184   if (!ga)
185     return SCM_UNSPECIFIED;
186
187   vector<Grob*> &array (ga->array_reference ());
188
189   for (vsize i = array.size (); i--;)
190     {
191       Grob *g = array[i];
192
193       if (!g || !g->is_live ())
194         /* UGH . potentially quadratic. */
195         array.erase (array.begin () + i);
196     }
197
198   return SCM_UNSPECIFIED;
199 }
200
201
202 ADD_INTERFACE (Paper_column,
203
204                "paper-column-interface",
205                "@code{Paper_column} objects form the top-most X-parents for items."
206                "  The are two types of columns: musical columns, where are attached to, and "
207                "  non-musical columns, where bar-lines, clefs etc. are attached to. "
208                "  The spacing engine determines the X-positions of these objects."
209                
210                "\n\n"
211                "They are\n"
212                "  numbered, the first (leftmost) is column 0. Numbering happens before\n"
213                "  line-breaking, and columns are not renumbered after line breaking.\n"
214                "  Since many columns go unused, you should only use the rank field to\n"
215                "  get ordering information.  Two adjacent columns may have\n"
216                "  non-adjacent numbers.\n",
217                
218
219                /* properties */
220                "between-cols "
221                "bounded-by-me "
222                "grace-spacing " 
223                "line-break-system-details "
224                "line-break-penalty "
225                "line-break-permission "
226                "page-break-penalty "
227                "page-break-permission "
228                "page-turn-penalty "
229                "page-turn-permission "
230                "shortest-playing-duration "
231                "shortest-starter-duration "
232                "spacing "
233                "used "
234                "when ");
235