]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
patch::: 1.3.18.jcn1
[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--1999 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_requests ();
34   virtual void acknowledge_element (Score_element_info);
35 };
36
37 ADD_THIS_TRANSLATOR (Text_engraver);
38
39 bool
40 Text_engraver::do_try_music (Music *m)
41 {
42   if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
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 i)
53 {
54   if (Note_head *n = dynamic_cast<Note_head*> (i.elem_l_))
55     {
56       for (int i=0; i < texts_.size (); i++)
57         {
58           Side_position_interface st (texts_[i]);
59           st.add_support (n);
60           if (st.get_axis( ) == X_AXIS
61               && !texts_[i]->parent_l (Y_AXIS))
62             texts_[i]->set_parent (n, Y_AXIS);
63         }
64     }
65   if (Stem *n = dynamic_cast<Stem*> (i.elem_l_))
66     {
67       for (int i=0; i < texts_.size (); i++)
68         {
69           Side_position_interface st(texts_[i]);
70           st.add_support (n);
71         }
72     }
73 }
74
75 void
76 Text_engraver::do_process_requests ()
77 {
78   for (int i=0; i < reqs_.size (); i++)
79     {
80       Text_script_req * r = reqs_[i];
81
82       Text_item *text = new Text_item;
83       Side_position_interface stafy (text);
84
85       SCM axisprop = get_property ("scriptHorizontal",0);
86       if (to_boolean (axisprop))
87         {
88           stafy.set_axis (X_AXIS);
89           //      text->set_parent (ss, Y_AXIS);
90         }
91       else
92         stafy.set_axis (Y_AXIS);
93       
94       text->set_elt_property ("script-priority",
95                             gh_int2scm (200));
96
97       if (r->get_direction ())
98         stafy.set_direction (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 empty = get_property ("textEmptyDimension", 0);
107       if (to_boolean (empty))
108         {
109           text->set_empty (X_AXIS);
110         }
111
112       announce_element (Score_element_info (text, r));
113       texts_.push (text);
114     }
115 }
116
117 void
118 Text_engraver::do_pre_move_processing ()
119 {
120   for (int i=0; i < texts_.size (); i++)
121     {
122       typeset_element (texts_[i]);
123     }
124   texts_.clear ();
125 }
126
127 void
128 Text_engraver::do_post_move_processing ()
129 {
130   reqs_.clear ();
131 }
132