]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-interface.cc
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / script-interface.cc
1 /*
2   script-interface.cc -- implement Script_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "script-interface.hh"
10
11 #include "directional-element-interface.hh"
12 #include "item.hh"
13 #include "warn.hh"
14 #include "font-interface.hh"
15 #include "side-position-interface.hh"
16 #include "output-def.hh"
17 #include "lookup.hh"
18 #include "stem.hh"
19 #include "note-column.hh"
20
21 Stencil
22 Script_interface::get_stencil (Grob *me, Direction d)
23 {
24   SCM s = me->get_property ("script-stencil");
25   assert (scm_is_pair (s));
26
27   SCM key = scm_car (s);
28   if (key == ly_symbol2scm ("feta"))
29     {
30       SCM name_entry = scm_cdr (s);
31       SCM str = ((scm_is_pair (name_entry)) ? index_get_cell (name_entry, d)
32                  : name_entry);
33       return Font_interface::get_default_font (me)
34         ->find_by_name ("scripts." + ly_scm2string (str));
35     }
36   else if (key == ly_symbol2scm ("accordion"))
37     return Lookup::accordion (scm_cdr (s), 1.0,
38                               Font_interface::get_default_font (me));
39   else
40     assert (false);
41
42   return Stencil ();
43 }
44
45 MAKE_SCHEME_CALLBACK (Script_interface, calc_direction, 1);
46 SCM
47 Script_interface::calc_direction (SCM smob)
48 {
49   Grob *me = unsmob_grob (smob);
50   Direction d = Side_position_interface::get_direction (me);
51
52   if (!d)
53     {
54       me->programming_error ("script direction not yet known");
55       d = DOWN;
56     }
57
58   if (Grob *par = me->get_parent (X_AXIS))
59     {
60       Grob *stem = Note_column::get_stem (par);
61       if (stem && Stem::first_head (stem))
62         me->set_parent (Stem::first_head (stem), X_AXIS);
63     }
64
65   return scm_from_int (d);
66 }
67
68 MAKE_SCHEME_CALLBACK (Script_interface, calc_cross_staff, 1);
69 SCM
70 Script_interface::calc_cross_staff (SCM smob)
71 {
72   Grob *me = unsmob_grob (smob);
73   Grob *stem = Note_column::get_stem (me->get_parent (X_AXIS));
74   return scm_from_bool (stem && to_boolean (stem->get_property ("cross-staff")));
75 }
76
77 MAKE_SCHEME_CALLBACK (Script_interface, print, 1);
78
79 SCM
80 Script_interface::print (SCM smob)
81 {
82   Grob *me = unsmob_grob (smob);
83
84   Direction dir = get_grob_direction (me);
85
86   return get_stencil (me, dir).smobbed_copy ();
87 }
88
89 struct Text_script
90 {
91   DECLARE_GROB_INTERFACE ();
92 };
93
94 ADD_INTERFACE (Text_script,
95                "An object that is put above or below a note",
96
97                /* properties */
98                "add-stem-support "
99                "avoid-slur "
100                "script-priority "
101                "slur "
102                );
103
104 /*
105   Hmm. Where should we put add-stem-support ?
106 */
107 ADD_INTERFACE (Script_interface,
108                "An object that is put above or below a note",
109                "add-stem-support "
110                "avoid-slur "
111                "script-priority "
112                "script-stencil "
113                "slur "
114                "slur-padding "
115                );
116