]> git.donarmstrong.com Git - lilypond.git/blob - lily/script.cc
fc00cc16d62151b68111cfabb3388dd9af71ef98
[lilypond.git] / lily / script.cc
1 /*   
2   script.cc --  implement Script_interface
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "warn.hh"
11 #include "script.hh"
12 #include "font-interface.hh"
13 #include "side-position-interface.hh"
14 #include "paper-def.hh"
15 #include "item.hh"
16 #include "molecule.hh"
17 #include "lookup.hh"
18 #include "stem.hh"
19 #include "note-column.hh"
20
21 Molecule
22 Script_interface::get_molecule (Grob * me, Direction d)
23 {
24   SCM s = me->get_grob_property ("script-molecule");
25   assert (gh_pair_p (s));
26
27   SCM key = ly_car (s);
28   if (key == ly_symbol2scm ("feta"))
29     {
30       SCM name_entry = ly_cdr (s);
31
32       SCM str = (gh_pair_p (name_entry)) ? index_get_cell (name_entry, d) :  name_entry;
33       return Font_interface::get_default_font (me)->find_by_name ("scripts-" +
34                                                                   ly_scm2string (str));
35     }
36  else if (key == ly_symbol2scm ("accordion"))
37     {
38       return Lookup::accordion (ly_cdr (s), 1.0, Font_interface::get_default_font (me));
39     }
40   else
41     assert (false);
42
43   return Molecule ();
44 }
45
46 MAKE_SCHEME_CALLBACK (Script_interface,before_line_breaking,1);
47 SCM
48 Script_interface::before_line_breaking (SCM smob)
49 {
50   Grob * me = unsmob_grob (smob);
51
52   Direction d = Side_position_interface::get_direction (me);
53
54   if (!d)
55     {
56       /*
57         we should not have `arbitrary' directions. 
58       */
59       programming_error ("Script direction not yet known!");
60       d = DOWN;
61     }
62   
63   set_grob_direction (me, d);
64
65   if (Grob * par = me->get_parent (X_AXIS))
66     {
67       Grob * stem = Note_column::get_stem (par);
68       if (stem && Stem::first_head (stem))
69         {
70           me->set_parent (Stem::first_head (stem), X_AXIS);
71         }
72     }
73   
74   return SCM_UNSPECIFIED;
75 }
76
77
78 MAKE_SCHEME_CALLBACK (Script_interface,brew_molecule,1);
79
80 SCM
81 Script_interface::brew_molecule (SCM smob)
82 {
83   Grob *me= unsmob_grob (smob);
84
85   Direction dir = Side_position_interface::get_direction (me);
86   if (!dir)
87     {
88       programming_error ("Script direction not known, but molecule wanted.");
89       dir= DOWN;
90     }
91   
92   return get_molecule (me, dir).smobbed_copy ();
93 }
94
95
96
97 struct Text_script
98 {
99     static bool has_interface (Grob*);
100 };
101
102 struct Skript
103 {
104     static bool has_interface (Grob*);
105 };
106
107 ADD_INTERFACE (Text_script,"text-script-interface",
108   "Any text script",
109   "script-priority");
110
111 ADD_INTERFACE (Script_interface, "script-interface",
112   "",
113   "script-priority script-molecule");
114