]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-interface.cc
* lily/rest.cc (y_offset_callback): use offset callback
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "script-interface.hh"
10
11 #include "directional-element-interface.hh"
12 #include "warn.hh"
13 #include "font-interface.hh"
14 #include "side-position-interface.hh"
15 #include "output-def.hh"
16 #include "lookup.hh"
17 #include "stem.hh"
18 #include "note-column.hh"
19
20 Stencil
21 Script_interface::get_stencil (Grob *me, Direction d)
22 {
23   SCM s = me->get_property ("script-stencil");
24   assert (scm_is_pair (s));
25
26   SCM key = scm_car (s);
27   if (key == ly_symbol2scm ("feta"))
28     {
29       SCM name_entry = scm_cdr (s);
30       SCM str = ((scm_is_pair (name_entry)) ? index_get_cell (name_entry, d)
31                  : name_entry);
32       return Font_interface::get_default_font (me)
33         ->find_by_name ("scripts." + ly_scm2string (str));
34     }
35   else if (key == ly_symbol2scm ("accordion"))
36     return Lookup::accordion (scm_cdr (s), 1.0,
37                               Font_interface::get_default_font (me));
38   else
39     assert (false);
40
41   return Stencil ();
42 }
43
44 /*
45 todo: use proper callbacks.
46 */
47 MAKE_SCHEME_CALLBACK (Script_interface, before_line_breaking, 1);
48 SCM
49 Script_interface::before_line_breaking (SCM smob)
50 {
51   Grob *me = unsmob_grob (smob);
52
53   Direction d = Side_position_interface::get_direction (me);
54
55   if (!d)
56     {
57       me->programming_error ("script direction not yet known");
58       d = DOWN;
59     }
60
61   set_grob_direction (me, d);
62
63   if (Grob *par = me->get_parent (X_AXIS))
64     {
65       Grob *stem = Note_column::get_stem (par);
66       if (stem && Stem::first_head (stem))
67         me->set_parent (Stem::first_head (stem), X_AXIS);
68     }
69   return SCM_UNSPECIFIED;
70 }
71
72 MAKE_SCHEME_CALLBACK (Script_interface, print, 1);
73
74 SCM
75 Script_interface::print (SCM smob)
76 {
77   Grob *me = unsmob_grob (smob);
78
79   Direction dir = Side_position_interface::get_direction (me);
80   if (!dir)
81     {
82       programming_error ("script direction unknown, but stencil wanted");
83       dir = DOWN;
84     }
85   return get_stencil (me, dir).smobbed_copy ();
86 }
87
88 struct Text_script
89 {
90   static bool has_interface (Grob *);
91 };
92
93 ADD_INTERFACE (Text_script, "text-script-interface",
94                "An object that is put above or below a note",
95
96                /* properties */
97                "add-stem-support "
98                "avoid-slur "
99                "script-priority "
100                "slur "
101                );
102
103 /*
104   Hmm. Where should we put add-stem-support ?
105 */
106 ADD_INTERFACE (Script_interface, "script-interface",
107                "An object that is put above or below a note",
108                "add-stem-support "
109                "avoid-slur "
110                "script-priority "
111                "script-stencil "
112                "slur "
113                "slur-padding "
114                );
115