2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "text-interface.hh"
23 #include "line-interface.hh"
25 #include "font-interface.hh"
26 #include "lily-guile.hh"
27 #include "output-def.hh"
30 #include "international.hh"
32 class Balloon_interface
35 DECLARE_SCHEME_CALLBACK (print, (SCM));
36 DECLARE_SCHEME_CALLBACK (print_spanner, (SCM));
37 DECLARE_GROB_INTERFACE ();
40 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
42 Balloon_interface::print (SCM smob)
44 Grob *me = unsmob_grob (smob);
46 Grob *p = me->get_parent (X_AXIS);
48 Offset off (me->relative_coordinate (p, X_AXIS),
49 me->relative_coordinate (p, Y_AXIS));
51 Box b (p->extent (p, X_AXIS),
52 p->extent (p, Y_AXIS));
54 Real padding = robust_scm2double (me->get_property ("padding"), .1);
55 b.widen (padding, padding);
59 if (to_boolean (me->get_property ("annotation-balloon")))
60 fr = Lookup::frame (b, 0.1, 0.05);
62 SCM bt = me->get_property ("text");
63 SCM chain = Font_interface::text_font_alist_chain (me);
65 SCM stencil = Text_interface::interpret_markup (me->layout ()->self_scm (),
68 Stencil *text_stil = unsmob_stencil (stencil);
71 for (int i = X_AXIS; i < NO_AXES; i++)
74 z1[a] = b[a].linear_combination (sign (off[a]));
75 text_stil->align_to (a, -sign (off[a]));
80 if (to_boolean (me->get_property ("annotation-line")))
81 fr.add_stencil (Line_interface::line (me, z1, z2));
83 text_stil->translate (z2);
84 fr.add_stencil (*text_stil);
87 return fr.smobbed_copy ();
90 // ugh...code dup...hopefully can be consolidated w/ above one day
91 MAKE_SCHEME_CALLBACK (Balloon_interface, print_spanner, 1);
93 Balloon_interface::print_spanner (SCM smob)
95 Spanner *me = unsmob_spanner (smob);
96 Spanner *parent = unsmob_spanner (me->get_property ("parent-spanner"));
98 message (_f ("foo %d", robust_scm2int (me->get_property ("spanner-to-annotate"), 0)));
99 message (_f ("bar %d", robust_scm2int (me->broken_intos_[0]->get_property ("spanner-to-annotate"), 0)));
100 if (parent->broken_intos_.size () == 0)
103 p = parent->broken_intos_[robust_scm2int (me->get_property ("spanner-to-annotate"), 0) % parent->broken_intos_.size ()];
106 Drul_array<Item *> bounds;
111 bounds[d] = me->get_bound (d);
113 while (flip (&d) != LEFT);
115 Grob *commonx = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS);
117 Offset off (me->relative_coordinate (commonx, X_AXIS),
118 me->relative_coordinate (p, Y_AXIS));
120 Box b (p->extent (p, X_AXIS),
121 p->extent (p, Y_AXIS));
123 Real padding = robust_scm2double (me->get_property ("padding"), .1);
124 b.widen (padding, padding);
128 if (to_boolean (me->get_property ("annotation-balloon")))
129 fr = Lookup::frame (b, 0.1, 0.05);
131 SCM bt = me->get_property ("text");
132 SCM chain = Font_interface::text_font_alist_chain (me);
134 SCM stencil = Text_interface::interpret_markup (me->layout ()->self_scm (),
137 Stencil *text_stil = unsmob_stencil (stencil);
140 for (int i = X_AXIS; i < NO_AXES; i++)
143 z1[a] = b[a].linear_combination (sign (off[a]));
144 text_stil->align_to (a, -sign (off[a]));
147 Offset z2 = z1 + off;
149 if (to_boolean (me->get_property ("annotation-line")))
150 fr.add_stencil (Line_interface::line (me, z1, z2));
152 text_stil->translate (z2);
153 fr.add_stencil (*text_stil);
156 return fr.smobbed_copy ();
159 ADD_INTERFACE (Balloon_interface,
160 "A collection of routines to put text balloons around an"
164 "annotation-balloon "
167 "spanner-to-annotate "