2 item.cc -- implement Item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "axis-group-interface.hh"
12 #include "paper-score.hh"
14 #include "paper-column.hh"
15 #include "lily-guile.hh"
17 #include "pointer-group-interface.hh"
20 Item::clone (int count) const
22 return new Item (*this, count);
25 Item::Item (SCM s, Object_key const *key)
28 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] = 0;
32 Item copy ctor. Copy nothing: everything should be a elt property
33 or a special purpose pointer (such as broken_to_drul_[]) */
34 Item::Item (Item const &s, int copy_count)
35 : Grob (s, copy_count)
37 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] = 0;
41 Item::is_non_musical (Grob *me)
46 Item *i = dynamic_cast<Item *> (me->get_parent (X_AXIS));
47 return i ? Item::is_non_musical (i) : to_boolean (me->get_property ("non-musical"));
51 Item::get_column () const
53 Item *parent = dynamic_cast<Item *> (get_parent (X_AXIS));
54 return parent ? parent->get_column () : 0;
58 Item::get_system () const
60 Grob *g = get_parent (X_AXIS);
61 return g ? g->get_system () : 0;
65 Item::copy_breakable_items ()
67 Drul_array<Item *> new_copies;
72 Grob *dolly = clone (count++);
73 Item *item = dynamic_cast<Item *> (dolly);
74 get_root_system (this)->typeset_grob (item);
77 while (flip (&i) != LEFT);
79 broken_to_drul_ = new_copies;
83 Item::is_broken () const
85 return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
89 Generate items for begin and end-of line.
92 Item::discretionary_processing ()
97 if (Item::is_non_musical (this))
98 copy_breakable_items ();
102 Item::find_broken_piece (System *l) const
104 if (get_system () == l)
105 return (Item *) (this);
110 Grob *s = broken_to_drul_[d];
111 if (s && s->get_system () == l)
114 while (flip (&d) != LEFT);
120 Item::find_prebroken_piece (Direction d) const
122 Item *me = (Item *) (this);
125 return dynamic_cast<Item *> (broken_to_drul_[d]);
129 Item::break_status_dir () const
133 Item *i = dynamic_cast<Item *> (original ());
135 return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
142 Item::handle_prebroken_dependencies ()
144 Grob::handle_prebroken_dependencies ();
147 Can't do this earlier, because try_visibility_lambda () might set
148 the elt property transparent, which would then be copied.
150 SCM vis = get_property ("break-visibility");
151 if (scm_is_vector (vis))
153 bool visible = to_boolean (scm_c_vector_ref (vis, break_status_dir () + 1));
161 Item::pure_is_visible (int start, int end) const
163 SCM vis = get_property ("break-visibility");
164 if (scm_is_vector (vis))
167 int pc_rank = Paper_column::get_rank (get_column ());
168 if (pc_rank == start)
170 else if (pc_rank == end)
172 return to_boolean (scm_vector_ref (vis, scm_from_int (pos)));
178 Item::spanned_rank_iv ()
180 int c = get_column ()->get_rank ();
181 return Interval_t<int> (c, c);
185 Item::derived_mark () const
187 if (broken_to_drul_[LEFT])
188 scm_gc_mark (broken_to_drul_[LEFT]->self_scm ());
189 if (broken_to_drul_[RIGHT])
190 scm_gc_mark (broken_to_drul_[RIGHT]->self_scm ());
196 return dynamic_cast<Item *> (unsmob_grob (s));
201 "Grobs can be distinguished in their role in the horizontal spacing.\n"
202 "Many grobs define constraints on the spacing by their sizes. For\n"
203 "example, note heads, clefs, stems, and all other symbols with a fixed\n"
204 "shape. These grobs form a subtype called @code{Item}.\n"
207 "Some items need special treatment for line breaking. For example, a\n"
208 "clef is normally only printed at the start of a line (i.e. after a\n"
209 "line break). To model this, `breakable' items (clef, key signature,\n"
210 "bar lines, etc.) are copied twice. Then we have three versions of each\n"
211 "breakable item: one version if there is no line break, one version\n"
212 "that is printed before the line break (at the end of a system), one\n"
213 "version that is printed after the line break.\n"
215 "Whether these versions are visible and take up space, is determined by\n"
216 "the outcome of the @code{break-visibility}. This grob property is a\n"
217 "function taking a direction (-1, 0 or 1) as argument. It returns a\n"
218 "cons of booleans, signifying whether this grob should be transparent\n"
219 "and have no extent.\n"
221 "The following variables for break-visibility are predefined:\n"
223 " grob will show: before no after\n"
224 " break break break\n"
225 " all-invisible no no no\n"
226 " begin-of-line-visible no no yes\n"
227 " end-of-line-visible yes no no\n"
228 " all-visible yes yes yes\n"
229 " begin-of-line-invisible yes yes no\n"
230 " end-of-line-invisible no yes yes\n"
231 " center-invisible yes no yes\n"