]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column.cc
release commit
[lilypond.git] / lily / script-column.cc
1 /*
2   script-column.cc -- implement Script_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "script-column.hh"
10
11 #include "directional-element-interface.hh"
12 #include "side-position-interface.hh"
13 #include "warn.hh"
14 #include "pointer-group-interface.hh"
15
16 void
17 Script_column::add_staff_sided (Grob *me, Item *item)
18 {
19   SCM p = item->get_property ("script-priority");
20   if (!scm_is_number (p))
21     return;
22
23   Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"), item);
24 }
25
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.")
29 {
30   Grob *i1 = unsmob_grob (a);
31   Grob *i2 = unsmob_grob (b);
32
33   SCM p1 = i1->get_property ("script-priority");
34   SCM p2 = i2->get_property ("script-priority");
35
36   return scm_to_int (p1) < scm_to_int (p2) ? SCM_BOOL_T : SCM_BOOL_F;
37 }
38
39 MAKE_SCHEME_CALLBACK (Script_column, before_line_breaking, 1);
40 SCM
41 Script_column::before_line_breaking (SCM smob)
42 {
43   Grob *me = unsmob_grob (smob);
44   Drul_array<SCM> scripts_drul (SCM_EOL, SCM_EOL);
45   Link_array<Grob> staff_sided;
46
47   extract_grob_set (me, "scripts", scripts);
48   for (int i = 0; i < scripts.size (); i++)
49     {
50       Grob *sc = scripts[i];
51
52       /*
53         Don't want to consider scripts horizontally next to notes.
54       */
55       if (sc->get_property_data (ly_symbol2scm ("X-offset")) !=
56           Side_position_interface::x_aligned_side_proc)
57         staff_sided.push (sc);
58     }
59
60   for (int i = 0; i < staff_sided.size (); i++)
61     {
62       Grob *g = staff_sided[i];
63       Direction d = get_grob_direction (g);
64
65       scripts_drul[d] = scm_cons (g->self_scm (), scripts_drul[d]);
66     }
67
68   Direction d = DOWN;
69   do
70     {
71       SCM ss = scm_reverse_x (scripts_drul[d], SCM_EOL);
72       ss = scm_stable_sort_x (ss, ly_grob_script_priority_less_proc);
73
74       Grob *last = 0;
75       for (SCM s = ss; scm_is_pair (s); s = scm_cdr (s))
76         {
77           Grob *g = unsmob_grob (scm_car (s));
78           if (last)
79             Side_position_interface::add_support (g, last);
80
81           last = g;
82         }
83     }
84   while (flip (&d) != DOWN);
85
86   return SCM_UNSPECIFIED;
87 }
88
89 ADD_INTERFACE (Script_column, "script-column-interface",
90                "An interface that sorts scripts "
91                "according to their @code{script-priority}",
92                "");