]> git.donarmstrong.com Git - lilypond.git/blob - lily/parenthesis-engraver.cc
Web-ja: update introduction
[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 (Context *c)
39   : Engraver (c)
40 {
41 }
42
43 void
44 Parenthesis_engraver::acknowledge_grob (Grob_info info)
45 {
46   if (Stream_event *ev = info.event_cause ())
47     {
48       if (to_boolean (ev->get_property ("parenthesize")))
49         {
50           if (Item *victim = dynamic_cast<Item *> (info.grob ()))
51             {
52               Engraver *eng = dynamic_cast<Engraver *> (info.origin_translator ());
53               Item *paren = eng->make_item ("ParenthesesItem", victim->self_scm ());
54               Pointer_group_interface::add_grob (paren, ly_symbol2scm ("elements"), victim);
55
56               paren->set_parent (victim, Y_AXIS);
57
58               Real size = robust_scm2double (paren->get_property ("font-size"), 0.0)
59                           + robust_scm2double (victim->get_property ("font-size"), 0.0);
60               paren->set_property ("font-size", scm_from_double (size));
61
62               /*
63                 TODO?
64
65                 enlarge victim to allow for parentheses space?
66               */
67             }
68           else
69             {
70               info.grob ()->warning ("Don't know how to parenthesize spanners.");
71             }
72         }
73     }
74 }
75
76 void
77 Parenthesis_engraver::boot ()
78 {
79   ADD_ACKNOWLEDGER (Parenthesis_engraver, grob);
80 }
81
82 ADD_TRANSLATOR (Parenthesis_engraver,
83                 /* doc */
84                 "Parenthesize objects whose music cause has the"
85                 " @code{parenthesize} property.",
86
87                 /* create */
88                 "ParenthesesItem ",
89
90                 /* read */
91                 "",
92
93                 /* write */
94                 ""
95                );