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