]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
release: 1.3.110
[lilypond.git] / lily / hyphen-engraver.cc
1 /*
2   hyphen-engraver.cc -- implement Hyphen_engraver
3
4   (c) 1999 Glen Prideaux <glenprideaux@iname.com>
5 */
6
7 #include "flower-proto.hh"
8 #include "musical-request.hh"
9 #include "hyphen-spanner.hh"
10 #include "paper-column.hh"
11 #include "item.hh"
12 #include "engraver.hh"
13
14 /**
15   Generate an centred hyphen.  Should make a Hyphen_spanner that
16   typesets a nice centred hyphen of varying length depending on the
17   gap between syllables.
18
19   We remember the last Item that come across. When we get a
20   request, we create the spanner, and attach the left point to the
21   last lyrics, and the right point to any lyrics we receive by
22   then.  */
23 class Hyphen_engraver : public Engraver
24 {
25   Grob *last_lyric_l_;
26   Grob *current_lyric_l_;
27   Hyphen_req* req_l_;
28   Spanner* hyphen_p_;
29 public:
30   Hyphen_engraver ();
31   VIRTUAL_COPY_CONS (Translator);
32
33 protected:
34   virtual void acknowledge_grob (Grob_info);
35   virtual void finalize();
36   virtual bool try_music (Music*);
37   virtual void stop_translation_timestep();
38   virtual void start_translation_timestep ();
39   virtual void create_grobs ();
40 private:
41
42 };
43
44 ADD_THIS_TRANSLATOR (Hyphen_engraver);
45
46 Hyphen_engraver::Hyphen_engraver ()
47 {
48   current_lyric_l_ = 0;
49   last_lyric_l_ = 0;
50   hyphen_p_ = 0;
51   req_l_ = 0;
52 }
53
54 void
55 Hyphen_engraver::acknowledge_grob (Grob_info i)
56 {
57   // -> text-item
58   if (i.elem_l_->has_interface (ly_symbol2scm ("lyric-syllable-interface")))
59     {
60       current_lyric_l_ = i.elem_l_;
61       if (hyphen_p_
62           && !hyphen_p_->get_bound (RIGHT)
63             )
64           {
65             Hyphen_spanner (hyphen_p_).set_textitem (RIGHT, i.elem_l_);
66           }
67     }
68 }
69
70
71 bool
72 Hyphen_engraver::try_music (Music* r)
73 {
74   if (Hyphen_req* p = dynamic_cast <Hyphen_req *> (r))
75     {
76       if (req_l_)
77         return false;
78
79       req_l_ = p;
80       return true;
81     }
82   return false;
83 }
84
85 void
86 Hyphen_engraver::finalize ()
87 {
88   if (hyphen_p_)
89     {
90       req_l_->origin ()->warning (_ ("unterminated hyphen"));
91       hyphen_p_->set_bound(RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
92     }
93 }
94
95 void
96 Hyphen_engraver::create_grobs ()
97 {
98   if (req_l_ &&! hyphen_p_)
99     {
100       if (!last_lyric_l_)
101         {
102           req_l_->origin ()->warning (_ ("Nothing to connect hyphen to on the left.  Ignoring hyphen request."));
103           return;
104         }
105       
106       hyphen_p_ = new Spanner (get_property ("LyricHyphen"));
107
108       Hyphen_spanner (hyphen_p_).set_textitem  (LEFT, last_lyric_l_);
109       announce_grob (hyphen_p_, req_l_);
110     }
111 }
112
113
114 void
115 Hyphen_engraver::stop_translation_timestep ()
116 {
117   if (hyphen_p_)
118     {
119       typeset_grob (hyphen_p_);
120       hyphen_p_ = 0;
121     }
122
123   if (current_lyric_l_)
124     {
125       last_lyric_l_ = current_lyric_l_;
126       current_lyric_l_ =0;
127     }
128 }
129
130 void
131 Hyphen_engraver::start_translation_timestep ()
132 {
133   req_l_ = 0;
134 }
135
136