]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / text-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1998--2015 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 "note-column.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
26 #include "stream-event.hh"
27 #include "text-interface.hh"
28
29 #include "translator.icc"
30
31 /**
32    typeset directions that are  plain text.
33 */
34
35 class Text_engraver : public Engraver
36 {
37   vector<Stream_event *> evs_;
38   vector<Grob *> scripts_;
39 public:
40   TRANSLATOR_DECLARATIONS (Text_engraver);
41 protected:
42   void stop_translation_timestep ();
43   void process_music ();
44
45   void acknowledge_note_column (Grob_info);
46   void listen_text_script (Stream_event *);
47 };
48
49 void
50 Text_engraver::listen_text_script (Stream_event *ev)
51 {
52   evs_.push_back (ev);
53 }
54
55 void
56 Text_engraver::process_music ()
57 {
58   for (vsize i = 0; i < evs_.size (); i++)
59     {
60       Stream_event *ev = evs_[i];
61
62       Item *script = make_item ("TextScript", ev->self_scm ());
63       scripts_.push_back (script);
64
65       int priority = robust_scm2int (script->get_property ("script-priority"),
66                                      200);
67
68       /* see script-engraver.cc */
69       priority += i;
70
71       script->set_property ("script-priority", scm_from_int (priority));
72
73       Direction dir = to_dir (ev->get_property ("direction"));
74       if (dir)
75         set_grob_direction (script, dir);
76
77       SCM mark = ev->get_property ("text");
78
79       script->set_property ("text", mark);
80     }
81 }
82
83 void
84 Text_engraver::acknowledge_note_column (Grob_info info)
85 {
86   // Make note column (or rest, if there are no heads) the parent of the script.
87   extract_grob_set (info.grob (), "note-heads", heads);
88   Grob *x_parent = (heads.size ()
89                     ? info.grob ()
90                     : unsmob<Grob> (info.grob ()->get_object ("rest")));
91
92   for (vsize i = 0; i < scripts_.size (); i++)
93     {
94       Grob *el = scripts_[i];
95
96       if (el && !el->get_parent (X_AXIS) && x_parent)
97         el->set_parent (x_parent, X_AXIS);
98     }
99 }
100
101 void
102 Text_engraver::stop_translation_timestep ()
103 {
104   evs_.clear ();
105   scripts_.clear ();
106 }
107
108 Text_engraver::Text_engraver (Context *c)
109   : Engraver (c)
110 {
111 }
112
113
114 void
115 Text_engraver::boot ()
116 {
117   ADD_LISTENER (Text_engraver, text_script);
118   ADD_ACKNOWLEDGER (Text_engraver, note_column);
119 }
120
121 ADD_TRANSLATOR (Text_engraver,
122                 /* doc */
123                 "Create text scripts.",
124
125                 /* create */
126                 "TextScript ",
127
128                 /* read */
129                 "",
130
131                 /* write */
132                 ""
133                );