]> git.donarmstrong.com Git - lilypond.git/blob - lily/mensural-ligature.cc
* lily/grob.cc: remove X-extent-callback / Y-extent-callback.
[lilypond.git] / lily / mensural-ligature.cc
1 /*
2   mensural-ligature.cc -- implement Mensural_ligature
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2005 Juergen Reuter <reuter@ipd.uka.de>,
7   Pal Benko <benkop@freestart.hu>
8 */
9
10
11 #include "mensural-ligature.hh"
12 #include "item.hh"
13 #include "font-interface.hh"
14 #include "lookup.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "note-head.hh"
17 #include "output-def.hh"
18 #include "warn.hh"
19
20 /*
21  * TODO: divide this function into mensural and neo-mensural style.
22  *
23  * TODO: move this function to class Lookup?
24  */
25 Stencil
26 brew_flexa (Grob *me,
27             Real interval,
28             bool solid,
29             Real width,
30             Real vertical_line_thickness)
31 {
32   Real staff_space = Staff_symbol_referencer::staff_space (me);
33   Real slope = (interval / 2.0 * staff_space) / width;
34
35   // Compensate optical illusion regarding vertical position of left
36   // and right endings due to slope.
37   Real ypos_correction = -0.1 * staff_space * sign (slope);
38   Real slope_correction = 0.2 * staff_space * sign (slope);
39   Real corrected_slope = slope + slope_correction / width;
40
41   Stencil stencil;
42   if (solid) // colorated flexae
43     {
44       Stencil solid_head
45         = Lookup::beam (corrected_slope, width, staff_space, 0.0);
46       stencil.add_stencil (solid_head);
47     }
48   else // outline
49     {
50       /*
51         The thickness of the horizontal lines of the flexa shape
52         should be equal to that of the horizontal lines of the
53         neomensural brevis note head (see mf/parmesan-heads.mf).
54       */
55       Real const horizontal_line_thickness = staff_space * 0.35;
56
57       // URGH!  vertical_line_thickness is adjustable (via thickness
58       // property), while horizontal_line_thickness is constant.
59       // Maybe both should be adjustable independently?
60
61       Real height = staff_space - horizontal_line_thickness;
62
63       Stencil left_edge
64         = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
65       stencil.add_stencil (left_edge);
66
67       Stencil right_edge
68         = Lookup::beam (corrected_slope, vertical_line_thickness, height, 0.0);
69       right_edge.translate_axis (width - vertical_line_thickness, X_AXIS);
70       right_edge.translate_axis ((width - vertical_line_thickness) *
71                                  corrected_slope, Y_AXIS);
72       stencil.add_stencil (right_edge);
73
74       Stencil bottom_edge
75         = Lookup::beam (corrected_slope, width,
76                         horizontal_line_thickness, 0.0);
77       bottom_edge.translate_axis (-0.5 * height, Y_AXIS);
78       stencil.add_stencil (bottom_edge);
79
80       Stencil top_edge
81         = Lookup::beam (corrected_slope, width,
82                         horizontal_line_thickness, 0.0);
83       top_edge.translate_axis (+0.5 * height, Y_AXIS);
84       stencil.add_stencil (top_edge);
85     }
86   stencil.translate_axis (ypos_correction, Y_AXIS);
87   return stencil;
88 }
89
90 Stencil
91 internal_brew_primitive (Grob *me)
92 {
93   SCM primitive_scm = me->get_property ("primitive");
94   if (primitive_scm == SCM_EOL)
95     {
96       programming_error ("Mensural_ligature: "
97                          "undefined primitive -> ignoring grob");
98       return Stencil ();
99     }
100   int primitive = scm_to_int (primitive_scm);
101
102   Stencil out;
103   int delta_pitch = 0;
104   Real thickness = 0.0;
105   Real width = 0.0;
106   Real staff_space = Staff_symbol_referencer::staff_space (me);
107   if (primitive & MLP_ANY)
108     thickness = robust_scm2double (me->get_property ("thickness"), .14);
109
110   if (primitive & MLP_FLEXA)
111     {
112       delta_pitch = robust_scm2int (me->get_property ("delta-pitch"),
113                                     0);
114       width
115         = robust_scm2double (me->get_property ("flexa-width"), 2.0 * staff_space);
116     }
117   if (primitive & MLP_SINGLE_HEAD)
118     width = robust_scm2double (me->get_property ("head-width"), staff_space);
119
120   switch (primitive & MLP_ANY)
121     {
122     case MLP_NONE:
123       return Stencil ();
124     case MLP_LONGA: // mensural brevis head with right cauda
125       out = Font_interface::get_default_font (me)->find_by_name
126         ("noteheads.s-2mensural");
127       break;
128     case MLP_BREVIS: // mensural brevis head
129       out = Font_interface::get_default_font (me)->find_by_name
130         ("noteheads.s-1mensural");
131       break;
132     case MLP_MAXIMA: // should be mensural maxima head without stem
133       out = Font_interface::get_default_font (me)->find_by_name
134         ("noteheads.s-1neomensural");
135       break;
136     case MLP_FLEXA:
137       out = brew_flexa (me, delta_pitch, false, width, thickness);
138       break;
139     default:
140       programming_error (_f ("Mensural_ligature: "
141                              "unexpected case fall-through"));
142       return Stencil ();
143     }
144
145   Real blotdiameter
146     = (me->get_layout ()->get_dimension (ly_symbol2scm ("blotdiameter")));
147
148   if (primitive & MLP_STEM)
149     {
150       // assume MLP_UP
151       Real y_bottom = 0.0, y_top = 3.0 * staff_space;
152
153       if (primitive & MLP_DOWN)
154         {
155           y_bottom = -y_top;
156           y_top = 0.0;
157         }
158
159       Interval x_extent (0, thickness);
160       Interval y_extent (y_bottom, y_top);
161       Box join_box (x_extent, y_extent);
162
163       Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
164       out.add_stencil (join);
165     }
166
167   SCM join_right_scm = me->get_property ("join-right-amount");
168
169   if (join_right_scm != SCM_EOL)
170     {
171       int join_right = scm_to_int (join_right_scm);
172       if (join_right)
173         {
174           Real y_top = join_right * 0.5 * staff_space;
175           Real y_bottom = 0.0;
176
177           if (y_top < 0.0)
178             {
179               y_bottom = y_top;
180               y_top = 0.0;
181             }
182
183           Interval x_extent (width - thickness, width);
184           Interval y_extent (y_bottom, y_top);
185           Box join_box (x_extent, y_extent);
186           Stencil join = Lookup::round_filled_box (join_box, blotdiameter);
187
188           out.add_stencil (join);
189         }
190       else
191         programming_error (_f ("Mensural_ligature: (join_right == 0)"));
192     }
193
194 #if 0 /* what happend with the ledger lines? */
195   int pos = Staff_symbol_referencer::get_rounded_position (me);
196   if (primitive & MLP_FLEXA)
197     {
198       pos += delta_pitch;
199       add_ledger_lines (me, &out, pos, 0.5 * delta_pitch, ledger_take_space);
200     }
201 #endif
202
203   return out;
204 }
205
206 MAKE_SCHEME_CALLBACK (Mensural_ligature, brew_ligature_primitive, 1);
207 SCM
208 Mensural_ligature::brew_ligature_primitive (SCM smob)
209 {
210   Grob *me = unsmob_grob (smob);
211   return internal_brew_primitive (me).smobbed_copy ();
212 }
213
214 MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1);
215 SCM
216 Mensural_ligature::print (SCM)
217 {
218   return SCM_EOL;
219 }
220
221 ADD_INTERFACE (Mensural_ligature, "mensural-ligature-interface",
222                "A mensural ligature",
223                "delta-pitch flexa-width head-width join-right-amount " // "add-join "
224                "primitive thickness");