]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
6bd2356cab176959cdacb948b425604c0fb2fedd
[lilypond.git] / lily / text-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2012 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 "directional-element-interface.hh"
21 #include "engraver.hh"
22 #include "item.hh"
23 #include "side-position-interface.hh"
24 #include "stream-event.hh"
25 #include "text-interface.hh"
26
27 #include "translator.icc"
28
29 /**
30    typeset directions that are  plain text.
31 */
32 class Text_engraver : public Engraver
33 {
34   vector<Stream_event *> evs_;
35 public:
36   TRANSLATOR_DECLARATIONS (Text_engraver);
37 protected:
38   void stop_translation_timestep ();
39   void process_music ();
40
41   DECLARE_TRANSLATOR_LISTENER (text_script);
42 };
43
44 IMPLEMENT_TRANSLATOR_LISTENER (Text_engraver, text_script);
45 void
46 Text_engraver::listen_text_script (Stream_event *ev)
47 {
48   evs_.push_back (ev);
49 }
50
51 void
52 Text_engraver::process_music ()
53 {
54   for (vsize i = 0; i < evs_.size (); i++)
55     {
56       Stream_event *r = evs_[i];
57
58       // URG: Text vs TextScript
59       Item *text = make_item ("TextScript", r->self_scm ());
60
61       int priority = robust_scm2int (text->get_property ("script-priority"),
62                                      200);
63
64       /* see script-engraver.cc */
65       priority += i;
66
67       text->set_property ("script-priority", scm_from_int (priority));
68
69       Direction dir = to_dir (r->get_property ("direction"));
70       if (dir)
71         set_grob_direction (text, dir);
72
73       SCM mark = r->get_property ("text");
74
75       text->set_property ("text", mark);
76     }
77 }
78
79 void
80 Text_engraver::stop_translation_timestep ()
81 {
82   evs_.clear ();
83 }
84
85 Text_engraver::Text_engraver ()
86 {
87 }
88
89 ADD_TRANSLATOR (Text_engraver,
90                 /* doc */
91                 "Create text scripts.",
92
93                 /* create */
94                 "TextScript ",
95
96                 /* read */
97                 "",
98
99                 /* write */
100                 ""
101                );