]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
789a9cfa7362f83c2b9ac2983b3af3209cdc149d
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "moment.hh"
10 #include "paper-column.hh"
11 #include "paper-score.hh"
12 #include "debug.hh"
13 #include "axis-group-interface.hh"
14 #include "spaceable-grob.hh"
15 #include "molecule.hh"
16 #include "text-item.hh"
17 #include "lookup.hh"
18 #include "font-interface.hh"
19
20
21 /*
22   Paper_columns form the top-most item parent. (The Paper_columns X
23   parent is Line_of_score, which is a spanner.)
24
25   Paper_columns form the units for the spacing engine. They are
26   numbered, the first (leftmost) is column 0. Numbering happens before
27   line-breaking, and columns are not renumbered after line breaking.
28
29   Since many columns go unused, you should only use the rank field to
30   get ordering information.  Two adjacent columns may have
31   non-adjacent numbers.
32   
33  */
34
35 void
36 Paper_column::do_break_processing ()
37 {
38   Spaceable_grob::remove_interface (this);
39   Item::do_break_processing ();
40 }
41
42 int
43 Paper_column::rank_i (Grob*me) 
44 {
45   return dynamic_cast<Paper_column*> (me)->rank_i_;
46 }
47
48 Line_of_score*
49 Paper_column::line_l () const
50 {
51   return line_l_;
52 }
53
54 Paper_column*
55 Paper_column::column_l () const
56 {
57   return (Paper_column*) (this);
58 }
59
60 Paper_column::Paper_column (SCM l)
61   : Item (l)            // guh.?
62 {
63   Axis_group_interface::set_interface (this);
64   Axis_group_interface::set_axes (this, X_AXIS, X_AXIS);
65   Spaceable_grob::set_interface (this);
66
67   line_l_=0;
68   rank_i_ = -1;
69 }
70
71 Moment
72 Paper_column::when_mom (Grob*me)
73 {
74   SCM m = me->get_grob_property ("when");
75   Moment s (0);
76   if (unsmob_moment (m))
77     {
78       return *unsmob_moment (m);
79     }
80   return s;
81 }
82
83 bool
84 Paper_column::musical_b (Grob *me)
85 {
86   SCM m = me->get_grob_property ("shortest-starter-duration");
87   Moment s (0);
88   if (unsmob_moment (m))
89     {
90       s = *unsmob_moment (m);
91     }
92   return s != Moment (0);
93   
94 }
95   
96
97 bool
98 Paper_column::used_b (Grob*me)
99 {
100   return gh_pair_p (me->get_grob_property ("elements")) ||  Item::breakable_b (me)
101     || gh_pair_p (me->get_grob_property ("bounded-by-me"))
102     ;
103 }
104
105 /*
106   Print a vertical line and  the rank number, to aid debugging.  
107  */
108
109 MAKE_SCHEME_CALLBACK(Paper_column,brew_molecule,1);
110 SCM
111 Paper_column::brew_molecule (SCM p)
112 {
113   Grob *me = unsmob_grob (p);
114
115   String r = to_str (Paper_column::rank_i (me));
116   SCM properties = Font_interface::font_alist_chain (me);
117   
118   Molecule t = Text_item::text2molecule (me, ly_str02scm (r.ch_C()),
119                                          properties);
120   t.align_to (X_AXIS, CENTER);
121   t.align_to (Y_AXIS, DOWN);
122   
123   Molecule l = Lookup::filledbox (Box (Interval (-0.01, 0.01),
124                                        Interval (-2, -1)));
125
126   t.add_molecule (l);
127   return t.smobbed_copy ();                                             
128 }
129