]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-engraver.cc
* lily/main.cc (setup_guile_env): new function. Set GC min_yields
[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--2005 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 "stem.hh"
13 #include "rhythmic-head.hh"
14 #include "text-interface.hh"
15
16 /**
17    typeset directions that are  plain text.
18 */
19 class Text_engraver : public Engraver
20 {
21   Link_array<Music> evs_;
22   Link_array<Item> texts_;
23 public:
24   TRANSLATOR_DECLARATIONS (Text_engraver);
25 protected:
26   virtual bool try_music (Music *m);
27   void stop_translation_timestep ();
28   void process_acknowledged ();
29
30   DECLARE_ACKNOWLEDGER(stem);
31   DECLARE_ACKNOWLEDGER(rhythmic_head);
32 };
33
34 bool
35 Text_engraver::try_music (Music *m)
36 {
37   if (m->is_mus_type ("text-script-event"))
38     {
39       evs_.push (m);
40       return true;
41     }
42   return false;
43 }
44
45 void
46 Text_engraver::acknowledge_rhythmic_head (Grob_info inf)
47 {
48   for (int i = 0; i < texts_.size (); i++)
49     {
50       Grob *t = texts_[i];
51       Side_position_interface::add_support (t, inf.grob ());
52
53       /*
54         ugh.
55       */
56       if (Side_position_interface::get_axis (t) == X_AXIS
57           && !t->get_parent (Y_AXIS))
58         t->set_parent (inf.grob (), Y_AXIS);
59       else if (Side_position_interface::get_axis (t) == Y_AXIS
60                && !t->get_parent (X_AXIS))
61         t->set_parent (inf.grob (), X_AXIS);
62     }
63 }
64
65 void
66 Text_engraver::acknowledge_stem (Grob_info inf)
67 {
68   for (int i = 0; i < texts_.size (); i++)
69     {
70       Side_position_interface::add_support (texts_[i], inf.grob ());
71     }
72 }
73
74 void
75 Text_engraver::process_acknowledged ()
76 {
77   if (texts_.size ())
78     return;
79   for (int i = 0; i < evs_.size (); i++)
80     {
81       Music *r = evs_[i];
82
83       // URG: Text vs TextScript
84       Item *text = make_item ("TextScript", r->self_scm ());
85
86       Axis ax = Y_AXIS;
87       Side_position_interface::set_axis (text, ax);
88
89       // Hmm
90       int priority = 200;
91       SCM s = text->get_property ("script-priority");
92       if (scm_is_number (s))
93         priority = scm_to_int (s);
94
95       /* see script-engraver.cc */
96       priority += i;
97
98       text->set_property ("script-priority", scm_from_int (priority));
99
100       Direction dir = to_dir (r->get_property ("direction"));
101       if (dir)
102         set_grob_direction (text, dir);
103
104       SCM mark = r->get_property ("text");
105
106       text->set_property ("text", mark);
107       texts_.push (text);
108     }
109 }
110
111 void
112 Text_engraver::stop_translation_timestep ()
113 {
114   texts_.clear ();
115   evs_.clear ();
116 }
117
118 Text_engraver::Text_engraver ()
119 {
120 }
121
122 #include "translator.icc"
123
124 ADD_ACKNOWLEDGER(Text_engraver, stem);
125 ADD_ACKNOWLEDGER(Text_engraver, rhythmic_head);
126 ADD_TRANSLATOR (Text_engraver,
127                 /* descr */ "Create text-scripts",
128                 /* creats*/ "TextScript",
129                 /* accepts */ "text-script-event",
130                 /* reads */ "",
131                 /* write */ "");