]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-align-item.cc
release: 1.1.48
[lilypond.git] / lily / break-align-item.cc
1 /*
2   break-align-item.cc -- implement Break_align_item
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "lily-guile.hh"
10 #include "break-align-item.hh"
11 #include "dimensions.hh"
12 #include "p-score.hh"
13 #include "paper-def.hh"
14 #include "p-col.hh"
15
16
17 /*
18   Handle spacing for prefatory matter. 
19
20
21
22   TODO: rewrite this.  It is kludgy
23 */
24
25 void
26 Break_align_item::do_pre_processing()
27 {
28   align_dir_ = break_status_dir();
29   flip (&align_dir_);
30   sort_elements ();
31   Real interline= paper_l ()->get_realvar (interline_scm_sym);  
32   
33   Link_array<Score_element> elems;
34   for (int i=0; i < elem_l_arr_.size(); i++) 
35     {
36       Interval y = elem_l_arr_[i]->extent(axis ());
37       if (!y.empty_b())
38         elems.push (dynamic_cast<Score_element*> (elem_l_arr_[i]));
39     }
40   
41
42   
43   if (!elems.size ())
44     return;
45
46   SCM symbol_list = SCM_EOL;
47   Array<Real> dists;
48   SCM current_origin = gh_str02scm ("");
49   for (int i=0; i <= elems.size (); i++)
50     {
51       Score_element *next_elt  = i < elems.size ()
52         ? elems[i]
53         : 0 ;
54       
55       SCM next_origin;
56
57       if (next_elt)
58         {
59           next_origin = next_elt->get_elt_property (origin_scm_sym);
60           next_origin =
61             (next_origin == SCM_BOOL_F)
62             ? gh_str02scm ("")
63             : SCM_CDR (next_origin);
64         }
65       else
66         next_origin = gh_str02scm ("begin-of-note");
67       
68       SCM extra_space
69         = scm_eval (scm_listify (ly_symbol ("break-align-spacer"),
70                                  current_origin, next_origin, SCM_UNDEFINED)); 
71       SCM symbol = SCM_CAR (extra_space);
72       Real spc = gh_scm2double (SCM_CADR(extra_space));
73       spc *= interline;
74
75       dists.push(spc);
76       symbol_list = gh_cons (symbol, symbol_list);
77       current_origin = next_origin;
78     }
79
80
81   // skip the first sym.
82   symbol_list  = SCM_CDR (scm_reverse (symbol_list));
83   for (int i=0; i <elems.size()-1; i++)
84     {
85       elems[i]->set_elt_property (SCM_CAR (symbol_list),
86                                   scm_cons (gh_double2scm (0),
87                                             gh_double2scm (dists[i+1])));
88
89       symbol_list = SCM_CDR (symbol_list);
90     }
91
92
93   // urg
94   SCM first_pair = elems[0]->get_elt_property (minimum_space_scm_sym);
95   if (first_pair == SCM_BOOL_F)
96     first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
97   else
98     first_pair = SCM_CDR (first_pair);
99   
100   scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
101   elems[0]->set_elt_property (minimum_space_scm_sym, first_pair);
102                                
103
104   
105   Axis_align_item::do_pre_processing();
106
107   Real pre_space = elems[0]->extent (X_AXIS)[LEFT];
108   Real spring_len = elems.top ()->extent (X_AXIS)[RIGHT];
109   if (SCM_CAR (symbol_list) == extra_space_scm_sym)
110     {
111       spring_len += dists.top ();
112     }
113   else if (SCM_CAR (symbol_list) == minimum_space_scm_sym)
114     {
115       spring_len = spring_len >? dists.top ();
116     }
117
118
119   /*
120     Hint the spacing engine how much space to put in.
121   */
122   column_l ()->set_elt_property (extra_space_scm_sym,
123                                  scm_cons (gh_double2scm (pre_space),
124                                            gh_double2scm (spring_len)));
125 }
126
127
128
129 Break_align_item::Break_align_item ()
130 {
131   stacking_dir_ = RIGHT;
132   set_axis (X_AXIS);
133 }
134
135 void
136 Break_align_item::add_breakable_item (Item *it)
137 {
138   SCM pr = it->remove_elt_property (break_priority_scm_sym); 
139
140   if (pr == SCM_BOOL_F)
141     return;
142
143   int priority = gh_scm2int (SCM_CDR (pr));
144
145   Score_element * column_l = get_elt_by_priority (priority);
146   Axis_group_item * hg=0;
147   if (column_l)
148     {
149       hg = dynamic_cast<Axis_group_item*> (column_l);
150     }
151   else
152     {
153       hg = new Axis_group_item;
154       hg->set_axes (X_AXIS,X_AXIS);
155
156       /*
157         this is quite ridiculous, but we do this anyway, to ensure that no
158         warning bells about missing Y refpoints go off later on.
159       */
160       hg->dim_cache_[Y_AXIS]->parent_l_ = dim_cache_[Y_AXIS];
161       hg->set_elt_property (ly_symbol("origin"), gh_str02scm (it->name()));
162
163       pscore_l_->typeset_element (hg);
164       add_element_priority (hg, priority);
165
166       if (priority == 0)
167         center_l_ = hg;
168     }
169   
170   hg->add_element (it);
171 }