2 balloon.cc -- implement Balloon
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "text-interface.hh"
11 #include "line-interface.hh"
13 #include "font-interface.hh"
14 #include "lily-guile.hh"
15 #include "output-def.hh"
18 class Balloon_interface
21 DECLARE_SCHEME_CALLBACK (print, (SCM));
22 static bool has_interface (Grob *);
25 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
27 Balloon_interface::print (SCM smob)
29 Grob *me = unsmob_grob (smob);
31 SCM stil = me->get_property ("original-stencil");
32 if (!unsmob_stencil (stil))
35 SCM scm_off = me->get_property ("balloon-text-offset");
37 if (!is_number_pair (scm_off))
40 Offset off = ly_scm2offset (scm_off);
41 Stencil *s = unsmob_stencil (stil);
42 Box orig_extent = s->extent_box ();
43 Box box_extent = orig_extent;
45 Real w = robust_scm2double (me->get_property ("balloon-padding"), .1);
46 box_extent.widen (w, w);
49 Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
53 SCM bt = me->get_property ("balloon-text");
54 SCM chain = Font_interface::text_font_alist_chain (me);
55 chain = scm_cons (me->get_property ("balloon-text-props"), chain);
57 SCM text = Text_interface::interpret_markup (me->layout ()->self_scm (),
60 Stencil *text_stil = unsmob_stencil (text);
63 for (int i = X_AXIS; i < NO_AXES; i++)
66 z1[a] = box_extent [a].linear_combination (sign (off[a]));
67 text_stil->align_to (a, -sign (off[a]));
72 fr.add_stencil (Line_interface::line (me, z1, z2));
74 text_stil->translate (z2);
75 fr.add_stencil (*text_stil);
77 fr = Stencil (orig_extent, fr.expr ());
78 return fr.smobbed_copy ();
81 ADD_INTERFACE (Balloon_interface, "text-balloon-interface",
82 "A collection of routines to put text balloons around an object.",
87 "balloon-text-offset "