2 item.cc -- implement Item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 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"
22 return new Item (*this);
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)
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;
71 Grob *dolly = clone ();
72 Item *item = dynamic_cast<Item *> (dolly);
73 get_root_system (this)->typeset_grob (item);
76 while (flip (&i) != LEFT);
78 broken_to_drul_ = new_copies;
82 Item::is_broken () const
84 return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
88 Generate items for begin and end-of line.
91 Item::discretionary_processing ()
96 if (Item::is_non_musical (this))
97 copy_breakable_items ();
101 Item::find_broken_piece (System *l) const
103 if (get_system () == l)
104 return (Item *) (this);
109 Grob *s = broken_to_drul_[d];
110 if (s && s->get_system () == l)
113 while (flip (&d) != LEFT);
119 Item::find_prebroken_piece (Direction d) const
121 Item *me = (Item *) (this);
124 return dynamic_cast<Item *> (broken_to_drul_[d]);
128 Item::break_status_dir () const
132 Item *i = dynamic_cast<Item *> (original ());
134 return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
141 Item::handle_prebroken_dependencies ()
143 Grob::handle_prebroken_dependencies ();
146 Can't do this earlier, because try_visibility_lambda () might set
147 the elt property transparent, which would then be copied.
149 SCM vis = get_property ("break-visibility");
150 if (scm_is_vector (vis))
152 bool visible = to_boolean (scm_c_vector_ref (vis, break_status_dir () + 1));
160 Item::pure_is_visible (int start, int end) const
162 SCM vis = get_property ("break-visibility");
163 if (scm_is_vector (vis))
166 int pc_rank = Paper_column::get_rank (get_column ());
167 if (pc_rank == start)
169 else if (pc_rank == end)
171 return to_boolean (scm_vector_ref (vis, scm_from_int (pos)));
177 Item::spanned_rank_iv ()
179 int c = get_column ()->get_rank ();
180 return Interval_t<int> (c, c);
184 Item::derived_mark () const
186 if (broken_to_drul_[LEFT])
187 scm_gc_mark (broken_to_drul_[LEFT]->self_scm ());
188 if (broken_to_drul_[RIGHT])
189 scm_gc_mark (broken_to_drul_[RIGHT]->self_scm ());
195 return dynamic_cast<Item *> (unsmob_grob (s));
200 "Grobs can be distinguished in their role in the horizontal spacing.\n"
201 "Many grobs define constraints on the spacing by their sizes. For\n"
202 "example, note heads, clefs, stems, and all other symbols with a fixed\n"
203 "shape. These grobs form a subtype called @code{Item}.\n"
206 "Some items need special treatment for line breaking. For example, a\n"
207 "clef is normally only printed at the start of a line (i.e. after a\n"
208 "line break). To model this, `breakable' items (clef, key signature,\n"
209 "bar lines, etc.) are copied twice. Then we have three versions of each\n"
210 "breakable item: one version if there is no line break, one version\n"
211 "that is printed before the line break (at the end of a system), one\n"
212 "version that is printed after the line break.\n"
214 "Whether these versions are visible and take up space, is determined by\n"
215 "the outcome of the @code{break-visibility}. This grob property is a\n"
216 "function taking a direction (-1, 0 or 1) as argument. It returns a\n"
217 "cons of booleans, signifying whether this grob should be transparent\n"
218 "and have no extent.\n"
220 "The following variables for break-visibility are predefined:\n"
222 " grob will show: before no after\n"
223 " break break break\n"
224 " all-invisible no no no\n"
225 " begin-of-line-visible no no yes\n"
226 " end-of-line-visible yes no no\n"
227 " all-visible yes yes yes\n"
228 " begin-of-line-invisible yes yes no\n"
229 " end-of-line-invisible no yes yes\n"
230 " center-invisible yes no yes\n"
235 "extra-spacing-width "
236 "infinite-spacing-height "