]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-text.cc
5a90191081e307575dfce3f143c8cb2c785451c7
[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 #include "item.hh"
17
18 class System_start_text
19 {
20 public:
21   static Stencil get_stencil (Grob *);
22   static bool has_interface (Grob *);
23
24   DECLARE_SCHEME_CALLBACK (print, (SCM));
25 };
26
27 Stencil
28 System_start_text::get_stencil (Grob *me_grob)
29 {
30   Spanner *me = dynamic_cast<Spanner*> (me_grob);
31   SCM t = me->get_property ("text");
32   if (me->get_break_index () == 0)
33     t = me->get_property ("long-text");
34            
35   
36   SCM chain = Font_interface::text_font_alist_chain (me);
37
38   SCM scm_stencil = Text_interface::is_markup (t)
39     ? Text_interface::interpret_markup (me->layout ()->self_scm (), chain, t)
40     : SCM_EOL;
41
42   
43   if (Stencil *p = unsmob_stencil (scm_stencil))
44     {
45       SCM align_y  = me_grob->get_property ("self-alignment-Y");
46       if (scm_is_number (align_y))
47         p->align_to (Y_AXIS, robust_scm2double (align_y, 0.0));
48       return *p;
49     }
50   return Stencil();
51 }
52
53
54 MAKE_SCHEME_CALLBACK (System_start_text, print, 1);
55 SCM
56 System_start_text::print (SCM smob)
57 {
58   Spanner *me = unsmob_spanner (smob);
59
60   if (!me->get_bound (LEFT)->break_status_dir ())
61     {
62       me->suicide ();
63       return SCM_EOL;
64     }
65
66   extract_grob_set (me, "elements", all_elts);
67   vector<Grob*> elts;
68   for (vsize i = 0; i < all_elts.size (); i++)
69     if (all_elts[i]->is_live ())
70       elts.push_back (all_elts[i]);
71
72   if (!elts.size ())
73     {
74       me->suicide ();
75       return SCM_EOL;
76     }
77   
78   Grob *common = common_refpoint_of_array (elts, me, Y_AXIS);
79
80   Interval ext;
81   for (vsize i = elts.size (); i--;)
82     {
83       Spanner *sp = dynamic_cast<Spanner *> (elts[i]);
84
85       if (sp
86           && sp->get_bound (LEFT) == me->get_bound (LEFT))
87         ext.add_point (sp->relative_coordinate (common, Y_AXIS));
88     }
89
90   Stencil m = get_stencil (me);
91   if (!ext.is_empty ())
92     m.translate_axis (ext.center (), Y_AXIS);
93   return m.smobbed_copy ();
94 }
95
96
97 ADD_INTERFACE (System_start_text,
98                "system-start-text-interface",
99                "Text in front of the system.",
100
101                /* properties */
102                "text "
103                "long-text "
104                "self-alignment-Y "
105                );