]> git.donarmstrong.com Git - lilypond.git/blob - lily/parenthesis-engraver.cc
trim outdated comment.
[lilypond.git] / lily / parenthesis-engraver.cc
1 /*
2   parenthesis-engraver.cc -- implement Parenthesis_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "engraver.hh"
11
12 #include "item.hh"
13 #include "pointer-group-interface.hh"
14 #include "simple-closure.hh"
15 #include "stream-event.hh"
16 #include "warn.hh"
17
18 #include "translator.icc"
19
20 class Parenthesis_engraver : public Engraver
21 {
22   TRANSLATOR_DECLARATIONS (Parenthesis_engraver);
23
24 protected:
25   DECLARE_ACKNOWLEDGER (grob);
26 };
27
28 Parenthesis_engraver::Parenthesis_engraver()
29 {
30 }
31
32 void
33 Parenthesis_engraver::acknowledge_grob (Grob_info info)
34 {
35   if (Stream_event *ev = info.event_cause ())
36     {
37       if (to_boolean (ev->get_property ("parenthesize")))
38         {
39           if (Item *victim = dynamic_cast<Item*> (info.grob ()))
40             {
41               Engraver *eng = dynamic_cast<Engraver*> (info.origin_translator ());
42               Item *paren = eng->make_item ("ParenthesesItem", victim->self_scm ());
43               Pointer_group_interface::add_grob (paren, ly_symbol2scm ("elements"), victim);
44
45               paren->set_parent (victim, Y_AXIS);
46               
47               Real size = robust_scm2double (paren->get_property ("font-size"), 0.0)
48                 + robust_scm2double (victim->get_property ("font-size"), 0.0);
49               paren->set_property ("font-size", scm_from_double (size));
50               
51               /*
52                 TODO?
53
54                 enlarge victim to allow for parentheses space? 
55               */
56             }
57           else
58             {
59               programming_error ("Don't know how to parenthesize spanners.");
60             }
61         }
62     }
63 }
64
65 ADD_ACKNOWLEDGER (Parenthesis_engraver, grob);
66 ADD_TRANSLATOR (Parenthesis_engraver,
67                 /* doc */ "Parenthesize objects whose music cause has the @code{parenthesize} "
68                 "property.",
69                 
70                 /* create */
71                 "ParenthesesItem ",
72                 /* read */ "",
73                 /* write */ "");