2 vertical-align-engraver.cc -- implement Vertical_align_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "paper-column.hh"
11 #include "align-interface.hh"
12 #include "span-bar.hh"
13 #include "axis-group-interface.hh"
14 #include "engraver.hh"
17 class Vertical_align_engraver
: public Engraver
20 bool qualifies (Grob_info
) const;
21 SCM id_to_group_hashtab_
;
24 TRANSLATOR_DECLARATIONS (Vertical_align_engraver
);
27 virtual void derived_mark () const;
28 virtual void acknowledge_grob (Grob_info
);
29 virtual void process_music ();
30 virtual void finalize ();
31 virtual void initialize ();
35 ADD_TRANSLATOR (Vertical_align_engraver
,
36 "Catch groups (staffs, lyrics lines, etc.) and stack "
38 /* creats*/ "VerticalAlignment",
40 /* acks */ "axis-group-interface",
45 Vertical_align_engraver::Vertical_align_engraver ()
48 id_to_group_hashtab_
= SCM_EOL
;
52 Vertical_align_engraver::derived_mark () const
54 scm_gc_mark (id_to_group_hashtab_
);
58 Vertical_align_engraver::initialize ()
60 id_to_group_hashtab_
= scm_c_make_hash_table (11);
65 Vertical_align_engraver::process_music ()
69 valign_
= make_spanner ("VerticalAlignment", SCM_EOL
);
70 valign_
->set_bound (LEFT
, unsmob_grob (get_property ("currentCommandColumn")));
75 Vertical_align_engraver::finalize ()
79 valign_
->set_bound (RIGHT
, unsmob_grob (get_property ("currentCommandColumn")));
85 Vertical_align_engraver::qualifies (Grob_info i
) const
87 int sz
= i
.origin_contexts ((Translator
*)this).size ();
89 return sz
> 0 && Axis_group_interface::has_interface (i
.grob ())
90 && !i
.grob ()->get_parent (Y_AXIS
) && Axis_group_interface::has_axis (i
.grob (), Y_AXIS
);
94 Vertical_align_engraver::acknowledge_grob (Grob_info i
)
98 String id
= i
.context ()->id_string ();
100 scm_hash_set_x (id_to_group_hashtab_
, scm_makfrom0str (id
.to_str0 ()),
101 i
.grob ()->self_scm ());
104 SCM before_id
= i
.context ()->get_property ("alignAboveContext");
105 SCM after_id
= i
.context ()->get_property ("alignBelowContext");
107 SCM before
= scm_hash_ref (id_to_group_hashtab_
, before_id
, SCM_BOOL_F
);
108 SCM after
= scm_hash_ref (id_to_group_hashtab_
, after_id
, SCM_BOOL_F
);
111 Align_interface::add_element (valign_
, i
.grob (),
112 get_property ("verticalAlignmentChildCallback"));
114 if (unsmob_grob (before
) || unsmob_grob (after
))
116 SCM elts
= valign_
->get_property ("elements");
117 SCM new_order
= scm_cdr (elts
);
118 SCM
*current
= &new_order
;
120 for (SCM s
= new_order
; scm_is_pair (s
); s
= scm_cdr (s
))
122 if (scm_car (s
) == after
)
124 *current
= scm_cons (i
.grob ()->self_scm(), s
);
127 else if (scm_car (s
) == before
)
129 scm_set_cdr_x (s
, scm_cons (i
.grob ()->self_scm (),
134 current
= SCM_CDRLOC (s
);
137 valign_
->set_property ("elements", new_order
);