]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column.cc
release: 1.3.109
[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--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include "script-column.hh"
10 #include "side-position-interface.hh"
11
12 #include "group-interface.hh"
13
14 void
15 Script_column::add_staff_sided (Grob *me, Item *i)
16 {
17   SCM p = i->get_grob_property ("script-priority");
18   if (!gh_number_p (p))
19     return;
20
21   Pointer_group_interface::add_element (me, "scripts",i);
22   
23   me->add_dependency (i);
24 }
25
26 static int
27 staff_side_compare (Grob * const &i1,
28                     Grob * const &i2)
29 {
30   SCM p1 = i1->get_grob_property ("script-priority");
31   SCM p2 = i2->get_grob_property ("script-priority");
32
33   return gh_scm2int (p1) - gh_scm2int (p2);
34 }
35
36 MAKE_SCHEME_CALLBACK(Script_column,before_line_breaking,1);
37
38 SCM
39 Script_column::before_line_breaking (SCM smob)
40 {
41   Grob* me = unsmob_element (smob);
42   Drul_array<Link_array<Grob> > arrs;
43   Link_array<Grob> staff_sided 
44     = Pointer_group_interface__extract_elements (me, (Grob*)0, "scripts");
45                                      
46                                      
47   for (int i=0; i < staff_sided.size (); i++)
48     {
49       arrs[Side_position::get_direction (staff_sided[i])]
50         .push (staff_sided[i]);
51     }
52
53   Direction d = DOWN;
54   do {
55     Link_array<Grob> &arr(arrs[d]);
56     
57     arr.sort (staff_side_compare);
58
59     Grob * last = 0;
60     for (int i=0; i < arr.size (); i++)
61       {
62
63         if (last)
64           Side_position::add_support( arr[i],last);
65             
66         arr[i]->remove_grob_property ("script-priority");
67         last = arr[i];
68       }
69     
70   } while (flip (&d) != DOWN);
71
72   return SCM_UNSPECIFIED;
73 }
74