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 = "TextScript";
91 if (r->style_str_== "finger")
95 Item *text = new Item (get_property (basic.ch_C()));
98 FIXME -> need to use basic props.
100 SCM axisprop = get_property ("scriptHorizontal");
102 Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
103 Side_position::set_axis (text, ax);
105 if (r->style_str_ == "finger" && ax == Y_AXIS)
108 nicely center the scripts.
110 text->add_offset_callback (Side_position::aligned_on_self_proc, X_AXIS);
111 text->add_offset_callback (Side_position::centered_on_parent_proc, X_AXIS);
117 make sure they're in order by adding i to the priority field.
119 text->set_elt_property ("script-priority",
120 gh_int2scm (200 + i));
122 if (r->get_direction ())
123 Side_position::set_direction (text, r->get_direction ());
125 if (r->text_str_.length_i ())
126 text->set_elt_property ("text",
127 ly_str02scm ( r->text_str_.ch_C ()));
130 text->set_elt_property ("text", r->text_scm_);
131 text->set_elt_property ("scm-text", r->text_scm_);
134 if (r->style_str_.length_i ())
135 text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
137 SCM nonempty = get_property ("textNonEmpty");
138 if (to_boolean (nonempty))
140 empty text: signal that no rods should be applied.
142 text->set_elt_property ("no-spacing-rods" , SCM_BOOL_F);
144 announce_element (text, r);
150 Text_engraver::do_pre_move_processing ()
152 for (int i=0; i < texts_.size (); i++)
154 Item *ti = texts_[i];
155 Side_position::add_staff_support (ti);
156 typeset_element (ti);
162 Text_engraver::do_post_move_processing ()
167 ADD_THIS_TRANSLATOR(Text_engraver);