]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.86
[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    typeset directions that are  plain text.
20  */
21 class Text_engraver : public Engraver
22 {
23   Link_array<Text_script_req> reqs_;
24   Link_array<Item> texts_;
25 public:
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_music ();
32   virtual void acknowledge_element (Score_element_info);
33 };
34
35
36 bool
37 Text_engraver::do_try_music (Music *m)
38 {
39   if (Text_script_req *r = dynamic_cast<Text_script_req*> (m))
40     {
41       reqs_.push (r);
42       return true;
43     }
44   return false;
45 }
46
47
48 void
49 Text_engraver::acknowledge_element (Score_element_info inf)
50 {
51   if (Rhythmic_head::has_interface (inf.elem_l_))
52     {
53       for (int i=0; i < texts_.size (); i++)
54         {
55           Score_element*t = texts_[i];
56           Side_position::add_support (t,inf.elem_l_);
57           if (Side_position::get_axis( t) == X_AXIS
58               && !t->parent_l (Y_AXIS))
59             t->set_parent (inf.elem_l_, Y_AXIS);
60         }
61     }
62   if (Stem::has_interface (inf.elem_l_))
63     {
64       for (int i=0; i < texts_.size (); i++)
65         {
66           Side_position::add_support(texts_[i],inf.elem_l_);
67         }
68     }
69 }
70
71 void
72 Text_engraver::do_process_music ()
73 {
74   for (int i=0; i < reqs_.size (); i++)
75     {
76       Text_script_req * r = reqs_[i];
77
78       Item *text = new Item (get_property ("basicTextScriptProperties"));
79       
80
81       SCM axisprop = get_property ("scriptHorizontal");
82
83       Side_position::set_axis (text, to_boolean (axisprop) ? X_AXIS : Y_AXIS);
84
85       /*
86         make sure they're in order by adding i to the priority field.
87         */
88       text->set_elt_property ("script-priority",
89                             gh_int2scm (200 + i));
90
91       if (r->get_direction ())
92         Side_position::set_direction (text, r->get_direction ());
93       
94       text->set_elt_property ("text",
95                               ly_str02scm ( r->text_str_.ch_C ()));
96       
97       if (r->style_str_.length_i ())
98         text->set_elt_property ("style", ly_str02scm (r->style_str_.ch_C()));
99       
100       /*
101        Text is empty by default, which means that the only condition
102        for not setting 'no-spacing-rods' should be: boolean && true.
103
104        Anyway, non-empty text has been broken for some time now.
105        */
106       SCM nonempty = get_property ("textNonEmpty");
107       if (!to_boolean (nonempty))
108         /*
109           empty text: signal that no rods should be applied.  
110          */
111         text->set_elt_property ("no-spacing-rods" , SCM_BOOL_T);
112
113                 
114       announce_element (text, r);
115       texts_.push (text);
116     }
117 }
118
119 void
120 Text_engraver::do_pre_move_processing ()
121 {
122   for (int i=0; i < texts_.size (); i++)
123     {
124       Item *ti = texts_[i];
125       Side_position::add_staff_support (ti);
126       typeset_element (ti);
127     }
128   texts_.clear ();
129 }
130
131 void
132 Text_engraver::do_post_move_processing ()
133 {
134   reqs_.clear ();
135 }
136
137 ADD_THIS_TRANSLATOR(Text_engraver);
138