]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.109
[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 try_music (Music* m);
30   virtual void stop_translation_timestep ();
31   virtual void start_translation_timestep ();
32   virtual void create_grobs ();
33   void deprecated_process_music ();
34   virtual void acknowledge_grob (Grob_info);
35 };
36
37 bool
38 Text_engraver::try_music (Music *m)
39 {
40   if (dynamic_cast<Text_script_req*> (m)
41       && m->get_mus_property ("text-type") != ly_symbol2scm ("dynamic"))
42     {
43       reqs_.push (dynamic_cast<Text_script_req*> (m));
44       return true;
45     }
46   return false;
47 }
48
49 void
50 Text_engraver::acknowledge_grob (Grob_info inf)
51 {
52   if (Rhythmic_head::has_interface (inf.elem_l_))
53     {
54       for (int i=0; i < texts_.size (); i++)
55         {
56           Grob*t = texts_[i];
57           Side_position::add_support (t,inf.elem_l_);
58
59           /*
60             ugh.
61            */
62           if (Side_position::get_axis( t) == X_AXIS
63               && !t->parent_l (Y_AXIS))
64             t->set_parent (inf.elem_l_, Y_AXIS);
65           else if (Side_position::get_axis(t) == Y_AXIS
66               && !t->parent_l (X_AXIS))
67             t->set_parent (inf.elem_l_, X_AXIS);
68         }
69     }
70   
71   if (Stem::has_interface (inf.elem_l_))
72     {
73       for (int i=0; i < texts_.size (); i++)
74         {
75           Side_position::add_support(texts_[i],inf.elem_l_);
76         }
77     }
78 }
79
80 void
81 Text_engraver::create_grobs ()
82 {
83   deprecated_process_music ();
84 }
85
86 void
87 Text_engraver::deprecated_process_music ()
88 {
89   if (texts_.size ())
90     return;
91   for (int i=0; i < reqs_.size (); i++)
92     {
93       Text_script_req * r = reqs_[i];
94       
95       // URG: Text vs TextScript
96       String basic = "TextScript";
97
98       if (r->get_mus_property ("text-type") == ly_symbol2scm ("finger"))
99         {
100           basic = "Fingering";
101         }
102
103       Item *text = new Item (get_property (basic.ch_C ()));
104
105       /*
106         FIXME -> need to use basic props.
107        */
108       SCM axisprop = get_property ("scriptHorizontal");
109       
110       Axis ax = to_boolean (axisprop) ? X_AXIS : Y_AXIS;
111       Side_position::set_axis (text, ax);
112
113 #if 0
114       if (r->style_str_ == "finger" && ax == Y_AXIS)
115         {
116           /*
117             nicely center the scripts.
118            */ 
119           text->add_offset_callback (Side_position::aligned_on_self_proc, X_AXIS);
120           text->add_offset_callback (Side_position::centered_on_parent_proc, X_AXIS);
121         }
122 #endif
123       
124
125       
126       /*
127         make sure they're in order by adding i to the priority field.
128         */
129       text->set_grob_property ("script-priority",
130                               gh_int2scm (200 + i));
131
132       if (r->get_direction ())
133         Side_position::set_direction (text, r->get_direction ());
134       
135       text->set_grob_property ("text", r->get_mus_property ("text"));
136       
137       SCM nonempty = get_property ("textNonEmpty");
138       if (to_boolean (nonempty))
139         /*
140           empty text: signal that no rods should be applied.  
141          */
142         text->set_grob_property ("no-spacing-rods" , SCM_BOOL_F);
143                 
144       announce_grob (text, r);
145       texts_.push (text);
146     }
147 }
148
149 void
150 Text_engraver::stop_translation_timestep ()
151 {
152   for (int i=0; i < texts_.size (); i++)
153     {
154       Item *ti = texts_[i];
155       Side_position::add_staff_support (ti);
156       typeset_grob (ti);
157     }
158   texts_.clear ();
159 }
160
161 void
162 Text_engraver::start_translation_timestep ()
163 {
164   reqs_.clear ();
165 }
166
167 ADD_THIS_TRANSLATOR(Text_engraver);
168