]> git.donarmstrong.com Git - lilypond.git/blob - lily/script-interface.cc
Web-ja: update introduction
[lilypond.git] / lily / script-interface.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "script-interface.hh"
21
22 #include "directional-element-interface.hh"
23 #include "item.hh"
24 #include "warn.hh"
25 #include "font-interface.hh"
26 #include "side-position-interface.hh"
27 #include "output-def.hh"
28 #include "lookup.hh"
29 #include "stem.hh"
30 #include "note-column.hh"
31
32 Stencil
33 Script_interface::get_stencil (Grob *me, Direction d)
34 {
35   SCM s = me->get_property ("script-stencil");
36   assert (scm_is_pair (s));
37
38   SCM key = scm_car (s);
39   if (scm_is_eq (key, ly_symbol2scm ("feta")))
40     {
41       SCM name_entry = scm_cdr (s);
42       SCM str = ((scm_is_pair (name_entry)) ? index_get_cell (name_entry, d)
43                  : name_entry);
44       return Font_interface::get_default_font (me)
45              ->find_by_name ("scripts." + ly_scm2string (str));
46     }
47   else
48     assert (false);
49
50   return Stencil ();
51 }
52
53 MAKE_SCHEME_CALLBACK (Script_interface, calc_positioning_done, 1);
54 SCM
55 Script_interface::calc_positioning_done (SCM smob)
56 {
57   Grob *me = unsmob<Grob> (smob);
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   return SCM_BOOL_T;
65 }
66
67 Direction
68 Script_interface::get_direction (Grob *me)
69 {
70   Direction relative_dir = Direction (1);
71   SCM reldir = me->get_property ("side-relative-direction");
72   if (is_direction (reldir))
73     relative_dir = to_dir (reldir);
74
75   SCM other_elt = me->get_object ("direction-source");
76   Grob *e = unsmob<Grob> (other_elt);
77   if (e)
78     return (Direction) (relative_dir * get_grob_direction (e));
79
80   return CENTER;
81 }
82
83 MAKE_SCHEME_CALLBACK (Script_interface, calc_direction, 1);
84 SCM
85 Script_interface::calc_direction (SCM smob)
86 {
87   Grob *me = unsmob<Grob> (smob);
88   Direction d = Script_interface::get_direction (me);
89
90   if (!d)
91     {
92       me->programming_error ("script direction not yet known");
93       d = DOWN;
94     }
95
96   (void) me->get_property ("positioning-done");
97   return scm_from_int (d);
98 }
99
100 MAKE_SCHEME_CALLBACK (Script_interface, calc_cross_staff, 1);
101 SCM
102 Script_interface::calc_cross_staff (SCM smob)
103 {
104   Grob *me = unsmob<Grob> (smob);
105   Grob *stem = Note_column::get_stem (me->get_parent (X_AXIS));
106
107   if (stem && to_boolean (stem->get_property ("cross-staff")))
108     return SCM_BOOL_T;
109
110   Grob *slur = unsmob<Grob> (me->get_object ("slur"));
111   SCM avoid_slur = me->get_property ("avoid-slur");
112   if (slur && to_boolean (slur->get_property ("cross-staff"))
113       && (scm_is_eq (avoid_slur, ly_symbol2scm ("outside"))
114           || scm_is_eq (avoid_slur, ly_symbol2scm ("around"))))
115     return SCM_BOOL_T;
116
117   return SCM_BOOL_F;
118 }
119
120 MAKE_SCHEME_CALLBACK (Script_interface, print, 1);
121
122 SCM
123 Script_interface::print (SCM smob)
124 {
125   Grob *me = unsmob<Grob> (smob);
126
127   Direction dir = get_grob_direction (me);
128
129   return get_stencil (me, dir).smobbed_copy ();
130 }
131
132 struct Text_script
133 {
134 };
135
136 ADD_INTERFACE (Text_script,
137                "An object that is put above or below a note.",
138
139                /* properties */
140                "avoid-slur "
141                "script-priority "
142                "slur "
143               );
144
145 /*
146   Hmm. Where should we put add-stem-support ?
147 */
148 ADD_INTERFACE (Script_interface,
149                "An object that is put above or below a note.",
150
151                /* properties */
152                "avoid-slur "
153                "direction-source "
154                "positioning-done "
155                "script-column "
156                "script-priority "
157                "script-stencil "
158                "side-relative-direction "
159                "slur "
160                "slur-padding "
161                "toward-stem-shift "
162                "toward-stem-shift-in-column "
163               );
164