]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
3d849d36d918cfdd9bd2112c24371f6421422fbe
[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--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10
11 #include "engraver.hh"
12 #include "side-position-interface.hh"
13 #include "item.hh"
14 #include "event.hh"
15 #include "stem.hh"
16 #include "rhythmic-head.hh"
17 #include "text-item.hh"
18
19
20 /**
21    typeset directions that are  plain text.
22  */
23 class Text_engraver : public Engraver
24 {
25   Link_array<Music> reqs_;
26   Link_array<Item> texts_;
27 public:
28   TRANSLATOR_DECLARATIONS(Text_engraver);
29 protected:
30   virtual bool try_music (Music* m);
31   virtual void stop_translation_timestep ();
32   virtual void process_acknowledged_grobs ();
33   virtual void acknowledge_grob (Grob_info);
34 };
35
36 bool
37 Text_engraver::try_music (Music *m)
38 {
39   if (m->is_mus_type ("text-script-event"))
40     {
41       reqs_.push (m);
42       return true;
43     }
44   return false;
45 }
46
47 void
48 Text_engraver::acknowledge_grob (Grob_info inf)
49 {
50   if (Rhythmic_head::has_interface (inf.grob_))
51     {
52       for (int i=0; i < texts_.size (); i++)
53         {
54           Grob*t = texts_[i];
55           Side_position_interface::add_support (t,inf.grob_);
56
57           /*
58             ugh.
59            */
60           if (Side_position_interface::get_axis (t) == X_AXIS
61               && !t->get_parent (Y_AXIS))
62             t->set_parent (inf.grob_, Y_AXIS);
63           else if (Side_position_interface::get_axis (t) == Y_AXIS
64               && !t->get_parent (X_AXIS))
65             t->set_parent (inf.grob_, X_AXIS);
66         }
67     }
68   
69   if (Stem::has_interface (inf.grob_))
70     {
71       for (int i=0; i < texts_.size (); i++)
72         {
73           Side_position_interface::add_support (texts_[i],inf.grob_);
74         }
75     }
76 }
77
78 void
79 Text_engraver::process_acknowledged_grobs ()
80 {
81   if (texts_.size ())
82     return;
83   for (int i=0; i < reqs_.size (); i++)
84     {
85       Music * r = reqs_[i];
86       
87       // URG: Text vs TextScript
88       String basic = "TextScript";
89
90       Item *text = new Item (get_property (basic.to_str0 ()));
91
92       /*
93         FIXME -> need to use basic props.
94        */
95       SCM axisprop = get_property ("scriptHorizontal");
96       
97       Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
98       Side_position_interface::set_axis (text, ax);
99
100       // Hmm
101       int priority = 200;
102       SCM s = text->get_grob_property ("script-priority");
103       if (gh_number_p (s))
104         priority = gh_scm2int (s);
105       
106       /* see script-engraver.cc */
107       priority += i;
108       
109       text->set_grob_property ("script-priority", gh_int2scm (priority));
110
111       Direction dir = to_dir (r->get_mus_property ("direction"));
112       if (dir)
113         Side_position_interface::set_direction (text, dir);
114
115
116       SCM mark = r->get_mus_property ("text");
117
118       text->set_grob_property ("text", mark);
119       announce_grob (text, r->self_scm ());
120       texts_.push (text);
121     }
122 }
123
124 void
125 Text_engraver::stop_translation_timestep ()
126 {
127   for (int i=0; i < texts_.size (); i++)
128     {
129       Item *ti = texts_[i];
130       if (!to_boolean (get_property ("scriptHorizontal")))
131         Side_position_interface::add_staff_support (ti);
132       typeset_grob (ti);
133     }
134   texts_.clear ();
135   reqs_.clear ();
136 }
137
138
139 Text_engraver::Text_engraver ()
140 {
141 }
142
143 ENTER_DESCRIPTION(Text_engraver,
144 /* descr */       "Create text-scripts",
145 /* creats*/       "TextScript",
146 /* accepts */     "text-script-event",
147 /* acks  */      "rhythmic-head-interface stem-interface",
148 /* reads */       "scriptHorizontal",
149 /* write */       "");