]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-item.cc
62fcdf4bbd7743b45add6b2fa06d792945d1bc80
[lilypond.git] / lily / percent-repeat-item.cc
1 /*
2   percent-repeat-item.cc -- implement Percent_repeat_item_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2001--2005  Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "percent-repeat-item.hh"
10
11
12 #include "lookup.hh"
13 #include "font-interface.hh"
14
15 Stencil
16 Percent_repeat_item_interface::brew_slash (Grob *me)
17 {
18   Real slope = robust_scm2double (me->get_property ("slope"), 1);
19   Real wid = 2.0 / slope;
20
21   /*
22     todo: check out if in staff-rule thickness normally.
23   */
24   Real thick = robust_scm2double (me->get_property ("thickness"), 1);
25   Stencil m = Lookup::repeat_slash (wid, slope, thick);
26   m.translate_axis (-m.extent (Y_AXIS).center (), Y_AXIS);
27   return m;
28 }
29
30 /*
31   todo: use grob props for dot_neg_kern, slash_neg_kern?
32 */
33 Stencil
34 Percent_repeat_item_interface::x_percent (Grob *me, int count,
35                                           Real dot_neg_kern,
36                                           Real slash_neg_kern)
37 {
38   Stencil m;
39   Stencil s = brew_slash (me);
40
41   for (int i = count; i--;)
42     m.add_at_edge (X_AXIS, RIGHT, s, -slash_neg_kern, 0);
43   Stencil d1 = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
44   Stencil d2 = d1;
45   d1.translate_axis (0.5, Y_AXIS);
46   d2.translate_axis (-0.5, Y_AXIS);
47
48   m.add_at_edge (X_AXIS, LEFT, d1, -dot_neg_kern, 0);
49   m.add_at_edge (X_AXIS, RIGHT, d2, -dot_neg_kern, 0);
50
51   return m;
52 }
53
54 MAKE_SCHEME_CALLBACK (Percent_repeat_item_interface, double_percent, 1);
55 SCM
56 Percent_repeat_item_interface::double_percent (SCM grob)
57 {
58   Grob *me = unsmob_grob (grob);
59   Stencil m = x_percent (me, 2, 0.75, 1.6);
60   m.translate_axis (- m.extent (X_AXIS).center (), X_AXIS);
61   return m.smobbed_copy ();
62 }
63
64 MAKE_SCHEME_CALLBACK (Percent_repeat_item_interface, beat_slash, 1);
65 SCM
66 Percent_repeat_item_interface::beat_slash (SCM grob)
67 {
68   Grob *me = unsmob_grob (grob);
69   Stencil m = brew_slash (me);
70
71   return m.smobbed_copy ();
72 }
73
74 ADD_INTERFACE (Percent_repeat_item_interface, "percent-repeat-interface",
75                "Repeats that look like percent signs",
76                "slope thickness");
77