]> git.donarmstrong.com Git - lilypond.git/blob - lily/parenthesis-engraver.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / lily / parenthesis-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22
23 #include "item.hh"
24 #include "pointer-group-interface.hh"
25 #include "stream-event.hh"
26 #include "warn.hh"
27
28 #include "translator.icc"
29
30 class Parenthesis_engraver : public Engraver
31 {
32   TRANSLATOR_DECLARATIONS (Parenthesis_engraver);
33
34 protected:
35   void acknowledge_grob (Grob_info);
36 };
37
38 Parenthesis_engraver::Parenthesis_engraver ()
39 {
40 }
41
42 void
43 Parenthesis_engraver::acknowledge_grob (Grob_info info)
44 {
45   if (Stream_event *ev = info.event_cause ())
46     {
47       if (to_boolean (ev->get_property ("parenthesize")))
48         {
49           if (Item *victim = dynamic_cast<Item *> (info.grob ()))
50             {
51               Engraver *eng = dynamic_cast<Engraver *> (info.origin_translator ());
52               Item *paren = eng->make_item ("ParenthesesItem", victim->self_scm ());
53               Pointer_group_interface::add_grob (paren, ly_symbol2scm ("elements"), victim);
54
55               paren->set_parent (victim, Y_AXIS);
56
57               Real size = robust_scm2double (paren->get_property ("font-size"), 0.0)
58                           + robust_scm2double (victim->get_property ("font-size"), 0.0);
59               paren->set_property ("font-size", scm_from_double (size));
60
61               /*
62                 TODO?
63
64                 enlarge victim to allow for parentheses space?
65               */
66             }
67           else
68             {
69               info.grob ()->warning ("Don't know how to parenthesize spanners.");
70             }
71         }
72     }
73 }
74
75 void
76 Parenthesis_engraver::boot ()
77 {
78   ADD_ACKNOWLEDGER (Parenthesis_engraver, grob);
79 }
80
81 ADD_TRANSLATOR (Parenthesis_engraver,
82                 /* doc */
83                 "Parenthesize objects whose music cause has the"
84                 " @code{parenthesize} property.",
85
86                 /* create */
87                 "ParenthesesItem ",
88
89                 /* read */
90                 "",
91
92                 /* write */
93                 ""
94                );