2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2001--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "accidental-interface.hh"
21 #include "font-interface.hh"
22 #include "international.hh"
24 #include "output-def.hh"
25 #include "paper-column.hh"
29 #include "skyline-pair.hh"
35 parenthesize (Grob *me, Stencil m)
38 = Font_interface::get_default_font (me);
40 = font->find_by_name ("accidentals.leftparen");
42 = font->find_by_name ("accidentals.rightparen");
44 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0);
45 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0);
50 MAKE_SCHEME_CALLBACK (Accidental_interface, horizontal_skylines, 1);
52 Accidental_interface::horizontal_skylines (SCM smob)
54 Grob *me = unsmob<Grob> (smob);
56 return Skyline_pair ().smobbed_copy ();
58 Stencil *my_stencil = unsmob<Stencil> (me->get_property ("stencil"));
60 return Skyline_pair ().smobbed_copy ();
64 (Stencil::skylines_from_stencil
65 (my_stencil->smobbed_copy (), 0.0, Y_AXIS));
67 SCM alist = me->get_property ("glyph-name-alist");
68 SCM alt = me->get_property ("alteration");
69 string glyph_name = robust_scm2string (ly_assoc_get (alt, alist, SCM_BOOL_F),
71 if (glyph_name == "accidentals.flat"
72 || glyph_name == "accidentals.flatflat")
74 // a bit more padding for the right of the stem
75 // we raise the stem horizontally to a bit less than the average
76 // horizontal "height" of the entire glyph. This will bring flats
77 // closer to doubleflats, which looks better (MS opinion).
78 // this should work for all fonts where the flat is not
80 Real left = my_stencil->extent (X_AXIS)[LEFT];
81 Real right = my_stencil->extent (X_AXIS)[RIGHT] * 0.375;
82 Real down = my_stencil->extent (Y_AXIS)[DOWN];
83 Real up = my_stencil->extent (Y_AXIS)[UP];
85 boxes.push_back (Box (Interval (left, right), Interval (down, up)));
86 Skyline merge_with_me (boxes, Y_AXIS, RIGHT);
87 (*sky)[RIGHT].merge (merge_with_me);
89 return sky->smobbed_copy ();
92 MAKE_SCHEME_CALLBACK (Accidental_interface, height, 1);
94 Accidental_interface::height (SCM smob)
96 Grob *me = unsmob<Grob> (smob);
97 Grob *tie = unsmob<Grob> (me->get_object ("tie"));
100 && !to_boolean (me->get_property ("forced"))
101 && to_boolean (me->get_property ("hide-tied-accidental-after-break")))
102 return ly_interval2scm (Interval ());
104 return Grob::stencil_height (smob);
107 MAKE_SCHEME_CALLBACK (Accidental_interface, remove_tied, 1);
109 Accidental_interface::remove_tied (SCM smob)
111 Grob *me = unsmob<Grob> (smob);
112 Grob *tie = unsmob<Grob> (me->get_object ("tie"));
115 && !to_boolean (me->get_property ("forced"))
116 && (to_boolean (me->get_property ("hide-tied-accidental-after-break"))
117 || !tie->original()))
120 return SCM_UNSPECIFIED;
123 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
125 Accidental_interface::print (SCM smob)
127 Grob *me = unsmob<Grob> (smob);
129 return get_stencil (me);
133 Accidental_interface::get_stencil (Grob *me)
135 Font_metric *fm = Font_interface::get_default_font (me);
137 SCM alist = me->get_property ("glyph-name-alist");
138 SCM alt = me->get_property ("alteration");
139 SCM glyph_name = ly_assoc_get (alt, alist, SCM_BOOL_F);
142 if (!scm_is_string (glyph_name))
144 me->warning (_f ("Could not find glyph-name for alteration %s",
145 ly_scm_write_string (alt).c_str ()));
146 mol = fm->find_by_name ("noteheads.s1cross");
149 mol = fm->find_by_name (ly_scm2string (glyph_name));
151 if (to_boolean (me->get_property ("restore-first")))
154 this isn't correct for ancient accidentals, but they don't
155 use double flats/sharps anyway.
157 Stencil acc (fm->find_by_name ("accidentals.natural"));
160 me->warning (_ ("natural alteration glyph not found"));
162 mol.add_at_edge (X_AXIS, LEFT, acc, 0.1);
165 if (to_boolean (me->get_property ("parenthesized")))
166 mol = parenthesize (me, mol);
168 return mol.smobbed_copy ();
171 ADD_INTERFACE (Accidental_interface,
172 "A single accidental.",
180 "hide-tied-accidental-after-break "