]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
release: 1.3.69
[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 "note-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 (Note_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       SCM empty = get_property ("textNonEmpty");
101       if (to_boolean (empty))
102         {
103           text->set_elt_property ("no-spacing-rods" , SCM_BOOL_F);
104           text->set_extent_callback (0, X_AXIS);
105         }
106       announce_element (Score_element_info (text, r));
107       texts_.push (text);
108     }
109 }
110
111 void
112 Text_engraver::do_pre_move_processing ()
113 {
114   for (int i=0; i < texts_.size (); i++)
115     {
116       Item *ti = texts_[i];
117       Side_position::add_staff_support (ti);
118       typeset_element (ti);
119     }
120   texts_.clear ();
121 }
122
123 void
124 Text_engraver::do_post_move_processing ()
125 {
126   reqs_.clear ();
127 }
128
129 ADD_THIS_TRANSLATOR(Text_engraver);
130