]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
* input/proportional.ly: use #'used property. Set break-overshoot property.
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.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 ADD_INTERFACE (Paper_column, "paper-column-interface",
30                "@code{Paper_column} objects form the top-most X-parents for items."
31                "  The are two types of columns: musical columns, where are attached to, and "
32                "  non-musical columns, where bar-lines, clefs etc. are attached to. "
33                "  The spacing engine determines the X-positions of these objects."
34                
35                "\n\n"
36                "They are\n"
37                "  numbered, the first (leftmost) is column 0. Numbering happens before\n"
38                "  line-breaking, and columns are not renumbered after line breaking.\n"
39                "  Since many columns go unused, you should only use the rank field to\n"
40                "  get ordering information.  Two adjacent columns may have\n"
41                "  non-adjacent numbers.\n",
42                
43                
44                "between-cols "
45                "bounded-by-me "
46                "page-penalty "
47                "shortest-playing-duration "
48                "shortest-starter-duration "
49                "used "
50                "when ");
51
52 void
53 Paper_column::do_break_processing ()
54 {
55   Spaceable_grob::remove_interface (this);
56   Item::do_break_processing ();
57 }
58
59 int
60 Paper_column::get_rank (Grob *me)
61 {
62   return dynamic_cast<Paper_column *> (me)->rank_;
63 }
64
65 System *
66 Paper_column::get_system () const
67 {
68   return system_;
69 }
70
71 Paper_column *
72 Paper_column::get_column () const
73 {
74   return (Paper_column *) (this);
75 }
76
77 Paper_column::Paper_column (SCM l, Object_key const *key)
78   : Item (l, key)               // guh.?
79 {
80   system_ = 0;
81   rank_ = -1;
82 }
83
84 Paper_column::Paper_column (Paper_column const &src, int count)
85   : Item (src, count)
86 {
87   system_ = 0;
88   rank_ = src.rank_;
89 }
90
91 Moment
92 Paper_column::when_mom (Grob *me)
93 {
94   SCM m = me->get_property ("when");
95   if (Moment *when = unsmob_moment (m))
96     return *when;
97   return Moment (0);
98 }
99
100 bool
101 Paper_column::is_musical (Grob *me)
102 {
103   SCM m = me->get_property ("shortest-starter-duration");
104   Moment s (0);
105   if (unsmob_moment (m))
106     s = *unsmob_moment (m);
107   return s != Moment (0);
108 }
109
110 bool
111 Paper_column::is_used (Grob *me)
112 {
113   extract_grob_set (me, "elements", elts);
114   if (elts.size ())
115     return true;
116
117   extract_grob_set (me, "bounded-by-me", bbm);
118   if (bbm.size ())
119     return true;
120   
121   if (Item::is_breakable (me))
122     return true;
123
124   if (to_boolean (me->get_property ("used")))
125     return true;
126   return false;
127 }
128
129 /*
130   Print a vertical line and  the rank number, to aid debugging.
131 */
132
133 MAKE_SCHEME_CALLBACK (Paper_column, print, 1);
134 SCM
135 Paper_column::print (SCM p)
136 {
137   Grob *me = unsmob_grob (p);
138
139   String r = to_string (Paper_column::get_rank (me));
140
141   Moment *mom = unsmob_moment (me->get_property ("when"));
142   String when = mom ? mom->to_string () : "?/?";
143
144   SCM properties = Font_interface::text_font_alist_chain (me);
145
146   SCM scm_mol = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
147                                                   properties,
148                                                   scm_makfrom0str (r.to_str0 ()));
149   SCM when_mol = Text_interface::interpret_markup (me->get_layout ()->self_scm (),
150                                                    properties,
151                                                    scm_makfrom0str (when.to_str0 ()));
152   Stencil t = *unsmob_stencil (scm_mol);
153   t.add_at_edge (Y_AXIS, DOWN, *unsmob_stencil (when_mol), 0.1, 0.1);
154   t.align_to (X_AXIS, CENTER);
155   t.align_to (Y_AXIS, DOWN);
156
157   Stencil l = Lookup::filled_box (Box (Interval (-0.01, 0.01),
158                                        Interval (-2, -1)));
159
160   t.add_stencil (l);
161   return t.smobbed_copy ();
162 }
163
164 /*
165   This is all too hairy. We use bounded-by-me to make sure that some
166   columns are kept "alive". Unfortunately, when spanners are suicided,
167   this falls apart again, because suicided spanners are still in
168   bounded-by-me
169
170   THIS IS BROKEN KLUDGE. WE SHOULD INVENT SOMETHING BETTER.
171 */
172 MAKE_SCHEME_CALLBACK (Paper_column, before_line_breaking, 1);
173 SCM
174 Paper_column::before_line_breaking (SCM grob)
175 {
176   Grob *me = unsmob_grob (grob);
177
178   SCM bbm = me->get_object ("bounded-by-me");
179   Grob_array *ga = unsmob_grob_array (bbm);
180   if (!ga)
181     return SCM_UNSPECIFIED;
182
183   Link_array<Grob> &array (ga->array_reference ());
184
185   for (int i = array.size (); i--;)
186     {
187       Grob *g = array[i];
188
189       if (!g || !g->is_live ())
190         {                       // UGH . potentially quadratic.
191           array.del (i);
192         }
193     }
194
195   return SCM_UNSPECIFIED;
196 }