]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-item.cc
Web-ja: update introduction
[lilypond.git] / lily / percent-repeat-item.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2001--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 "percent-repeat-item.hh"
21
22 #include "item.hh"
23 #include "font-interface.hh"
24 #include "lookup.hh"
25 #include "stream-event.hh"
26
27 Stencil
28 Percent_repeat_item_interface::brew_slash (Grob *me, int count)
29 {
30   Real slope = robust_scm2double (me->get_property ("slope"), 1);
31   Real wid = 2.0 / slope;
32
33   /*
34     todo: check out if in staff-rule thickness normally.
35   */
36   Real thick = robust_scm2double (me->get_property ("thickness"), 1);
37   Stencil slash = Lookup::repeat_slash (wid, slope, thick);
38   Stencil m = slash;
39
40   Real slash_neg_kern
41     = robust_scm2double (me->get_property ("slash-negative-kern"), 1.6);
42   for (int i = count - 1; i--;)
43     m.add_at_edge (X_AXIS, RIGHT, slash, -slash_neg_kern);
44
45   m.translate_axis (-m.extent (Y_AXIS).center (), Y_AXIS);
46   return m;
47 }
48
49 Stencil
50 Percent_repeat_item_interface::x_percent (Grob *me, int count)
51 {
52   Stencil m = brew_slash (me, count);
53
54   Real dot_neg_kern
55     = robust_scm2double (me->get_property ("dot-negative-kern"), 0.75);
56
57   Stencil d1 = Font_interface::get_default_font (me)->find_by_name ("dots.dot");
58   Stencil d2 = d1;
59   d1.translate_axis (0.5, Y_AXIS);
60   d2.translate_axis (-0.5, Y_AXIS);
61
62   m.add_at_edge (X_AXIS, LEFT, d1, -dot_neg_kern);
63   m.add_at_edge (X_AXIS, RIGHT, d2, -dot_neg_kern);
64
65   return m;
66 }
67
68 MAKE_SCHEME_CALLBACK (Percent_repeat_item_interface, double_percent, 1);
69 SCM
70 Percent_repeat_item_interface::double_percent (SCM grob)
71 {
72   Grob *me = unsmob<Grob> (grob);
73   Stencil m = x_percent (me, 2);
74   m.translate_axis (-m.extent (X_AXIS).center (), X_AXIS);
75   return m.smobbed_copy ();
76 }
77
78 MAKE_SCHEME_CALLBACK (Percent_repeat_item_interface, beat_slash, 1);
79 SCM
80 Percent_repeat_item_interface::beat_slash (SCM grob)
81 {
82   Grob *me = unsmob<Grob> (grob);
83   Stream_event *cause = unsmob<Stream_event> (me->get_property ("cause"));
84   int count = robust_scm2int (cause->get_property ("slash-count"), 1);
85
86   Stencil m;
87   if (count == 0)
88     m = x_percent (me, 2);
89   else
90     m = brew_slash (me, count);
91
92   return m.smobbed_copy ();
93 }
94
95 ADD_INTERFACE (Percent_repeat_item_interface,
96                "Repeats that look like percent signs.",
97
98                /* properties */
99                "dot-negative-kern "
100                "slash-negative-kern "
101                "slope "
102                "thickness "
103               );