]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
patch::: 1.3.96.jcn9
[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       reqs_.push (r);
42       return true;
43     }
44   return false;
45 }
46
47 void
48 Text_engraver::acknowledge_element (Score_element_info inf)
49 {
50   if (Rhythmic_head::has_interface (inf.elem_l_))
51     {
52       for (int i=0; i < texts_.size (); i++)
53         {
54           Score_element*t = texts_[i];
55           Side_position::add_support (t,inf.elem_l_);
56
57           /*
58             ugh.
59            */
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           else if (Side_position::get_axis(t) == Y_AXIS
64               && !t->parent_l (X_AXIS))
65             t->set_parent (inf.elem_l_, X_AXIS);
66         }
67     }
68   
69   if (Stem::has_interface (inf.elem_l_))
70     {
71       for (int i=0; i < texts_.size (); i++)
72         {
73           Side_position::add_support(texts_[i],inf.elem_l_);
74         }
75     }
76 }
77
78 void
79 Text_engraver::do_process_music ()
80 {
81   for (int i=0; i < reqs_.size (); i++)
82     {
83       Text_script_req * r = reqs_[i];
84       
85       // URG: Text vs TextScript
86       String basic = "TextScript";
87
88 #if 0
89       // maybe use some sort of TYPE for script/dynamic/finger?
90       
91                                 // separate engraver?
92       if (r->style_str_== "finger")
93         {
94           basic = "Fingering";
95         }
96 #endif
97       Item *text = new Item (get_property (basic.ch_C ()));
98
99       /*
100         FIXME -> need to use basic props.
101        */
102       SCM axisprop = get_property ("scriptHorizontal");
103       
104       Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
105       Side_position::set_axis (text, ax);
106
107 #if 0
108       if (r->style_str_ == "finger" && ax == Y_AXIS)
109         {
110           /*
111             nicely center the scripts.
112            */ 
113           text->add_offset_callback (Side_position::aligned_on_self_proc, X_AXIS);
114           text->add_offset_callback (Side_position::centered_on_parent_proc, X_AXIS);
115         }
116 #endif
117       
118
119       
120       /*
121         make sure they're in order by adding i to the priority field.
122         */
123       text->set_elt_property ("script-priority",
124                               gh_int2scm (200 + i));
125
126       if (r->get_direction ())
127         Side_position::set_direction (text, r->get_direction ());
128       
129       text->set_elt_property ("text", r->get_mus_property ("text"));
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