Correct left text alignment of DynamicTextSpanner.
[lilypond.git] / lily / script-column.cc
blobb249fd00ac7e6b4a5e1440812c2857ac6cac6dbd
1 /*
2 script-column.cc -- implement Script_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "script-column.hh"
11 #include "accidental-placement.hh"
12 #include "arpeggio.hh"
13 #include "directional-element-interface.hh"
14 #include "side-position-interface.hh"
15 #include "warn.hh"
16 #include "grob.hh"
17 #include "pointer-group-interface.hh"
19 #include <map>
21 typedef map<Grob*, vector <Grob*> > Grob_scripts_map;
23 void
24 Script_column::add_side_positioned (Grob *me, Grob *script)
26 SCM p = script->get_property ("script-priority");
27 if (!scm_is_number (p))
28 return;
30 Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"), script);
33 LY_DEFINE (ly_grob_script_priority_less, "ly:grob-script-priority-less",
34 2, 0, 0, (SCM a, SCM b),
35 "Compare two grobs by script priority. For internal use.")
37 Grob *i1 = unsmob_grob (a);
38 Grob *i2 = unsmob_grob (b);
40 SCM p1 = i1->get_property ("script-priority");
41 SCM p2 = i2->get_property ("script-priority");
43 return scm_to_int (p1) < scm_to_int (p2) ? SCM_BOOL_T : SCM_BOOL_F;
46 MAKE_SCHEME_CALLBACK (Script_column, row_before_line_breaking, 1);
47 SCM
48 Script_column::row_before_line_breaking (SCM smob)
50 Grob *me = unsmob_grob (smob);
51 vector<Grob*> horizontal_grobs;
52 extract_grob_set (me, "scripts", scripts);
54 Grob_scripts_map head_scripts_map;
55 vector<Grob *> affect_all_grobs;
56 for (vsize i = 0; i < scripts.size (); i++)
58 Grob *sc = scripts[i];
61 Don't want to consider scripts horizontally next to notes.
63 if (Accidental_placement::has_interface (sc)
64 || Arpeggio::has_interface (sc))
66 affect_all_grobs.push_back (sc);
68 else if (sc->get_property_data ("Y-offset") !=
69 Side_position_interface::x_aligned_side_proc)
71 head_scripts_map[sc->get_parent (Y_AXIS)].push_back (sc);
75 for (Grob_scripts_map::const_iterator i (head_scripts_map.begin ());
76 i != head_scripts_map.end ();
77 i++)
79 vector<Grob*> grobs = (*i).second;
81 // this isn't right in all cases, but in general a safe assumption.
82 concat (grobs, affect_all_grobs);
83 order_grobs (grobs);
86 return SCM_UNSPECIFIED;
90 MAKE_SCHEME_CALLBACK (Script_column, before_line_breaking, 1);
91 SCM
92 Script_column::before_line_breaking (SCM smob)
94 Grob *me = unsmob_grob (smob);
95 vector<Grob*> staff_sided;
97 extract_grob_set (me, "scripts", scripts);
98 for (vsize i = 0; i < scripts.size (); i++)
100 Grob *sc = scripts[i];
102 Don't want to consider scripts horizontally next to notes.
104 if (sc->get_property_data ("X-offset") !=
105 Side_position_interface::x_aligned_side_proc)
106 staff_sided.push_back (sc);
109 order_grobs (staff_sided);
110 return SCM_UNSPECIFIED;
113 void
114 Script_column::order_grobs (vector<Grob*> grobs)
116 Drul_array<SCM> scripts_drul (SCM_EOL, SCM_EOL);
117 for (vsize i = 0; i < grobs.size (); i++)
119 Grob *g = grobs[i];
120 Direction d = get_grob_direction (g);
122 scripts_drul[d] = scm_cons (g->self_scm (), scripts_drul[d]);
125 Direction d = DOWN;
128 SCM ss = scm_reverse_x (scripts_drul[d], SCM_EOL);
129 ss = scm_stable_sort_x (ss, ly_grob_script_priority_less_proc);
131 Grob *last = 0;
132 for (SCM s = ss; scm_is_pair (s); s = scm_cdr (s))
134 Grob *g = unsmob_grob (scm_car (s));
135 if (last)
137 SCM outside_staff = last->get_property ("outside-staff-priority");
138 if (scm_is_number (outside_staff))
140 /* we allow the outside-staff-priority ordering to override the
141 script-priority ordering */
142 if (!scm_is_number (g->get_property ("outside-staff-priority")))
143 g->set_property ("outside-staff-priority",
144 scm_from_double (scm_to_double (outside_staff) + 0.1));
146 else
147 Side_position_interface::add_support (g, last);
150 last = g;
153 while (flip (&d) != DOWN);
156 ADD_INTERFACE (Script_column,
157 "An interface that sorts scripts according to their"
158 " @code{script-priority}.",
160 /* properties */