]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
patch::: 1.3.108.jcn3
[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   Score_element *last_lyric_l_;
26   Score_element *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_element (Score_element_info);
35   virtual void do_removal_processing();
36   void deprecated_process_music();
37   virtual bool do_try_music (Music*);
38   virtual void do_pre_move_processing();
39   virtual void do_post_move_processing ();
40   virtual void process_acknowledged ();
41 private:
42
43 };
44
45 ADD_THIS_TRANSLATOR (Hyphen_engraver);
46
47 Hyphen_engraver::Hyphen_engraver ()
48 {
49   current_lyric_l_ = 0;
50   last_lyric_l_ = 0;
51   hyphen_p_ = 0;
52   req_l_ = 0;
53 }
54
55 void
56 Hyphen_engraver::acknowledge_element (Score_element_info i)
57 {
58   // -> text-item
59   if (i.elem_l_->has_interface (ly_symbol2scm ("lyric-syllable-interface")))
60     {
61       current_lyric_l_ = i.elem_l_;
62       if (hyphen_p_
63           && !hyphen_p_->get_bound (RIGHT)
64             )
65           {
66             Hyphen_spanner (hyphen_p_).set_textitem (RIGHT, i.elem_l_);
67           }
68     }
69 }
70
71
72 bool
73 Hyphen_engraver::do_try_music (Music* r)
74 {
75   if (Hyphen_req* p = dynamic_cast <Hyphen_req *> (r))
76     {
77       if (req_l_)
78         return false;
79
80       req_l_ = p;
81       return true;
82     }
83   return false;
84 }
85
86 void
87 Hyphen_engraver::do_removal_processing ()
88 {
89   if (hyphen_p_)
90     {
91       req_l_->origin ()->warning (_ ("unterminated hyphen"));
92       hyphen_p_->set_bound(RIGHT, unsmob_element (get_property ("currentCommandColumn")));
93     }
94 }
95
96 void
97 Hyphen_engraver::process_acknowledged ()
98 {
99   deprecated_process_music ();
100 }
101
102 void
103 Hyphen_engraver::deprecated_process_music ()
104 {
105   if (req_l_ &&! hyphen_p_)
106     {
107       if (!last_lyric_l_)
108         {
109           req_l_->origin ()->warning (_ ("Nothing to connect hyphen to on the left.  Ignoring hyphen request."));
110           return;
111         }
112       
113       hyphen_p_ = new Spanner (get_property ("LyricHyphen"));
114
115       Hyphen_spanner (hyphen_p_).set_textitem  (LEFT, last_lyric_l_);
116       announce_element (hyphen_p_, req_l_);
117     }
118 }
119
120
121 void
122 Hyphen_engraver::do_pre_move_processing ()
123 {
124   if (hyphen_p_)
125     {
126       typeset_element (hyphen_p_);
127       hyphen_p_ = 0;
128     }
129
130   if (current_lyric_l_)
131     {
132       last_lyric_l_ = current_lyric_l_;
133       current_lyric_l_ =0;
134     }
135 }
136
137 void
138 Hyphen_engraver::do_post_move_processing ()
139 {
140   req_l_ = 0;
141 }
142
143