]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon.cc
* lily/text-item.cc (interpret_string): new file, select font with
[lilypond.git] / lily / balloon.cc
1 /*
2   balloon.cc -- implement Balloon objects
3  */
4
5 #include "text-item.hh"
6 #include "grob.hh"
7 #include "line-interface.hh"
8 #include "lookup.hh"
9 #include "font-interface.hh"
10 #include "stencil.hh"
11 #include "lily-guile.hh"
12 #include "paper-def.hh"
13 #include "misc.hh"
14
15 struct Balloon_interface
16 {
17   
18 public:
19   DECLARE_SCHEME_CALLBACK (print, (SCM));
20   static bool has_interface (Grob*);
21 };
22
23 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
24 SCM
25 Balloon_interface::print (SCM smob) 
26 {
27   Grob *me= unsmob_grob (smob);
28
29   SCM cb = me->get_property ("balloon-original-callback");
30   SCM scm_mol  =  SCM_EOL;
31
32   if (is_procedure (cb))
33     {
34       scm_mol = scm_call_1 (cb, smob);
35     }
36
37   if (!unsmob_stencil (scm_mol))
38     return scm_mol;
39
40   SCM scm_off = me->get_property ("balloon-text-offset");
41
42   if (!is_number_pair (scm_off))
43     return scm_mol;
44
45   Offset off = ly_scm2offset (scm_off);
46   Stencil * m = unsmob_stencil (scm_mol);
47   Box orig_extent = m->extent_box ();
48   Box box_extent = orig_extent;
49
50   Real w = robust_scm2double (me->get_property ("balloon-padding"),  .1);
51   box_extent.widen (w, w);
52   
53   
54   Stencil fr = Lookup::frame (box_extent, 0.1, 0.05);
55
56   
57   fr.add_stencil (*m);
58
59
60
61   SCM bt = me->get_property ("balloon-text");
62   SCM chain = Font_interface::text_font_alist_chain (me);
63   chain = scm_cons (me->get_property ("balloon-text-props"), chain);
64
65
66   SCM text = Text_item::interpret_markup (me->get_paper ()->self_scm (), chain, bt);
67
68   
69   Stencil *text_mol = unsmob_stencil (text);
70   
71   Offset z1;
72
73   for (int i = X_AXIS; i < NO_AXES; i++)
74     {
75       Axis  a ((Axis)i);
76       z1[a] = box_extent [a].linear_combination (sign (off[a]));
77       text_mol->align_to (a, -sign (off[a]));
78     }
79
80   Offset z2 = z1 + off;
81   
82   fr.add_stencil (Line_interface::line (me, z1, z2));
83
84   text_mol->translate (z2);
85   fr.add_stencil (*text_mol);
86   
87   fr = Stencil (orig_extent, fr.get_expr ());
88   return fr.smobbed_copy ();
89 }
90
91 ADD_INTERFACE (Balloon_interface,"text-balloon-interface",
92                "A collection of routines to put text balloons around an object.",
93                "balloon-padding balloon-text-props balloon-text-offset balloon-text balloon-original-callback");
94