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