(process_acknowledged_grobs):
[lilypond.git] / lily / text-engraver.cc
blobfe64b4473dcfb0be833ce17dbfc5dc35eb313c8b
1 /*
2 text-engraver.cc -- implement Text_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
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"
20 /**
21 typeset directions that are plain text.
23 class Text_engraver : public Engraver
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);
37 bool
38 Text_engraver::try_music (Music *m)
40 if (m->is_mus_type ("text-script-event"))
42 reqs_.push (m);
43 return true;
45 return false;
48 void
49 Text_engraver::acknowledge_grob (Grob_info inf)
51 if (Rhythmic_head::has_interface (inf.grob_))
53 for (int i=0; i < texts_.size (); i++)
55 Grob*t = texts_[i];
56 Side_position_interface::add_support (t,inf.grob_);
59 ugh.
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);
70 if (Stem::has_interface (inf.grob_))
72 for (int i=0; i < texts_.size (); i++)
74 Side_position_interface::add_support (texts_[i],inf.grob_);
79 void
80 Text_engraver::process_acknowledged_grobs ()
82 if (texts_.size ())
83 return;
84 for (int i=0; i < reqs_.size (); i++)
86 Music * r = reqs_[i];
88 // URG: Text vs TextScript
89 String basic = "TextScript";
91 Item *text = new Item (get_property (basic.to_str0 ()));
94 FIXME -> need to use basic props.
96 SCM axisprop = get_property ("scriptHorizontal");
98 Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
99 Side_position_interface::set_axis (text, ax);
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);
107 /* see script-engraver.cc */
108 priority += i;
110 text->set_grob_property ("script-priority", gh_int2scm (priority));
112 Direction dir = to_dir (r->get_mus_property ("direction"));
113 if (dir)
114 Side_position_interface::set_direction (text, dir);
117 SCM mark = r->get_mus_property ("text");
119 text->set_grob_property ("text", mark);
120 announce_grob (text, r->self_scm ());
121 texts_.push (text);
125 void
126 Text_engraver::stop_translation_timestep ()
128 for (int i=0; i < texts_.size (); i++)
130 Item *ti = texts_[i];
131 if (!to_boolean (get_property ("scriptHorizontal")))
132 Side_position_interface::add_staff_support (ti);
133 typeset_grob (ti);
135 texts_.clear ();
138 void
139 Text_engraver::start_translation_timestep ()
141 reqs_.clear ();
145 Text_engraver::Text_engraver(){}
147 ENTER_DESCRIPTION(Text_engraver,
148 /* descr */ "Create text-scripts",
149 /* creats*/ "TextScript",
150 /* accepts */ "text-script-event",
151 /* acks */ "rhythmic-head-interface stem-interface",
152 /* reads */ "scriptHorizontal",
153 /* write */ "");