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"
32 parenthesize (Grob *me, Stencil m)
35 = Font_interface::get_default_font (me);
37 = font->find_by_name ("accidentals.leftparen");
39 = font->find_by_name ("accidentals.rightparen");
41 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0);
42 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0);
47 MAKE_SCHEME_CALLBACK (Accidental_interface, horizontal_skylines, 1);
49 Accidental_interface::horizontal_skylines (SCM smob)
51 Grob *me = unsmob<Grob> (smob);
53 return Skyline_pair ().smobbed_copy ();
55 Stencil *my_stencil = unsmob<Stencil> (me->get_property ("stencil"));
57 return Skyline_pair ().smobbed_copy ();
61 (Stencil::skylines_from_stencil
62 (my_stencil->smobbed_copy (), 0.0, Y_AXIS));
64 SCM alist = me->get_property ("glyph-name-alist");
65 SCM alt = me->get_property ("alteration");
66 string glyph_name = robust_scm2string (ly_assoc_get (alt, alist, SCM_BOOL_F),
68 if (glyph_name == "accidentals.flat"
69 || glyph_name == "accidentals.flatflat")
71 // a bit more padding for the right of the stem
72 // we raise the stem horizontally to a bit less than the average
73 // horizontal "height" of the entire glyph. This will bring flats
74 // closer to doubleflats, which looks better (MS opinion).
75 // this should work for all fonts where the flat is not
77 Real left = my_stencil->extent (X_AXIS)[LEFT];
78 Real right = my_stencil->extent (X_AXIS)[RIGHT] * 0.375;
79 Real down = my_stencil->extent (Y_AXIS)[DOWN];
80 Real up = my_stencil->extent (Y_AXIS)[UP];
82 boxes.push_back (Box (Interval (left, right), Interval (down, up)));
83 Skyline merge_with_me (boxes, Y_AXIS, RIGHT);
84 (*sky)[RIGHT].merge (merge_with_me);
86 return sky->smobbed_copy ();
89 MAKE_SCHEME_CALLBACK (Accidental_interface, height, 1);
91 Accidental_interface::height (SCM smob)
93 Grob *me = unsmob<Grob> (smob);
94 Grob *tie = unsmob<Grob> (me->get_object ("tie"));
97 && !to_boolean (me->get_property ("forced"))
98 && to_boolean (me->get_property ("hide-tied-accidental-after-break")))
99 return ly_interval2scm (Interval ());
101 return Grob::stencil_height (smob);
104 MAKE_SCHEME_CALLBACK (Accidental_interface, remove_tied, 1);
106 Accidental_interface::remove_tied (SCM smob)
108 Grob *me = unsmob<Grob> (smob);
109 Grob *tie = unsmob<Grob> (me->get_object ("tie"));
112 && !to_boolean (me->get_property ("forced"))
113 && (to_boolean (me->get_property ("hide-tied-accidental-after-break"))
114 || !tie->original()))
117 return SCM_UNSPECIFIED;
120 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
122 Accidental_interface::print (SCM smob)
124 Grob *me = unsmob<Grob> (smob);
126 return get_stencil (me);
130 Accidental_interface::get_stencil (Grob *me)
132 Font_metric *fm = Font_interface::get_default_font (me);
134 SCM alist = me->get_property ("glyph-name-alist");
135 SCM alt = me->get_property ("alteration");
136 SCM glyph_name = ly_assoc_get (alt, alist, SCM_BOOL_F);
139 if (!scm_is_string (glyph_name))
141 me->warning (_f ("Could not find glyph-name for alteration %s",
142 ly_scm_write_string (alt).c_str ()));
143 mol = fm->find_by_name ("noteheads.s1cross");
146 mol = fm->find_by_name (ly_scm2string (glyph_name));
148 if (to_boolean (me->get_property ("restore-first")))
151 this isn't correct for ancient accidentals, but they don't
152 use double flats/sharps anyway.
154 Stencil acc (fm->find_by_name ("accidentals.natural"));
157 me->warning (_ ("natural alteration glyph not found"));
159 mol.add_at_edge (X_AXIS, LEFT, acc, 0.1);
162 if (to_boolean (me->get_property ("parenthesized")))
163 mol = parenthesize (me, mol);
165 return mol.smobbed_copy ();
168 ADD_INTERFACE (Accidental_interface,
169 "A single accidental.",
177 "hide-tied-accidental-after-break "