]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
*** empty log message ***
[lilypond.git] / lily / text-engraver.cc
1 /*   
2   text-engraver.cc --  implement Text_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "directional-element-interface.hh"
11 #include "engraver.hh"
12 #include "side-position-interface.hh"
13 #include "stem.hh"
14 #include "rhythmic-head.hh"
15 #include "text-item.hh"
16
17 /**
18    typeset directions that are  plain text.
19  */
20 class Text_engraver : public Engraver
21 {
22   Link_array<Music> evs_;
23   Link_array<Item> texts_;
24 public:
25   TRANSLATOR_DECLARATIONS (Text_engraver);
26 protected:
27   virtual bool try_music (Music* m);
28   virtual void stop_translation_timestep ();
29   virtual void process_acknowledged_grobs ();
30   virtual void acknowledge_grob (Grob_info);
31 };
32
33 bool
34 Text_engraver::try_music (Music *m)
35 {
36   if (m->is_mus_type ("text-script-event"))
37     {
38       evs_.push (m);
39       return true;
40     }
41   return false;
42 }
43
44 void
45 Text_engraver::acknowledge_grob (Grob_info inf)
46 {
47   if (Rhythmic_head::has_interface (inf.grob_))
48     {
49       for (int i = 0; i < texts_.size (); i++)
50         {
51           Grob*t = texts_[i];
52           Side_position_interface::add_support (t,inf.grob_);
53
54           /*
55             ugh.
56            */
57           if (Side_position_interface::get_axis (t) == X_AXIS
58               && !t->get_parent (Y_AXIS))
59             t->set_parent (inf.grob_, Y_AXIS);
60           else if (Side_position_interface::get_axis (t) == Y_AXIS
61               && !t->get_parent (X_AXIS))
62             t->set_parent (inf.grob_, X_AXIS);
63         }
64     }
65   
66   if (Stem::has_interface (inf.grob_))
67     {
68       for (int i = 0; i < texts_.size (); i++)
69         {
70           Side_position_interface::add_support (texts_[i],inf.grob_);
71         }
72     }
73 }
74
75 void
76 Text_engraver::process_acknowledged_grobs ()
77 {
78   if (texts_.size ())
79     return;
80   for (int i = 0; i < evs_.size (); i++)
81     {
82       Music * r = evs_[i];
83       
84       // URG: Text vs TextScript
85       Item *text = make_item ("TextScript", r->self_scm ());
86
87       
88       Axis ax = Y_AXIS;
89       Side_position_interface::set_axis (text, ax);
90
91       // Hmm
92       int priority = 200;
93       SCM s = text->get_property ("script-priority");
94       if (scm_is_number (s))
95         priority = scm_to_int (s);
96       
97       /* see script-engraver.cc */
98       priority += i;
99       
100       text->set_property ("script-priority", scm_int2num (priority));
101
102       Direction dir = to_dir (r->get_property ("direction"));
103       if (dir)
104         set_grob_direction (text, dir);
105
106
107       SCM mark = r->get_property ("text");
108
109       text->set_property ("text", mark);
110       texts_.push (text);
111     }
112 }
113
114 void
115 Text_engraver::stop_translation_timestep ()
116 {
117   texts_.clear ();
118   evs_.clear ();
119 }
120
121
122 Text_engraver::Text_engraver ()
123 {
124 }
125
126 ADD_TRANSLATOR (Text_engraver,
127 /* descr */       "Create text-scripts",
128 /* creats*/       "TextScript",
129 /* accepts */     "text-script-event",
130 /* acks  */      "rhythmic-head-interface stem-interface",
131 /* reads */       "",
132 /* write */       "");