]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
2003 -> 2004
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include "directional-element-interface.hh"
10 #include "engraver.hh"
11 #include "side-position-interface.hh"
12 #include "item.hh"
13 #include "event.hh"
14 #include "stem.hh"
15 #include "rhythmic-head.hh"
16 #include "text-item.hh"
17
18
19 /**
20    typeset directions that are  plain text.
21  */
22 class Text_engraver : public Engraver
23 {
24   Link_array<Music> reqs_;
25   Link_array<Item> texts_;
26 public:
27   TRANSLATOR_DECLARATIONS(Text_engraver);
28 protected:
29   virtual bool try_music (Music* m);
30   virtual void stop_translation_timestep ();
31   virtual void process_acknowledged_grobs ();
32   virtual void acknowledge_grob (Grob_info);
33 };
34
35 bool
36 Text_engraver::try_music (Music *m)
37 {
38   if (m->is_mus_type ("text-script-event"))
39     {
40       reqs_.push (m);
41       return true;
42     }
43   return false;
44 }
45
46 void
47 Text_engraver::acknowledge_grob (Grob_info inf)
48 {
49   if (Rhythmic_head::has_interface (inf.grob_))
50     {
51       for (int i=0; i < texts_.size (); i++)
52         {
53           Grob*t = texts_[i];
54           Side_position_interface::add_support (t,inf.grob_);
55
56           /*
57             ugh.
58            */
59           if (Side_position_interface::get_axis (t) == X_AXIS
60               && !t->get_parent (Y_AXIS))
61             t->set_parent (inf.grob_, Y_AXIS);
62           else if (Side_position_interface::get_axis (t) == Y_AXIS
63               && !t->get_parent (X_AXIS))
64             t->set_parent (inf.grob_, X_AXIS);
65         }
66     }
67   
68   if (Stem::has_interface (inf.grob_))
69     {
70       for (int i=0; i < texts_.size (); i++)
71         {
72           Side_position_interface::add_support (texts_[i],inf.grob_);
73         }
74     }
75 }
76
77 void
78 Text_engraver::process_acknowledged_grobs ()
79 {
80   if (texts_.size ())
81     return;
82   for (int i=0; i < reqs_.size (); i++)
83     {
84       Music * r = reqs_[i];
85       
86       // URG: Text vs TextScript
87       String basic = "TextScript";
88
89       Item *text = new Item (get_property (basic.to_str0 ()));
90
91       
92       Axis ax = Y_AXIS;
93       Side_position_interface::set_axis (text, ax);
94
95       // Hmm
96       int priority = 200;
97       SCM s = text->get_grob_property ("script-priority");
98       if (gh_number_p (s))
99         priority = gh_scm2int (s);
100       
101       /* see script-engraver.cc */
102       priority += i;
103       
104       text->set_grob_property ("script-priority", gh_int2scm (priority));
105
106       Direction dir = to_dir (r->get_mus_property ("direction"));
107       if (dir)
108         set_grob_direction (text, dir);
109
110
111       SCM mark = r->get_mus_property ("text");
112
113       text->set_grob_property ("text", mark);
114       announce_grob (text, r->self_scm ());
115       texts_.push (text);
116     }
117 }
118
119 void
120 Text_engraver::stop_translation_timestep ()
121 {
122   for (int i=0; i < texts_.size (); i++)
123     {
124       Item *ti = texts_[i];
125       typeset_grob (ti);
126     }
127   texts_.clear ();
128   reqs_.clear ();
129 }
130
131
132 Text_engraver::Text_engraver ()
133 {
134 }
135
136 ENTER_DESCRIPTION(Text_engraver,
137 /* descr */       "Create text-scripts",
138 /* creats*/       "TextScript",
139 /* accepts */     "text-script-event",
140 /* acks  */      "rhythmic-head-interface stem-interface",
141 /* reads */       "",
142 /* write */       "");