]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
Web-ja: update introduction
[lilypond.git] / lily / balloon.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "text-interface.hh"
21 #include "grob.hh"
22 #include "item.hh"
23 #include "line-interface.hh"
24 #include "lookup.hh"
25 #include "font-interface.hh"
26 #include "lily-guile.hh"
27 #include "output-def.hh"
28 #include "misc.hh"
29 #include "spanner.hh"
30
31 class Balloon_interface
32 {
33 public:
34   DECLARE_SCHEME_CALLBACK (print, (SCM));
35   DECLARE_SCHEME_CALLBACK (print_spanner, (SCM));
36
37   static SCM internal_balloon_print (Grob *me, Grob *p, Offset off);
38 };
39
40 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
41 SCM
42 Balloon_interface::print (SCM smob)
43 {
44   Grob *me = unsmob<Grob> (smob);
45
46   if (Item *item = dynamic_cast<Item *> (me))
47     if (!Item::break_visible (item))
48       return SCM_EOL;
49
50   Grob *p = me->get_parent (X_AXIS);
51
52   Offset off (me->relative_coordinate (p, X_AXIS),
53               me->relative_coordinate (p, Y_AXIS));
54
55   return internal_balloon_print (me, p, off);
56 }
57
58 MAKE_SCHEME_CALLBACK (Balloon_interface, print_spanner, 1);
59 SCM
60 Balloon_interface::print_spanner (SCM smob)
61 {
62   Spanner *me = unsmob<Spanner> (smob);
63   Spanner *orig = dynamic_cast<Spanner *> (me->original ());
64
65   if (orig)
66     {
67       Direction spanner_placement = robust_scm2dir (me->get_property ("spanner-placement"), LEFT);
68
69       Spanner *wanted = (spanner_placement != RIGHT)
70                         ? orig->broken_intos_[0]
71                         : orig->broken_intos_.back ();
72
73       if (me != wanted)
74         return SCM_EOL;
75     }
76
77   Spanner *p = dynamic_cast<Spanner *> (me->get_parent (Y_AXIS));
78
79   if (!p)
80     return SCM_EOL;
81
82   Offset off (me->relative_coordinate (me->get_bound (LEFT), X_AXIS),
83               me->relative_coordinate (p, Y_AXIS));
84   return internal_balloon_print (me, p, off);
85 }
86
87 SCM
88 Balloon_interface::internal_balloon_print (Grob *me, Grob *p, Offset off)
89 {
90   Box b (robust_relative_extent (p, p, X_AXIS),
91          robust_relative_extent (p, p, Y_AXIS));
92   Real padding = robust_scm2double (me->get_property ("padding"), .1);
93   b.widen (padding, padding);
94
95   // FIXME
96   Stencil fr;
97   if (to_boolean (me->get_property ("annotation-balloon")))
98     fr = Lookup::frame (b, 0.1, 0.05);
99
100   SCM bt = me->get_property ("text");
101   SCM chain = Font_interface::text_font_alist_chain (me);
102   SCM stencil = Text_interface::interpret_markup (me->layout ()->self_scm (),
103                                                   chain, bt);
104   Stencil *text_stil = unsmob<Stencil> (stencil);
105
106   Offset z1;
107
108   for (int i = X_AXIS; i < NO_AXES; i++)
109     {
110       Axis a ((Axis)i);
111       z1[a] = b[a].linear_combination (sign (off[a]));
112       text_stil->align_to (a, -sign (off[a]));
113     }
114
115   Offset z2 = z1 + off;
116
117   if (to_boolean (me->get_property ("annotation-line")))
118     fr.add_stencil (Line_interface::line (me, z1, z2));
119
120   text_stil->translate (z2);
121   fr.add_stencil (*text_stil);
122
123   fr.translate (-off);
124   return fr.smobbed_copy ();
125 }
126
127 ADD_INTERFACE (Balloon_interface,
128                "A collection of routines to put text balloons around an"
129                " object.",
130
131                /* properties */
132                "annotation-balloon "
133                "annotation-line "
134                "padding "
135                "spanner-placement "
136                "text "
137               );
138