2 spacing-loose-columns.cc -- implement loose column spacing.
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "paper-column.hh"
11 #include "column-x-positions.hh"
12 #include "pointer-group-interface.hh"
13 #include "staff-spacing.hh"
14 #include "note-spacing.hh"
15 #include "spacing-spanner.hh"
18 #include "spacing-options.hh"
20 /* Find the loose columns in POSNS, and drape them around the columns
21 specified in BETWEEN-COLS. */
23 set_loose_columns (System *which, Column_x_positions const *posns)
25 int loose_col_count = posns->loose_cols_.size ();
29 for (int i = 0; i < loose_col_count; i++)
32 Item *loose = dynamic_cast<Item *> (posns->loose_cols_[i]);
33 Paper_column *col = dynamic_cast<Paper_column *> (loose);
35 if (col->get_system ())
44 SCM between = loose->get_object ("between-cols");
45 if (!scm_is_pair (between))
48 Item *le = dynamic_cast<Item *> (unsmob_grob (scm_car (between)));
49 Item *re = dynamic_cast<Item *> (unsmob_grob (scm_cdr (between)));
56 left = le->get_column ();
57 if (!left->get_system ())
58 left = left->find_prebroken_piece (RIGHT);
60 clique.push_back (left);
63 clique.push_back (loose);
66 loose = right = re->get_column ();
69 if (!right->get_system ())
70 right = right->find_prebroken_piece (LEFT);
72 Grob *common = right->common_refpoint (left, X_AXIS);
74 clique.push_back (right);
76 vector<Real> clique_spacing;
77 clique_spacing.push_back (0.0);
78 for (vsize j = 1; j < clique.size () - 1; j ++)
80 Grob *clique_col = clique[j];
82 Paper_column *loose_col = dynamic_cast<Paper_column *> (clique[j]);
83 Paper_column *next_col = dynamic_cast<Paper_column *> (clique[j + 1]);
85 Grob *spacing = unsmob_grob (clique_col->get_object ("spacing"));
86 if (Grob *grace_spacing = unsmob_grob (clique_col->get_object ("grace-spacing")))
88 spacing = grace_spacing;
91 Spacing_options options;
93 options.init_from_grob (spacing);
95 programming_error ("Column without spacing object");
97 bool expand_only = false;
98 Real base_note_space = 0.0;
100 if (Paper_column::is_musical (next_col)
101 && Paper_column::is_musical (loose_col))
102 base_note_space = Spacing_spanner::note_spacing (spacing, loose_col, next_col,
103 &options, &expand_only);
108 Spacing_spanner::standard_breakable_column_spacing (spacing,
113 base_note_space = space;
116 base_note_space = max (base_note_space,
117 robust_relative_extent (loose_col, loose_col, X_AXIS)[RIGHT]
118 - robust_relative_extent (next_col, next_col, X_AXIS)[LEFT]);
120 clique_spacing.push_back (base_note_space);
123 Real default_padding = 1.0;
124 clique_spacing.push_back (default_padding);
126 Real right_point = robust_relative_extent (clique.back (), common, X_AXIS)[LEFT];
129 Grob *finished_right_column = clique.back ();
131 for (vsize j = clique.size () - 2; j > 0; j--)
133 Paper_column *clique_col = dynamic_cast<Paper_column *> (clique[j]);
135 right_point = finished_right_column->relative_coordinate (common, X_AXIS);
137 Real distance_to_next = clique_spacing[j];
139 Real my_offset = right_point - distance_to_next;
141 clique_col->set_system (which);
142 clique_col->translate_axis (my_offset - clique_col->relative_coordinate (common, X_AXIS), X_AXIS);
144 finished_right_column = clique_col;