]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column-engraver.cc
Update.
[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 /**
14    Find potentially colliding scripts, and put them in a
15    Script_column, that will fix the collisions.  */
16 class Script_column_engraver : public Engraver
17 {
18   Grob *scol_;
19   Link_array<Item> scripts_;
20
21 public:
22   TRANSLATOR_DECLARATIONS (Script_column_engraver);
23 protected:
24   virtual void acknowledge_grob (Grob_info);
25   virtual void process_acknowledged_grobs ();
26   virtual void stop_translation_timestep ();
27 };
28
29 Script_column_engraver::Script_column_engraver ()
30 {
31   scol_ = 0;
32 }
33
34 void
35 Script_column_engraver::stop_translation_timestep ()
36 {
37   scol_ = 0;
38   scripts_.clear ();
39 }
40
41 void
42 Script_column_engraver::acknowledge_grob (Grob_info inf)
43 {
44   Item *thing = dynamic_cast<Item *> (inf.grob_);
45   if (thing && Side_position_interface::has_interface (inf.grob_)) // ugh FIXME
46     {
47       if (!Item::is_breakable (thing)
48           && Side_position_interface::get_axis (inf.grob_) == Y_AXIS)
49         {
50           scripts_.push (thing);
51         }
52     }
53 }
54
55 void
56 Script_column_engraver::process_acknowledged_grobs ()
57 {
58   if (!scol_ && scripts_.size () > 1)
59     {
60       scol_ = make_item ("ScriptColumn", SCM_EOL);
61     }
62
63   if (scol_)
64     {
65       for (int i = 0; i < scripts_.size (); i++)
66         Script_column::add_staff_sided (scol_, scripts_[i]);
67       scripts_.clear ();
68     }
69 }
70
71 ADD_TRANSLATOR (Script_column_engraver,
72                 /* descr */ "",
73                 /* creats*/ "ScriptColumn",
74                 /* accepts */ "",
75                 /* acks  */ "side-position-interface",
76                 /* reads */ "",
77                 /* write */ "");