]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "note-column.hh"
10 #include "side-position-interface.hh"
11 #include "engraver.hh"
12
13 class Text_spanner_engraver : public Engraver
14 {
15 public:
16   TRANSLATOR_DECLARATIONS (Text_spanner_engraver);  
17 protected:
18   virtual void finalize ();
19   virtual void acknowledge_grob (Grob_info);
20   virtual bool try_music (Music *);
21   virtual void stop_translation_timestep ();
22   virtual void process_music ();
23
24 private:
25   Spanner *span_;
26   Spanner *finished_;
27   Music *current_req_;
28   Drul_array<Music*> req_drul_;
29   void typeset_all ();
30 };
31
32
33 Text_spanner_engraver::Text_spanner_engraver ()
34 {
35   finished_ = 0;
36   current_req_ = 0;
37   span_ =0;
38   req_drul_[START] = 0;
39   req_drul_[STOP] = 0;
40 }
41
42 bool
43 Text_spanner_engraver::try_music (Music *m)
44 {
45   if (m->is_mus_type ("text-span-event"))
46     {
47       Direction d = to_dir (m->get_property ("span-direction"));
48       req_drul_[d] = m;
49       return true;
50     }
51
52   return false;
53 }
54
55 void
56 Text_spanner_engraver::process_music ()
57 {
58   if (req_drul_[STOP])
59     {
60       if (!span_)
61         {
62           req_drul_[STOP]->origin ()->warning (_ ("can't find start of text spanner"));
63         }
64       else
65         {
66           finished_ = span_;
67           span_ = 0;
68           current_req_ = 0;
69         }
70     }
71
72   if (req_drul_[START])
73     {
74       if (current_req_)
75         {
76           req_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
77         }
78       else
79         {
80           current_req_ = req_drul_[START];
81           span_  = make_spanner ("TextSpanner", req_drul_[START]->self_scm ());
82
83           
84           Side_position_interface::set_axis (span_, Y_AXIS);
85           req_drul_[START] = 0;
86         }
87     }
88 }
89
90 void
91 Text_spanner_engraver::acknowledge_grob (Grob_info info)
92 {
93   Spanner * spans[2] ={span_, finished_};
94   for (int i = 0;  i < 2 ; i++)
95     {
96       if (spans[i] && Note_column::has_interface (info.grob_))
97         {
98           Side_position_interface::add_support (spans[i], info.grob_);
99           add_bound_item (spans[i], dynamic_cast<Item*> (info.grob_));
100         }
101     }
102 }
103
104 void
105 Text_spanner_engraver::typeset_all ()
106 {  
107   if (finished_)
108     {
109       if (!finished_->get_bound (RIGHT))
110         {
111           Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
112           finished_->set_bound (RIGHT, e);
113         }
114       finished_ = 0;
115     }
116 }
117
118 void
119 Text_spanner_engraver::stop_translation_timestep ()
120 {
121   if (span_ && !span_->get_bound (LEFT))
122     {
123       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
124       span_->set_bound (LEFT, e);
125     }
126
127   typeset_all ();
128   req_drul_[START] = 0;
129   req_drul_[STOP] = 0;
130 }
131
132 void
133 Text_spanner_engraver::finalize ()
134 {
135   typeset_all ();
136   if (span_)
137     {
138       current_req_->origin ()->warning (_ ("unterminated text spanner"));
139       span_->suicide ();
140       span_ = 0;
141     }
142 }
143
144 ENTER_DESCRIPTION (Text_spanner_engraver,
145 /* descr */       "Create text spanner from a Music.",
146 /* creats*/       "TextSpanner",
147 /* accepts */     "text-span-event",
148 /* acks  */      "note-column-interface",
149 /* reads */       "",
150 /* write */       "");