]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-column-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / script-column-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "script-column.hh"
22 #include "side-position-interface.hh"
23 #include "item.hh"
24
25 #include "translator.icc"
26
27 /**
28    Find potentially colliding scripts, and put them in a
29    Script_column, that will fix the collisions.  */
30 class Script_column_engraver : public Engraver
31 {
32   Grob *script_column_;
33   vector<Grob *> scripts_;
34
35 public:
36   TRANSLATOR_DECLARATIONS (Script_column_engraver);
37 protected:
38   DECLARE_ACKNOWLEDGER (side_position);
39   void process_acknowledged ();
40   void stop_translation_timestep ();
41 };
42
43 Script_column_engraver::Script_column_engraver ()
44 {
45   script_column_ = 0;
46 }
47
48 void
49 Script_column_engraver::stop_translation_timestep ()
50 {
51   if (script_column_)
52     {
53       for (vsize i = 0; i < scripts_.size (); i++)
54         if (Side_position_interface::get_axis (scripts_[i]) == Y_AXIS)
55           Script_column::add_side_positioned (script_column_, scripts_[i]);
56     }
57
58   script_column_ = 0;
59   scripts_.clear ();
60 }
61
62 void
63 Script_column_engraver::acknowledge_side_position (Grob_info inf)
64 {
65   Item *thing = dynamic_cast<Item *> (inf.grob ());
66   if (thing)
67     {
68       if (!Item::is_non_musical (thing))
69         scripts_.push_back (thing);
70     }
71 }
72
73 void
74 Script_column_engraver::process_acknowledged ()
75 {
76   if (!script_column_ && scripts_.size () > 1)
77     script_column_ = make_item ("ScriptColumn", SCM_EOL);
78 }
79
80 ADD_ACKNOWLEDGER (Script_column_engraver, side_position);
81 ADD_TRANSLATOR (Script_column_engraver,
82                 /* doc */
83                 "Find potentially colliding scripts and put them into a"
84                 " @code{ScriptColumn} object; that will fix the collisions.",
85
86                 /* create */
87                 "ScriptColumn ",
88
89                 /* read */
90                 "",
91
92                 /* write */
93                 ""
94                );