]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.94
[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 /**
20    typeset directions that are  plain text.
21  */
22 class Text_engraver : public Engraver
23 {
24   Link_array<Text_script_req> reqs_;
25   Link_array<Item> texts_;
26 public:
27   VIRTUAL_COPY_CONS(Translator);
28 protected:
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);
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 void
51 Text_engraver::acknowledge_element (Score_element_info inf)
52 {
53   if (Rhythmic_head::has_interface (inf.elem_l_))
54     {
55       for (int i=0; i < texts_.size (); i++)
56         {
57           Score_element*t = texts_[i];
58           Side_position::add_support (t,inf.elem_l_);
59
60           /*
61             ugh.
62            */
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);
69         }
70     }
71   
72   if (Stem::has_interface (inf.elem_l_))
73     {
74       for (int i=0; i < texts_.size (); i++)
75         {
76           Side_position::add_support(texts_[i],inf.elem_l_);
77         }
78     }
79 }
80
81 void
82 Text_engraver::do_process_music ()
83 {
84   for (int i=0; i < reqs_.size (); i++)
85     {
86       Text_script_req * r = reqs_[i];
87
88       String basic =  "TextScript";
89
90                                 // separate engraver?
91       if (r->style_str_== "finger")
92         {
93           basic = "Fingering";
94         }
95       Item *text = new Item (get_property (basic.ch_C()));
96
97       /*
98         FIXME -> need to use basic props.
99        */
100       SCM axisprop = get_property ("scriptHorizontal");
101       
102       Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
103       Side_position::set_axis (text, ax);
104
105       if (r->style_str_ == "finger" && ax == Y_AXIS)
106         {
107           /*
108             nicely center the scripts.
109            */ 
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);
112         }
113       
114
115       
116       /*
117         make sure they're in order by adding i to the priority field.
118         */
119       text->set_elt_property ("script-priority",
120                               gh_int2scm (200 + i));
121
122       if (r->get_direction ())
123         Side_position::set_direction (text, r->get_direction ());
124       
125       text->set_elt_property ("text",
126                               ly_str02scm ( r->text_str_.ch_C ()));
127       
128       if (r->style_str_.length_i ())
129         text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
130
131       SCM nonempty = get_property ("textNonEmpty");
132       if (to_boolean (nonempty))
133         /*
134           empty text: signal that no rods should be applied.  
135          */
136         text->set_elt_property ("no-spacing-rods" , SCM_BOOL_F);
137                 
138       announce_element (text, r);
139       texts_.push (text);
140     }
141 }
142
143 void
144 Text_engraver::do_pre_move_processing ()
145 {
146   for (int i=0; i < texts_.size (); i++)
147     {
148       Item *ti = texts_[i];
149       Side_position::add_staff_support (ti);
150       typeset_element (ti);
151     }
152   texts_.clear ();
153 }
154
155 void
156 Text_engraver::do_post_move_processing ()
157 {
158   reqs_.clear ();
159 }
160
161 ADD_THIS_TRANSLATOR(Text_engraver);
162