]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-interface.cc
Fix 893.
[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--2009 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
37     assert (false);
38
39   return Stencil ();
40 }
41
42 MAKE_SCHEME_CALLBACK (Script_interface, calc_positioning_done, 1);
43 SCM
44 Script_interface::calc_positioning_done (SCM smob)
45 {
46   Grob *me = unsmob_grob (smob);
47   if (Grob *par = me->get_parent (X_AXIS))
48     {
49       Grob *stem = Note_column::get_stem (par);
50       if (stem && Stem::first_head (stem))
51         me->set_parent (Stem::first_head (stem), X_AXIS);
52     }
53   return SCM_BOOL_T;
54 }
55
56 Direction
57 Script_interface::get_direction (Grob *me)
58 {
59   Direction relative_dir = Direction (1);
60   SCM reldir = me->get_property ("side-relative-direction");
61   if (is_direction (reldir))
62     relative_dir = to_dir (reldir);
63
64   SCM other_elt = me->get_object ("direction-source");
65   Grob *e = unsmob_grob (other_elt);
66   if (e)
67     return (Direction) (relative_dir * get_grob_direction (e));
68
69   return CENTER;
70 }
71
72 MAKE_SCHEME_CALLBACK (Script_interface, calc_direction, 1);
73 SCM
74 Script_interface::calc_direction (SCM smob)
75 {
76   Grob *me = unsmob_grob (smob);
77   Direction d = Script_interface::get_direction (me);
78
79   if (!d)
80     {
81       me->programming_error ("script direction not yet known");
82       d = DOWN;
83     }
84
85   (void) me->get_property ("positioning-done");
86   return scm_from_int (d);
87 }
88
89 MAKE_SCHEME_CALLBACK (Script_interface, calc_cross_staff, 1);
90 SCM
91 Script_interface::calc_cross_staff (SCM smob)
92 {
93   Grob *me = unsmob_grob (smob);
94   Grob *stem = Note_column::get_stem (me->get_parent (X_AXIS));
95
96   if (stem && to_boolean (stem->get_property ("cross-staff")))
97     return SCM_BOOL_T;
98
99   Grob *slur = unsmob_grob (me->get_object ("slur"));
100   SCM avoid_slur = me->get_property ("avoid-slur");
101   if (slur && to_boolean (slur->get_property ("cross-staff"))
102       && (avoid_slur == ly_symbol2scm ("outside")
103           || avoid_slur == ly_symbol2scm ("around")))
104     return SCM_BOOL_T;
105
106   return SCM_BOOL_F;
107 }
108
109 MAKE_SCHEME_CALLBACK (Script_interface, print, 1);
110
111 SCM
112 Script_interface::print (SCM smob)
113 {
114   Grob *me = unsmob_grob (smob);
115
116   Direction dir = get_grob_direction (me);
117
118   return get_stencil (me, dir).smobbed_copy ();
119 }
120
121 struct Text_script
122 {
123   DECLARE_GROB_INTERFACE ();
124 };
125
126 ADD_INTERFACE (Text_script,
127                "An object that is put above or below a note.",
128
129                /* properties */
130                "add-stem-support "
131                "avoid-slur "
132                "script-priority "
133                "slur "
134                );
135
136 /*
137   Hmm. Where should we put add-stem-support ?
138 */
139 ADD_INTERFACE (Script_interface,
140                "An object that is put above or below a note.",
141
142                /* properties */
143                "add-stem-support "
144                "avoid-slur "
145                "direction-source "
146                "positioning-done "
147                "script-priority "
148                "script-stencil "
149                "side-relative-direction "
150                "slur "
151                "slur-padding "
152                "toward-stem-shift "
153                );
154