]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-column.cc
5c344836d4bf576e5407c629b9eed5d87be6058c
[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--2002 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
23
24 ADD_INTERFACE (Paper_column, "paper-column-interface",
25   "  Paper_columns form the top-most item parent. (The Paper_columns X
26   parent is System, which is a spanner.)
27
28   Paper_columns form the units for the spacing engine. They are
29   numbered, the first (leftmost) is column 0. Numbering happens before
30   line-breaking, and columns are not renumbered after line breaking.
31
32   Since many columns go unused, you should only use the rank field to
33   get ordering information.  Two adjacent columns may have
34   non-adjacent numbers.
35
36   Don't be confused by right-items: each spacing wish can also contain
37   a number of items, with which a spacing constraint may be kept. It's
38   a little baroque, but it might come in handy later on?
39 ",
40   "between-cols between-system-string when bounded-by-me shortest-playing-duration shortest-starter-duration");
41
42
43 void
44 Paper_column::do_break_processing ()
45 {
46   Spaceable_grob::remove_interface (this);
47   Item::do_break_processing ();
48 }
49
50 int
51 Paper_column::rank_i (Grob*me) 
52 {
53   return dynamic_cast<Paper_column*> (me)->rank_i_;
54 }
55
56 System*
57 Paper_column::line_l () const
58 {
59   return line_l_;
60 }
61
62 Paper_column*
63 Paper_column::column_l () const
64 {
65   return (Paper_column*) (this);
66 }
67
68 Paper_column::Paper_column (SCM l)
69   : Item (l)            // guh.?
70 {
71   line_l_=0;
72   rank_i_ = -1;
73 }
74
75 Moment
76 Paper_column::when_mom (Grob*me)
77 {
78   SCM m = me->get_grob_property ("when");
79   Moment s (0);
80   if (unsmob_moment (m))
81     {
82       return *unsmob_moment (m);
83     }
84   return s;
85 }
86
87 bool
88 Paper_column::musical_b (Grob *me)
89 {
90   SCM m = me->get_grob_property ("shortest-starter-duration");
91   Moment s (0);
92   if (unsmob_moment (m))
93     {
94       s = *unsmob_moment (m);
95     }
96   return s != Moment (0);
97   
98 }
99   
100
101 bool
102 Paper_column::used_b (Grob*me)
103 {
104   return gh_pair_p (me->get_grob_property ("elements")) ||  Item::breakable_b (me)
105     || gh_pair_p (me->get_grob_property ("bounded-by-me"))
106     ;
107 }
108
109 /*
110   Print a vertical line and  the rank number, to aid debugging.  
111  */
112
113 MAKE_SCHEME_CALLBACK(Paper_column,brew_molecule,1);
114 SCM
115 Paper_column::brew_molecule (SCM p)
116 {
117   Grob *me = unsmob_grob (p);
118
119   String r = to_str (Paper_column::rank_i (me));
120   SCM properties = Font_interface::font_alist_chain (me);
121   
122   Molecule t = Text_item::text2molecule (me, ly_str02scm (r.ch_C()),
123                                          properties);
124   t.align_to (X_AXIS, CENTER);
125   t.align_to (Y_AXIS, DOWN);
126   
127   Molecule l = Lookup::filledbox (Box (Interval (-0.01, 0.01),
128                                        Interval (-2, -1)));
129
130   t.add_molecule (l);
131   return t.smobbed_copy ();                                             
132 }
133