]> 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--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 start_translation_timestep ();
33   virtual void process_acknowledged_grobs ();
34   virtual void acknowledge_grob (Grob_info);
35 };
36
37 bool
38 Text_engraver::try_music (Music *m)
39 {
40   if (m->is_mus_type ("text-script-event"))
41     {
42       reqs_.push (m);
43       return true;
44     }
45   return false;
46 }
47
48 void
49 Text_engraver::acknowledge_grob (Grob_info inf)
50 {
51   if (Rhythmic_head::has_interface (inf.grob_))
52     {
53       for (int i=0; i < texts_.size (); i++)
54         {
55           Grob*t = texts_[i];
56           Side_position_interface::add_support (t,inf.grob_);
57
58           /*
59             ugh.
60            */
61           if (Side_position_interface::get_axis (t) == X_AXIS
62               && !t->get_parent (Y_AXIS))
63             t->set_parent (inf.grob_, Y_AXIS);
64           else if (Side_position_interface::get_axis (t) == Y_AXIS
65               && !t->get_parent (X_AXIS))
66             t->set_parent (inf.grob_, X_AXIS);
67         }
68     }
69   
70   if (Stem::has_interface (inf.grob_))
71     {
72       for (int i=0; i < texts_.size (); i++)
73         {
74           Side_position_interface::add_support (texts_[i],inf.grob_);
75         }
76     }
77 }
78
79 void
80 Text_engraver::process_acknowledged_grobs ()
81 {
82   if (texts_.size ())
83     return;
84   for (int i=0; i < reqs_.size (); i++)
85     {
86       Music * r = reqs_[i];
87       
88       // URG: Text vs TextScript
89       String basic = "TextScript";
90
91       Item *text = new Item (get_property (basic.to_str0 ()));
92
93       /*
94         FIXME -> need to use basic props.
95        */
96       SCM axisprop = get_property ("scriptHorizontal");
97       
98       Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
99       Side_position_interface::set_axis (text, ax);
100
101       // Hmm
102       int priority = 200;
103       SCM s = text->get_grob_property ("script-priority");
104       if (gh_number_p (s))
105         priority = gh_scm2int (s);
106       
107       /* see script-engraver.cc */
108       priority += i;
109       
110       text->set_grob_property ("script-priority", gh_int2scm (priority));
111
112       Direction dir = to_dir (r->get_mus_property ("direction"));
113       if (dir)
114         Side_position_interface::set_direction (text, dir);
115
116
117       SCM mark = r->get_mus_property ("text");
118
119       text->set_grob_property ("text", mark);
120       announce_grob (text, r->self_scm ());
121       texts_.push (text);
122     }
123 }
124
125 void
126 Text_engraver::stop_translation_timestep ()
127 {
128   for (int i=0; i < texts_.size (); i++)
129     {
130       Item *ti = texts_[i];
131       if (!to_boolean (get_property ("scriptHorizontal")))
132         Side_position_interface::add_staff_support (ti);
133       typeset_grob (ti);
134     }
135   texts_.clear ();
136   reqs_.clear ();
137 }
138
139
140 Text_engraver::Text_engraver(){}
141
142 ENTER_DESCRIPTION(Text_engraver,
143 /* descr */       "Create text-scripts",
144 /* creats*/       "TextScript",
145 /* accepts */     "text-script-event",
146 /* acks  */      "rhythmic-head-interface stem-interface",
147 /* reads */       "scriptHorizontal",
148 /* write */       "");