]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-text.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / system-start-text.cc
1 /*
2   system-start-text.cc -- implement System_start_text
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "text-interface.hh"
11 #include "pointer-group-interface.hh"
12 #include "output-def.hh"
13 #include "font-interface.hh"
14 #include "spanner.hh"
15 #include "stencil.hh"
16
17 class System_start_text
18 {
19 public:
20   static Stencil get_stencil (Grob *);
21   static bool has_interface (Grob *);
22
23   DECLARE_SCHEME_CALLBACK (print, (SCM));
24 };
25
26 Stencil
27 System_start_text::get_stencil (Grob *me_grob)
28 {
29   Spanner *me = dynamic_cast<Spanner*> (me_grob);
30   SCM t = me->get_property ("text");
31   if (me->get_break_index () == 0)
32     t = me->get_property ("long-text");
33            
34   
35   SCM chain = Font_interface::text_font_alist_chain (me);
36
37   SCM scm_stencil = Text_interface::is_markup (t)
38     ? Text_interface::interpret_markup (me->layout ()->self_scm (), chain, t)
39     : SCM_EOL;
40
41   
42   if (Stencil *p = unsmob_stencil (scm_stencil))
43     {
44       SCM align_y  = me_grob->get_property ("self-alignment-Y");
45       if (scm_is_number (align_y))
46         p->align_to (Y_AXIS, robust_scm2double (align_y, 0.0));
47       return *p;
48     }
49   return Stencil();
50 }
51
52
53 MAKE_SCHEME_CALLBACK (System_start_text, print, 1);
54 SCM
55 System_start_text::print (SCM smob)
56 {
57   Spanner *me = unsmob_spanner (smob);
58
59   extract_grob_set (me, "elements", all_elts);
60   vector<Grob*> elts;
61   for (vsize i = 0; i < all_elts.size (); i++)
62     if (all_elts[i]->is_live ())
63       elts.push_back (all_elts[i]);
64
65   if (!elts.size ())
66     {
67       me->suicide ();
68       return SCM_EOL;
69     }
70   
71   Grob *common = common_refpoint_of_array (elts, me, Y_AXIS);
72
73   Interval ext;
74   for (vsize i = elts.size (); i--;)
75     {
76       Spanner *sp = dynamic_cast<Spanner *> (elts[i]);
77
78       if (sp
79           && sp->get_bound (LEFT) == me->get_bound (LEFT))
80         ext.add_point (sp->relative_coordinate (common, Y_AXIS));
81     }
82
83   Stencil m = get_stencil (me);
84   m.translate_axis (ext.center (), Y_AXIS);
85   return m.smobbed_copy ();
86 }
87
88
89 ADD_INTERFACE (System_start_text,
90                "system-start-text-interface",
91                "Text in front of the system.",
92
93                /* properties */
94                "text "
95                "long-text "
96                "self-alignment-Y "
97                );