]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.90
[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--2000 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 "musical-request.hh"
15 #include "stem.hh"
16 #include "rhythmic-head.hh"
17
18 /**
19    typeset directions that are  plain text.
20  */
21 class Text_engraver : public Engraver
22 {
23   Link_array<Text_script_req> reqs_;
24   Link_array<Item> texts_;
25 public:
26   VIRTUAL_COPY_CONS(Translator);
27 protected:
28   virtual bool do_try_music (Music* m);
29   virtual void do_pre_move_processing ();
30   virtual void do_post_move_processing ();
31   virtual void do_process_music ();
32   virtual void acknowledge_element (Score_element_info);
33 };
34
35
36 bool
37 Text_engraver::do_try_music (Music *m)
38 {
39   if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
40     {
41       if (r->style_str_ == "dynamic")
42         return false;
43       
44       reqs_.push (r);
45       return true;
46     }
47   return false;
48 }
49
50
51 void
52 Text_engraver::acknowledge_element (Score_element_info inf)
53 {
54   if (Rhythmic_head::has_interface (inf.elem_l_))
55     {
56       for (int i=0; i < texts_.size (); i++)
57         {
58           Score_element*t = texts_[i];
59           Side_position::add_support (t,inf.elem_l_);
60           if (Side_position::get_axis( t) == X_AXIS
61               && !t->parent_l (Y_AXIS))
62             t->set_parent (inf.elem_l_, Y_AXIS);
63         }
64     }
65   if (Stem::has_interface (inf.elem_l_))
66     {
67       for (int i=0; i < texts_.size (); i++)
68         {
69           Side_position::add_support(texts_[i],inf.elem_l_);
70         }
71     }
72 }
73
74 void
75 Text_engraver::do_process_music ()
76 {
77   for (int i=0; i < reqs_.size (); i++)
78     {
79       Text_script_req * r = reqs_[i];
80
81       /*
82         Urg:  Text_engraver loads TextScriptProperties
83        */
84       Item *text = new Item (get_property ("basicTextScriptProperties"));
85       
86
87       SCM axisprop = get_property ("scriptHorizontal");
88
89       Side_position::set_axis (text, to_boolean (axisprop) ? X_AXIS : Y_AXIS);
90
91       /*
92         make sure they're in order by adding i to the priority field.
93         */
94       text->set_elt_property ("script-priority",
95                               gh_int2scm (200 + i));
96
97       if (r->get_direction ())
98         Side_position::set_direction (text, r->get_direction ());
99       
100       text->set_elt_property ("text",
101                               ly_str02scm ( r->text_str_.ch_C ()));
102       
103       if (r->style_str_.length_i ())
104         text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
105
106       SCM nonempty = get_property ("textNonEmpty");
107       if (to_boolean (nonempty))
108         /*
109           empty text: signal that no rods should be applied.  
110          */
111         text->set_elt_property ("no-spacing-rods" , SCM_BOOL_F);
112                 
113       announce_element (text, r);
114       texts_.push (text);
115     }
116 }
117
118 void
119 Text_engraver::do_pre_move_processing ()
120 {
121   for (int i=0; i < texts_.size (); i++)
122     {
123       Item *ti = texts_[i];
124       Side_position::add_staff_support (ti);
125       typeset_element (ti);
126     }
127   texts_.clear ();
128 }
129
130 void
131 Text_engraver::do_post_move_processing ()
132 {
133   reqs_.clear ();
134 }
135
136 ADD_THIS_TRANSLATOR(Text_engraver);
137