2 text-engraver.cc -- implement Text_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "engraver.hh"
12 #include "side-position-interface.hh"
14 #include "musical-request.hh"
16 #include "rhythmic-head.hh"
20 typeset directions that are plain text.
22 class Text_engraver : public Engraver
24 Link_array<Text_script_req> reqs_;
25 Link_array<Item> texts_;
27 VIRTUAL_COPY_CONS(Translator);
29 virtual bool do_try_music (Music* m);
30 virtual void do_pre_move_processing ();
31 virtual void do_post_move_processing ();
32 virtual void do_process_music ();
33 virtual void acknowledge_element (Score_element_info);
37 Text_engraver::do_try_music (Music *m)
39 if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
41 if (r->style_str_ == "dynamic")
51 Text_engraver::acknowledge_element (Score_element_info inf)
53 if (Rhythmic_head::has_interface (inf.elem_l_))
55 for (int i=0; i < texts_.size (); i++)
57 Score_element*t = texts_[i];
58 Side_position::add_support (t,inf.elem_l_);
63 if (Side_position::get_axis( t) == X_AXIS
64 && !t->parent_l (Y_AXIS))
65 t->set_parent (inf.elem_l_, Y_AXIS);
66 else if (Side_position::get_axis(t) == Y_AXIS
67 && !t->parent_l (X_AXIS))
68 t->set_parent (inf.elem_l_, X_AXIS);
72 if (Stem::has_interface (inf.elem_l_))
74 for (int i=0; i < texts_.size (); i++)
76 Side_position::add_support(texts_[i],inf.elem_l_);
82 Text_engraver::do_process_music ()
84 for (int i=0; i < reqs_.size (); i++)
86 Text_script_req * r = reqs_[i];
88 String basic = "basicTextScriptProperties";
91 if (r->style_str_== "finger")
93 basic = "basicFingeringProperties";
95 Item *text = new Item (get_property (basic.ch_C()));
98 SCM axisprop = get_property ("scriptHorizontal");
99 Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
100 Side_position::set_axis (text, ax);
102 if (r->style_str_ == "finger" && ax == Y_AXIS)
105 nicely center the scripts.
107 text->add_offset_callback (Side_position::aligned_on_self, X_AXIS);
108 text->add_offset_callback (Side_position::centered_on_parent, X_AXIS);
114 make sure they're in order by adding i to the priority field.
116 text->set_elt_property ("script-priority",
117 gh_int2scm (200 + i));
119 if (r->get_direction ())
120 Side_position::set_direction (text, r->get_direction ());
122 text->set_elt_property ("text",
123 ly_str02scm ( r->text_str_.ch_C ()));
125 if (r->style_str_.length_i ())
126 text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
128 SCM nonempty = get_property ("textNonEmpty");
129 if (to_boolean (nonempty))
131 empty text: signal that no rods should be applied.
133 text->set_elt_property ("no-spacing-rods" , SCM_BOOL_F);
135 announce_element (text, r);
141 Text_engraver::do_pre_move_processing ()
143 for (int i=0; i < texts_.size (); i++)
145 Item *ti = texts_[i];
146 Side_position::add_staff_support (ti);
147 typeset_element (ti);
153 Text_engraver::do_post_move_processing ()
158 ADD_THIS_TRANSLATOR(Text_engraver);