]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-align-item.cc
release: 1.3.22
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <math.h>
9
10 #include "warn.hh"
11 #include "dimension-cache.hh"
12 #include "lily-guile.hh"
13 #include "break-align-item.hh"
14 #include "dimensions.hh"
15 #include "paper-score.hh"
16 #include "paper-def.hh"
17 #include "paper-column.hh"
18
19 /*
20   Handle spacing for prefatory matter. 
21
22   TODO: rewrite this.  It is kludgy
23 */
24
25 void
26 Break_align_item::do_pre_processing()
27 {
28   if (break_status_dir() == LEFT)
29     align_dir_ = LEFT;
30   else
31     align_dir_ = RIGHT;
32   
33   flip (&align_dir_);
34
35   Real interline= paper_l ()->get_var ("interline");    
36   
37   Link_array<Score_element> elems;
38   Link_array<Score_element> all_elems (elem_l_arr ());
39   
40   for (int i=0; i < all_elems.size(); i++) 
41     {
42       Interval y = all_elems[i]->extent(axis ());
43       if (!y.empty_b())
44         elems.push (dynamic_cast<Score_element*> (all_elems[i]));
45     }
46   
47   if (!elems.size ())
48     return;
49
50   SCM symbol_list = SCM_EOL;
51   Array<Real> dists;
52   SCM current_origin = ly_str02scm ("");
53   for (int i=0; i <= elems.size (); i++)
54     {
55       Score_element *next_elt  = i < elems.size ()
56         ? elems[i]
57         : 0 ;
58       
59       SCM next_origin;
60
61       if (next_elt)
62         {
63           next_origin = next_elt->get_elt_property ("origin");
64           next_origin =
65             (next_origin == SCM_UNDEFINED)
66             ? ly_str02scm ("")
67             : next_origin;
68         }
69       else
70         next_origin = ly_str02scm ("begin-of-note");
71       
72       SCM extra_space
73         = scm_eval (scm_listify (ly_symbol2scm ("break-align-spacer"),
74                                  current_origin, next_origin, SCM_UNDEFINED)); 
75       SCM symbol = gh_car  (extra_space);
76       Real spc = gh_scm2double (SCM_CADR(extra_space));
77       spc *= interline;
78
79       dists.push(spc);
80       symbol_list = gh_cons (symbol, symbol_list);
81       current_origin = next_origin;
82     }
83
84
85   // skip the first sym.
86   symbol_list  = gh_cdr (scm_reverse (symbol_list));
87   for (int i=0; i <elems.size()-1; i++)
88     {
89       String sym_str = ly_symbol2string (gh_car  (symbol_list));
90       elems[i]->set_elt_property (sym_str,
91                                   scm_cons (gh_double2scm (0),
92                                             gh_double2scm (dists[i+1])));
93
94       symbol_list = gh_cdr (symbol_list);
95     }
96
97
98   // urg
99   SCM first_pair = elems[0]->get_elt_property ("minimum-space");
100   if (gh_pair_p (first_pair))
101     first_pair = first_pair;
102   else
103     first_pair = gh_cons (gh_double2scm (0.0), gh_double2scm (0.0));
104   
105   scm_set_car_x (first_pair, gh_double2scm (-dists[0]));
106   elems[0]->set_elt_property ("minimum-space", first_pair);
107   
108   Axis_align_item::do_pre_processing();
109
110
111   Real pre_space = elems[0]->relative_coordinate (column_l (), X_AXIS);
112
113   Real xl = elems[0]->extent (X_AXIS)[LEFT];
114   if (!isinf (xl))
115     pre_space += xl;
116   else
117     programming_error ("Infinity reached. ");
118
119   Real xr = elems.top ()->extent (X_AXIS)[RIGHT];
120   Real spring_len = elems.top ()->relative_coordinate (column_l (), X_AXIS);
121   if (!isinf (xr))
122     spring_len += xr;
123   else
124     programming_error ("Infinity reached.");
125   
126   Real stretch_distance =0.;
127   
128   if (gh_car  (symbol_list) == ly_symbol2scm ("extra-space"))
129     {
130       spring_len += dists.top ();
131       stretch_distance = dists.top ();
132     }
133   else if (gh_car  (symbol_list) == ly_symbol2scm ("minimum-space"))
134     {
135       spring_len = spring_len >? dists.top ();
136       stretch_distance = spring_len;
137     }
138
139   /*
140     Hint the spacing engine how much space to put in.
141
142
143     The pairs are in the format of an interval (ie. CAR <  CDR).
144   */
145   column_l ()->set_elt_property ("extra-space",
146                                  scm_cons (gh_double2scm (pre_space),
147                                            gh_double2scm (spring_len)));
148
149   column_l ()->set_elt_property ("stretch-distance",
150                                  gh_cons (gh_double2scm (-dists[0]),
151                                           gh_double2scm (stretch_distance)));
152                                  
153 }
154
155 Break_align_item::Break_align_item ()
156 {
157   stacking_dir_ = RIGHT;
158   set_axis (X_AXIS);
159 }