]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
Do not generate negative dash pattern entries for small dash-periods.
[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--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10
11 #include "international.hh"
12 #include "note-column.hh"
13 #include "side-position-interface.hh"
14 #include "spanner.hh"
15 #include "stream-event.hh"
16
17 #include "translator.icc"
18
19 class Text_spanner_engraver : public Engraver
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Text_spanner_engraver);
23 protected:
24   virtual void finalize ();
25   DECLARE_TRANSLATOR_LISTENER (text_span);
26   void stop_translation_timestep ();
27   void process_music ();
28
29 private:
30   Spanner *span_;
31   Spanner *finished_;
32   Stream_event *current_event_;
33   Drul_array<Stream_event *> event_drul_;
34   void typeset_all ();
35 };
36
37 Text_spanner_engraver::Text_spanner_engraver ()
38 {
39   finished_ = 0;
40   current_event_ = 0;
41   span_ = 0;
42   event_drul_[START] = 0;
43   event_drul_[STOP] = 0;
44 }
45
46 IMPLEMENT_TRANSLATOR_LISTENER (Text_spanner_engraver, text_span);
47 void
48 Text_spanner_engraver::listen_text_span (Stream_event *ev)
49 {
50   Direction d = to_dir (ev->get_property ("span-direction"));
51   ASSIGN_EVENT_ONCE (event_drul_[d], ev);
52 }
53
54 void
55 Text_spanner_engraver::process_music ()
56 {
57   if (event_drul_[STOP])
58     {
59       if (!span_)
60         event_drul_[STOP]->origin ()->warning (_ ("cannot find start of text spanner"));
61       else
62         {
63           finished_ = span_;
64           span_ = 0;
65           current_event_ = 0;
66         }
67     }
68
69   if (event_drul_[START])
70     {
71       if (current_event_)
72         event_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
73       else
74         {
75           current_event_ = event_drul_[START];
76           span_ = make_spanner ("TextSpanner", event_drul_[START]->self_scm ());
77
78           Side_position_interface::set_axis (span_, Y_AXIS);
79           event_drul_[START] = 0;
80         }
81     }
82 }
83
84 void
85 Text_spanner_engraver::typeset_all ()
86 {
87   if (finished_)
88     {
89       if (!finished_->get_bound (RIGHT))
90         {
91           Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
92           finished_->set_bound (RIGHT, e);
93         }
94       finished_ = 0;
95     }
96 }
97
98 void
99 Text_spanner_engraver::stop_translation_timestep ()
100 {
101   if (span_ && !span_->get_bound (LEFT))
102     {
103       Grob *e = unsmob_grob (get_property ("currentMusicalColumn"));
104       span_->set_bound (LEFT, e);
105     }
106
107   typeset_all ();
108   event_drul_[START] = 0;
109   event_drul_[STOP] = 0;
110 }
111
112 void
113 Text_spanner_engraver::finalize ()
114 {
115   typeset_all ();
116   if (span_)
117     {
118       current_event_->origin ()->warning (_ ("unterminated text spanner"));
119       span_->suicide ();
120       span_ = 0;
121     }
122 }
123
124 ADD_TRANSLATOR (Text_spanner_engraver,
125                 /* doc */
126                 "Create text spanner from an event.",
127                 /* create */
128                 "TextSpanner ",
129                 /* read */
130                 "",
131                 /* write */
132                 ""
133                 );