2 text-engraver.cc -- implement Text_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 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 try_music (Music
* m
);
30 virtual void stop_translation_timestep ();
31 virtual void start_translation_timestep ();
32 virtual void create_grobs ();
33 virtual void acknowledge_grob (Grob_info
);
37 Text_engraver::try_music (Music
*m
)
39 if (dynamic_cast<Text_script_req
*> (m
)
40 && m
->get_mus_property ("text-type") != ly_symbol2scm ("dynamic"))
42 reqs_
.push (dynamic_cast<Text_script_req
*> (m
));
49 Text_engraver::acknowledge_grob (Grob_info inf
)
51 if (Rhythmic_head::has_interface (inf
.elem_l_
))
53 for (int i
=0; i
< texts_
.size (); i
++)
56 Side_position_interface::add_support (t
,inf
.elem_l_
);
61 if (Side_position_interface::get_axis (t
) == X_AXIS
62 && !t
->parent_l (Y_AXIS
))
63 t
->set_parent (inf
.elem_l_
, Y_AXIS
);
64 else if (Side_position_interface::get_axis (t
) == Y_AXIS
65 && !t
->parent_l (X_AXIS
))
66 t
->set_parent (inf
.elem_l_
, X_AXIS
);
70 if (Stem::has_interface (inf
.elem_l_
))
72 for (int i
=0; i
< texts_
.size (); i
++)
74 Side_position_interface::add_support (texts_
[i
],inf
.elem_l_
);
80 Text_engraver::create_grobs ()
84 for (int i
=0; i
< reqs_
.size (); i
++)
86 Text_script_req
* r
= reqs_
[i
];
88 // URG: Text vs TextScript
89 String basic
= "TextScript";
91 if (r
->get_mus_property ("text-type") == ly_symbol2scm ("finger"))
96 Item
*text
= new Item (get_property (basic
.ch_C ()));
99 FIXME -> need to use basic props.
101 SCM axisprop
= get_property ("scriptHorizontal");
103 Axis ax
= to_boolean (axisprop
) ? X_AXIS
: Y_AXIS
;
104 Side_position_interface::set_axis (text
, ax
);
107 if (r
->style_str_
== "finger" && ax
== Y_AXIS
)
110 nicely center the scripts.
112 text
->add_offset_callback (Side_position_interface::aligned_on_self_proc
, X_AXIS
);
113 text
->add_offset_callback (Side_position_interface::centered_on_parent_proc
, X_AXIS
);
120 make sure they're in order by adding i to the priority field.
122 text
->set_grob_property ("script-priority",
123 gh_int2scm (200 + i
));
125 if (r
->get_direction ())
126 Side_position_interface::set_direction (text
, r
->get_direction ());
128 text
->set_grob_property ("text", r
->get_mus_property ("text"));
130 SCM nonempty
= get_property ("textNonEmpty");
131 if (to_boolean (nonempty
))
133 empty text: signal that no rods should be applied.
135 text
->set_grob_property ("no-spacing-rods" , SCM_BOOL_F
);
137 announce_grob (text
, r
);
143 Text_engraver::stop_translation_timestep ()
145 for (int i
=0; i
< texts_
.size (); i
++)
147 Item
*ti
= texts_
[i
];
148 Side_position_interface::add_staff_support (ti
);
155 Text_engraver::start_translation_timestep ()
160 ADD_THIS_TRANSLATOR (Text_engraver
);