]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
patch::: 1.3.116.jcn2
[lilypond.git] / lily / text-spanner-engraver.cc
1 /*
2   text-spanner-engraver.cc -- implement Text_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "dimensions.hh"
10 #include "musical-request.hh"
11 #include "paper-column.hh"
12 #include "note-column.hh"
13 #include "item.hh"
14 #include "side-position-interface.hh"
15 #include "engraver.hh"
16 #include "group-interface.hh"
17 #include "directional-element-interface.hh"
18 #include "translator-group.hh"
19 #include "axis-group-interface.hh"
20
21
22 class Text_spanner_engraver : public Engraver
23 {
24 public:
25   VIRTUAL_COPY_CONS (Translator);
26   Text_spanner_engraver ();
27   
28 protected:
29   virtual void finalize ();
30   virtual void acknowledge_grob (Grob_info);
31   virtual bool try_music (Music *);
32   virtual void stop_translation_timestep ();
33   virtual void start_translation_timestep ();
34   virtual void create_grobs ();
35
36 private:
37   Spanner *span_;
38   Spanner *finished_;
39   Span_req *current_req_;
40   Drul_array<Span_req*> req_drul_;
41   void typeset_all ();
42 };
43
44 ADD_THIS_TRANSLATOR (Text_spanner_engraver);
45
46
47 Text_spanner_engraver::Text_spanner_engraver ()
48 {
49   finished_ = 0;
50   current_req_ = 0;
51   span_ =0;
52   req_drul_[START] = 0;
53   req_drul_[STOP] = 0;
54 }
55
56 void
57 Text_spanner_engraver::start_translation_timestep ()
58 {
59   req_drul_[START] = 0;
60   req_drul_[STOP] = 0;
61 }
62
63 bool
64 Text_spanner_engraver::try_music (Music *m)
65 {
66   if (Span_req *s =  dynamic_cast <Span_req*> (m))
67     {
68       String t =  ly_scm2string (s->get_mus_property ("span-type"));            
69       if (t == "abort")
70         {
71           req_drul_[LEFT] = 0;
72           req_drul_[RIGHT] = 0;
73           if (span_)
74             span_->suicide ();
75           span_ = 0;
76         }
77       else if (t == "text")
78         {
79           req_drul_[s->get_span_dir()] = s;
80           return true;
81         }
82     }
83   return false;
84 }
85
86 void
87 Text_spanner_engraver::create_grobs ()
88 {
89   /////
90   if (req_drul_[STOP])
91     {
92       if (!span_)
93         {
94           req_drul_[STOP]->origin ()->warning
95             (_ ("can't find start of text spanner"));
96         }
97       else
98         {
99           assert (!finished_);
100           Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
101           span_->set_bound (RIGHT, e);
102
103           finished_ = span_;
104           span_ = 0;
105           current_req_ = 0;
106         }
107     }
108
109   if (req_drul_[START])
110     {
111       if (current_req_)
112         {
113           req_drul_[START]->origin ()->warning
114             (_ ("already have a text spanner"));
115         }
116       else
117         {
118           current_req_ = req_drul_[START];
119           span_  = new Spanner (get_property ("TextSpanner"));
120           
121           /* Don't remove me without testing.
122
123              Urg.  It seems that a padding property with empty cdr
124              ``(padding)'' is set somewhere, overriding the default
125              TextSpanner properties.  Also, my gdb won't print *span_
126              or span_->mutable_property_alis_ here */
127           if (1)//!gh_number_p (span_->get_grob_property ("padding")))
128             {
129               span_->remove_grob_property ("padding");
130               span_->set_grob_property ("padding", gh_double2scm (0));
131             }
132             
133           Side_position::set_axis (span_, Y_AXIS);
134           Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
135           span_->set_bound (LEFT, e);
136           announce_grob (span_, req_drul_[START]);
137         }
138     }
139 }
140
141 void
142 Text_spanner_engraver::acknowledge_grob (Grob_info info)
143 {
144   if (span_ && Note_column::has_interface (info.elem_l_))
145     {
146       Side_position::add_support (span_, info.elem_l_);
147       add_bound_item (span_, dynamic_cast<Item*> (info.elem_l_));
148     }
149 }
150
151 void
152 Text_spanner_engraver::typeset_all ()
153 {  
154   if (finished_)
155     {
156       Side_position::add_staff_support (finished_);
157       typeset_grob (finished_);
158       finished_ = 0;
159     }
160 }
161
162 void
163 Text_spanner_engraver::stop_translation_timestep ()
164 {
165   typeset_all ();
166 }
167
168 void
169 Text_spanner_engraver::finalize ()
170 {
171   typeset_all ();
172   if (span_)
173     {
174       current_req_->origin ()->warning (_ ("unterminated text spanner"));
175       span_->suicide ();
176       span_ = 0;
177     }
178 }
179