]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.67
[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 "item.hh"
14 #include "musical-request.hh"
15
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<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
37 bool
38 Text_engraver::do_try_music (Music *m)
39 {
40   if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
41     {
42       reqs_.push (r);
43       return true;
44     }
45   return false;
46 }
47
48
49 void
50 Text_engraver::acknowledge_element (Score_element_info inf)
51 {
52   if (to_boolean (inf.elem_l_->get_elt_property ("note-head-interface")))
53     {
54       for (int i=0; i < texts_.size (); i++)
55         {
56           Side_position_interface st (texts_[i]);
57           st.add_support (inf.elem_l_);
58           if (st.get_axis( ) == X_AXIS
59               && !texts_[i]->parent_l (Y_AXIS))
60             texts_[i]->set_parent (inf.elem_l_, Y_AXIS);
61         }
62     }
63   if (Stem *n = dynamic_cast<Stem*> (inf.elem_l_))
64     {
65       for (int i=0; i < texts_.size (); i++)
66         {
67           Side_position_interface st(texts_[i]);
68           st.add_support (n);
69         }
70     }
71 }
72
73 void
74 Text_engraver::do_process_music ()
75 {
76   for (int i=0; i < reqs_.size (); i++)
77     {
78       Text_script_req * r = reqs_[i];
79
80       Item *text = new Item (get_property ("basicTextScriptProperties"));
81       Side_position_interface stafy (text);
82
83       SCM axisprop = get_property ("scriptHorizontal");
84       if (to_boolean (axisprop))
85         {
86           stafy.set_axis (X_AXIS);
87           //      text->set_parent (ss, Y_AXIS);
88         }
89       else
90         stafy.set_axis (Y_AXIS);
91
92       /*
93         make sure they're in order by adding i to the priority field.
94         */
95       text->set_elt_property ("script-priority",
96                             gh_int2scm (200 + i));
97
98       if (r->get_direction ())
99         stafy.set_direction (r->get_direction ());
100       
101       text->set_elt_property ("text",
102                               ly_str02scm ( r->text_str_.ch_C ()));
103       
104       if (r->style_str_.length_i ())
105         text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
106       
107       SCM empty = get_property ("textNonEmpty");
108       if (to_boolean (empty))
109         {
110           text->set_elt_property ("no-spacing-rods" , SCM_BOOL_F);
111           text->set_extent_callback (0, X_AXIS);
112         }
113       announce_element (Score_element_info (text, r));
114       texts_.push (text);
115     }
116 }
117
118 void
119 Text_engraver::do_pre_move_processing ()
120 {
121   for (int i=0; i < texts_.size (); i++)
122     {
123       Item *ti = texts_[i];
124       Side_position_interface (ti).add_staff_support ();
125       typeset_element (ti);
126     }
127   texts_.clear ();
128 }
129
130 void
131 Text_engraver::do_post_move_processing ()
132 {
133   reqs_.clear ();
134 }
135
136 ADD_THIS_TRANSLATOR(Text_engraver);
137