]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column-engraver.cc
5e9c668093bc9e6a6331576521480690c684b3a8
[lilypond.git] / lily / script-column-engraver.cc
1 /*
2   script-column-engraver.cc -- implement Script_column_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
10 #include "script-column.hh"
11 #include "side-position-interface.hh"
12
13 #include "translator.icc"
14
15 /**
16    Find potentially colliding scripts, and put them in a
17    Script_column, that will fix the collisions.  */
18 class Script_column_engraver : public Engraver
19 {
20   Grob *scol_;
21   Link_array<Item> scripts_;
22
23 public:
24   TRANSLATOR_DECLARATIONS (Script_column_engraver);
25 protected:
26   DECLARE_ACKNOWLEDGER (side_position);
27   void process_acknowledged ();
28   void stop_translation_timestep ();
29 };
30
31 Script_column_engraver::Script_column_engraver ()
32 {
33   scol_ = 0;
34 }
35
36 void
37 Script_column_engraver::stop_translation_timestep ()
38 {
39   scol_ = 0;
40   scripts_.clear ();
41 }
42
43 void
44 Script_column_engraver::acknowledge_side_position (Grob_info inf)
45 {
46   Item *thing = dynamic_cast<Item *> (inf.grob ());
47   if (thing)
48     {
49       if (!Item::is_breakable (thing)
50           && Side_position_interface::get_axis (inf.grob ()) == Y_AXIS)
51         scripts_.push (thing);
52     }
53 }
54
55 void
56 Script_column_engraver::process_acknowledged ()
57 {
58   if (!scol_ && scripts_.size () > 1)
59     scol_ = make_item ("ScriptColumn", SCM_EOL);
60
61   if (scol_)
62     {
63       for (int i = 0; i < scripts_.size (); i++)
64         Script_column::add_staff_sided (scol_, scripts_[i]);
65       scripts_.clear ();
66     }
67 }
68 ADD_ACKNOWLEDGER (Script_column_engraver, side_position);
69 ADD_TRANSLATOR (Script_column_engraver,
70                 /* doc */ "",
71                 /* create */ "ScriptColumn",
72                 /* accept */ "",
73                 /* read */ "",
74                 /* write */ "");