]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.0
[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 #include "dimension-cache.hh"
10
11 #include "engraver.hh"
12 #include "staff-side.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 class Text_engraver : public Engraver
20 {
21   Link_array<Text_script_req> reqs_;
22   Link_array<Staff_side_item> positionings_;
23   Link_array<Text_item> texts_;
24 public:
25   Text_engraver();
26   VIRTUAL_COPY_CONS(Translator);
27 protected:
28   virtual bool do_try_music (Music* m);
29   virtual void do_pre_move_processing ();
30   virtual void do_post_move_processing ();
31   virtual void do_process_requests ();
32   virtual void acknowledge_element (Score_element_info);
33 };
34
35 Text_engraver::Text_engraver ()
36 {
37   
38 }
39
40 bool
41 Text_engraver::do_try_music (Music *m)
42 {
43   if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
44     {
45       reqs_.push (r);
46       return true;
47     }
48   return false;
49 }
50
51
52 void
53 Text_engraver::acknowledge_element (Score_element_info i)
54 {
55   if (Note_head *n = dynamic_cast<Note_head*> (i.elem_l_))
56     {
57       for (int i=0; i < positionings_.size (); i++)
58         {
59           positionings_[i]->add_support (n);
60           if (positionings_[i]->axis_ == X_AXIS
61               && !positionings_[i]->parent_l (Y_AXIS))
62             positionings_[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 < positionings_.size (); i++)
68         {
69           positionings_[i]->add_support (n);
70         }
71     }
72 }
73
74 void
75 Text_engraver::do_process_requests ()
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       Staff_side_item *ss = new Staff_side_item;
83
84
85
86       SCM axisprop = get_property ("scriptHorizontal",0);
87       if (gh_boolean_p (axisprop) && gh_scm2bool (axisprop))
88         {
89           ss->axis_ = X_AXIS;
90           text->set_parent (ss, Y_AXIS);
91                                
92         }
93       ss->set_victim (text);
94       ss->set_elt_property (script_priority_scm_sym,
95                             gh_int2scm (200));
96
97       ss->dir_ = r->dir_;
98
99       text->text_str_ = r->text_str_;
100       
101       if (r->style_str_.empty_b ())
102         {
103           SCM p (get_property ("textStyle", 0));
104           if (gh_string_p (p))
105             text->style_str_ = ly_scm2string(p);
106         }
107       else
108         text->style_str_ = r->style_str_;
109       
110       SCM padding = get_property ("textScriptPadding", 0);
111       if (SCM_NUMBERP(padding))
112         {
113           ss->set_elt_property (padding_scm_sym, padding);
114         }
115
116       SCM empty = get_property ("textEmptyDimension", 0);
117       if (gh_boolean_p (empty) && gh_scm2bool (empty))
118         {
119           text->set_empty (true, X_AXIS);
120         }
121
122       announce_element (Score_element_info (text, r));
123       announce_element (Score_element_info (ss, r));
124
125       texts_.push (text);
126       positionings_.push (ss);
127     }
128 }
129
130 void
131 Text_engraver::do_pre_move_processing ()
132 {
133   for (int i=0; i < texts_.size (); i++)
134     {
135       typeset_element (texts_[i]);
136       typeset_element (positionings_[i]);
137     }
138   texts_.clear ();
139   positionings_.clear ();
140 }
141
142 void
143 Text_engraver::do_post_move_processing ()
144 {
145   reqs_.clear ();
146 }
147
148 ADD_THIS_TRANSLATOR(Text_engraver);