]> git.donarmstrong.com Git - lilypond.git/blob - lily/lyric-engraver.cc
release: 1.1.24
[lilypond.git] / lily / lyric-engraver.cc
1 /*
2   lyric-engraver.cc -- implement Lyric_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "musical-request.hh"
11 #include "main.hh"
12 #include "dimensions.hh"
13 #include "g-text-item.hh"
14 #include "engraver.hh"
15 #include "array.hh"
16 #include "lily-proto.hh"
17
18 class Lyric_engraver : public Engraver 
19 {
20 protected:
21   virtual void do_pre_move_processing();
22   virtual bool do_try_music (Music*);
23   virtual void do_process_requests();
24
25 public:
26   Lyric_engraver();
27   VIRTUAL_COPY_CONS(Translator);
28
29 private:
30   Link_array<Lyric_req> lyric_req_l_arr_;
31   Link_array<Item> text_p_arr_;
32 };
33
34
35 ADD_THIS_TRANSLATOR(Lyric_engraver);
36
37
38 Lyric_engraver::Lyric_engraver()
39 {
40 }
41
42 bool
43 Lyric_engraver::do_try_music (Music*r)
44 {
45   if (Lyric_req* l = dynamic_cast <Lyric_req *> (r))
46     {
47       lyric_req_l_arr_.push (l);
48       return true;
49     }
50   return false;
51 }
52
53 void
54 Lyric_engraver::do_process_requests()
55 {
56   if (text_p_arr_.size ())
57     return;
58
59   for (int i=0; i < lyric_req_l_arr_.size (); i++)
60     {
61       Lyric_req* request_l = lyric_req_l_arr_[i];
62       G_text_item* item_p =  new G_text_item;
63       item_p->text_str_ = request_l->text_str_;
64
65       Scalar style = get_property ("textstyle", 0);
66       if (style.length_i ())
67         item_p->style_str_ = style;
68       // urg, when/how can one get the height of this thing?
69       item_p->translate (Offset (0, - i * 12 PT));
70       
71       text_p_arr_.push (item_p);
72       announce_element (Score_element_info (item_p, request_l));
73     }
74 }
75
76 void
77 Lyric_engraver::do_pre_move_processing()
78 {
79   for (int i=0; i < text_p_arr_.size (); i++)
80     {
81       typeset_element (text_p_arr_[i]);
82     }
83   text_p_arr_.clear ();
84   lyric_req_l_arr_.clear ();
85 }
86