]> git.donarmstrong.com Git - lilypond.git/blob - lily/parenthesis-engraver.cc
*** empty log message ***
[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 "warn.hh"
13 #include "simple-closure.hh"
14 #include "music.hh"
15 #include "grob.hh"
16 #include "item.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
33
34 void
35 Parenthesis_engraver::acknowledge_grob (Grob_info info)
36 {
37   if (Music *music = info.music_cause ())
38     {
39       if (to_boolean (music->get_property ("parenthesize")))
40         {
41           if (Item *victim = dynamic_cast<Item*> (info.grob ()))
42             {
43               Engraver *eng = dynamic_cast<Engraver*> (info.origin_translator ());
44               Item *paren = make_item_from_properties (eng,
45                                                        ly_symbol2scm ("ParenthesesItem"),
46                                                        victim->self_scm (),
47                                                        "ParenthesesItem");
48
49               paren->set_parent (victim, Y_AXIS);
50               paren->set_parent (victim, X_AXIS);
51               Real size = robust_scm2double (paren->get_property ("font-size"), 0.0)
52                 + robust_scm2double (victim->get_property ("font-size"), 0.0);
53               paren->set_property ("font-size", scm_from_double (size));
54               
55               /*
56                 TODO?
57
58                 enlarge victim to allow for parentheses space? 
59               */
60             }
61           else
62             {
63               programming_error ("Don't know how to parenthesize spanners.");
64             }
65         }
66     }
67 }
68
69 ADD_ACKNOWLEDGER (Parenthesis_engraver, grob);
70 ADD_TRANSLATOR (Parenthesis_engraver,
71                 /* doc */ "Parenthesize objects whose music cause has the @code{parenthesize} "
72                 "property.",
73                 
74                 /* create */ "ParenthesesItem",
75                 /* accept */ "",
76                 /* read */ "",
77                 /* write */ "");