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