]> git.donarmstrong.com Git - lilypond.git/blob - lily/parenthesis-engraver.cc
lilypond-book: Textwidth detection with included file (issue 3136).
[lilypond.git] / lily / parenthesis-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2012 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 "simple-closure.hh"
26 #include "stream-event.hh"
27 #include "warn.hh"
28
29 #include "translator.icc"
30
31 class Parenthesis_engraver : public Engraver
32 {
33   TRANSLATOR_DECLARATIONS (Parenthesis_engraver);
34
35 protected:
36   DECLARE_ACKNOWLEDGER (grob);
37 };
38
39 Parenthesis_engraver::Parenthesis_engraver ()
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               programming_error ("Don't know how to parenthesize spanners.");
71             }
72         }
73     }
74 }
75
76 ADD_ACKNOWLEDGER (Parenthesis_engraver, grob);
77 ADD_TRANSLATOR (Parenthesis_engraver,
78                 /* doc */
79                 "Parenthesize objects whose music cause has the"
80                 " @code{parenthesize} property.",
81
82                 /* create */
83                 "ParenthesesItem ",
84
85                 /* read */
86                 "",
87
88                 /* write */
89                 ""
90                );