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