]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[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 const *me)
38 {
39   return dynamic_cast<Paper_column const *> (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   Paper_column *pa = dynamic_cast<Paper_column*> (a);
87   Paper_column *pb = dynamic_cast<Paper_column*> (b);
88   
89   return pa->rank_ < pb->rank_;
90 }
91
92 Moment
93 Paper_column::when_mom (Grob *me)
94 {
95   SCM m = me->get_property ("when");
96   if (Moment *when = unsmob_moment (m))
97     return *when;
98   return Moment (0);
99 }
100
101 bool
102 Paper_column::is_musical (Grob *me)
103 {
104   SCM m = me->get_property ("shortest-starter-duration");
105   Moment s (0);
106   if (unsmob_moment (m))
107     s = *unsmob_moment (m);
108   return s != Moment (0);
109 }
110
111 bool
112 Paper_column::is_used (Grob *me)
113 {
114   extract_grob_set (me, "elements", elts);
115   if (elts.size ())
116     return true;
117
118   extract_grob_set (me, "bounded-by-me", bbm);
119   if (bbm.size ())
120     return true;
121   
122   if (Paper_column::is_breakable (me))
123     return true;
124
125   if (to_boolean (me->get_property ("used")))
126     return true;
127   return false;
128 }
129
130 bool
131 Paper_column::is_breakable (Grob *me)
132 {
133   return scm_is_symbol (me->get_property ("line-break-permission"));
134 }
135
136 /*
137   Print a vertical line and  the rank number, to aid debugging.
138 */
139
140 MAKE_SCHEME_CALLBACK (Paper_column, print, 1);
141 SCM
142 Paper_column::print (SCM p)
143 {
144   Grob *me = unsmob_grob (p);
145
146   string r = to_string (Paper_column::get_rank (me));
147
148   Moment *mom = unsmob_moment (me->get_property ("when"));
149   string when = mom ? mom->to_string () : "?/?";
150
151   SCM properties = Font_interface::text_font_alist_chain (me);
152
153   SCM scm_mol = Text_interface::interpret_markup (me->layout ()->self_scm (),
154                                                   properties,
155                                                   scm_makfrom0str (r.c_str ()));
156   SCM when_mol = Text_interface::interpret_markup (me->layout ()->self_scm (),
157                                                    properties,
158                                                    scm_makfrom0str (when.c_str ()));
159   Stencil t = *unsmob_stencil (scm_mol);
160   t.add_at_edge (Y_AXIS, DOWN, *unsmob_stencil (when_mol), 0.1, 0.1);
161   t.align_to (X_AXIS, CENTER);
162   t.align_to (Y_AXIS, DOWN);
163
164   Stencil l = Lookup::filled_box (Box (Interval (-0.01, 0.01),
165                                        Interval (-2, -1)));
166
167   t.add_stencil (l);
168   return t.smobbed_copy ();
169 }
170
171 /*
172   This is all too hairy. We use bounded-by-me to make sure that some
173   columns are kept "alive". Unfortunately, when spanners are suicided,
174   this falls apart again, because suicided spanners are still in
175   bounded-by-me
176
177   THIS IS BROKEN KLUDGE. WE SHOULD INVENT SOMETHING BETTER.
178 */
179 MAKE_SCHEME_CALLBACK (Paper_column, before_line_breaking, 1);
180 SCM
181 Paper_column::before_line_breaking (SCM grob)
182 {
183   Grob *me = unsmob_grob (grob);
184
185   SCM bbm = me->get_object ("bounded-by-me");
186   Grob_array *ga = unsmob_grob_array (bbm);
187   if (!ga)
188     return SCM_UNSPECIFIED;
189
190   vector<Grob*> &array (ga->array_reference ());
191
192   for (vsize i = array.size (); i--;)
193     {
194       Grob *g = array[i];
195
196       if (!g || !g->is_live ())
197         /* UGH . potentially quadratic. */
198         array.erase (array.begin () + i);
199     }
200
201   return SCM_UNSPECIFIED;
202 }
203
204
205 ADD_INTERFACE (Paper_column,
206                "@code{Paper_column} objects form the top-most X-parents for items."
207                "  The are two types of columns: musical columns, where are attached to, and "
208                "  non-musical columns, where bar-lines, clefs etc. are attached to. "
209                "  The spacing engine determines the X-positions of these objects."
210                
211                "\n\n"
212                "They are\n"
213                "  numbered, the first (leftmost) is column 0. Numbering happens before\n"
214                "  line-breaking, and columns are not renumbered after line breaking.\n"
215                "  Since many columns go unused, you should only use the rank field to\n"
216                "  get ordering information.  Two adjacent columns may have\n"
217                "  non-adjacent numbers.\n",
218                
219
220                /* properties */
221                "between-cols "
222                "bounded-by-me "
223                "grace-spacing " 
224                "line-break-system-details "
225                "line-break-penalty "
226                "line-break-permission "
227                "page-break-penalty "
228                "page-break-permission "
229                "page-turn-penalty "
230                "page-turn-permission "
231                "rhythmic-location "
232                "shortest-playing-duration "
233                "shortest-starter-duration "
234                "spacing "
235                "used "
236                "when ");
237