]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
0f222daab1bd2f1d6022c20729ed0fe437647a96
[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 #include "dimension-cache.hh"
11 #include "engraver.hh"
12 #include "side-position-interface.hh"
13 #include "text-item.hh"
14 #include "musical-request.hh"
15 #include "note-head.hh"
16 #include "stem.hh"
17 #include "staff-symbol.hh"
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<Text_item> texts_;
26 public:
27
28   VIRTUAL_COPY_CONS(Translator);
29 protected:
30   virtual bool do_try_music (Music* m);
31   virtual void do_pre_move_processing ();
32   virtual void do_post_move_processing ();
33   virtual void do_process_music ();
34   virtual void acknowledge_element (Score_element_info);
35 };
36
37
38 bool
39 Text_engraver::do_try_music (Music *m)
40 {
41   if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
42     {
43       reqs_.push (r);
44       return true;
45     }
46   return false;
47 }
48
49
50 void
51 Text_engraver::acknowledge_element (Score_element_info i)
52 {
53   if (Note_head *n = dynamic_cast<Note_head*> (i.elem_l_))
54     {
55       for (int i=0; i < texts_.size (); i++)
56         {
57           Side_position_interface st (texts_[i]);
58           st.add_support (n);
59           if (st.get_axis( ) == X_AXIS
60               && !texts_[i]->parent_l (Y_AXIS))
61             texts_[i]->set_parent (n, Y_AXIS);
62         }
63     }
64   if (Stem *n = dynamic_cast<Stem*> (i.elem_l_))
65     {
66       for (int i=0; i < texts_.size (); i++)
67         {
68           Side_position_interface st(texts_[i]);
69           st.add_support (n);
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       Text_item *text = new Text_item;
82       Side_position_interface stafy (text);
83
84       SCM axisprop = get_property ("scriptHorizontal");
85       if (to_boolean (axisprop))
86         {
87           stafy.set_axis (X_AXIS);
88           //      text->set_parent (ss, Y_AXIS);
89         }
90       else
91         stafy.set_axis (Y_AXIS);
92       
93       text->set_elt_property ("script-priority",
94                             gh_int2scm (200));
95
96       if (r->get_direction ())
97         stafy.set_direction (r->get_direction ());
98       
99       text->set_elt_property ("text",
100                               ly_str02scm ( r->text_str_.ch_C ()));
101       
102       if (r->style_str_.length_i ())
103         text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
104       
105       SCM empty = get_property ("textNonEmpty");
106       if (!to_boolean (empty))
107         text->set_extent_callback (0, X_AXIS);
108
109       announce_element (Score_element_info (text, r));
110       texts_.push (text);
111     }
112 }
113
114 void
115 Text_engraver::do_pre_move_processing ()
116 {
117   for (int i=0; i < texts_.size (); i++)
118     {
119       side_position (texts_[i]).add_staff_support ();
120       typeset_element (texts_[i]);
121     }
122   texts_.clear ();
123 }
124
125 void
126 Text_engraver::do_post_move_processing ()
127 {
128   reqs_.clear ();
129 }
130
131 ADD_THIS_TRANSLATOR(Text_engraver);
132