]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-align-item.cc
release: 1.3.6
[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 "dimension-cache.hh"
10 #include "lily-guile.hh"
11 #include "break-align-item.hh"
12 #include "dimensions.hh"
13 #include "paper-score.hh"
14 #include "paper-def.hh"
15 #include "paper-column.hh"
16
17 /*
18   Handle spacing for prefatory matter. 
19
20   TODO: rewrite this.  It is kludgy
21 */
22
23 void
24 Break_align_item::do_pre_processing()
25 {
26   if (break_status_dir() == LEFT)
27     align_dir_ = LEFT;
28   else
29     align_dir_ = RIGHT;
30   
31   flip (&align_dir_);
32   sort_elements ();
33   Real interline= paper_l ()->get_var ("interline");    
34   
35   Link_array<Score_element> elems;
36   for (int i=0; i < elem_l_arr_.size(); i++) 
37     {
38       Interval y = elem_l_arr_[i]->extent(axis ());
39       if (!y.empty_b())
40         elems.push (dynamic_cast<Score_element*> (elem_l_arr_[i]));
41     }
42   
43   if (!elems.size ())
44     return;
45
46   SCM symbol_list = SCM_EOL;
47   Array<Real> dists;
48   SCM current_origin = ly_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");
60           next_origin =
61             (next_origin == SCM_UNDEFINED)
62             ? ly_str02scm ("")
63             : next_origin;
64         }
65       else
66         next_origin = ly_str02scm ("begin-of-note");
67       
68       SCM extra_space
69         = scm_eval (scm_listify (ly_symbol2scm ("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       String sym_str = ly_scm2string (SCM_CAR (symbol_list));
86       elems[i]->set_elt_property (sym_str,
87                                   scm_cons (gh_double2scm (0),
88                                             gh_double2scm (dists[i+1])));
89
90       symbol_list = SCM_CDR (symbol_list);
91     }
92
93
94   // urg
95   SCM first_pair = elems[0]->get_elt_property ("minimum-space");
96   if (first_pair == SCM_UNDEFINED)
97     first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
98   else
99     first_pair = first_pair;
100   
101   scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
102   elems[0]->set_elt_property ("minimum-space", first_pair);
103   
104   Axis_align_item::do_pre_processing();
105
106
107   Real pre_space = elems[0]->extent (X_AXIS)[LEFT]
108     + elems[0]->relative_coordinate (column_l (), X_AXIS);
109   Real spring_len = elems.top ()->extent (X_AXIS)[RIGHT]
110     + elems.top ()->relative_coordinate (column_l (), X_AXIS);
111   
112   Real stretch_distance =0.;
113   
114   if (SCM_CAR (symbol_list) == ly_symbol2scm ("extra-space"))
115     {
116       spring_len += dists.top ();
117       stretch_distance = dists.top ();
118     }
119   else if (SCM_CAR (symbol_list) == ly_symbol2scm ("minimum-space"))
120     {
121       spring_len = spring_len >? dists.top ();
122       stretch_distance = spring_len;
123     }
124
125   /*
126     Hint the spacing engine how much space to put in.
127
128
129     The pairs are in the format of an interval (ie. CAR <  CDR).
130   */
131   column_l ()->set_elt_property ("extra-space",
132                                  scm_cons (gh_double2scm (pre_space),
133                                            gh_double2scm (spring_len)));
134
135   column_l ()->set_elt_property ("stretch-distance",
136                                  gh_cons (gh_double2scm (-dists[0]),
137                                           gh_double2scm (stretch_distance)));
138                                  
139 }
140
141 Break_align_item::Break_align_item ()
142 {
143   stacking_dir_ = RIGHT;
144   set_axis (X_AXIS);
145 }