]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-loose-columns.cc
329a77a7dd0daf425d68950c90ba2bd572519e5b
[lilypond.git] / lily / spacing-loose-columns.cc
1 /*
2   spacing-loose-columns.cc --  implement loose column spacing.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "system.hh"
11 #include "paper-column.hh"
12 #include "column-x-positions.hh"
13 #include "staff-spacing.hh"
14
15
16 /* Find the loose columns in POSNS, and drape them around the columns
17    specified in BETWEEN-COLS.  */
18 void
19 set_loose_columns (System* which, Column_x_positions const *posns)
20 {
21   int loose_col_count = posns->loose_cols_.size ();
22   for (int i = 0; i < loose_col_count; i++)
23     {
24       int divide_over = 1;
25       Item *loose = dynamic_cast<Item*> (posns->loose_cols_[i]);
26       Paper_column* col = dynamic_cast<Paper_column*> (loose);
27       
28       if (col->system_)
29         continue;
30       
31       Item *left = 0;
32       Item *right = 0;
33       while (1)
34         {
35           SCM between = loose->get_property ("between-cols");
36           if (!scm_is_pair (between))
37             break;
38
39           Item *le = dynamic_cast<Item*> (unsmob_grob (scm_car (between)));
40           Item *re = dynamic_cast<Item*> (unsmob_grob (scm_cdr (between)));
41
42           if (!(le && re))
43             break;
44           
45           if (!left && le)
46             {
47               left = le->get_column ();
48               if (!left->get_system ())
49                 left = left->find_prebroken_piece (RIGHT);
50             }
51
52           divide_over++;
53           loose = right = re->get_column ();
54         }
55
56       if (!right->get_system ())
57         right = right->find_prebroken_piece (LEFT);
58       
59       Grob *common = right->common_refpoint (left, X_AXIS);
60
61       int count = 0;
62       Real total_space = 0.0;  
63       Real total_fixed = 0.0; 
64       for (SCM wish = col->get_property ("spacing-wishes"); scm_is_pair (wish); wish = scm_cdr (wish))
65         {
66           Grob *spacing = unsmob_grob (scm_car (wish));
67           if (Staff_spacing::has_interface (spacing))
68             {
69               Real space = 0.0;
70               Real fixed = 0.0;
71               Staff_spacing::get_spacing_params (spacing, &space, &fixed);
72
73               total_fixed += fixed;
74               total_space += space;
75               count ++;
76             }
77         }
78
79       Real right_point = 0.0;
80       Real distance_to_next = 0.0;
81       if (count)
82         {
83           total_space /= count;
84           total_fixed /= count;
85
86           distance_to_next = total_space;
87           right_point = right->relative_coordinate (common, X_AXIS);
88         }
89       else
90         {
91           Interval my_extent = col->extent (col, X_AXIS);
92           distance_to_next = my_extent[RIGHT] + 1.0;
93           right_point = right->extent (common, X_AXIS)[LEFT];
94         }
95 #if 0
96       Real left_point = left->extent (common, X_AXIS)[RIGHT];
97
98       Real space_left = ((right_point - left_point) >? 0.0)
99         - (my_extent.is_empty() ? 0.0 : my_extent.length ());
100
101       Real padding = (space_left / 2) <? 1.0;
102       /*
103         Put it just left of the right column, with a bit of extra space 
104        */
105 #endif
106       Real my_offset = right_point - distance_to_next;
107
108       col->system_ = which;
109       col->translate_axis (my_offset - col->relative_coordinate (common, X_AXIS), X_AXIS);
110     }
111 }
112