2 script-column.cc -- implement Script_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "script-column.hh"
11 #include "directional-element-interface.hh"
12 #include "side-position-interface.hh"
14 #include "pointer-group-interface.hh"
17 Script_column::add_staff_sided (Grob *me, Item *item)
19 SCM p = item->get_property ("script-priority");
20 if (!scm_is_number (p))
23 Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"), item);
26 LY_DEFINE (ly_grob_script_priority_less, "ly:grob-script-priority-less",
27 2, 0, 0, (SCM a, SCM b),
28 "Compare two grobs by script priority. For internal use.")
30 Grob *i1 = unsmob_grob (a);
31 Grob *i2 = unsmob_grob (b);
33 SCM p1 = i1->get_property ("script-priority");
34 SCM p2 = i2->get_property ("script-priority");
36 return scm_to_int (p1) < scm_to_int (p2) ? SCM_BOOL_T : SCM_BOOL_F;
39 MAKE_SCHEME_CALLBACK (Script_column, before_line_breaking, 1);
41 Script_column::before_line_breaking (SCM smob)
43 Grob *me = unsmob_grob (smob);
44 Drul_array<SCM> scripts_drul (SCM_EOL, SCM_EOL);
45 vector<Grob*> staff_sided;
47 extract_grob_set (me, "scripts", scripts);
48 for (vsize i = 0; i < scripts.size (); i++)
50 Grob *sc = scripts[i];
53 Don't want to consider scripts horizontally next to notes.
55 if (sc->get_property_data (ly_symbol2scm ("X-offset")) !=
56 Side_position_interface::x_aligned_side_proc)
57 staff_sided.push_back (sc);
60 for (vsize i = 0; i < staff_sided.size (); i++)
62 Grob *g = staff_sided[i];
63 Direction d = get_grob_direction (g);
65 scripts_drul[d] = scm_cons (g->self_scm (), scripts_drul[d]);
71 SCM ss = scm_reverse_x (scripts_drul[d], SCM_EOL);
72 ss = scm_stable_sort_x (ss, ly_grob_script_priority_less_proc);
75 for (SCM s = ss; scm_is_pair (s); s = scm_cdr (s))
77 Grob *g = unsmob_grob (scm_car (s));
79 Side_position_interface::add_support (g, last);
84 while (flip (&d) != DOWN);
86 return SCM_UNSPECIFIED;
89 ADD_INTERFACE (Script_column, "script-column-interface",
90 "An interface that sorts scripts "
91 "according to their @code{script-priority}",